Exemple #1
0
 public static void OnFinishedCardChoice()
 {
     if (!FactionManager.RequireManualUnitDeployment())
     {
         StartGame();
     }
     else
     {
         instance.StartCoroutine(instance.DelayUnitDeployment(0.25f));
     }
 }
Exemple #2
0
 public void OnAutoNCompleteButton()
 {
     if (FactionManager.IsDeploymentComplete())
     {
         _Hide();
     }
     else
     {
         FactionManager.AutoDeployCurrentFaction();
     }
 }
Exemple #3
0
 private void ResetTurnCounter()
 {
     if (TurnControl.GetTurnMode() == _TurnMode.UnitPerTurn)
     {
         turnCounter = FactionManager.GetTotalUnitCount();
     }
     else
     {
         turnCounter = FactionManager.GetTotalFactionCount();
     }
 }
Exemple #4
0
        public void OnButton(GameObject butObj, int pointerID = -1)
        {
            int prevID = FactionManager.GetDeployingUnitID();

            buttonList[prevID].imgHighlight.enabled = false;

            int ID = GetButtonID(butObj);

            buttonList[ID].imgHighlight.enabled = true;

            FactionManager.SetDeployingUnitID(ID);
        }
Exemple #5
0
 public void _StartGame()
 {
     if (turnMode == _TurnMode.FactionPerTurn && moveOrder != _MoveOrder.Free)
     {
         FactionManager.EndTurn_FactionPerTurn();
         TBTK.OnNewTurn(IsPlayerTurn());
     }
     else
     {
         EndTurn();
     }
 }
Exemple #6
0
		public static void SetupHostileInRangeforTile(Unit unit, List<Tile> tileList){
			List<Unit> allUnitList=FactionManager.GetAllUnit();
			List<Unit> allHostileUnitList=new List<Unit>();
			for(int i=0; i<allUnitList.Count; i++){
				if(allUnitList[i].factionID!=unit.factionID) allHostileUnitList.Add(allUnitList[i]);
			}
			
			List<Unit> allFriendlyUnitList=new List<Unit>();
			if(GameControl.EnableFogOfWar()) allFriendlyUnitList=FactionManager.GetAllUnitsOfFaction(unit.factionID);
			
			int range=unit.GetAttackRange();
			int rangeMin=unit.GetAttackRangeMin();
			int sight=unit.GetSight();
			
			for(int i=0; i<tileList.Count; i++){
				Tile srcTile=tileList[i];
				List<Tile> hostileInRangeList=new List<Tile>();
				
				for(int j=0; j<allHostileUnitList.Count; j++){
					Tile targetTile=allHostileUnitList[j].tile;
					
					if(GridManager.GetDistance(srcTile, targetTile)>range) continue;
					if(GridManager.GetDistance(srcTile, targetTile)<rangeMin) continue;
					
					if(!GameControl.EnableFogOfWar() && !GameControl.AttackThroughObstacle()){
						if(!FogOfWar.InLOS(srcTile, targetTile, 0)) continue;
					}
					
					bool inSight=GameControl.EnableFogOfWar() ? false : true;
					if(GameControl.EnableFogOfWar()){
						if(FogOfWar.InLOS(srcTile, targetTile) && GridManager.GetDistance(srcTile, targetTile)<=sight){
							inSight=true;
						}
						else if(!unit.requireDirectLOSToAttack){
							for(int n=0; n<allFriendlyUnitList.Count; n++){
								if(allFriendlyUnitList[n]==unit) continue;
								if(GridManager.GetDistance(allFriendlyUnitList[n].tile, targetTile)>allFriendlyUnitList[n].GetSight()) continue;
								if(FogOfWar.InLOS(allFriendlyUnitList[n].tile, targetTile)){
									inSight=true;
									break;
								}
							}
						}
					}
					
					if(inSight) hostileInRangeList.Add(targetTile);
					
				}
				
				tileList[i].SetHostileInRange(hostileInRangeList);
			}
		}
Exemple #7
0
        void OnGameOver(int factionID)
        {
            bool playerWon = FactionManager.IsPlayerFaction(factionID);

            if (playerWon && gameWonSound != null)
            {
                _PlaySound(gameWonSound);
            }
            else if (!playerWon && gameLostSound != null)
            {
                _PlaySound(gameLostSound);
            }
        }
Exemple #8
0
        IEnumerator DelayHide()
        {
            yield return(new WaitForSeconds(0.35f));

            canvasGroup.interactable   = false;
            canvasGroup.blocksRaycasts = false;

            yield return(new WaitForSeconds(0.5f));

            thisObj.SetActive(false);

            FactionManager.CompleteDeployment();
        }
Exemple #9
0
        void Awake()
        {
            instance = (GameControl)target;
            LoadDB();

            turnControl        = (TurnControl)FindObjectOfType(typeof(TurnControl));
            gridManager        = (GridManager)FindObjectOfType(typeof(GridManager));
            factionManager     = (FactionManager)FindObjectOfType(typeof(FactionManager));
            collectibleManager = (CollectibleManager)FindObjectOfType(typeof(CollectibleManager));
            settingDB          = SettingDB.LoadDB();

            InitLabel();
        }
Exemple #10
0
        void Awake()
        {
            instance = (GridManager)target;
            instance.SetInstance();

            //factionManager = (FactionManager)FindObjectOfType(typeof(FactionManager));
            factionManager     = FactionManager.SetInstance();
            collectibleManager = CollectibleManager.SetInstance();

            LoadDB();

            InitLabel();
        }
