Пример #1
0
        // Use this for initialization
        void Awake()
        {
            instance = this;

            List <UnitTower> dbList = TowerDB.GetList();

            for (int i = 0; i < dbList.Count; i++)
            {
                if (!unavailablePrefabIDList.Contains(dbList[i].prefabID) && !dbList[i].hideInInspector)
                {
                    buildableList.Add(dbList[i]);
                }
            }

            for (int i = 0; i < buildableList.Count; i++)
            {
                GameObject obj = (GameObject)Instantiate(buildableList[i].gameObject);
                sampleList.Add(obj.GetComponent <UnitTower>());
                sampleList[sampleList.Count - 1].isPreview        = true;
                sampleList[sampleList.Count - 1].gameObject.layer = TDTK.GetLayerTerrain();
                sampleList[sampleList.Count - 1].transform.parent = transform;
                obj.SetActive(false);
            }

            //Debug.Log("remove this");
            //for(int i=0; i<buildableList.Count; i++) buildableList[i].prefabID=i;
        }
Пример #2
0
 protected override void ShiftItemDown()
 {
     if (selectID < TowerDB.GetList().Count - 1)
     {
         ShiftItem(1);
     }
 }
Пример #3
0
        private void ShiftItem(int dir)
        {
            UnitTower tower = TowerDB.GetList()[selectID];

            TowerDB.GetList()[selectID]       = TowerDB.GetList()[selectID + dir];
            TowerDB.GetList()[selectID + dir] = tower;
            selectID += dir;
        }
Пример #4
0
        private void SelectItem(int newID)
        {
            selectID = newID;
            if (TowerDB.GetList().Count <= 0)
            {
                return;
            }

            selectID = Mathf.Clamp(selectID, 0, TowerDB.GetList().Count - 1);
            UpdateObjHierarchyList(TowerDB.GetList()[selectID].transform);
        }
Пример #5
0
        private int _NewItem(UnitTower tower)
        {
            if (TowerDB.GetList().Contains(tower))
            {
                return(selectID);
            }

            tower.prefabID = TDE.GenerateNewID(TowerDB.GetPrefabIDList());

            TowerDB.GetList().Add(tower);
            TowerDB.UpdateLabel();

            return(TowerDB.GetList().Count - 1);
        }
Пример #6
0
        public void OnGUI()
        {
            TDE.InitGUIStyle();

            if (!CheckIsPlaying())
            {
                return;
            }
            if (window == null)
            {
                Init();
            }


            List <UnitTower> towerList = TowerDB.GetList();

            Undo.RecordObject(this, "window");
            Undo.RecordObject(TowerDB.GetDB(), "towerDB");
            if (towerList.Count > 0)
            {
                Undo.RecordObject(towerList[selectID], "tower");
            }


            if (GUI.Button(new Rect(Math.Max(260, window.position.width - 120), 5, 100, 25), "Save"))
            {
                TDE.SetDirty();
            }

            UnitTower newTower = null;

            TDE.Label(5, 7, 150, 17, "Add New Tower:", "Drag tower prefab to this slot to add it to the list");
            newTower = (UnitTower)EditorGUI.ObjectField(new Rect(115, 7, 150, 17), newTower, typeof(UnitTower), false);
            if (newTower != null)
            {
                Select(NewItem(newTower));
            }


            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 = DrawTowerList(startX, startY, towerList);

            startX = v2.x + 25;

            if (towerList.Count == 0)
            {
                return;
            }


            Rect visibleRect = new Rect(startX, startY, window.position.width - startX, window.position.height - startY);
            Rect contentRect = new Rect(startX, startY, contentWidth, contentHeight);

            scrollPos = GUI.BeginScrollView(visibleRect, scrollPos, contentRect);

            v2            = DrawUnitConfigurator(startX, startY, towerList[selectID]);
            contentWidth  = v2.x - startX;
            contentHeight = v2.y - 55;

            GUI.EndScrollView();


            if (GUI.changed)
            {
                TDE.SetDirty();
            }
        }
Пример #7
0
 protected override void DeleteItem()
 {
     TowerDB.GetList().RemoveAt(deleteID);
     TowerDB.UpdateLabel();
 }
