Beispiel #1
0
    public static void LeftClick(Vector3 startingMousePosition, Vector3 endingMousePosition, RaycastHit hit)
    {
        //click
        if (startingMousePosition == endingMousePosition)
        {
            switch (hit.transform.gameObject.layer)
            {
            case unitLayer:
                PlayerUnits.DeselectAll();
                PlayerUnits.SingleSelect(hit.collider.gameObject);
                break;

            case movableLayer:
                PlayerUnits.MoveSelected(hit.point);
                break;

            case buildingLayer:
                PlayerBuildings.Select(hit.collider.gameObject);
                break;

            default:
                break;
            }
        }
        //drag
        else
        {
            PlayerUnits.BoxSelect(startingMousePosition);
        }
    }
Beispiel #2
0
        private void DespawnedUnitServerHandler(Unit unit)
        {
            if (unit.connectionToClient.connectionId != connectionToClient.connectionId)
            {
                return;
            }

            PlayerUnits.Remove(unit);
        }
Beispiel #3
0
        private void Initialize()
        {
            PlayerUnits = GetComponentInChildren <PlayerUnits> ();
            EnemyUnits  = GetComponentInChildren <EnemyUnits> ();
            EnemyUnits.Init();

            _enemySpawners = GetComponentsInChildren <EnemySpawner>();
            foreach (var enemySpawner in _enemySpawners)
            {
                enemySpawner.Init(EnemyUnits);
            }

#if UNITY_EDITOR
            if (Global.Instance.CurrentGameData == null)
            {
                Global.Instance.CurrentGameData = new GameData()
                {
                    Level       = 1,
                    PlayerDatas = new List <PlayerData>()
                    {
                        new PlayerData()
                        {
                            Controller = InputManager.ControllerType.KeyboardArrow,
                            Id         = PlayerData.PlayerId.Player1,
                            Lives      = 3,
                            UnitType   = PlayerUnit.UnitType.Balanced
                        },
                        new PlayerData()
                        {
                            Controller = InputManager.ControllerType.KeyboardWasd,
                            Id         = PlayerData.PlayerId.Player2,
                            Lives      = 3,
                            UnitType   = PlayerUnit.UnitType.Heavy
                        }
                    }
                };
            }
#endif

            PlayerUnits.Init(Global.Instance.CurrentGameData.PlayerDatas.ToArray());

            InputManager = gameObject.GetOrAddComponent <InputManager> ();
            InputManager.Init(this, InputManager.ControllerType.KeyboardWasd,
                              InputManager.ControllerType.KeyboardArrow,
                              InputManager.ControllerType.Gamepad1);

            // All conditions should be parented to LevelManager
            _conditions = GetComponentsInChildren <ConditionBase> ();
            foreach (var condition in _conditions)
            {
                condition.Init(this);
            }
        }
        private void Initialize()
        {
            PlayerUnits = GetComponentInChildren <PlayerUnits> ();
            EnemyUnits  = GetComponentInChildren <EnemyUnits> ();

            EnemyUnits.Init();

            // TODO: Get player data from GameManager (new data or saved data)
            PlayerData playerData = new PlayerData()
            {
                Id       = PlayerData.PlayerId.Player1,
                UnitType = PlayerUnit.UnitType.Heavy,
                Lives    = 3
            };

            PlayerUnits.Init(playerData);
        }
 public void UpdateMovement(InputManager.ControllerType controller,
                            Vector3 input, bool shoot)
 {
     PlayerUnits.UpdateMovement(controller, input, shoot);
 }
