Ejemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        gm = (GridManager)target;

        //DrawDefaultInspector();

        EditorGUILayout.Space();


        cont = new GUIContent("Randomize Grid On Start", "check to regenerate the tiles when the scene is loaded\nthis will generate all the units as well");
        gm.randomizeGridUponStart = EditorGUILayout.Toggle(cont, gm.randomizeGridUponStart);

        cont = new GUIContent("Randomize Unit On Start", "check to regenerate the units on the grid when the scene is loaded\nexisting unit will be removed");
        gm.randomizeUnitUponStart = EditorGUILayout.Toggle(cont, gm.randomizeUnitUponStart);

        cont         = new GUIContent("Show Gizmo", "check to show gizmos on scene view");
        gm.showGizmo = EditorGUILayout.Toggle(cont, gm.showGizmo);

        EditorGUILayout.Space();

        int type = (int)gm.type;

        cont  = new GUIContent("Grid Type:", "Turn mode to be used in this scene");
        contL = new GUIContent[tileTypeLabel.Length];
        for (int i = 0; i < contL.Length; i++)
        {
            contL[i] = new GUIContent(tileTypeLabel[i], tileTypeTooltip[i]);
        }
        type    = EditorGUILayout.IntPopup(cont, type, contL, intVal);
        gm.type = (_TileType)type;

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


        EditorGUILayout.BeginHorizontal();
        cont     = new GUIContent("Num of Column:", "the width(x-axis) of the area to cover for the whole grid");
        gm.width = EditorGUILayout.FloatField(cont, gm.width, GUILayout.ExpandWidth(true));
        //~ gm.width=EditorGUILayout.FloatField(cont, gm.width, GUILayout.MinWidth(160));
        //~ gm.width=Mathf.Round(Mathf.Clamp(gm.width, 0, 50));
        //~ cont=new GUIContent("Actual:"+(gm.width*gm.gridSize).ToString("f2"), "after multiply the GridSize");
        //~ EditorGUILayout.LabelField(cont, GUILayout.ExpandWidth(true));
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        cont      = new GUIContent("Num of Row:", "the length(z-axis) of the area to cover for the whole grid");
        gm.length = EditorGUILayout.FloatField(cont, gm.length, GUILayout.ExpandWidth(true));
        //~ gm.length=EditorGUILayout.FloatField(cont, gm.length, GUILayout.MinWidth(160));
        //~ gm.length=Mathf.Round(Mathf.Clamp(gm.length, 0, 50));
        //~ cont=new GUIContent("Actual:"+(gm.length*gm.gridSize).ToString("f2"), "after multiply the GridSize");
        //~ EditorGUILayout.LabelField(cont, GUILayout.ExpandWidth(true));
        EditorGUILayout.EndHorizontal();

        cont          = new GUIContent("Area Height:", "the position of the grid on y-axis\nThis is a relative value from the GridManager's transform");
        gm.baseHeight = EditorGUILayout.FloatField(cont, gm.baseHeight);
        //cont=new GUIContent("Max Height:", "the position of the grid on y-axis\nThis is a relative value from the GridManager's transform");
        //gm.maxHeight=EditorGUILayout.FloatField(cont, gm.maxHeight);

        cont = new GUIContent("GridToTileSizeRatio:", "the size ratio of a single unit in the grid with respect to an individual tile");
        gm.gridToTileSizeRatio = EditorGUILayout.FloatField(cont, gm.gridToTileSizeRatio);
        gm.gridToTileSizeRatio = Mathf.Max(0, gm.gridToTileSizeRatio);

        cont = new GUIContent("UnwalkableTileRate:", "the percentage of the unwalkable tile of the whole grid");
        gm.unwalkableRate = EditorGUILayout.FloatField(cont, gm.unwalkableRate);
        gm.unwalkableRate = Mathf.Clamp(gm.unwalkableRate, 0f, 1f);

        if (gm.unwalkableRate > 0)
        {
            cont           = new GUIContent("UseObstacle:", "the percentage of the unwalkable tile of the whole grid");
            gm.useObstacle = EditorGUILayout.Toggle(cont, gm.useObstacle);

            bool changedFlag = GUI.changed;


            if (gm.useObstacle)
            {
                for (int n = 0; n < obstacleList.Count; n++)
                {
                    GUI.changed = false;

                    bool flag = false;
                    if (n == 0)
                    {
                        flag = gm.enableInvUnwalkable;
                    }
                    else if (n == 1)
                    {
                        flag = gm.enableVUnwalkable;
                    }
                    else
                    {
                        if (gm.obstaclePrefabList.Contains(obstacleList[n]))
                        {
                            flag = true;
                        }
                    }

                    cont = new GUIContent("  -  " + obstacleNameList[n] + ":", "");
                    flag = EditorGUILayout.Toggle(cont, flag);

                    if (n == 0)
                    {
                        gm.enableInvUnwalkable = flag;
                    }
                    else if (n == 1)
                    {
                        gm.enableVUnwalkable = flag;
                    }
                    else
                    {
                        if (GUI.changed)
                        {
                            if (gm.obstaclePrefabList.Contains(obstacleList[n]))
                            {
                                gm.obstaclePrefabList.Remove(obstacleList[n]);
                            }
                            else
                            {
                                gm.obstaclePrefabList.Add(obstacleList[n]);
                            }

                            GUI.changed = false;
                        }
                    }
                }
            }

            if (gm.obstaclePrefabList.Count == 0)
            {
                if (!gm.enableInvUnwalkable && !gm.enableVUnwalkable)
                {
                    gm.enableVUnwalkable = true;
                }
            }

            EditorGUILayout.Space();
            if (!GUI.changed)
            {
                GUI.changed = changedFlag;
            }
        }
        else
        {
            EditorGUILayout.Space();
        }


        cont             = new GUIContent("AddCollectible:", "check to add collectible items to the grid when generating the grid");
        gm.addColletible = EditorGUILayout.Toggle(cont, gm.addColletible);

        if (gm.addColletible)
        {
            EditorGUILayout.BeginHorizontal();
            cont = new GUIContent("CollectibleCount (min/max):", "The number of collectible to be spawned on the grid");
            EditorGUILayout.LabelField(cont, GUILayout.MinWidth(170), GUILayout.MaxWidth(170));
            gm.minCollectibleCount = EditorGUILayout.IntField(gm.minCollectibleCount, GUILayout.MaxWidth(30));
            gm.maxCollectibleCount = EditorGUILayout.IntField(gm.maxCollectibleCount, GUILayout.MaxWidth(30));
            EditorGUILayout.EndHorizontal();

            bool changedFlag = GUI.changed;

            if (collectibleList.Count > 0)
            {
                for (int n = 0; n < collectibleList.Count; n++)
                {
                    GUI.changed = false;

                    bool flag = false;
                    if (gm.collectiblePrefabList.Contains(collectibleList[n]))
                    {
                        flag = true;
                    }

                    cont = new GUIContent("  -  " + collectibleNameList[n] + ":", "");
                    flag = EditorGUILayout.Toggle(cont, flag);

                    if (GUI.changed)
                    {
                        if (gm.collectiblePrefabList.Contains(collectibleList[n]))
                        {
                            gm.collectiblePrefabList.Remove(collectibleList[n]);
                        }
                        else
                        {
                            gm.collectiblePrefabList.Add(collectibleList[n]);
                        }

                        GUI.changed = false;
                    }
                }
            }
            else
            {
                EditorGUILayout.LabelField("- No collectible in CollectibleManager -");
            }

            EditorGUILayout.Space();
            if (!GUI.changed)
            {
                GUI.changed = changedFlag;
            }
        }
        else
        {
            EditorGUILayout.Space();
        }


        //cont=new GUIContent("Tile Prefab:", "the gameObject prefab to be used as the tile");
        //gm.tilePrefab=(GameObject)EditorGUILayout.ObjectField(cont, gm.tilePrefab, typeof(GameObject), false);

        if (gm.type == _TileType.Hex)
        {
            cont             = new GUIContent("HexTile Prefab:", "the gameObject prefab to be used as the tile");
            gm.hexTilePrefab = (GameObject)EditorGUILayout.ObjectField(cont, gm.hexTilePrefab, typeof(GameObject), false);
        }
        else if (gm.type == _TileType.Square)
        {
            cont = new GUIContent("SquareTile Prefab:", "the gameObject prefab to be used as the tile");
            gm.squareTilePrefab = (GameObject)EditorGUILayout.ObjectField(cont, gm.squareTilePrefab, typeof(GameObject), false);
        }


        if (gc != null)
        {
            if (gc.playerFactionID.Count != gm.playerPlacementAreas.Count)
            {
                gm.playerPlacementAreas = MatchRectListLength(gm.playerPlacementAreas, gc.playerFactionID.Count);
            }

            for (int i = 0; i < gc.playerFactionID.Count; i++)
            {
                EditorGUILayout.Space();
                cont = new GUIContent("Player (ID:" + gc.playerFactionID[i] + ") Placement Area:", "The area on the grid which player will be able to place the starting unit, as shown as the green colored square on the gizmo");
                gm.playerPlacementAreas[i] = EditorGUILayout.RectField(cont, gm.playerPlacementAreas[i]);
            }

            if (gc.playerFactionID.Count == 0)
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("No player faction set in GameControl");
            }
        }
        else
        {
            gc = (GameControlTB)FindObjectOfType(typeof(GameControlTB));
        }
        EditorGUILayout.Space();


        //cont=new GUIContent("Player Placement Area:", "The area on the grid which player will be able to place the starting unit, as shown as the green colored square on the gizmo");
        //gm.playerPlacementArea=EditorGUILayout.RectField(cont,  gm.playerPlacementArea);


        //~ showIndicatorList
        string label = "Indicators (Show)";

        if (showIndicatorList)
        {
            label = "Indicators (Hide)";
        }
        cont = new GUIContent(label, "list of various indicators used in run time. Optional. If left empty the defaults will be loaded");
        showIndicatorList = EditorGUILayout.Foldout(showIndicatorList, cont);
        if (showIndicatorList)
        {
            gm.indicatorSelect  = (Transform)EditorGUILayout.ObjectField("IndicatorSelect:", gm.indicatorSelect, typeof(Transform), false);
            gm.indicatorCursor  = (Transform)EditorGUILayout.ObjectField("IndicatorCursor:", gm.indicatorCursor, typeof(Transform), false);
            gm.indicatorHostile = (Transform)EditorGUILayout.ObjectField("IndicatorHostile:", gm.indicatorHostile, typeof(Transform), false);
        }

        //~ gm.playerPlacementArea=EditorGUILayout.RectField("Player Placement Area:", gm.playerPlacementArea);

        int num;

        label = "Faction (Show)";
        if (showFactionList)
        {
            label = "Faction (Hide)";
        }
        cont            = new GUIContent(label, "list of factions in this scene.");
        showFactionList = EditorGUILayout.Foldout(showFactionList, cont);
        if (showFactionList)
        {
            GUILayout.BeginHorizontal();    GUILayout.Space(15);
            GUILayout.BeginVertical();

            cont = new GUIContent("Add Faction", "add a new faction to the list");
            if (GUILayout.Button(cont))
            {
                Faction fac = new Faction();
                fac.factionID = gm.factionList.Count;
                fac.color     = new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), 1);
                gm.factionList.Add(fac);
            }


            for (int i = 0; i < gm.factionList.Count; i++)
            {
                Rect rectBase = EditorGUILayout.BeginVertical();
                GUILayout.Space(5);
                rectBase.width += 5;      rectBase.height += 0;
                GUI.Box(rectBase, "");

                Faction fac = gm.factionList[i];
                cont          = new GUIContent("ID:", "The ID of the faction. 2 factions entry will the same ID will be recognised as 1 faction in runtime. Player's faction's ID is 0 by default");
                fac.factionID = EditorGUILayout.IntField(cont, fac.factionID);
                cont          = new GUIContent("Color:", "Color of the faction. This is simply for gizmo purpose to identify different spawn area in SceneView");
                fac.color     = EditorGUILayout.ColorField(cont, fac.color);

                cont = new GUIContent("Add Area", "add an additional spawn area for the faction");
                if (GUILayout.Button(cont))
                {
                    FactionSpawnInfo sInfo = new FactionSpawnInfo();
                    if (fac.spawnInfo.Count > 0)
                    {
                        sInfo.area.x      = fac.spawnInfo[fac.spawnInfo.Count - 1].area.x;
                        sInfo.area.y      = fac.spawnInfo[fac.spawnInfo.Count - 1].area.y;
                        sInfo.area.width  = fac.spawnInfo[fac.spawnInfo.Count - 1].area.width;
                        sInfo.area.height = fac.spawnInfo[fac.spawnInfo.Count - 1].area.height;
                    }
                    fac.spawnInfo.Add(sInfo);
                }

                GUILayout.BeginHorizontal();    GUILayout.Space(10);
                GUILayout.BeginVertical();

                for (int nn = 0; nn < fac.spawnInfo.Count; nn++)
                {
                    FactionSpawnInfo sInfo = fac.spawnInfo[nn];

                    Rect rectSub = EditorGUILayout.BeginVertical();
                    rectSub.x -= 5; rectSub.width += 10;        rectSub.height += 5;
                    GUI.Box(rectSub, "");



                    int spawnQuota = (int)sInfo.spawnQuota;
                    cont  = new GUIContent("SpawnQuota:", "type of spawning algorithm to be used");
                    contL = new GUIContent[spawnQuotaLabel.Length];
                    for (int n = 0; n < contL.Length; n++)
                    {
                        contL[n] = new GUIContent(spawnQuotaLabel[n], spawnQuotaTooltip[n]);
                    }
                    spawnQuota       = EditorGUILayout.IntPopup(cont, spawnQuota, contL, intVal);
                    sInfo.spawnQuota = (_SpawnQuota)spawnQuota;

                    if (sInfo.spawnQuota == _SpawnQuota.UnitBased)
                    {
                        cont            = new GUIContent("Number to Spawn:", "number of unit to spawn for this spawn area");
                        sInfo.unitCount = EditorGUILayout.IntField(cont, sInfo.unitCount, GUILayout.MaxHeight(14));
                    }
                    else if (sInfo.spawnQuota == _SpawnQuota.BudgetBased)
                    {
                        cont         = new GUIContent("Spawn Budget:", "Point budget allocated for the units to be spawned");
                        sInfo.budget = EditorGUILayout.IntField(cont, sInfo.budget, GUILayout.MaxHeight(14));
                    }


                    cont       = new GUIContent("Spawn Area:", "The area covered in which the units will be spawned in");
                    sInfo.area = EditorGUILayout.RectField(cont, sInfo.area);


                    cont  = new GUIContent("Rotation:", "The direction which the unit spawned in this area will be facing");
                    contL = new GUIContent[rotationLabel.Length];
                    for (int n = 0; n < contL.Length; n++)
                    {
                        contL[n] = new GUIContent(rotationLabel[n], "");
                    }
                    sInfo.unitRotation = EditorGUILayout.IntPopup(cont, sInfo.unitRotation, contL, intVal);


                    label = "Unit Prefab Pool (Show)";
                    if (sInfo.showUnitPrefabList)
                    {
                        label = "Unit Prefab Pool (Hide)";
                    }
                    cont = new GUIContent(label, "the list possible unit to be spawned in the area specified");
                    sInfo.showUnitPrefabList = EditorGUILayout.Foldout(sInfo.showUnitPrefabList, label);
                    if (sInfo.showUnitPrefabList)
                    {
                        num = sInfo.unitPrefabs.Length;
                        num = EditorGUILayout.IntField("  num of prefab:", num, GUILayout.MaxHeight(14));
                        if (num != sInfo.unitPrefabs.Length)
                        {
                            sInfo.unitPrefabs = MatchUnitPrefabListLength(sInfo.unitPrefabs, num);
                        }
                        if (num != sInfo.unitPrefabsMax.Length)
                        {
                            sInfo.unitPrefabsMax = MatchUnitPrefabMaxListLength(sInfo.unitPrefabsMax, num);
                        }
                        for (int n = 0; n < num; n++)
                        {
                            int unitID = -1;
                            for (int m = 0; m < unitList.Count; m++)
                            {
                                if (unitList[m] == sInfo.unitPrefabs[n])
                                {
                                    unitID = m;
                                    break;
                                }
                            }

                            EditorGUILayout.BeginHorizontal();
                            if (sInfo.spawnQuota == _SpawnQuota.UnitBased)
                            {
                                unitID = EditorGUILayout.IntPopup("   - unit" + n + "(max): ", unitID, unitNameList, intVal, GUILayout.MaxHeight(13));
                                sInfo.unitPrefabsMax[n] = EditorGUILayout.IntField(sInfo.unitPrefabsMax[n], GUILayout.MaxWidth(25));
                            }
                            else if (sInfo.spawnQuota == _SpawnQuota.BudgetBased)
                            {
                                unitID = EditorGUILayout.IntPopup("   - unit" + n + "(max): ", unitID, unitNameList, intVal);
                            }
                            EditorGUILayout.EndHorizontal();

                            if (unitID >= 0)
                            {
                                sInfo.unitPrefabs[n] = unitList[unitID];
                            }
                            else
                            {
                                sInfo.unitPrefabs[n] = null;
                            }
                        }
                    }

                    int totalUnitCount = 0;
                    for (int n = 0; n < sInfo.unitPrefabsMax.Length; n++)
                    {
                        totalUnitCount += sInfo.unitPrefabsMax[n];
                    }

                    sInfo.unitCount = Mathf.Min(totalUnitCount, sInfo.unitCount);

                    cont = new GUIContent("Remove area", "remove this spawn area");
                    if (GUILayout.Button(cont))
                    {
                        fac.spawnInfo.Remove(sInfo);
                    }

                    EditorGUILayout.EndVertical();
                }


                GUILayout.EndVertical();
                GUILayout.Space(10);
                GUILayout.EndHorizontal();

                GUILayout.Space(5);
                if (GUILayout.Button("Remove Faction"))
                {
                    gm.factionList.Remove(fac);
                }
                GUILayout.Space(5);

                EditorGUILayout.EndVertical();

                GUILayout.Space(5);
            }
            GUILayout.Space(10);
            GUILayout.EndVertical();
            //~ GUILayout.Space (5);
            GUILayout.EndHorizontal();
        }


        EditorGUILayout.Space();
        cont = new GUIContent("Generate Grid", "Procedurally generate a new grid with the configured setting\nPlease note that generate a large map (30x30 and above) might take a while");
        if (GUILayout.Button(cont))
        {
            GenerateGrid();
        }

        cont = new GUIContent("Generate Unit", "Procedurally place unit on the grid with the configured setting");
        if (GUILayout.Button(cont))
        {
            GenerateUnit();
        }

        //~ if(GUILayout.Button("testGenerate")) TestGenerate();
        //~ if(GUILayout.Button("testDestroy")) TestDestroy();
        EditorGUILayout.Space();


        if (GUI.changed)
        {
            EditorUtility.SetDirty(gm);
        }
    }
Ejemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        gm = (GridManager)target;

        //DrawDefaultInspector();

        EditorGUILayout.Space();

        cont=new GUIContent("Randomize Grid On Start", "check to regenerate the tiles when the scene is loaded\nthis will generate all the units as well");
        gm.randomizeGridUponStart=EditorGUILayout.Toggle(cont, gm.randomizeGridUponStart);

        cont=new GUIContent("Randomize Unit On Start", "check to regenerate the units on the grid when the scene is loaded\nexisting unit will be removed");
        gm.randomizeUnitUponStart=EditorGUILayout.Toggle(cont, gm.randomizeUnitUponStart);

        cont=new GUIContent("Show Gizmo", "check to show gizmos on scene view");
        gm.showGizmo=EditorGUILayout.Toggle(cont, gm.showGizmo);

        EditorGUILayout.Space();

        int type=(int)gm.type;
        cont=new GUIContent("Grid Type:", "Turn mode to be used in this scene");
        contL=new GUIContent[tileTypeLabel.Length];
        for(int i=0; i<contL.Length; i++) contL[i]=new GUIContent(tileTypeLabel[i], tileTypeTooltip[i]);
        type = EditorGUILayout.IntPopup(cont, type, contL, intVal);
        gm.type=(_TileType)type;

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

        EditorGUILayout.BeginHorizontal();
        cont=new GUIContent("Num of Column:", "the width(x-axis) of the area to cover for the whole grid");
        gm.width=EditorGUILayout.FloatField(cont, gm.width, GUILayout.ExpandWidth(true));
        //~ gm.width=EditorGUILayout.FloatField(cont, gm.width, GUILayout.MinWidth(160));
        //~ gm.width=Mathf.Round(Mathf.Clamp(gm.width, 0, 50));
        //~ cont=new GUIContent("Actual:"+(gm.width*gm.gridSize).ToString("f2"), "after multiply the GridSize");
        //~ EditorGUILayout.LabelField(cont, GUILayout.ExpandWidth(true));
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        cont=new GUIContent("Num of Row:", "the length(z-axis) of the area to cover for the whole grid");
        gm.length=EditorGUILayout.FloatField(cont, gm.length, GUILayout.ExpandWidth(true));
        //~ gm.length=EditorGUILayout.FloatField(cont, gm.length, GUILayout.MinWidth(160));
        //~ gm.length=Mathf.Round(Mathf.Clamp(gm.length, 0, 50));
        //~ cont=new GUIContent("Actual:"+(gm.length*gm.gridSize).ToString("f2"), "after multiply the GridSize");
        //~ EditorGUILayout.LabelField(cont, GUILayout.ExpandWidth(true));
        EditorGUILayout.EndHorizontal();

        cont=new GUIContent("Area Height:", "the position of the grid on y-axis\nThis is a relative value from the GridManager's transform");
        gm.baseHeight=EditorGUILayout.FloatField(cont, gm.baseHeight);
        //cont=new GUIContent("Max Height:", "the position of the grid on y-axis\nThis is a relative value from the GridManager's transform");
        //gm.maxHeight=EditorGUILayout.FloatField(cont, gm.maxHeight);

        cont=new GUIContent("GridToTileSizeRatio:", "the size ratio of a single unit in the grid with respect to an individual tile");
        gm.gridToTileSizeRatio=EditorGUILayout.FloatField(cont, gm.gridToTileSizeRatio);
        gm.gridToTileSizeRatio=Mathf.Max(0, gm.gridToTileSizeRatio);

        cont=new GUIContent("UnwalkableTileRate:", "the percentage of the unwalkable tile of the whole grid");
        gm.unwalkableRate=EditorGUILayout.FloatField(cont, gm.unwalkableRate);
        gm.unwalkableRate=Mathf.Clamp(gm.unwalkableRate, 0f, 1f);

        if(gm.unwalkableRate>0){
            cont=new GUIContent("UseObstacle:", "the percentage of the unwalkable tile of the whole grid");
            gm.useObstacle=EditorGUILayout.Toggle(cont, gm.useObstacle);

            bool changedFlag=GUI.changed;

            if(gm.useObstacle){
                for(int n=0; n<obstacleList.Count; n++){

                    GUI.changed=false;

                    bool flag=false;
                    if(n==0) flag=gm.enableInvUnwalkable;
                    else if(n==1) flag=gm.enableVUnwalkable;
                    else{
                        if(gm.obstaclePrefabList.Contains(obstacleList[n])) flag=true;
                    }

                    cont=new GUIContent("  -  "+obstacleNameList[n]+":", "");
                    flag=EditorGUILayout.Toggle(cont, flag);

                    if(n==0) gm.enableInvUnwalkable=flag;
                    else if(n==1) gm.enableVUnwalkable=flag;
                    else{
                        if(GUI.changed){
                            if(gm.obstaclePrefabList.Contains(obstacleList[n]))
                                gm.obstaclePrefabList.Remove(obstacleList[n]);
                            else gm.obstaclePrefabList.Add(obstacleList[n]);

                            GUI.changed=false;
                        }
                    }
                }
            }

            if(gm.obstaclePrefabList.Count==0){
                if(!gm.enableInvUnwalkable && !gm.enableVUnwalkable){
                    gm.enableVUnwalkable=true;
                }
            }

            EditorGUILayout.Space();
            if(!GUI.changed) GUI.changed=changedFlag;
        }
        else EditorGUILayout.Space();

        cont=new GUIContent("AddCollectible:", "check to add collectible items to the grid when generating the grid");
        gm.addColletible=EditorGUILayout.Toggle(cont, gm.addColletible);

        if(gm.addColletible){

            EditorGUILayout.BeginHorizontal();
            cont=new GUIContent("CollectibleCount (min/max):", "The number of collectible to be spawned on the grid");
            EditorGUILayout.LabelField(cont, GUILayout.MinWidth(170), GUILayout.MaxWidth(170));
            gm.minCollectibleCount=EditorGUILayout.IntField(gm.minCollectibleCount, GUILayout.MaxWidth(30));
            gm.maxCollectibleCount=EditorGUILayout.IntField(gm.maxCollectibleCount, GUILayout.MaxWidth(30));
            EditorGUILayout.EndHorizontal();

            bool changedFlag=GUI.changed;

            if(collectibleList.Count>0){
                for(int n=0; n<collectibleList.Count; n++){

                    GUI.changed=false;

                    bool flag=false;
                    if(gm.collectiblePrefabList.Contains(collectibleList[n])) flag=true;

                    cont=new GUIContent("  -  "+collectibleNameList[n]+":", "");
                    flag=EditorGUILayout.Toggle(cont, flag);

                    if(GUI.changed){
                        if(gm.collectiblePrefabList.Contains(collectibleList[n]))
                            gm.collectiblePrefabList.Remove(collectibleList[n]);
                        else gm.collectiblePrefabList.Add(collectibleList[n]);

                        GUI.changed=false;
                    }
                }
            }
            else{
                EditorGUILayout.LabelField("- No collectible in CollectibleManager -");
            }

            EditorGUILayout.Space();
            if(!GUI.changed) GUI.changed=changedFlag;
        }
        else EditorGUILayout.Space();

        //cont=new GUIContent("Tile Prefab:", "the gameObject prefab to be used as the tile");
        //gm.tilePrefab=(GameObject)EditorGUILayout.ObjectField(cont, gm.tilePrefab, typeof(GameObject), false);

        if(gm.type==_TileType.Hex){
            cont=new GUIContent("HexTile Prefab:", "the gameObject prefab to be used as the tile");
            gm.hexTilePrefab=(GameObject)EditorGUILayout.ObjectField(cont, gm.hexTilePrefab, typeof(GameObject), false);
        }
        else if(gm.type==_TileType.Square){
            cont=new GUIContent("SquareTile Prefab:", "the gameObject prefab to be used as the tile");
            gm.squareTilePrefab=(GameObject)EditorGUILayout.ObjectField(cont, gm.squareTilePrefab, typeof(GameObject), false);
        }

        if(gc!=null){
            if(gc.playerFactionID.Count!=gm.playerPlacementAreas.Count) gm.playerPlacementAreas=MatchRectListLength(gm.playerPlacementAreas, gc.playerFactionID.Count);

            for(int i=0; i<gc.playerFactionID.Count; i++){
                EditorGUILayout.Space();
                cont=new GUIContent("Player (ID:"+gc.playerFactionID[i]+") Placement Area:", "The area on the grid which player will be able to place the starting unit, as shown as the green colored square on the gizmo");
                gm.playerPlacementAreas[i]=EditorGUILayout.RectField(cont,  gm.playerPlacementAreas[i]);
            }

            if(gc.playerFactionID.Count==0){
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("No player faction set in GameControl");
            }
        }
        else{
            gc=(GameControlTB)FindObjectOfType(typeof(GameControlTB));
        }
        EditorGUILayout.Space();

        //cont=new GUIContent("Player Placement Area:", "The area on the grid which player will be able to place the starting unit, as shown as the green colored square on the gizmo");
        //gm.playerPlacementArea=EditorGUILayout.RectField(cont,  gm.playerPlacementArea);

        //~ showIndicatorList
        string label="Indicators (Show)";
        if(showIndicatorList) label="Indicators (Hide)";
        cont=new GUIContent(label, "list of various indicators used in run time. Optional. If left empty the defaults will be loaded");
        showIndicatorList = EditorGUILayout.Foldout(showIndicatorList, cont);
        if(showIndicatorList){
            gm.indicatorSelect=(Transform)EditorGUILayout.ObjectField("IndicatorSelect:", gm.indicatorSelect, typeof(Transform), false);
            gm.indicatorCursor=(Transform)EditorGUILayout.ObjectField("IndicatorCursor:", gm.indicatorCursor, typeof(Transform), false);
            gm.indicatorHostile=(Transform)EditorGUILayout.ObjectField("IndicatorHostile:", gm.indicatorHostile, typeof(Transform), false);
        }

        //~ gm.playerPlacementArea=EditorGUILayout.RectField("Player Placement Area:", gm.playerPlacementArea);

        int num;

        label="Faction (Show)";
        if(showFactionList) label="Faction (Hide)";
        cont=new GUIContent(label, "list of factions in this scene.");
        showFactionList = EditorGUILayout.Foldout(showFactionList, cont);
        if(showFactionList){
            GUILayout.BeginHorizontal();	GUILayout.Space (15);
            GUILayout.BeginVertical();

            cont=new GUIContent("Add Faction", "add a new faction to the list");
            if(GUILayout.Button(cont)){
                Faction fac=new Faction();
                fac.factionID=gm.factionList.Count;
                fac.color=new Color(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f), 1);
                gm.factionList.Add(fac);
            }

            for(int i=0; i<gm.factionList.Count; i++){
                Rect rectBase = EditorGUILayout.BeginVertical();
                GUILayout.Space (5);
                rectBase.width+=5;	rectBase.height+=0;
                GUI.Box(rectBase, "");

                Faction fac=gm.factionList[i];
                cont=new GUIContent("ID:", "The ID of the faction. 2 factions entry will the same ID will be recognised as 1 faction in runtime. Player's faction's ID is 0 by default");
                fac.factionID = EditorGUILayout.IntField(cont, fac.factionID);
                cont=new GUIContent("Color:", "Color of the faction. This is simply for gizmo purpose to identify different spawn area in SceneView");
                fac.color = EditorGUILayout.ColorField(cont, fac.color);

                cont=new GUIContent("Add Area", "add an additional spawn area for the faction");
                if(GUILayout.Button(cont)){
                    FactionSpawnInfo sInfo=new FactionSpawnInfo();
                    if(fac.spawnInfo.Count>0){
                        sInfo.area.x=fac.spawnInfo[fac.spawnInfo.Count-1].area.x;
                        sInfo.area.y=fac.spawnInfo[fac.spawnInfo.Count-1].area.y;
                        sInfo.area.width=fac.spawnInfo[fac.spawnInfo.Count-1].area.width;
                        sInfo.area.height=fac.spawnInfo[fac.spawnInfo.Count-1].area.height;
                    }
                    fac.spawnInfo.Add(sInfo);
                }

                GUILayout.BeginHorizontal();	GUILayout.Space (10);
                GUILayout.BeginVertical();

                for(int nn=0; nn<fac.spawnInfo.Count; nn++){
                    FactionSpawnInfo sInfo=fac.spawnInfo[nn];

                    Rect rectSub = EditorGUILayout.BeginVertical();
                    rectSub.x-=5; rectSub.width+=10;	rectSub.height+=5;
                    GUI.Box(rectSub, "");

                    int spawnQuota=(int)sInfo.spawnQuota;
                    cont=new GUIContent("SpawnQuota:", "type of spawning algorithm to be used");
                    contL=new GUIContent[spawnQuotaLabel.Length];
                    for(int n=0; n<contL.Length; n++) contL[n]=new GUIContent(spawnQuotaLabel[n], spawnQuotaTooltip[n]);
                    spawnQuota = EditorGUILayout.IntPopup(cont, spawnQuota, contL, intVal);
                    sInfo.spawnQuota=(_SpawnQuota)spawnQuota;

                    if(sInfo.spawnQuota==_SpawnQuota.UnitBased){
                        cont=new GUIContent("Number to Spawn:", "number of unit to spawn for this spawn area");
                        sInfo.unitCount=EditorGUILayout.IntField(cont, sInfo.unitCount, GUILayout.MaxHeight(14));
                    }
                    else if(sInfo.spawnQuota==_SpawnQuota.BudgetBased){
                        cont=new GUIContent("Spawn Budget:", "Point budget allocated for the units to be spawned");
                        sInfo.budget=EditorGUILayout.IntField(cont, sInfo.budget, GUILayout.MaxHeight(14));
                    }

                    cont=new GUIContent("Spawn Area:", "The area covered in which the units will be spawned in");
                    sInfo.area=EditorGUILayout.RectField(cont, sInfo.area);

                    cont=new GUIContent("Rotation:", "The direction which the unit spawned in this area will be facing");
                    contL=new GUIContent[rotationLabel.Length];
                    for(int n=0; n<contL.Length; n++) contL[n]=new GUIContent(rotationLabel[n], "");
                    sInfo.unitRotation = EditorGUILayout.IntPopup(cont, sInfo.unitRotation, contL, intVal);

                    label="Unit Prefab Pool (Show)";
                    if(sInfo.showUnitPrefabList) label="Unit Prefab Pool (Hide)";
                    cont=new GUIContent(label, "the list possible unit to be spawned in the area specified");
                    sInfo.showUnitPrefabList = EditorGUILayout.Foldout(sInfo.showUnitPrefabList, label);
                    if(sInfo.showUnitPrefabList){
                        num=sInfo.unitPrefabs.Length;
                        num=EditorGUILayout.IntField("  num of prefab:", num, GUILayout.MaxHeight(14));
                        if(num!=sInfo.unitPrefabs.Length) sInfo.unitPrefabs=MatchUnitPrefabListLength(sInfo.unitPrefabs, num);
                        if(num!=sInfo.unitPrefabsMax.Length) sInfo.unitPrefabsMax=MatchUnitPrefabMaxListLength(sInfo.unitPrefabsMax, num);
                        for(int n=0; n<num; n++){
                            int unitID=-1;
                            for(int m=0; m<unitList.Count; m++){
                                if(unitList[m]==sInfo.unitPrefabs[n]){
                                    unitID=m;
                                    break;
                                }
                            }

                            EditorGUILayout.BeginHorizontal();
                                if(sInfo.spawnQuota==_SpawnQuota.UnitBased){
                                    unitID = EditorGUILayout.IntPopup("   - unit"+n+"(max): ", unitID, unitNameList, intVal,  GUILayout.MaxHeight(13));
                                    sInfo.unitPrefabsMax[n] = EditorGUILayout.IntField(sInfo.unitPrefabsMax[n], GUILayout.MaxWidth(25));
                                }
                                else if(sInfo.spawnQuota==_SpawnQuota.BudgetBased){
                                    unitID = EditorGUILayout.IntPopup("   - unit"+n+"(max): ", unitID, unitNameList, intVal);
                                }
                            EditorGUILayout.EndHorizontal();

                            if(unitID>=0) sInfo.unitPrefabs[n]=unitList[unitID];
                            else sInfo.unitPrefabs[n]=null;
                        }
                    }

                    int totalUnitCount=0;
                    for(int n=0; n<sInfo.unitPrefabsMax.Length; n++) totalUnitCount+=sInfo.unitPrefabsMax[n];

                    sInfo.unitCount=Mathf.Min(totalUnitCount, sInfo.unitCount);

                    cont=new GUIContent("Remove area", "remove this spawn area");
                    if(GUILayout.Button(cont)){
                        fac.spawnInfo.Remove(sInfo);
                    }

                    EditorGUILayout.EndVertical();
                }

                GUILayout.EndVertical();
                GUILayout.Space (10);
                GUILayout.EndHorizontal ();

                GUILayout.Space (5);
                if(GUILayout.Button("Remove Faction")){
                    gm.factionList.Remove(fac);
                }
                GUILayout.Space (5);

                EditorGUILayout.EndVertical();

                GUILayout.Space (5);
            }
            GUILayout.Space (10);
            GUILayout.EndVertical();
            //~ GUILayout.Space (5);
            GUILayout.EndHorizontal ();
        }

        EditorGUILayout.Space();
            cont=new GUIContent("Generate Grid", "Procedurally generate a new grid with the configured setting\nPlease note that generate a large map (30x30 and above) might take a while");
            if(GUILayout.Button(cont)) GenerateGrid();

            cont=new GUIContent("Generate Unit", "Procedurally place unit on the grid with the configured setting");
            if(GUILayout.Button(cont)) GenerateUnit();

            //~ if(GUILayout.Button("testGenerate")) TestGenerate();
            //~ if(GUILayout.Button("testDestroy")) TestDestroy();
        EditorGUILayout.Space();

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