Пример #8
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (instance == null)
            {
                Awake(); return;
            }

            GUI.changed = false;

            Undo.RecordObject(instance, "BuildPlatform");

            EditorGUILayout.Space();

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("", GUILayout.MaxWidth(10));
            showList = EditorGUILayout.Foldout(showList, "Show Tower List");
            EditorGUILayout.EndHorizontal();
            if (showList)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.Space();
                if (GUILayout.Button("EnableAll") && !Application.isPlaying)
                {
                    instance.unavailablePrefabIDList = new List <int>();
                }
                if (GUILayout.Button("DisableAll") && !Application.isPlaying)
                {
                    instance.unavailablePrefabIDList = TowerDB.GetPrefabIDList();
                }
                EditorGUILayout.Space();
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();


                List <UnitTower> towerList = TowerDB.GetList();
                for (int i = 0; i < towerList.Count; i++)
                {
                    if (towerList[i].hideInInspector)
                    {
                        continue;
                    }

                    UnitTower tower = towerList[i];

                    GUILayout.BeginHorizontal();

                    EditorGUILayout.Space();

                    GUILayout.Box("", GUILayout.Width(40), GUILayout.Height(40));
                    TDE.DrawSprite(GUILayoutUtility.GetLastRect(), tower.icon, tower.desp, false);

                    GUILayout.BeginVertical();
                    EditorGUILayout.Space();
                    GUILayout.Label(tower.unitName, GUILayout.ExpandWidth(false));

                    EditorGUI.BeginChangeCheck();
                    bool flag = !instance.unavailablePrefabIDList.Contains(tower.prefabID) ? true : false;
                    flag = EditorGUILayout.Toggle(new GUIContent(" - enabled: ", "check to enable the tower type to be build on this platform"), flag);

                    if (!Application.isPlaying && EditorGUI.EndChangeCheck())
                    {
                        if (!flag && !instance.unavailablePrefabIDList.Contains(tower.prefabID))
                        {
                            instance.unavailablePrefabIDList.Add(tower.prefabID);
                        }
                        else if (flag)
                        {
                            instance.unavailablePrefabIDList.Remove(tower.prefabID);
                        }
                    }

                    GUILayout.EndVertical();

                    GUILayout.EndHorizontal();
                }
            }

            EditorGUILayout.Space();

            DefaultInspector();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(instance);
            }
        }
Пример #9
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (instance == null)
            {
                Awake(); return;
            }

            GUI.changed = false;

            Undo.RecordObject(instance, "TowerManager");

            EditorGUILayout.Space();

            cont = new GUIContent("Grid Size:", "The size of a single tile on the grid");
            instance.gridSize = EditorGUILayout.FloatField(cont, instance.gridSize);

            cont = new GUIContent("Auto Adjust Texture:", "Check to automatically adjust the texture on the platform to fit the grid");
            instance.autoAdjustTextureToGrid = EditorGUILayout.Toggle(cont, instance.autoAdjustTextureToGrid);

            EditorGUILayout.Space();

            cont = new GUIContent("Free Form Mode:", "Check to enable free form placement of tower, they can be placed anywhere in the world (not limited to platform) as long as the space is not occupied by other towers or obstacle\n\nOnly Applicable for DragNDrop mode");
            instance.freeFormMode = EditorGUILayout.Toggle(cont, instance.freeFormMode);

            cont = new GUIContent("Cast For Terrain:", "Check to have the raycast to get a position from terrain object in the scene when trying to look for a build pos.\n\nThis is only useful for DragNDrop mode when not using when the tower need to place on the terrain even there is no valid build point\nHowever you need to make sure the platform are not obstructed by the terrain collider\n\nThis is always true when using free-form mode");
            instance.raycastForTerrain = EditorGUILayout.Toggle(cont, instance.raycastForTerrain);

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("", GUILayout.MaxWidth(10));
            showList = EditorGUILayout.Foldout(showList, "Show Tower List");
            EditorGUILayout.EndHorizontal();
            if (showList)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.Space();
                if (GUILayout.Button("EnableAll") && !Application.isPlaying)
                {
                    instance.unavailablePrefabIDList = new List <int>();
                }
                if (GUILayout.Button("DisableAll") && !Application.isPlaying)
                {
                    instance.unavailablePrefabIDList = TowerDB.GetPrefabIDList();
                }
                EditorGUILayout.Space();
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();


                List <UnitTower> towerList = TowerDB.GetList();
                for (int i = 0; i < towerList.Count; i++)
                {
                    if (towerList[i].hideInInspector)
                    {
                        continue;
                    }

                    UnitTower tower = towerList[i];

                    GUILayout.BeginHorizontal();

                    EditorGUILayout.Space();

                    GUILayout.Box("", GUILayout.Width(40), GUILayout.Height(40));
                    TDE.DrawSprite(GUILayoutUtility.GetLastRect(), tower.icon, tower.desp, false);

                    GUILayout.BeginVertical();
                    EditorGUILayout.Space();
                    GUILayout.Label(tower.unitName, GUILayout.ExpandWidth(false));

                    EditorGUI.BeginChangeCheck();
                    bool flag = !instance.unavailablePrefabIDList.Contains(tower.prefabID) ? true : false;
                    flag = EditorGUILayout.Toggle(new GUIContent(" - enabled: ", "check to enable the tower in this level"), flag);

                    if (!Application.isPlaying && EditorGUI.EndChangeCheck())
                    {
                        if (!flag && !instance.unavailablePrefabIDList.Contains(tower.prefabID))
                        {
                            instance.unavailablePrefabIDList.Add(tower.prefabID);
                        }
                        else if (flag)
                        {
                            instance.unavailablePrefabIDList.Remove(tower.prefabID);
                        }
                    }

                    GUILayout.EndVertical();

                    GUILayout.EndHorizontal();
                }
            }

            EditorGUILayout.Space();

            DefaultInspector();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(instance);
            }
        }