示例#1
0
        public static UnitAI_DB Init()
        {
            if (instance != null)
            {
                return(instance);
            }
            instance = LoadDB();

                        #if UNITY_2018_3_OR_NEWER
            instance.FillObjectList();
                        #endif

            return(instance);
        }
示例#2
0
        public static void LoadUnitAI()
        {
            unitAIDB = UnitAI_DB.LoadDB();

            for (int i = 0; i < unitAIDB.unitList.Count; i++)
            {
                if (unitAIDB.unitList[i] != null)
                {
                    //unitAIDB.unitList[i].prefabID=i;
                    unitAIIDList.Add(unitAIDB.unitList[i].prefabID);
                }
                else
                {
                    unitAIDB.unitList.RemoveAt(i);
                    i -= 1;
                }
            }

            UpdateLabel_UnitAI();

            TDSEditorWindow.SetUnitAIDB(unitAIDB, unitAIIDList, unitAILabel);
            TDSEditorInspector.SetUnitAIDB(unitAIDB, unitAIIDList, unitAILabel);
        }
示例#3
0
 public static void SetUnitAIDB(UnitAI_DB db, List <int> IDList, string[] label)
 {
     unitAIDB     = db;
     unitAIIDList = IDList;
     unitAILabel  = label;
 }
        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);
        }