VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
AVR_Component_NetworkWizard.cs
1 #if AVR_NET
2 
3 using UnityEditor;
4 using UnityEngine;
5 
6 using AVR.Core;
7 using System.Linq;
8 using System.Reflection;
9 
10 namespace AVR.UEditor.Core {
11  public class AVR_Component_NetworkWizard : ScriptableWizard
12  {
13  public AVR_Component component;
14  public bool DestroyOnRemote = true;
15  public bool ChangeLayerOnRemote = false;
16  public bool ChangeLayerOnRemote_IncludeChildren = false;
17  public int RemoteLayer = 0;
18  public UnityEngine.Events.UnityEvent onRemoteStart;
19 
20  private SerializedObject serializedObject;
21 
22  public static void CreateWizard(AVR_Component component)
23  {
24  AVR_Component_NetworkWizard wiz = ScriptableWizard.DisplayWizard<AVR_Component_NetworkWizard>("AVR_Component Network Settings", "Apply");
25  wiz.component = component;
26  wiz.serializedObject = new SerializedObject(component);
27 
28  wiz.DestroyOnRemote = component.destroyOnRemote;
29  wiz.ChangeLayerOnRemote = component.changeLayerOnRemote;
30  wiz.ChangeLayerOnRemote_IncludeChildren = component.changeLayerOnRemote_IncludeChildren;
31  wiz.RemoteLayer = component.remoteLayer;
32  wiz.onRemoteStart = component.onRemoteStart;
33  }
34 
35  // Called when Apply-Button is pressed
36  void OnWizardCreate()
37  {
38  component.destroyOnRemote = DestroyOnRemote;
39  component.changeLayerOnRemote = ChangeLayerOnRemote;
40  component.changeLayerOnRemote_IncludeChildren = ChangeLayerOnRemote_IncludeChildren;
41  component.remoteLayer = RemoteLayer;
42  component.onRemoteStart = onRemoteStart;
43 
44  serializedObject.ApplyModifiedProperties();
45 
46  UnityEditor.EditorUtility.SetDirty(component);
47  }
48 
49  void OnWizardUpdate()
50  {
51  helpString = "Set how this component behaves on a network.";
52 
53  errorString = "";
54  }
55 
56  protected override bool DrawWizardGUI()
57  {
58  bool b = base.DrawWizardGUI();
59 
60  try
61  {
62  foreach (var field in component.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
63  {
64  // Check if the field is CockpitControlled
65  var att = field.GetCustomAttributes(typeof(AVR.Core.Attributes.ShowInNetPrompt), true).FirstOrDefault();
66  if (att != null)
67  {
68  SerializedProperty prop = serializedObject.FindProperty(field.Name);
69  EditorGUILayout.PropertyField(prop);
70  }
71  }
72  }
73  catch(System.Exception)
74  {
75  return false;
76  }
77 
78  return b;
79  }
80  }
81 }
82 
83 #endif