Beispiel #6
0
    public override void OnInspectorGUI()
    {
        //uc = (UnitControl)target;
        if (gc == null)
        {
            gc = uc.gameObject.GetComponent <GameControlTB>();
            if (gc == null)
            {
                Debug.Log("No GameControlTB component on UnitControl Object");
                return;
            }
            else
            {
                InitPlayerUnitsList();
            }
        }

        DrawDefaultInspector();



        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Starting Units");

        for (int n = 0; n < uc.playerUnits.Count; n++)
        {
            PlayerUnits pUnits = uc.playerUnits[n];

            int num = pUnits.starting.Count;

            //~ EditorGUILayout.BeginHorizontal();
            string label = "FactionID:" + pUnits.factionID.ToString() + " (show unit)";
            if (pUnits.showInInspector)
            {
                label = "FactionID:" + pUnits.factionID.ToString() + " (hide unit)";
            }
            cont = new GUIContent(label, "The player faction's unit to be deployed at the start of the scene");
            pUnits.showInInspector = EditorGUILayout.Foldout(pUnits.showInInspector, cont);
            //~ EditorGUILayout.EndHorizontal();

            if (pUnits.showInInspector)
            {
                num = EditorGUILayout.IntField("  Number of units:", num, GUILayout.MaxHeight(14));
                if (num != pUnits.starting.Count)
                {
                    pUnits.starting = MatchStartingUnitListLength(pUnits.starting, num);
                }
                for (int i = 0; i < num; i++)
                {
                    int unitID = -1;
                    for (int j = 0; j < unitList.Count; j++)
                    {
                        if (pUnits.starting[i] != null)
                        {
                            if (unitList[j].prefabID == pUnits.starting[i].prefabID)
                            {
                                unitID = j;
                                break;
                            }
                        }
                    }
                    unitID = EditorGUILayout.IntPopup("     - unit" + i + ": ", unitID, unitNameList, intVal, GUILayout.MaxHeight(13));

                    if (!Application.isPlaying)
                    {
                        if (unitID >= 0)
                        {
                            pUnits.starting[i] = unitList[unitID];
                        }
                        else
                        {
                            pUnits.starting[i] = null;
                        }
                    }
                }
            }
            EditorGUILayout.Space();
        }

        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        cont = new GUIContent("Faction Colors:", "optional colors assignment to faction in runtime as displayed on the overlay. First color assigned to the first faction and so on. If left unassigned, a random color will be used instead");
        EditorGUILayout.LabelField(cont, GUILayout.MaxWidth(120));
        if (GUILayout.Button("+", GUILayout.MaxWidth(50)))
        {
            uc.factionColors.Add(Color.white);
        }
        if (GUILayout.Button("-", GUILayout.MaxWidth(50)))
        {
            if (uc.factionColors.Count > 0)
            {
                uc.factionColors.RemoveAt(uc.factionColors.Count - 1);
            }
        }
        EditorGUILayout.EndHorizontal();
        for (int i = 0; i < uc.factionColors.Count; i++)
        {
            uc.factionColors[i] = EditorGUILayout.ColorField("Faction" + i, uc.factionColors[i]);
        }


        EditorGUILayout.Space();

        /*
         * //old code before hot seat mode, obsoleted
         * int numm=uc.startingUnit.Count;
         *
         * string labell="Starting Units (Show)";
         * if(showStartingUnitList) labell="Starting Units (Hide)";
         * cont=new GUIContent(labell, "The player unit ready to be deployed at the start of the scene");
         * showStartingUnitList = EditorGUILayout.Foldout(showStartingUnitList, cont);
         * if(showStartingUnitList){
         *      numm=EditorGUILayout.IntField("  Number of units:", numm, GUILayout.MaxHeight(14));
         *      if(numm!=uc.startingUnit.Count) uc.startingUnit=MatchStartingUnitListLength(uc.startingUnit, numm);
         *      for(int i=0; i<numm; i++){
         *              int unitID=-1;
         *              for(int j=0; j<unitList.Count; j++){
         *                      if(uc.startingUnit[i]!=null){
         *                              if(unitList[j].prefabID==uc.startingUnit[i].prefabID){
         *                                      unitID=j;
         *                                      break;
         *                              }
         *                      }
         *              }
         *              unitID = EditorGUILayout.IntPopup("     - unit"+i+": ", unitID, unitNameList, intVal,  GUILayout.MaxHeight(13));
         *              if(unitID>=0) uc.startingUnit[i]=unitList[unitID];
         *              else uc.startingUnit[i]=null;
         *      }
         * }
         */

        EditorGUILayout.Space();
    }
Beispiel #7
0
 private void InitializePlayerUnits()
 {
     playerUnits   = new PlayerUnits();
     selectedUnits = new List <GameObject>();
     playerUnits.SetStartingUnits(GameObject.FindGameObjectsWithTag("PlayerUnit"));
 }
Beispiel #8
0
 void Start()
 {
     player         = GameObject.FindWithTag("Player");
     unitProperties = unit.GetComponent <UnitProperties>();
     playerUnits    = player.GetComponent <PlayerUnits>();
 }
Beispiel #9
0
 //called when a unit placement phase is initiated for a faction
 void OnNewPlacement(PlayerUnits pUnits)
 {
     allPlaceableTiles=new List<Tile>();
     for(int i=0; i<allTiles.Count; i++){
         Tile hT=allTiles[i];
         if(hT.openForPlacement && hT.placementID==pUnits.factionID){
             hT.openForPlacement=true;
             hT.placementID=pUnits.factionID;
             hT.SetState(_TileState.Walkable);
             allPlaceableTiles.Add(hT);
         }
         else hT.SetState(_TileState.Default);
     }
 }
Beispiel #10
0
 private void DespawnedUnitClientHandler(Unit unit)
 {
     PlayerUnits.Remove(unit);
 }
Beispiel #11
0
 private void SpawnedUnitClientHandler(Unit unit)
 {
     PlayerUnits.Add(unit);
 }
Beispiel #12
0
 public static void RightClick()
 {
     PlayerUnits.DeselectAll();
     PlayerBuildings.Deselect();
 }
Beispiel #13
0
 public PlayerUnitManager()
 {
     selectedObjects  = new SelectedObjects();
     units            = new PlayerUnits();
     hasUnitsSelected = false;
 }
 public override void OnCreate()
 {
     playerUnits = DataManager.GetInstance().GetPlayerUnits();
     unitsProtos = DataManager.GetInstance().unitsProtoData;
 }
Beispiel #15
0
 public void Init(PlayerUnits playerUnits)
 {
     _playerUnits = playerUnits;
 }