|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Reflection;
|
4 | 4 | using MLAPI;
|
| 5 | +using MLAPI.NetworkedVar; |
5 | 6 | using UnityEngine;
|
6 | 7 |
|
7 | 8 | namespace UnityEditor
|
@@ -51,6 +52,15 @@ void RenderNetworkedVar(int index)
|
51 | 52 | MonoScript targetScript = scriptProperty.objectReferenceValue as MonoScript;
|
52 | 53 | Init(targetScript);
|
53 | 54 | }
|
| 55 | + |
| 56 | + object value = networkedVarFields[networkedVarNames[index]].GetValue(target); |
| 57 | + if (value == null) |
| 58 | + { |
| 59 | + Type fieldType = networkedVarFields[networkedVarNames[index]].FieldType; |
| 60 | + INetworkedVar var = (INetworkedVar) Activator.CreateInstance(fieldType, true); |
| 61 | + networkedVarFields[networkedVarNames[index]].SetValue(target, var); |
| 62 | + } |
| 63 | + |
54 | 64 | Type type = networkedVarFields[networkedVarNames[index]].GetValue(target).GetType();
|
55 | 65 | Type genericType = type.GetGenericArguments()[0];
|
56 | 66 |
|
@@ -83,19 +93,19 @@ void RenderNetworkedVarValueType<T>(int index) where T : struct
|
83 | 93 | if (type == typeof(int))
|
84 | 94 | val = EditorGUILayout.IntField(name, (int)val);
|
85 | 95 | else if (type == typeof(uint))
|
86 |
| - val = EditorGUILayout.LongField(name, (long)((uint)val)); |
| 96 | + val = (uint)EditorGUILayout.LongField(name, (long)((uint)val)); |
87 | 97 | else if (type == typeof(short))
|
88 |
| - val = EditorGUILayout.IntField(name, (int)((short)val)); |
| 98 | + val = (short)EditorGUILayout.IntField(name, (int)((short)val)); |
89 | 99 | else if (type == typeof(ushort))
|
90 |
| - val = EditorGUILayout.IntField(name, (int)((ushort)val)); |
| 100 | + val = (ushort)EditorGUILayout.IntField(name, (int)((ushort)val)); |
91 | 101 | else if (type == typeof(sbyte))
|
92 |
| - val = EditorGUILayout.IntField(name, (int)((sbyte)val)); |
| 102 | + val = (sbyte)EditorGUILayout.IntField(name, (int)((sbyte)val)); |
93 | 103 | else if (type == typeof(byte))
|
94 |
| - val = EditorGUILayout.IntField(name, (int)((byte)val)); |
| 104 | + val = (byte)EditorGUILayout.IntField(name, (int)((byte)val)); |
95 | 105 | else if (type == typeof(long))
|
96 | 106 | val = EditorGUILayout.LongField(name, (long)val);
|
97 | 107 | else if (type == typeof(ulong))
|
98 |
| - val = EditorGUILayout.LongField(name, (long)((ulong)val)); |
| 108 | + val = (ulong)EditorGUILayout.LongField(name, (long)((ulong)val)); |
99 | 109 | else if (type == typeof(bool))
|
100 | 110 | val = EditorGUILayout.Toggle(name, (bool)val);
|
101 | 111 | else if (type == typeof(string))
|
|
0 commit comments