void MergeTypeSelected(object userData) { ObjectSelection selection = (ObjectSelection)userData; ASOReferenceData[] toMergeReferences = ASOManager.Me.GetReferencesOn(propertyASO); if (selection.Selected == "Current") { if (toMergeReferences.Length > 1) { if (!EditorUtility.DisplayDialog( "Object is referenced", string.Format("Merging this object will lose references on {0} objects. Continue?", toMergeReferences.Length - 1), "Confirm", "Cancel")) { return; } } AlterProperty(selection.Property, AdvancedScriptableObjectUtility.MergeCurrent( parentASO, propertyASO)); } else if (selection.Selected == "All") { if (toMergeReferences.Length > 1) { if (!EditorUtility.DisplayDialog( "Object is referenced", string.Format("Merging this object will lose references on multiple objects. Continue?"), "Confirm", "Cancel")) { return; } } AlterProperty(selection.Property, AdvancedScriptableObjectUtility.MergeAll( parentASO, parentASO, propertyASO)); } else if (selection.Selected == "Current Copy") { AlterProperty(selection.Property, AdvancedScriptableObjectUtility.MergeCurrent( parentASO, propertyASO, true)); } else if (selection.Selected == "All Copy") { AlterProperty(selection.Property, AdvancedScriptableObjectUtility.MergeAll( parentASO, parentASO, propertyASO, true)); } }
void SetupLists() { _lists = new Dictionary <string, Editor_List>(); _asoLists = new Dictionary <string, Editor_ASOList>(); //Create new lists for each array property #region Create Lists from Properties SerializedProperty properties = serializedObject.GetIterator(); while (properties.NextVisible(true)) { if (properties.isArray && properties.propertyType != SerializedPropertyType.String) { //Debug.Log(properties.name); if (properties.name == "data") { continue; } System.Type type = AdvancedScriptableObjectUtility.GetSerializedPropertyType(properties); //Debug.Log(type); if (type != null) { if (type.GetElementType().IsSubclassOf(typeof(AdvancedScriptableObject))) { SerializedProperty asoPropCopy = properties.Copy(); if (!_asoLists.ContainsKey(asoPropCopy.name)) { _asoLists.Add(asoPropCopy.name, new Editor_ASOList(asoPropCopy)); } continue; } else { SerializedProperty propCopy = properties.Copy(); if (!_asoLists.ContainsKey(propCopy.name)) { _lists.Add(propCopy.name, new Editor_List(propCopy)); } continue; } } } } #endregion _bListsCreated = true; //Debug.Log(string.Format("List count:{0} ASOList count:{1}",_lists.Count,_asoLists.Count)); }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { foreach (string str in importedAssets) { Object obj = AssetDatabase.LoadAssetAtPath(str, typeof(Object)); if (obj != null) { if (obj.GetType().IsSubclassOf(typeof(AdvancedScriptableObject))) { //Check if there are existing references if so then no need to update. AdvancedScriptableObject aso = (AdvancedScriptableObject)obj; if (ASOManager.Me.GetReferencesOn(aso).Length == 0) { AdvancedScriptableObjectUtility.AddReferences(aso); } } } } }
void UnmergeTypeSelected(object userData) { ObjectSelection selection = (ObjectSelection)userData; if (selection.Selected == "Current") { AlterProperty(selection.Property, AdvancedScriptableObjectUtility.UnmergeCurrent( parentASO, propertyASO)); AddReferenceData(selection.Property); } else if (selection.Selected == "All") { //Need to first remove the object from serialized object AlterProperty(selection.Property, AdvancedScriptableObjectUtility.UnmergeAll( parentASO, propertyASO)); AddReferenceData(selection.Property); } }
void CreateNew(SerializedProperty property) { System.Type propType; propType = AdvancedScriptableObjectUtility.GetSerializedPropertyType(property); System.Type[] types = Assembly.GetAssembly(propType).GetTypes(); List <string> allTypes = (from System.Type t in types where t.IsSubclassOf(propType) select t.FullName).ToList(); if (!propType.IsAbstract) { allTypes.Add(propType.FullName); } var menu = new GenericMenu(); for (int i = 0; i < allTypes.Count; i++) { GUIContent gc = new GUIContent(allTypes[i]); menu.AddItem(gc, false, CreateObjectSelected, new ObjectSelection(property, allTypes[i])); } menu.ShowAsContext(); }
void AddReferenceData(SerializedProperty property) { bool bIsArrayElement; if (property.propertyPath.Contains("[")) { bIsArrayElement = true; } else { bIsArrayElement = false; } if (!bIsArrayElement) { ASOManager.Me.AddReferenceData(parentASO, propertyASO, property.name); } else { FieldInfo field; System.Type parentType = parentASO.GetType(); string arrayName = AdvancedScriptableObjectUtility.GetArrayName(property); string arrayIndex = ""; field = parentType.GetField(arrayName); if (field != null) { var arrayElements = field.GetValue(parentASO) as Array; for (int i = 0; i < arrayElements.Length; i++) { if ((AdvancedScriptableObject)arrayElements.GetValue(i) == propertyASO) { arrayIndex = i.ToString(); break; } } } ASOManager.Me.AddReferenceData(parentASO, propertyASO, string.Format("{0}[{1}]", arrayName, arrayIndex)); } }
void List_AddDropdown(Rect buttonRect, ReorderableList list) { System.Type propType = AdvancedScriptableObjectUtility.GetSerializedPropertyType(_property).GetElementType(); System.Type[] types = Assembly.GetAssembly(propType).GetTypes(); List <string> allTypes = (from System.Type t in types where t.IsSubclassOf(propType) select t.FullName).ToList(); if (!propType.IsAbstract) { allTypes.Add(propType.FullName); } allTypes.Insert(0, "Empty"); var menu = new GenericMenu(); for (int i = 0; i < allTypes.Count; i++) { GUIContent gc = new GUIContent(allTypes[i]); menu.AddItem(gc, false, List_Dropdown_OnSelected, allTypes[i]); } menu.ShowAsContext(); }
void DrawBaseExcept() { SerializedProperty myProp = serializedObject.GetIterator(); while (myProp.NextVisible(true)) { if (!myProp.isArray && myProp.propertyType != SerializedPropertyType.ArraySize || myProp.isArray && myProp.propertyType == SerializedPropertyType.String) { if (myProp.name != "_parentAsset" && myProp.name != "data") { if (myProp.propertyType == SerializedPropertyType.ObjectReference) { System.Type type = AdvancedScriptableObjectUtility.GetSerializedPropertyType(myProp); if (type != null) { if (type.IsSubclassOf(typeof(AdvancedScriptableObject))) { EditorGUILayout.PropertyField(myProp); //var asoPropEditor = Editor.CreateEditor(myProp.objectReferenceValue); //asoPropEditor.OnInspectorGUI(); //ManualDrawASOProperty(myProp, type); } else { EditorGUILayout.PropertyField(myProp, new GUIContent(myProp.displayName), false); serializedObject.ApplyModifiedProperties(); } } } else { EditorGUILayout.PropertyField(myProp, new GUIContent(myProp.displayName), false); serializedObject.ApplyModifiedProperties(); } } } else if (myProp.isArray) { if (myProp.name != "_protoChildren") { System.Type type = AdvancedScriptableObjectUtility.GetSerializedPropertyType(myProp); if (type != null) { if (type.GetElementType().IsSubclassOf(typeof(AdvancedScriptableObject))) { if (_asoLists.ContainsKey(myProp.name)) { _asoLists[myProp.name].DrawList(); } } else { if (_lists.ContainsKey(myProp.name)) { _lists[myProp.name].DrawList(); } } } } } } }
public override void OnInspectorGUI() { //If in isolated editing mode if (Selection.activeObject == serializedObject.targetObject) { if (_aso.ParentAsset != null) { var parentChain = GetParentChain(new List <AdvancedScriptableObject>(), _aso); EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.LabelField("Object Hierarchy"); EditorGUILayout.BeginHorizontal(); for (int i = parentChain.Count - 1; i > -1; i--) { if (GUILayout.Button(parentChain[i].name)) { Selection.activeObject = parentChain[i]; } GUILayout.Label("<"); //Create new line every 4 buttons if (i % 4 == 0) { EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); } } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); } } EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); _parent = EditorGUILayout.ObjectField("Prototype Parent", _parent, typeof(AdvancedScriptableObject), true) as AdvancedScriptableObject; if (EditorGUI.EndChangeCheck()) { ParentChanged(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(_parent == null); if (GUILayout.Button("Apply")) { if (EditorUtility.DisplayDialog("Apply values to prototype", "Overwrite values of parent?", "Confirm", "Cancel")) { var parSerObj = new SerializedObject(_parent); AdvancedScriptableObjectUtility.CleanObject(_parent); //parSerObj.ApplyModifiedProperties(); //parSerObj.Update(); AdvancedScriptableObjectUtility.CloneData(_parent, _aso, _parent); //parSerObj.Update(); //parSerObj.ApplyModifiedProperties(); //AdvancedScriptableObjectUtility.CopyDataUnity(parSerObj, serializedObject, parSerObj); } } if (GUILayout.Button("Restore")) { if (EditorUtility.DisplayDialog("Restore to prototype values", "Overwrite values of this object to match prototype?", "Confirm", "Cancel")) { AdvancedScriptableObjectUtility.CleanObject(_aso); serializedObject.ApplyModifiedProperties(); AdvancedScriptableObjectUtility.CloneData(_aso, _parent, _aso); serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(serializedObject.targetObject); serializedObject.UpdateIfRequiredOrScript(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } } if (GUILayout.Button("Break")) { BreakTieToParent(); } EditorGUI.EndDisabledGroup(); if (GUILayout.Button("Clean")) { if (EditorUtility.DisplayDialog("Clean", "Delete all values of this object?", "Confirm", "Cancel")) { AdvancedScriptableObjectUtility.CleanObject(_aso); serializedObject.ApplyModifiedProperties(); serializedObject.UpdateIfRequiredOrScript(); } } if (GUILayout.Button("Alter")) { SetToPrototype(); } EditorGUILayout.EndHorizontal(); if (_aso != null) { EditorGUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(_aso.ProtoChildren.Count < 1); EditorGUILayout.LabelField(string.Format("Children:{0}", _aso.ProtoChildren.Count)); if (GUILayout.Button("Goto")) { GoToChild(); } if (GUILayout.Button("Update")) { AdvancedScriptableObjectUtility.UpdateChildren(_aso); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); //Referencing EditorGUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(_relevantRefData == null || _relevantRefData.Length == 0); EditorGUILayout.LabelField(string.Format("Externally Referenced by:{0}", _relevantRefData.Length)); if (GUILayout.Button("GoTo")) { GoToReferencerMenu(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); //DrawDefaultInspector(); DrawBaseExcept(); }
void Delete(SerializedProperty property) { AdvancedScriptableObjectUtility.Delete(parentASO, propertyASO); AlterProperty(property, null); property.serializedObject.UpdateIfRequiredOrScript(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); float widthUnit = position.width / 10; EditorGUI.LabelField(new Rect(position.x, position.y, widthUnit * 2, EditorGUIUtility.singleLineHeight), property.displayName); parentASO = (AdvancedScriptableObject)property.serializedObject.targetObject; if (property.objectReferenceValue != null) { propertyASO = (AdvancedScriptableObject)property.objectReferenceValue; if (!BIsMerged(property)) { GUI.color = Color.green; if (GUI.Button(new Rect(position.x + (widthUnit * 3), position.y, widthUnit, EditorGUIUtility.singleLineHeight), "><")) { MergeMenu(property); } GUI.color = Color.white; if (GUI.Button(new Rect(position.x + (widthUnit * 4), position.y, widthUnit, EditorGUIUtility.singleLineHeight), "Null")) { NullASOProperty(property); } GUI.color = Color.white; //Disabled for control over reference handling. GUI.enabled = false; EditorGUI.PropertyField(new Rect(position.x + (widthUnit * 5), position.y, widthUnit * 5, EditorGUIUtility.singleLineHeight), property, GUIContent.none, true); GUI.enabled = true; } else { GUI.color = Color.cyan; if (GUI.Button(new Rect(position.x + (widthUnit * 3), position.y, widthUnit, EditorGUIUtility.singleLineHeight), "<>")) { UnmergeMenu(property); } GUI.color = Color.red; if (GUI.Button(new Rect(position.x + (widthUnit * 4), position.y, widthUnit, EditorGUIUtility.singleLineHeight), "X")) { Delete(property); } GUI.color = Color.white; if (GUI.Button(new Rect(position.x + (widthUnit * 5), position.y, widthUnit * 4, EditorGUIUtility.singleLineHeight), property.objectReferenceValue.name)) { EnterChildASO(property); } if (GUI.Button(new Rect(position.x + (widthUnit * 9), position.y, widthUnit, EditorGUIUtility.singleLineHeight), "C")) { AdvancedScriptableObjectUtility.CopyASO(property); } } } else { if (GUI.Button(new Rect(position.x + (widthUnit * 2), position.y, widthUnit * 2, EditorGUIUtility.singleLineHeight), "Create")) { CreateNew(property); } EditorGUI.BeginChangeCheck(); EditorGUI.PropertyField(new Rect(position.x + (widthUnit * 4), position.y, widthUnit * 5, EditorGUIUtility.singleLineHeight), property, GUIContent.none, true); if (EditorGUI.EndChangeCheck()) { if (AdvancedScriptableObjectUtility.BWillCreateCircleReference(parentASO, propertyASO)) { AlterProperty(property, null); Debug.LogError("Object reference will create circular reference. These are not supported."); } else { AlterProperty(property, (AdvancedScriptableObject)property.objectReferenceValue); AddReferenceData(property); } } if (AdvancedScriptableObjectUtility.BCanPaste(property)) { if (GUI.Button(new Rect(position.x + (widthUnit * 9), position.y, widthUnit, EditorGUIUtility.singleLineHeight), "P")) { AdvancedScriptableObjectUtility.PasteASO(property); } } else { GUI.color = Color.grey; GUI.Button(new Rect(position.x + (widthUnit * 9), position.y, widthUnit, EditorGUIUtility.singleLineHeight), "P"); GUI.color = Color.white; } } EditorGUI.EndProperty(); }