Ejemplo n.º 1
0
        public static Collectible_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 LoadCollectible()
        {
            collectibleDB = Collectible_DB.LoadDB();

            for (int i = 0; i < collectibleDB.collectibleList.Count; i++)
            {
                if (collectibleDB.collectibleList[i] != null)
                {
                    //collectibleDB.collectibleList[i].ID=i;
                    collectibleIDList.Add(collectibleDB.collectibleList[i].ID);
                }
                else
                {
                    collectibleDB.collectibleList.RemoveAt(i);
                    i -= 1;
                }
            }

            UpdateLabel_Collectible();

            TDSEditorWindow.SetCollectibleDB(collectibleDB, collectibleIDList, collectibleLabel);
            TDSEditorInspector.SetCollectibleDB(collectibleDB, collectibleIDList, collectibleLabel);
        }
Ejemplo n.º 3
0
 public static void SetCollectibleDB(Collectible_DB db, List <int> IDList, string[] label)
 {
     collectibleDB     = db;
     collectibleIDList = IDList;
     collectibleLabel  = label;
 }
        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();
            }

            if (!Collectible_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"))
                {
                    Collectible_DB.CopyFromOldDB();         selectID = 0;     SelectItem();
                }
                GUI.color = Color.white;
            }


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

            EditorGUI.BeginChangeCheck();

            v2            = DrawCollectibleConfigurator(startX, startY, cltToEdit);
            contentWidth  = v2.x + 35;
            contentHeight = v2.y - 55;

            if (EditorGUI.EndChangeCheck() && selectID >= 0)
            {
                                        #if UNITY_2018_3_OR_NEWER
                //GameObject collectibleObj=PrefabUtility.LoadPrefabContents(AssetDatabase.GetAssetPath(collectibleList[selectID].gameObject));
                //Collectible selectedItem=collectibleObj.GetComponent<Collectible>();
                //selectedItem=collectibleList[selectID];
                //GameObject obj=PrefabUtility.SavePrefabAsset(selectedItem.gameObject);

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

                GameObject  itemObj     = PrefabUtility.LoadPrefabContents(assetPath);
                Collectible selectedObj = itemObj.GetComponent <Collectible>();

                EditorUtility.CopySerialized(collectibleList[selectID], selectedObj);

                PrefabUtility.SaveAsPrefabAsset(itemObj, assetPath);
                PrefabUtility.UnloadPrefabContents(itemObj);
                                        #endif
            }

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