Exemple #11
0
        public static void Load(string levelName)
        {
            //so that the factionData can be set even if the game is not over (lost unit remain lost)
            if (gamePhase != _GamePhase.Over)
            {
                FactionManager.GameOver();
            }

                        #if UNITY_5_3_OR_NEWER
            SceneManager.LoadScene(levelName);
                        #else
            Application.LoadLevel(levelName);
                        #endif
        }
        public static void Init(FactionManager facManager = null)
        {
            // Get existing open window or if none, make a new one:
            window         = (NewFactionManagerEditorWindow)EditorWindow.GetWindow(typeof(NewFactionManagerEditorWindow), false, "FactionManager Editor");
            window.minSize = new Vector2(420, 300);

            LoadDB();

            InitLabel();

            if (facManager != null)
            {
                instance = facManager;
            }
        }
Exemple #13
0
		public void _OnTile(Tile tile){
			if(!FactionManager.IsPlayerTurn()) return;
			
			if(tile.unit!=null){
				if(attackableTileList.Contains(tile)) GameControl.GetSelectedUnit().Attack(tile.unit);
				else GameControl.SelectUnit(tile.unit);
			}
			//if the tile is within the move range of current selected unit, move to it
			else if(walkableTileList.Contains(tile)){
				ClearWalkableHostileList();	//in case the unit move into the destination and has insufficient ap to attack
				GameControl.GetSelectedUnit().Move(tile);
			}
			
			ClearHoveredTile();	//clear the hovered tile so all the UI overlay will be cleared
		}
        //public static void AbilityTargetSelected(Tile tile){ instance._AbilityTargetSelected(tile); }
        public void AbilityTargetSelected(Tile tile)
        {
            if (targetModeTileList.Count > 0 && !targetModeTileList.Contains(tile))
            {
                GameControl.DisplayMessage("Out of Range");
                return;
            }

            bool invalidFlag = false;

            if (targetModeType == _TargetType.AllUnit)
            {
                invalidFlag = (tile.unit == null);
            }
            else if (targetModeType == _TargetType.HostileUnit)
            {
                int currentFacID = FactionManager.GetSelectedFactionID();
                invalidFlag = (tile.unit == null || tile.unit.factionID == currentFacID);
            }
            else if (targetModeType == _TargetType.FriendlyUnit)
            {
                int currentFacID = FactionManager.GetSelectedFactionID();
                invalidFlag = (tile.unit == null || tile.unit.factionID != currentFacID);
            }
            else if (targetModeType == _TargetType.EmptyTile)
            {
                invalidFlag = (tile.unit != null || !tile.walkable);
            }
            else if (targetModeType == _TargetType.AllTile)
            {
            }

            if (invalidFlag)
            {
                GameControl.DisplayMessage("Invalid target");
            }
            else
            {
                if (targetSelectedCallBack != null)
                {
                    targetSelectedCallBack(tile, abilityIndex);
                }

                TBTK.OnAbilityActivated();

                ExitAbilityTargetMode();
            }
        }
        //used to check if AI faction can see a given tile
        public static bool IsTileVisibleToFaction(Tile tile, int factionID)
        {
            List <Unit> unitList = FactionManager.GetAllUnitsOfFaction(factionID);

            for (int i = 0; i < unitList.Count; i++)
            {
                if (GridManager.GetDistance(tile, unitList[i].tile) <= unitList[i].GetSight())               //return true;
                {
                    if (InLOS(tile, unitList[i].tile))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        //check a tile visiblility to player's faction
        public static bool CheckTileVisibility(Tile tile)
        {
            List <Unit> unitList = FactionManager.GetAllPlayerUnits();

            for (int i = 0; i < unitList.Count; i++)
            {
                if (GridManager.GetDistance(tile, unitList[i].tile) <= unitList[i].GetSight())               //return true;
                //if(InLOS(tile, unitList[i].tile, true)) return true;		//for showing LOS cast
                {
                    if (InLOS(tile, unitList[i].tile))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #17
0
        public static void GameOver(int factionID)
        {
            if (FactionManager.IsPlayerFaction(factionID))
            {
                PerkManager.GainPerkCurrencyOnVictory();
            }

            //if(onGameMessageE!=null) onGameMessageE("GameOver");
            TBTK.OnGameMessage("GameOver");

            gamePhase = _GamePhase.Over;

            FactionManager.GameOver();

            //if(onGameOverE!=null) onGameOverE(factionID);
            TBTK.OnGameOver(factionID);
        }
Exemple #18
0
        public IEnumerator _EndTurn()
        {
            if (GameControl.GetGamePhase() == _GamePhase.Over)
            {
                yield break;
            }

            yield return(new WaitForSeconds(0.2f));

            currentTurnID += 1;

            if (turnMode == _TurnMode.FactionPerTurn)
            {
                if (moveOrder == _MoveOrder.Free)
                {
                    FactionManager.EndTurn_FactionPerTurn();
                }
                else
                {
                    if (FactionManager.SelectNextUnitInFaction_NotFree())
                    {
                        TBTK.OnNewTurn(IsPlayerTurn());
                        yield break;
                    }
                    else
                    {
                        FactionManager.EndTurn_FactionPerTurn();
                    }
                }
            }
            else if (turnMode == _TurnMode.FactionUnitPerTurn)
            {
                CheckPlayerMoveFlag(false);
                FactionManager.EndTurn_FactionUnitPerTurn();
            }

            IterateEndTurn();
            if (turnMode == _TurnMode.UnitPerTurn)
            {
                FactionManager.EndTurn_UnitPerTurn();
            }


            TBTK.OnNewTurn(IsPlayerTurn());
        }
Exemple #19
0
		public void _OnTileAlt(Tile tile){
			if(!FactionManager.IsPlayerTurn()) return;
			
			//change the unit facing
			/*
			if(GameControl.selectedUnit!=null){
				if(tile==GameControl.selectedUnit.tile) return;
				
				float x=GameControl.selectedUnit.tile.GetPos().x-tile.GetPos().x;
				float z=GameControl.selectedUnit.tile.GetPos().z-tile.GetPos().z;
				Vector2 dir=new Vector2(x, z);
				
				float angle=Utilities.Vector2ToAngle(dir);
				
				GameControl.selectedUnit.Rotate(Quaternion.Euler(0, 360-angle-90, 0));
			}
			*/
		}
Exemple #20
0
        //call by unit when all action is depleted
        public static void SelectedUnitMoveDepleted()
        {
            if (GameControl.GetGamePhase() == _GamePhase.Over)
            {
                return;
            }

            if (instance.turnMode == _TurnMode.FactionPerTurn)
            {
                //if not in free move order, cant switch to next unit without end turn
                if (instance.moveOrder != _MoveOrder.Free)
                {
                    TBTK.OnAllUnitOutOfMove();
                    if (GameControl.GetSelectedUnit().HP <= 0)
                    {
                        instance.StartCoroutine(instance.AutoEndTurn());
                    }
                }
                else
                {
                    if (!FactionManager.SelectNextUnitInFaction_Free())
                    {
                        TBTK.OnAllUnitOutOfMove();
                    }
                }
            }
            else if (instance.turnMode == _TurnMode.FactionUnitPerTurn)
            {
                TBTK.OnAllUnitOutOfMove();
                if (GameControl.GetSelectedUnit().HP <= 0)
                {
                    instance.StartCoroutine(instance.AutoEndTurn());
                }
            }
            else if (instance.turnMode == _TurnMode.UnitPerTurn)
            {
                TBTK.OnAllUnitOutOfMove();
                if (GameControl.GetSelectedUnit().HP <= 0)
                {
                    instance.StartCoroutine(instance.AutoEndTurn());
                }
            }
        }
        public static void InitGrid(List <Tile> tileList)
        {
            if (!GameControl.EnableFogOfWar())
            {
                return;
            }

            for (int i = 0; i < tileList.Count; i++)
            {
                tileList[i].SetVisible(false);
            }

            List <Unit> unitList = FactionManager.GetAllPlayerUnits();

            for (int i = 0; i < unitList.Count; i++)
            {
                unitList[i].SetupFogOfWar(true);
            }
        }
Exemple #22
0
        public void _Show(int winningFactionID)
        {
            canvasGroup.interactable   = true;
            canvasGroup.blocksRaycasts = true;

            if (FactionManager.IsPlayerFaction(winningFactionID))
            {
                lbStatus.text = "Victory!!";
            }
            else
            {
                if (!UIMainControl.ShowContinueButtonWhenLost() && continueButton != null)
                {
                    continueButton.SetActive(false);
                }
            }

            UIMainControl.FadeIn(canvasGroup, 0.25f);
        }
        public void _OnNewTurn(bool flag)
        {
            if (!flag)
            {
                return;
            }

            abilityList = FactionManager.GetCurrentFaction().abilityInfo.abilityList;

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

            for (int i = 0; i < buttonList.Count; i++)
            {
                if (i >= abilityList.Count)
                {
                    buttonList[i].SetActive(false);
                }
                else
                {
                    buttonList[i].imgIcon.sprite      = abilityList[i].icon;
                    buttonList[i].label.text          = abilityList[i].GetUseRemain() > 0 ? abilityList[i].GetUseRemain().ToString() : "∞";
                    buttonList[i].button.interactable = (abilityList[i].IsAvailable() == "");
                    buttonList[i].SetActive(true);
                }
            }

            if (abilityList.Count == 0)
            {
                lineRectT.sizeDelta = new Vector2(0, lineRectT.sizeDelta.y);
            }
            else
            {
                lineRectT.sizeDelta = new Vector2(20 + abilityList.Count * 60, lineRectT.sizeDelta.y);
            }

            UpdateEnergyDisplay();

            _Show();
        }
Exemple #24
0
 public static bool CanSelectUnit(Unit unit)
 {
     if (TurnControl.GetMoveOrder() != _MoveOrder.Free)
     {
         return(false);
     }
     if (TurnControl.GetTurnMode() == _TurnMode.FactionUnitPerTurn && TurnControl.HasMoved())
     {
         return(false);
     }
     if (TurnControl.GetTurnMode() == _TurnMode.UnitPerTurn)
     {
         return(false);
     }
     if (FactionManager.GetSelectedFactionID() != unit.factionID)
     {
         return(false);
     }
     return(true);
 }
Exemple #25
0
        public static void SelectUnit(Unit unit, bool userInitiated = true)
        {
            if (userInitiated && !CanSelectUnit(unit))
            {
                return;
            }

            if (selectedUnit == unit)
            {
                Debug.Log("attempt to select the same unit");
                return;
            }

            selectedUnit = unit;
            GridManager.SelectUnit(unit);
            FactionManager.SelectUnit();

            selectedUnit.PlaySelectAudio();

            TBTK.OnUnitSelected(selectedUnit);
        }
Exemple #26
0
        IEnumerator DelayStartGame(float delay = 0.5f)
        {
            yield return(null);

            FactionManager.SetupFaction();
            GridManager.SetupGridForFogOfWar();
            yield return(null);

            PerkManager.InitPerkProgress();             //initiate prepurchase perk and so on

            if (delay > 0)
            {
                yield return(new WaitForSeconds(delay));
            }

            gamePhase = _GamePhase.Play;
            TurnControl.StartGame();                    //this will initiate unit selection and start the game
            yield return(null);

            //if(onGameStartE!=null) onGameStartE();
            TBTK.OnGameStart();
        }
Exemple #27
0
		public void _OnCursorDown(int cursorID=-1){
			//Debug.Log("_OnCursorDown");
			
			if(hoveredTile==null) return;
			
			if(TBTK.IsCursorOnUI(cursorID)) return;
			
			if(!TurnControl.ClearToProceed()) return;
			
			if(GameControl.GetGamePhase()==_GamePhase.Over) return;
			
			if(GameControl.GetGamePhase()==_GamePhase.UnitDeployment){
				if(hoveredTile.unit==null) FactionManager.DeployUnitOnTile(hoveredTile);
				else if(hoveredTile.unit!=null) FactionManager.UndeployUnit(hoveredTile.unit);
				return;
			}
			
			if(AbilityManager.InTargetMode()){
				Debug.Log("AbilityTargetSelected");
				targetModeTargetSelected(hoveredTile);
			}
			else OnTile(hoveredTile);
		}
Exemple #28
0
        public override void OnInspectorGUI()
        {
            EditorGUIUtility.labelWidth = 150;

            base.OnInspectorGUI();

            GUI.changed = false;
            Undo.RecordObject(instance, "GameControl");
            Undo.RecordObject(turnControl, "TurnControl");
            Undo.RecordObject(gridManager, "GridManager");
            Undo.RecordObject(factionManager, "FactionManager");
            Undo.RecordObject(settingDB, "SettingDB");


            EditorGUILayout.Space();

            cont = new GUIContent("Use Global Setting:", "Check to use a global setting. This setting will be used for all the scene in the project that have this flag checked");
            instance.useGlobalSetting = EditorGUILayout.Toggle(cont, instance.useGlobalSetting);

            EditorGUILayout.LabelField("_____________________________________________________________________________________");
            EditorGUILayout.Space();


            if (instance.useGlobalSetting)
            {
                EditorGUIUtility.labelWidth = 180;

                if (gridManager == null)
                {
                    EditorGUILayout.HelpBox("There's no GridManager in the scene", MessageType.Warning);
                }
                if (factionManager == null)
                {
                    EditorGUILayout.HelpBox("There's no FactionManager in the scene", MessageType.Warning);
                }

                cont = new GUIContent("Generate Grid On Start:", "Check to regenerate grid upon game start, any preset (including units) on the grid will be override");
                settingDB.generateGridOnStart = EditorGUILayout.Toggle(cont, settingDB.generateGridOnStart);

                cont = new GUIContent("Generate Unit On Start:", "Check to regenerate unit upon game start, any existing unit on the grid will be removed");
                settingDB.generateUnitOnStart = EditorGUILayout.Toggle(cont, settingDB.generateUnitOnStart);

                cont = new GUIContent("Generate Collectible On Start:", "Check to regenerate collectibles upon game start, any existing collectibles on the grid will be removed");
                settingDB.generateCollectibleOnStart = EditorGUILayout.Toggle(cont, settingDB.generateCollectibleOnStart);

                EditorGUIUtility.labelWidth = 150;

                EditorGUILayout.Space();

                int turnMode = (int)settingDB.turnMode;
                cont  = new GUIContent("Turn Mode:", "The turn logic to be used. Determine how each faction takes turn");
                contL = new GUIContent[turnModeLabel.Length];
                for (int i = 0; i < contL.Length; i++)
                {
                    contL[i] = new GUIContent(turnModeLabel[i], turnModeTooltip[i]);
                }
                turnMode           = EditorGUILayout.Popup(cont, turnMode, contL);
                settingDB.turnMode = (_TurnMode)turnMode;

                if (turnControl.turnMode != _TurnMode.UnitPerTurn)
                {
                    int moveOrder = (int)settingDB.moveOrder;
                    cont  = new GUIContent("Move Order:", "The move order to be used. Determine which unit gets to move first");
                    contL = new GUIContent[moveOrderLabel.Length];
                    for (int i = 0; i < contL.Length; i++)
                    {
                        contL[i] = new GUIContent(moveOrderLabel[i], moveOrderTooltip[i]);
                    }
                    moveOrder           = EditorGUILayout.Popup(cont, moveOrder, contL);
                    settingDB.moveOrder = (_MoveOrder)moveOrder;
                }
                else
                {
                    cont = new GUIContent("Move Order:", "The move order to be used. Determine which unit gets to move first");
                    EditorGUILayout.LabelField(cont, new GUIContent("N/A"));
                }

                EditorGUILayout.Space();

                cont = new GUIContent("Enable Unit Deployment:", "Check to enable player to manually deploy their predetermined starting unit, otherwise they will be deployed automatically");
                settingDB.enableManualUnitDeployment = EditorGUILayout.Toggle(cont, settingDB.enableManualUnitDeployment);

                EditorGUILayout.Space();

                cont = new GUIContent("Enable ActionAfterAttack:", "Check to enable unit to perform other action after attacking a target");
                settingDB.enableActionAfterAttack = EditorGUILayout.Toggle(cont, settingDB.enableActionAfterAttack);

                cont = new GUIContent("Enable CounterAttack:", "Check to enable unit to counter attack when attacked. The counter is subject to the unit attack range, counter move remain, AP, etc.");
                settingDB.enableCounter = EditorGUILayout.Toggle(cont, settingDB.enableCounter);

                cont = new GUIContent(" - Damage Multiplier:", "Multiplier to damage inflicted when the unit are attacking via a counter attack move. Takes value from 0 and above with 0.6 being 60% of the default damage");
                if (settingDB.enableCounter)
                {
                    settingDB.counterDamageMultiplier = EditorGUILayout.FloatField(cont, settingDB.counterDamageMultiplier);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                cont = new GUIContent(" - Counter AP Multiplier:", "Multiplier to attack AP cost when the unit are attacking via a counter attack move. Takes value from 0 and above with 0.7 being 70% of the default AP cost");
                if (settingDB.enableCounter && settingDB.useAPForAttack)
                {
                    settingDB.counterAPMultiplier = EditorGUILayout.FloatField(cont, settingDB.counterAPMultiplier);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                EditorGUILayout.Space();

                cont = new GUIContent("Restore Unit AP on Turn:", "Check to have unit's AP restored to full on each turn");
                settingDB.restoreUnitAPOnTurn = EditorGUILayout.Toggle(cont, settingDB.restoreUnitAPOnTurn);

                cont = new GUIContent("Use AP For Move:", "Check to have unit use AP for each move");
                settingDB.useAPForMove = EditorGUILayout.Toggle(cont, settingDB.useAPForMove);

                cont = new GUIContent("Use AP For Attack:", "Check to have unit use AP for each attack");
                settingDB.useAPForAttack = EditorGUILayout.Toggle(cont, settingDB.useAPForAttack);

                EditorGUILayout.Space();

                cont = new GUIContent("Attack Through Obstacle:", "Check to enable unit to attack through obstacle.\nOnly applies when Fog-of-War is disabled\n\nNote: only obstacle wth full cover can obstruct an attack. Unit can always attack through obstacle with half cover");
                if (settingDB.enableFogOfWar)
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }
                else
                {
                    settingDB.attackThroughObstacle = EditorGUILayout.Toggle(cont, settingDB.attackThroughObstacle);
                }

                EditorGUILayout.Space();

                cont = new GUIContent("Overwatch Hit Penalty:", "Hit chance penalty for any overwatch attack.\nTakes value from 0-1 with 0.2 being 20% reduction in hit chance");
                settingDB.overwatchHitPenalty = EditorGUILayout.FloatField(cont, settingDB.overwatchHitPenalty);

                cont = new GUIContent("Overwatch Crit Penalty:", "Crit chance penalty for any overwatch attack.\nTakes value from 0-1 with 0.2 being 20% reduction in critical chance");
                settingDB.overwatchCritPenalty = EditorGUILayout.FloatField(cont, settingDB.overwatchCritPenalty);

                EditorGUILayout.Space();

                cont = new GUIContent("Enable Fog-Of-War:", "Check to enable Fog-of-War in the game");
                settingDB.enableFogOfWar = EditorGUILayout.Toggle(cont, settingDB.enableFogOfWar);

                cont = new GUIContent(" - Peek Factor:", "A value indicate if the units can peek around a obstacle to see what's on the other end.\nTakes value from 0-0.5\nWhen set to 0, unit cannot peek at all (can only see 45degree from the obstacle)\nWhen set to 0.5, unit can peek and will be able to see what's behind the obstacle");
                if (settingDB.enableFogOfWar)
                {
                    settingDB.peekFactor = EditorGUILayout.FloatField(cont, settingDB.peekFactor);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                EditorGUILayout.Space();

                cont = new GUIContent("Enable Cover System:", "Check to enable cover system in the game. Unit will get a hit penalty when attacking target behind a wall/obstacle (in cover) as well as getting a critical bonus when attacking a target not in cover.");
                settingDB.enableCover = EditorGUILayout.Toggle(cont, settingDB.enableCover);

                cont = new GUIContent(" - Effective Angle:", "The maximum angle from the attacking unit to target's cover facing for the cover to have effect. Anything beyond the angle, the target is considered not in covered");
                if (settingDB.enableCover)
                {
                    settingDB.effectiveCoverAngle = EditorGUILayout.IntField(cont, settingDB.effectiveCoverAngle);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                cont = new GUIContent(" - Exposed Critical Bonus:", "The citical chance bonus for attacking a unit not in cover. Value is used to modify the critical chance directly. ie. 0.25 means 25% increase in critical chance");
                if (settingDB.enableCover)
                {
                    settingDB.exposedCritBonus = EditorGUILayout.FloatField(cont, settingDB.exposedCritBonus);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                cont = new GUIContent(" - Full Cover Bonus:", "The dodge bonus for unit attacked from behind a 'full' cover. Value is used to modify the unit dodge directly. ie. 0.25 means 25% increase in dodge chance");
                if (settingDB.enableCover)
                {
                    settingDB.fullCoverBonus = EditorGUILayout.FloatField(cont, settingDB.fullCoverBonus);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                cont = new GUIContent(" - Half Cover Bonus:", "The dodge bonus for unit attacked from behind a 'half' cover. Value is used to modify the unit dodge directly. ie. 0.25 means 25% increase in dodge chance");
                if (settingDB.enableCover)
                {
                    settingDB.halfCoverBonus = EditorGUILayout.FloatField(cont, settingDB.halfCoverBonus);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                EditorGUILayout.Space();

                cont = new GUIContent("Enable Flanking:", "Check to enable flanking, unit will get a damage bonus when attacking a target from the rear");
                settingDB.enableFlanking = EditorGUILayout.Toggle(cont, settingDB.enableFlanking);

                cont = new GUIContent(" - Flanking Angle:", "The angle at which the target will be considered flanked. This angle origin from target's front. ie, when set to 80, the target is considered flanked when attacked from the side");
                if (settingDB.enableFlanking)
                {
                    settingDB.flankingAngle = EditorGUILayout.FloatField(cont, settingDB.flankingAngle);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                cont = new GUIContent(" - Flanking Bonus:", "The damage multiplier to be applied to the damage. Takes value from 0 and above with 0.2 being increase damage by 20%");
                if (settingDB.enableFlanking)
                {
                    instance.flankingBonus = EditorGUILayout.FloatField(cont, settingDB.flankingBonus);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                EditorGUILayout.Space();

                cont = new GUIContent("Enable Action Cam:", "Check to enable dynamic action camera for attack and ability casting. Note that this is still subject to the frequency of each event");
                settingDB.enableActionCam = EditorGUILayout.Toggle(cont, settingDB.enableActionCam);

                cont = new GUIContent(" - Attack Frequency:", "The chance at which action camera will trigger when a unit is attacking. Takes value from 0-1 with 0.2 being 20% chance to trigger.");
                if (settingDB.enableActionCam)
                {
                    settingDB.actionCamFreqAttack = EditorGUILayout.FloatField(cont, settingDB.actionCamFreqAttack);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                cont = new GUIContent(" - Ability Frequency:", "The chance at which action camera will trigger when a unit is casting an ability. Takes value from 0-1 with 0.2 being 20% chance to trigger.");
                if (settingDB.enableActionCam)
                {
                    settingDB.actionCamFreqAbility = EditorGUILayout.FloatField(cont, settingDB.actionCamFreqAbility);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }
            }
            else
            {
                EditorGUIUtility.labelWidth = 180;

                if (gridManager != null)
                {
                    cont = new GUIContent("Generate Grid On Start:", "Check to regenerate grid upon game start, any preset (including units) on the grid will be override");
                    gridManager.generateGridOnStart = EditorGUILayout.Toggle(cont, gridManager.generateGridOnStart);
                }
                else
                {
                    EditorGUILayout.HelpBox("There's no GridManager in the scene", MessageType.Warning);
                }

                if (factionManager != null)
                {
                    cont = new GUIContent("Generate Unit On Start:", "Check to regenerate unit upon game start, any existing unit on the grid will be removed");
                    factionManager.generateUnitOnStart = EditorGUILayout.Toggle(cont, factionManager.generateUnitOnStart);
                }
                else
                {
                    EditorGUILayout.HelpBox("There's no FactionManager in the scene", MessageType.Warning);
                }

                if (collectibleManager != null)
                {
                    cont = new GUIContent("Generate Collectible On Start:", "Check to regenerate collectibles upon game start, any existing collectibles on the grid will be removed");
                    collectibleManager.generateCollectibleOnStart = EditorGUILayout.Toggle(cont, collectibleManager.generateCollectibleOnStart);
                }
                else
                {
                    EditorGUILayout.HelpBox("There's no CollectibleManager in the scene", MessageType.Warning);
                }

                EditorGUIUtility.labelWidth = 150;

                EditorGUILayout.Space();

                int turnMode = (int)turnControl.turnMode;
                cont  = new GUIContent("Turn Mode:", "The turn logic to be used. Determine how each faction takes turn");
                contL = new GUIContent[turnModeLabel.Length];
                for (int i = 0; i < contL.Length; i++)
                {
                    contL[i] = new GUIContent(turnModeLabel[i], turnModeTooltip[i]);
                }
                turnMode             = EditorGUILayout.Popup(cont, turnMode, contL);
                turnControl.turnMode = (_TurnMode)turnMode;

                if (turnControl.turnMode != _TurnMode.UnitPerTurn)
                {
                    int moveOrder = (int)turnControl.moveOrder;
                    cont  = new GUIContent("Move Order:", "The move order to be used. Determine which unit gets to move first");
                    contL = new GUIContent[moveOrderLabel.Length];
                    for (int i = 0; i < contL.Length; i++)
                    {
                        contL[i] = new GUIContent(moveOrderLabel[i], moveOrderTooltip[i]);
                    }
                    moveOrder             = EditorGUILayout.Popup(cont, moveOrder, contL);
                    turnControl.moveOrder = (_MoveOrder)moveOrder;
                }
                else
                {
                    cont = new GUIContent("Move Order:", "The move order to be used. Determine which unit gets to move first");
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                EditorGUILayout.Space();

                cont = new GUIContent("Enable Unit Deployment:", "Check to enable player to manually deploy their predetermined starting unit, otherwise they will be deployed automatically");
                instance.enableManualUnitDeployment = EditorGUILayout.Toggle(cont, instance.enableManualUnitDeployment);

                EditorGUILayout.Space();

                cont = new GUIContent("Enable ActionAfterAttack:", "Check to enable unit to perform other action after attacking a target");
                instance.enableActionAfterAttack = EditorGUILayout.Toggle(cont, instance.enableActionAfterAttack);

                cont = new GUIContent("Enable CounterAttack:", "Check to enable unit to counter attack when attacked. The counter is subject to the unit attack range, counter move remain, AP, etc.");
                instance.enableCounter = EditorGUILayout.Toggle(cont, instance.enableCounter);

                cont = new GUIContent(" - Damage Multiplier:", "Multiplier to damage inflicted when the unit are attacking via a counter attack move. Takes value from 0 and above with 0.6 being 60% of the default damage");
                if (instance.enableCounter)
                {
                    instance.counterDamageMultiplier = EditorGUILayout.FloatField(cont, instance.counterDamageMultiplier);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                cont = new GUIContent(" - Counter AP Multiplier:", "Multiplier to attack AP cost when the unit are attacking via a counter attack move. Takes value from 0 and above with 0.7 being 70% of the default AP cost");
                if (instance.enableCounter && instance.useAPForAttack)
                {
                    instance.counterAPMultiplier = EditorGUILayout.FloatField(cont, instance.counterAPMultiplier);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                EditorGUILayout.Space();

                cont = new GUIContent("Restore Unit AP on Turn:", "Check to have unit's AP restored to full on each turn");
                instance.restoreUnitAPOnTurn = EditorGUILayout.Toggle(cont, instance.restoreUnitAPOnTurn);

                cont = new GUIContent("Use AP For Move:", "Check to have unit use AP for each move");
                instance.useAPForMove = EditorGUILayout.Toggle(cont, instance.useAPForMove);

                cont = new GUIContent("Use AP For Attack:", "Check to have unit use AP for each attack");
                instance.useAPForAttack = EditorGUILayout.Toggle(cont, instance.useAPForAttack);

                EditorGUILayout.Space();

                cont = new GUIContent("Attack Through Obstacle:", "Check to enable unit to attack through obstacle.\nOnly applies when Fog-of-War is disabled\n\nNote: only obstacle wth full cover can obstruct an attack. Unit can always attack through obstacle with half cover");
                if (instance.enableFogOfWar)
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }
                else
                {
                    instance.attackThroughObstacle = EditorGUILayout.Toggle(cont, instance.attackThroughObstacle);
                }

                EditorGUILayout.Space();

                cont = new GUIContent("Overwatch Hit Penalty:", "Hit chance penalty for any overwatch attack.\nTakes value from 0-1 with 0.2 being 20% reduction in hit chance");
                instance.overwatchHitPenalty = EditorGUILayout.FloatField(cont, instance.overwatchHitPenalty);

                cont = new GUIContent("Overwatch Crit Penalty:", "Crit chance penalty for any overwatch attack.\nTakes value from 0-1 with 0.2 being 20% reduction in critical chance");
                instance.overwatchCritPenalty = EditorGUILayout.FloatField(cont, instance.overwatchCritPenalty);

                EditorGUILayout.Space();

                cont = new GUIContent("Enable Fog-Of-War:", "Check to enable Fog-of-War in the game");
                instance.enableFogOfWar = EditorGUILayout.Toggle(cont, instance.enableFogOfWar);

                cont = new GUIContent(" - Peek Factor:", "A value indicate if the units can peek around a obstacle to see what's on the other end.\nTakes value from 0-0.5\nWhen set to 0, unit cannot peek at all (can only see 45degree from the obstacle)\nWhen set to 0.5, unit can peek and will be able to see what's behind the obstacle");
                if (instance.enableFogOfWar)
                {
                    instance.peekFactor = EditorGUILayout.FloatField(cont, instance.peekFactor);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                EditorGUILayout.Space();

                cont = new GUIContent("Enable Cover System:", "Check to enable cover system in the game. Unit will get a hit penalty when attacking target behind a wall/obstacle (in cover) as well as getting a critical bonus when attacking a target not in cover.");
                instance.enableCover = EditorGUILayout.Toggle(cont, instance.enableCover);

                cont = new GUIContent(" - Effective Angle:", "The maximum angle from the attacking unit to target's cover facing for the cover to have effect. Anything beyond the angle, the target is considered not in covered");
                if (instance.enableCover)
                {
                    instance.effectiveCoverAngle = EditorGUILayout.IntField(cont, instance.effectiveCoverAngle);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                cont = new GUIContent(" - Exposed Critical Bonus:", "The citical chance bonus for attacking a unit not in cover. Value is used to modify the critical chance directly. ie. 0.25 means 25% increase in critical chance");
                if (instance.enableCover)
                {
                    instance.exposedCritBonus = EditorGUILayout.FloatField(cont, instance.exposedCritBonus);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                cont = new GUIContent(" - Full Cover Bonus:", "The dodge bonus for unit attacked from behind a 'full' cover. Value is used to modify the unit dodge directly. ie. 0.25 means 25% increase in dodge chance");
                if (instance.enableCover)
                {
                    instance.fullCoverBonus = EditorGUILayout.FloatField(cont, instance.fullCoverBonus);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                cont = new GUIContent(" - Half Cover Bonus:", "The dodge bonus for unit attacked from behind a 'half' cover. Value is used to modify the unit dodge directly. ie. 0.25 means 25% increase in dodge chance");
                if (instance.enableCover)
                {
                    instance.halfCoverBonus = EditorGUILayout.FloatField(cont, instance.halfCoverBonus);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                EditorGUILayout.Space();

                cont = new GUIContent("Enable Flanking:", "Check to enable flanking, unit will get a damage bonus when attacking a target from the rear");
                instance.enableFlanking = EditorGUILayout.Toggle(cont, instance.enableFlanking);

                cont = new GUIContent(" - Flanking Angle:", "The angle at which the target will be considered flanked. This angle origin from target's front. ie, when set to 80, the target is considered flanked when attacked from the side");
                if (instance.enableFlanking)
                {
                    instance.flankingAngle = EditorGUILayout.FloatField(cont, instance.flankingAngle);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                cont = new GUIContent(" - Flanking Bonus:", "The damage multiplier to be applied to the damage. Takes value from 0 and above with 0.2 being increase damage by 20%");
                if (instance.enableFlanking)
                {
                    instance.flankingBonus = EditorGUILayout.FloatField(cont, instance.flankingBonus);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                EditorGUILayout.Space();

                cont = new GUIContent("Enable Action Cam:", "Check to enable dynamic action camera for attack and ability casting. Note that this is still subject to the frequency of each event");
                instance.enableActionCam = EditorGUILayout.Toggle(cont, instance.enableActionCam);

                cont = new GUIContent(" - Attack Frequency:", "The chance at which action camera will trigger when a unit is attacking. Takes value from 0-1 with 0.2 being 20% chance to trigger.");
                if (instance.enableActionCam)
                {
                    instance.actionCamFreqAttack = EditorGUILayout.FloatField(cont, instance.actionCamFreqAttack);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }

                cont = new GUIContent(" - Ability Frequency:", "The chance at which action camera will trigger when a unit is casting an ability. Takes value from 0-1 with 0.2 being 20% chance to trigger.");
                if (instance.enableActionCam)
                {
                    instance.actionCamFreqAbility = EditorGUILayout.FloatField(cont, instance.actionCamFreqAbility);
                }
                else
                {
                    EditorGUILayout.LabelField(cont, new GUIContent("-"));
                }
            }


            EditorGUILayout.LabelField("_____________________________________________________________________________________");
            EditorGUILayout.Space();


            EditorGUIUtility.labelWidth = 120;
            cont = new GUIContent("Next Scene Name:", "Scene's name to be loaded when this level is completed");
            instance.nextScene = EditorGUILayout.TextField(cont, instance.nextScene);
            cont = new GUIContent("Main Menu Name:", "Scene's name of the main menu to be loaded when return to menu on UI is called");
            instance.mainMenu = EditorGUILayout.TextField(cont, instance.mainMenu);


            EditorGUILayout.LabelField("_____________________________________________________________________________________");
            EditorGUILayout.Space();

            if (!Application.isPlaying)
            {
                if (gridManager != null)
                {
                    if (GUILayout.Button("Generate Grid", GUILayout.MaxWidth(258)))
                    {
                        gridManager.GenerateGrid();
                    }
                }
                if (factionManager != null)
                {
                    if (GUILayout.Button("Generate Unit", GUILayout.MaxWidth(258)))
                    {
                        FactionManager.GenerateUnit();
                    }
                }
            }


            EditorGUILayout.Space();



            EditorGUILayout.Space();

            DefaultInspector();


            if (GUI.changed)
            {
                EditorUtility.SetDirty(instance);
                EditorUtility.SetDirty(turnControl);
                EditorUtility.SetDirty(gridManager);
                EditorUtility.SetDirty(factionManager);
                EditorUtility.SetDirty(settingDB);
            }
        }
 private bool GetFactionManager()
 {
     instance = (FactionManager)FindObjectOfType(typeof(FactionManager));
     return(instance == null ? false : true);
 }
		//called by GameControl to initiate the factions, 
		//load from data when needed, spawn the startingUnit, initiate the unit (abillities), check if unit deployment is required....
		public void Init(){
			if(instance==null) instance=this;
			
			if(generateUnitOnStart) GenerateUnit();
			
			//setup all the unit in the game
			for(int i=0; i<factionList.Count; i++){
				for(int n=0; n<factionList[i].allUnitList.Count; n++){
					if(factionList[i].allUnitList[n]==null){ factionList[i].allUnitList.RemoveAt(n);	n--; continue; }
					factionList[i].allUnitList[n].InitUnitAbility();
					factionList[i].allUnitList[n].isAIUnit=!factionList[i].isPlayerFaction;
				}
			}
			
			Vector3 pos=new Vector3(0, 99999, 0);
			Quaternion rot=Quaternion.identity;
			for(int i=0; i<factionList.Count; i++){
				Faction fac=factionList[i];
				
				//if load from data, then load the list from data and then put it to startingUnitList
				/*
				if(fac.loadFromData){ 
					fac.dataList=TBData.GetStartData(fac.dataID);
					if(fac.dataList!=null && fac.dataList.Count>0){
						fac.startingUnitList=new List<Unit>();
						for(int n=0; n<fac.dataList.Count; n++) fac.startingUnitList.Add(fac.dataList[n].unit);
						
						//put the data list back into the end data first, to save the current starting lineup for next menu loading
						//in case the player didnt finish the level and GameOver is not called
						TBData.SetEndData(fac.dataID, fac.dataList);
					}
					else fac.loadFromData=false;
				}
				if(!fac.loadFromData){	
					//if using default startingUnitList, make sure none of the element in startingUnitList is empty
					for(int n=0; n<fac.startingUnitList.Count; n++){
						if(fac.startingUnitList[n]==null){ fac.startingUnitList.RemoveAt(n); n-=1; }
					}
				}
				*/
				
				if(fac.loadFromData){ 
					fac.startingUnitList=new List<Unit>();
					fac.dataList=TBData.GetStartData(fac.dataID);
					if(fac.dataList==null){
						Debug.LogWarning("TBTK faction's data not setup properly", this);
						continue;
					}
					Debug.Log("unit from data: "+fac.dataList.Count);
					for(int n=0; n<fac.dataList.Count; n++) fac.startingUnitList.Add(fac.dataList[n].unit);
					
					//put the data list back into the end data first, to save the current starting lineup for next menu loading
					//in case the player didnt finish the level and GameOver is not called
					TBData.SetEndData(fac.dataID, fac.dataList);
				}
				else{	
					//if using default startingUnitList, make sure none of the element in startingUnitList is empty
					for(int n=0; n<fac.startingUnitList.Count; n++){
						if(fac.startingUnitList[n]==null){ fac.startingUnitList.RemoveAt(n); n-=1; }
					}
				}
				
				for(int n=0; n<fac.startingUnitList.Count; n++){
					GameObject unitObj=(GameObject)Instantiate(fac.startingUnitList[n].gameObject, pos, rot);
					fac.startingUnitList[n]=unitObj.GetComponent<Unit>();
					fac.startingUnitList[n].InitUnitAbility();
					fac.startingUnitList[n].isAIUnit=!fac.isPlayerFaction;
					unitObj.transform.parent=transform;
					unitObj.SetActive(false);
					
					if(fac.loadFromData) //fac.startingUnitList[n].ModifyStatsToData(fac.dataList[n], n);
						fac.dataList[n].CopyStatsToUnit(fac.startingUnitList[n], n);
				}
				
				if(fac.isPlayerFaction && fac.startingUnitList.Count>0 && !requireDeployment){
					if(deployingFactionID==-1) deployingFactionID=i;
					requireDeployment=true;
				}
			}
			
			if(!GameControl.EnableManualUnitDeployment()){
				for(int i=0; i<factionList.Count; i++){
					if(factionList[i].startingUnitList.Count<=0) continue;
					
					AutoDeployFaction(i);
					for(int n=0; n<deployedUnitList.Count; n++){
						deployedUnitList[n].factionID=factionList[i].ID;
						factionList[i].allUnitList.Add(deployedUnitList[n]);
					}
					deployedUnitList=new List<Unit>();
				}
			}
		}