void IDeserializationCallback.OnDeserialization(object sender) { if (_bundle == null) { return; } var resourceId = _info.GetString("sp*id"); var obj = _bundle.LoadAsset(resourceId); if (obj == null) { return; } obj = UnityEngine.Object.Instantiate(obj); foreach (var pobj in ObjUtil.GetAllFromSource <IPersistantAsset>(obj)) { pobj.OnDeserialize(_info, _context, _bundle); } }
private static void ApplyDefaultAsList(SerializedProperty property, System.Type elementType, System.Type restrictionType, EntityRelativity relativity) { if (property.arraySize != 0) { return; } if (elementType == null || restrictionType == null) { return; } if (TypeUtil.IsType(elementType, typeof(VariantReference))) { var targ = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject); if (object.ReferenceEquals(targ, null)) { var obj = ObjUtil.GetAsFromSource(restrictionType, property.serializedObject.targetObject); if (obj != null) { property.arraySize = 1; var variant = EditorHelper.GetTargetObjectOfProperty(property.GetArrayElementAtIndex(0)) as VariantReference; if (variant == null) { return; } variant.Value = obj; property.serializedObject.Update(); GUI.changed = true; } else if (property.arraySize > 0) { property.arraySize = 0; GUI.changed = true; } return; } switch (relativity) { case EntityRelativity.Entity: { targ = targ.FindRoot(); var arr = ObjUtil.GetAllFromSource(restrictionType, targ, true); property.arraySize = arr.Length; for (int i = 0; i < arr.Length; i++) { var variant = EditorHelper.GetTargetObjectOfProperty(property.GetArrayElementAtIndex(i)) as VariantReference; if (variant != null) { variant.Value = arr[i]; } } property.serializedObject.Update(); GUI.changed = true; } break; case EntityRelativity.Self: { var arr = ObjUtil.GetAllFromSource(restrictionType, targ, false); property.arraySize = arr.Length; for (int i = 0; i < arr.Length; i++) { var variant = EditorHelper.GetTargetObjectOfProperty(property.GetArrayElementAtIndex(i)) as VariantReference; if (variant != null) { variant.Value = arr[i]; } } property.serializedObject.Update(); GUI.changed = true; } break; case EntityRelativity.SelfAndChildren: { var arr = ObjUtil.GetAllFromSource(restrictionType, targ, true); property.arraySize = arr.Length; for (int i = 0; i < arr.Length; i++) { var variant = EditorHelper.GetTargetObjectOfProperty(property.GetArrayElementAtIndex(i)) as VariantReference; if (variant != null) { variant.Value = arr[i]; } } property.serializedObject.Update(); GUI.changed = true; } break; } } else if (TypeUtil.IsType(elementType, typeof(UnityEngine.Object))) { var targ = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject); if (object.ReferenceEquals(targ, null)) { var obj = ObjUtil.GetAsFromSource(restrictionType, property.serializedObject.targetObject) as UnityEngine.Object; if (obj != null) { property.arraySize = 1; property.GetArrayElementAtIndex(0).objectReferenceValue = obj; GUI.changed = true; } else if (property.arraySize > 0) { property.arraySize = 0; GUI.changed = true; } return; } switch (relativity) { case EntityRelativity.Entity: { targ = targ.FindRoot(); var arr = ObjUtil.GetAllFromSource(restrictionType, targ, true); property.arraySize = arr.Length; for (int i = 0; i < arr.Length; i++) { property.GetArrayElementAtIndex(i).objectReferenceValue = arr[i] as UnityEngine.Object; } } break; case EntityRelativity.Self: { var arr = ObjUtil.GetAllFromSource(restrictionType, targ, false); property.arraySize = arr.Length; for (int i = 0; i < arr.Length; i++) { property.GetArrayElementAtIndex(i).objectReferenceValue = arr[i] as UnityEngine.Object; } } break; case EntityRelativity.SelfAndChildren: { var arr = ObjUtil.GetAllFromSource(restrictionType, targ, true); property.arraySize = arr.Length; for (int i = 0; i < arr.Length; i++) { property.GetArrayElementAtIndex(i).objectReferenceValue = arr[i] as UnityEngine.Object; } } break; } } }
private void DrawAdvanced_TriggerSelected(Rect area, SerializedProperty property) { /* * //Draw Target * var targRect = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight); * var targProp = property.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_TRIGGERABLETARG); * var targLabel = EditorHelper.TempContent("Triggerable Target"); * var targGo = GameObjectUtil.GetGameObjectFromSource(targProp.objectReferenceValue); * var newTargGo = EditorGUI.ObjectField(targRect, targLabel, targGo, typeof(GameObject), true) as GameObject; * if (newTargGo != targGo) * { * targGo = newTargGo; * targProp.objectReferenceValue = (targGo != null) ? targGo.GetComponent<ITriggerableMechanism>() as Component : null; * } * * var targCompPopupRect = new Rect(area.xMin, targRect.yMax, area.width, EditorGUIUtility.singleLineHeight); * if (targProp.objectReferenceValue != null) * { * var selectedType = targProp.objectReferenceValue.GetType(); * var availableMechanismTypes = (from c in targGo.GetComponents<ITriggerableMechanism>() select c.GetType()).ToArray(); * var availableMechanismTypeNames = availableMechanismTypes.Select((tp) => tp.Name).ToArray(); * * var index = System.Array.IndexOf(availableMechanismTypes, selectedType); * EditorGUI.BeginChangeCheck(); * index = EditorGUI.Popup(targCompPopupRect, "Target Component", index, availableMechanismTypeNames); * if (EditorGUI.EndChangeCheck()) * { * targProp.objectReferenceValue = (index >= 0) ? targGo.GetComponent(availableMechanismTypes[index]) : null; * } * } * else * { * EditorGUI.LabelField(targCompPopupRect, "Target Component", "(First Select a Target)"); * } * * //Draw Triggerable Arg * var argRect = new Rect(area.xMin, targCompPopupRect.yMax, area.width - ARG_BTN_WIDTH, EditorGUIUtility.singleLineHeight); * var btnRect = new Rect(argRect.xMax, argRect.yMin, ARG_BTN_WIDTH, EditorGUIUtility.singleLineHeight); * var argArrayProp = property.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_TRIGGERABLEARGS); * if (argArrayProp.arraySize == 0) * { * EditorGUI.LabelField(argRect, _defaultArgLabel, _undefinedArgLabel); * if (GUI.Button(btnRect, _argBtnLabel)) * { * argArrayProp.arraySize = 1; * argArrayProp.serializedObject.ApplyModifiedProperties(); * } * } * else * { * if (argArrayProp.arraySize > 1) argArrayProp.arraySize = 1; * var argProp = argArrayProp.GetArrayElementAtIndex(0); * //EditorGUI.PropertyField(argRect, argProp, _defaultArgLabel); * _variantDrawer.RestrictVariantType = false; * _variantDrawer.ForcedObjectType = null; * _variantDrawer.OnGUI(argRect, argProp, _defaultArgLabel); * * if (GUI.Button(btnRect, _argBtnLabel)) * { * argArrayProp.arraySize = 0; * argArrayProp.serializedObject.ApplyModifiedProperties(); * } * } */ var targRect = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight); var targProp = property.FindPropertyRelative(EventTriggerTargetPropertyDrawer.PROP_TRIGGERABLETARG); targRect = EditorGUI.PrefixLabel(targRect, EditorHelper.TempContent("Triggerable Target")); //validate if (!GameObjectUtil.IsGameObjectSource(targProp.objectReferenceValue) && !(targProp.objectReferenceValue is ITriggerable)) { targProp.objectReferenceValue = null; } //draw obj field if (targProp.objectReferenceValue != null) { if (SPEditorGUI.XButton(ref targRect, "Clear Selected Object", true)) { targProp.objectReferenceValue = null; goto DrawTriggerableArg; } var targObj = targProp.objectReferenceValue; var availableMechanisms = ObjUtil.GetAllFromSource <ITriggerable>(targObj); var availableMechanismTypeNames = availableMechanisms.Select((o) => EditorHelper.TempContent(o.GetType().Name)).ToArray(); var index = System.Array.IndexOf(availableMechanisms, targObj); EditorGUI.BeginChangeCheck(); index = EditorGUI.Popup(targRect, GUIContent.none, index, availableMechanismTypeNames); if (EditorGUI.EndChangeCheck()) { targObj = (index >= 0) ? availableMechanisms[index] as UnityEngine.Object : null; targProp.objectReferenceValue = targObj; } } else { EditorGUI.BeginChangeCheck(); var targObj = TargetObjectField(targRect, GUIContent.none, targProp.objectReferenceValue); if (EditorGUI.EndChangeCheck()) { targObj = ObjUtil.GetAsFromSource <ITriggerable>(targObj) as UnityEngine.Object; targProp.objectReferenceValue = targObj; } } //Draw Triggerable Arg DrawTriggerableArg: var argRect = new Rect(area.xMin, targRect.yMax, area.width - ARG_BTN_WIDTH, EditorGUIUtility.singleLineHeight); var btnRect = new Rect(argRect.xMax, argRect.yMin, ARG_BTN_WIDTH, EditorGUIUtility.singleLineHeight); var argArrayProp = property.FindPropertyRelative(EventTriggerTargetPropertyDrawer.PROP_TRIGGERABLEARGS); if (argArrayProp.arraySize == 0) { EditorGUI.LabelField(argRect, _defaultArgLabel, _undefinedArgLabel); if (GUI.Button(btnRect, _argBtnLabel)) { argArrayProp.arraySize = 1; argArrayProp.serializedObject.ApplyModifiedProperties(); } } else { if (argArrayProp.arraySize > 1) { argArrayProp.arraySize = 1; } var argProp = argArrayProp.GetArrayElementAtIndex(0); //EditorGUI.PropertyField(argRect, argProp, _defaultArgLabel); _variantDrawer.RestrictVariantType = false; _variantDrawer.ForcedObjectType = null; _variantDrawer.OnGUI(argRect, argProp, _defaultArgLabel); if (GUI.Button(btnRect, _argBtnLabel)) { argArrayProp.arraySize = 0; argArrayProp.serializedObject.ApplyModifiedProperties(); } } }