public override bool OnGUI() { if (!base.OnGUI()) { return(true); } if (window == null) { Init(); } List <Collectible> collectibleList = collectibleDB.collectibleList; Undo.RecordObject(this, "window"); Undo.RecordObject(collectibleDB, "collectibleDB"); if (collectibleList.Count > 0 && selectID >= 0) { Undo.RecordObject(collectibleList[selectID], "collectible"); } if (GUI.Button(new Rect(Math.Max(260, window.position.width - 120), 5, 100, 25), "Save")) { SetDirtyTDS(); } EditorGUI.LabelField(new Rect(5, 7, 150, 17), "Add New Collectible:"); Collectible newCollectible = null; newCollectible = (Collectible)EditorGUI.ObjectField(new Rect(125, 7, 140, 17), newCollectible, typeof(Collectible), false); if (newCollectible != null) { Select(NewItem(newCollectible)); } float startX = 5; float startY = 55; if (minimiseList) { if (GUI.Button(new Rect(startX, startY - 20, 30, 18), ">>")) { minimiseList = false; } } else { if (GUI.Button(new Rect(startX, startY - 20, 30, 18), "<<")) { minimiseList = true; } } Vector2 v2 = DrawCollectibleList(startX, startY, collectibleList); startX = v2.x + 25; if (collectibleList.Count == 0) { return(true); } Rect visibleRect = new Rect(startX, startY, window.position.width - startX - 10, window.position.height - startY - 5); Rect contentRect = new Rect(startX, startY, contentWidth - startY, contentHeight); scrollPos = GUI.BeginScrollView(visibleRect, scrollPos, contentRect); if (srlObj.isEditingMultipleObjects) { EditorGUI.HelpBox(new Rect(startX, startY, width + spaceX, 40), "More than 1 Collectible instance is selected\nMulti-instance editing is not supported\nTry use Inspector instead", MessageType.Warning); startY += 55; } Collectible cltToEdit = selectedCltList.Count != 0 ? selectedCltList[0] : collectibleList[selectID]; Undo.RecordObject(cltToEdit, "cltToEdit"); v2 = DrawCollectibleConfigurator(startX, startY, cltToEdit); contentWidth = v2.x + 35; contentHeight = v2.y - 55; srlObj.ApplyModifiedProperties(); if (selectedCltList.Count > 0 && TDSEditor.IsPrefabInstance(selectedCltList[0].gameObject)) { PrefabUtility.RecordPrefabInstancePropertyModifications(selectedCltList[0]); } GUI.EndScrollView(); if (GUI.changed) { SetDirtyTDS(); for (int i = 0; i < selectedCltList.Count; i++) { EditorUtility.SetDirty(selectedCltList[i]); } } return(true); }
public override bool OnGUI() { if (!base.OnGUI()) { return(true); } if (window == null) { Init(); } List <UnitAI> unitList = unitAIDB.unitList; Undo.RecordObject(this, "window"); Undo.RecordObject(unitAIDB, "unitAIDB"); if (unitList.Count > 0 && selectID >= 0) { Undo.RecordObject(unitList[selectID], "unitAI"); } if (GUI.Button(new Rect(Math.Max(260, window.position.width - 120), 5, 100, 25), "Save")) { SetDirtyTDS(); } if (!UnitAI_DB.UpdatedToPost_2018_3()) { GUI.color = new Color(0, 1f, 1f, 1f); if (GUI.Button(new Rect(Math.Max(260, window.position.width - 230), 5, 100, 25), "Copy Old DB")) { UnitAI_DB.CopyFromOldDB(); Select(0); } GUI.color = Color.white; } EditorGUI.LabelField(new Rect(5, 7, 150, 17), "Add New AI Unit:"); UnitAI newUnit = null; newUnit = (UnitAI)EditorGUI.ObjectField(new Rect(125, 7, 140, 17), newUnit, typeof(UnitAI), false); if (newUnit != null) { Select(NewItem(newUnit)); } float startX = 5; float startY = 55; if (minimiseList) { if (GUI.Button(new Rect(startX, startY - 20, 30, 18), ">>")) { minimiseList = false; } } else { if (GUI.Button(new Rect(startX, startY - 20, 30, 18), "<<")) { minimiseList = true; } } Vector2 v2 = DrawUnitList(startX, startY, unitList); startX = v2.x + 25; if (unitList.Count == 0 || srlObj == null) { return(true); } Rect visibleRect = new Rect(startX, startY, window.position.width - startX - 10, window.position.height - startY - 5); Rect contentRect = new Rect(startX, startY, contentWidth - startY, contentHeight); scrollPos = GUI.BeginScrollView(visibleRect, scrollPos, contentRect); srlObj.Update(); if (srlObj.isEditingMultipleObjects) { EditorGUI.HelpBox(new Rect(startX, startY, width + spaceX, 40), "More than 1 UnitAI instance is selected\nMulti-instance editing is not supported\nTry use Inspector instead", MessageType.Warning); startY += 55; } UnitAI unitToEdit = selectedUnitList.Count != 0 ? selectedUnitList[0] : unitList[selectID]; Undo.RecordObject(unitToEdit, "unitToEdit"); EditorGUI.BeginChangeCheck(); v2 = DrawUnitConfigurator(startX, startY, unitToEdit); contentWidth = v2.x + 35; contentHeight = v2.y - 55; if (EditorGUI.EndChangeCheck() && selectID >= 0) { #if UNITY_2018_3_OR_NEWER //GameObject unitObj=PrefabUtility.LoadPrefabContents(AssetDatabase.GetAssetPath(unitList[selectID].gameObject)); //UnitAI selectedUnit=unitObj.GetComponent<UnitAI>(); //selectedUnit=unitList[selectID]; //GameObject obj=PrefabUtility.SavePrefabAsset(selectedUnit.gameObject); string assetPath = AssetDatabase.GetAssetPath(unitList[selectID].gameObject); GameObject unitObj = PrefabUtility.LoadPrefabContents(assetPath); UnitAI selectedUnit = unitObj.GetComponent <UnitAI>(); EditorUtility.CopySerialized(unitList[selectID], selectedUnit); PrefabUtility.SaveAsPrefabAsset(unitObj, assetPath); PrefabUtility.UnloadPrefabContents(unitObj); #endif } srlObj.ApplyModifiedProperties(); if (selectedUnitList.Count > 0 && TDSEditor.IsPrefabInstance(selectedUnitList[0].gameObject)) { PrefabUtility.RecordPrefabInstancePropertyModifications(selectedUnitList[0]); } GUI.EndScrollView(); if (GUI.changed) { SetDirtyTDS(); for (int i = 0; i < selectedUnitList.Count; i++) { EditorUtility.SetDirty(selectedUnitList[i]); } } return(true); }
public override bool OnGUI() { if (!base.OnGUI()) { return(true); } if (window == null) { Init(); } List <UnitPlayer> unitList = unitPlayerDB.unitList; Undo.RecordObject(this, "window"); Undo.RecordObject(unitPlayerDB, "unitPlayerDB"); if (unitList.Count > 0 && selectID >= 0) { Undo.RecordObject(unitList[selectID], "unitPlayer"); } if (GUI.Button(new Rect(Math.Max(260, window.position.width - 120), 5, 100, 25), "Save")) { SetDirtyTDS(); } EditorGUI.LabelField(new Rect(5, 7, 150, 17), "Add New Player Unit:"); UnitPlayer newUnit = null; newUnit = (UnitPlayer)EditorGUI.ObjectField(new Rect(125, 7, 140, 17), newUnit, typeof(UnitPlayer), false); if (newUnit != null) { Select(NewItem(newUnit)); } float startX = 5; float startY = 55; if (minimiseList) { if (GUI.Button(new Rect(startX, startY - 20, 30, 18), ">>")) { minimiseList = false; } } else { if (GUI.Button(new Rect(startX, startY - 20, 30, 18), "<<")) { minimiseList = true; } } Vector2 v2 = DrawUnitList(startX, startY, unitList); startX = v2.x + 25; if (unitList.Count == 0) { return(true); } Rect visibleRect = new Rect(startX, startY, window.position.width - startX - 10, window.position.height - startY - 5); Rect contentRect = new Rect(startX, startY, contentWidth - startY, contentHeight); scrollPos = GUI.BeginScrollView(visibleRect, scrollPos, contentRect); UnitPlayer unitToEdit = selectedUnitList.Count != 0 ? selectedUnitList[0] : unitList[selectID]; Undo.RecordObject(unitToEdit, "unitToEdit"); v2 = DrawUnitConfigurator(startX, startY, unitToEdit); contentWidth = v2.x + 35; contentHeight = v2.y - 55; srlObj.ApplyModifiedProperties(); if (selectedUnitList.Count > 0 && TDSEditor.IsPrefabInstance(selectedUnitList[0].gameObject)) { PrefabUtility.RecordPrefabInstancePropertyModifications(selectedUnitList[0]); } GUI.EndScrollView(); if (GUI.changed) { SetDirtyTDS(); for (int i = 0; i < selectedUnitList.Count; i++) { EditorUtility.SetDirty(selectedUnitList[i]); } } return(true); }