VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
AVR_Component.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using Unity.Netcode;
4 using UnityEngine;
5 
6 namespace AVR.Core {
7  /// <summary>
8  /// Base class for all arc-vr components. A component is typically a Monobehaviour that represents a virtual device, feature-provider or module.
9  /// </summary>
10  [AVR.Core.Attributes.DocumentationUrl("class_a_v_r_1_1_core_1_1_a_v_r___component.html")]
12  {
13  /// <summary> Events called when this component awakes. </summary>
14  [HideInInspector] public UnityEngine.Events.UnityEvent onAwake;
15 
16  /// <summary> Events called when this component starts. </summary>
17  [HideInInspector] public UnityEngine.Events.UnityEvent onStart;
18 
19  /// <summary> Events called when this component is enabled. </summary>
20  [HideInInspector] public UnityEngine.Events.UnityEvent onEnable;
21 
22  /// <summary> Events called when this component is disabled. </summary>
23  [HideInInspector] public UnityEngine.Events.UnityEvent onDisable;
24 
25  protected virtual void Awake() {
26  onAwake.Invoke();
27  }
28 
29  protected virtual void Start() {
30  onStart.Invoke();
31  }
32 
33  protected virtual void OnEnable() {
34  onEnable.Invoke();
35  }
36 
37  protected virtual void OnDisable() {
38  onDisable.Invoke();
39  }
40 
41 #if AVR_NET
42  public override void OnNetworkSpawn()
43  {
44  base.OnNetworkSpawn();
45  if(!IsLocalPlayer)
46  {
47  onRemoteStart.Invoke();
48 
49  if (changeLayerOnRemote)
50  {
51  gameObject.layer = remoteLayer;
52  if (changeLayerOnRemote_IncludeChildren)
53  {
54  foreach (Transform child in GetComponentsInChildren<Transform>())
55  {
56  child.gameObject.layer = remoteLayer;
57  }
58  }
59  }
60 
61  if (destroyOnRemote)
62  {
63  GameObject.Destroy(this);
64  // Under normal conditions Update() runs for 1 frame before Destroy takes place. DestroyImmediate is dangerous to use here.
65  // This is a hacky way of preventing Update from running: We set gameobject.active = false (component.enabled doesn't do the trick)
66  // And then re-enable the gameobject at the end of the frame through AVR_Root.
67  gameObject.SetActive(false);
68  AVR_Root.Instance.ReEnableAtEndOfFrame(gameObject);
69  }
70  }
71  }
72 
73  [HideInInspector]
74  public bool destroyOnRemote = true;
75  [HideInInspector]
76  public bool changeLayerOnRemote = false;
77  [HideInInspector]
78  public bool changeLayerOnRemote_IncludeChildren = false;
79  [HideInInspector]
80  public int remoteLayer = 0;
81 
82  [HideInInspector] public UnityEngine.Events.UnityEvent onRemoteStart;
83 
84  protected interface IInternalState<T> : Unity.Netcode.INetworkSerializable where T : AVR_Component
85  {
86  public void FromReference(T reference);
87  public void ApplyState(T reference);
88  }
89 #endif
90  }
91 }
Monobehaviour but with an added URL button to a documentation page.
UnityEngine.Events.UnityEvent onAwake
Events called when this component awakes.
virtual void Awake()
Sets the documentation html file inside of Packages/com.avr.core/Documentation/html of a given class...
virtual void Start()
UnityEngine.Events.UnityEvent onDisable
Events called when this component is disabled.
virtual void OnDisable()
UnityEngine.Events.UnityEvent onStart
Events called when this component starts.
Base class for all arc-vr components. A component is typically a Monobehaviour that represents a virt...
virtual void OnEnable()
UnityEngine.Events.UnityEvent onEnable
Events called when this component is enabled.