Ejemplo n.º 1
0
        public static UnitPlayer_DB Init()
        {
            if (instance != null)
            {
                return(instance);
            }
            instance = LoadDB();

                        #if UNITY_2018_3_OR_NEWER
            instance.FillObjectList();
                        #endif

            return(instance);
        }
Ejemplo n.º 2
0
        public static void LoadUnitPlayer()
        {
            unitPlayerDB = UnitPlayer_DB.LoadDB();

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

            UpdateLabel_UnitPlayer();

            TDSEditorWindow.SetUnitPlayerDB(unitPlayerDB, unitPlayerIDList, unitPlayerLabel);
            TDSEditorInspector.SetUnitPlayerDB(unitPlayerDB, unitPlayerIDList, unitPlayerLabel);
        }
Ejemplo n.º 3
0
 public static void SetUnitPlayerDB(UnitPlayer_DB db, List <int> IDList, string[] label)
 {
     unitPlayerDB     = db;
     unitPlayerIDList = IDList;
     unitPlayerLabel  = label;
 }
Ejemplo n.º 4
0
        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();
            }

            if (!UnitPlayer_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"))
                {
                    UnitPlayer_DB.CopyFromOldDB();          Select(0);
                }
                GUI.color = Color.white;
            }


            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");

            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));
                //UnitPlayer selectedUnit=unitObj.GetComponent<UnitPlayer>();
                //selectedUnit=unitList[selectID];
                //GameObject obj=PrefabUtility.SavePrefabAsset(selectedUnit.gameObject);

                string assetPath = AssetDatabase.GetAssetPath(unitList[selectID].gameObject);

                GameObject unitObj      = PrefabUtility.LoadPrefabContents(assetPath);
                UnitPlayer selectedUnit = unitObj.GetComponent <UnitPlayer>();

                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);
        }