SFC.ReadSmartFloatSet CreateReadSmartFloatSet(SFD.FloatSet s) { var go = new GameObject("READER"); var l = go.AddComponent <SFC.ReadSmartFloatSet>(); var sol = new SerializedObject(l); var arr = sol.FindProperty("_data"); arr.arraySize++; var el = arr.GetArrayElementAtIndex(0); el.FindPropertyRelative("_smartSet").objectReferenceValue = s; sol.ApplyModifiedProperties(); sol.Update(); var evt = ((UnityEvent <float>)el.FindPropertyRelative("_onAdd").GetObject()); evt.AddListener(OnAdded); evt = ((UnityEvent <float>)el.FindPropertyRelative("_onRemove").GetObject()); evt.AddListener(OnRemoved); ((SmartFloat.FloatSetReader)el.GetObject()).unityEventOnReceive = true; return(l); }
SF.FloatSetWriter CreateSetRefWriter(SFD.FloatSet smart) { var r = new SF.FloatSetWriter(); SetupSetRef(r, smart); return(r); }
SFC.WriteSmartFloatSet CreateWriteFloatSet(SFD.FloatSet s) { var go = new GameObject("WRITER"); var w = go.AddComponent <SFC.WriteSmartFloatSet>(); var sow = new SerializedObject(w); sow.FindProperty("_data").FindPropertyRelative("_smartSet").objectReferenceValue = s; sow.ApplyModifiedProperties(); sow.Update(); return(w); }
void SetupSetRef(object r, SFD.FloatSet smart) { var b = BindingFlags.Instance | BindingFlags.NonPublic; r.GetType().GetFieldPrivate("_smartSet", b).SetValue(r, smart); r.GetType().GetFieldPrivate("_onAdd", b).SetValue(r, new SmartFloat.Data.FloatVar.FloatEvent()); r.GetType().GetFieldPrivate("_onRemove", b).SetValue(r, new SmartFloat.Data.FloatVar.FloatEvent()); if (r is ISerializationCallbackReceiver) { ((ISerializationCallbackReceiver)r).OnAfterDeserialize(); } (r as SmartData.Abstract.SmartRefBase).unityEventOnReceive = true; }