// called in server to start the game spawning the initial units private void SpawnUnits() { List <SpawnPoint> spawnPoints = JuloFind.allWithComponent <SpawnPoint>(); foreach (SpawnPoint sp in spawnPoints) { int role = sp.playerId; if (playerMap.ContainsKey(role)) { PlayerWrapper wrapper = playerMap[role]; DualGamePlayer player = wrapper.player; if (role >= 0 && role < numPlayers) { SpawnUnit(player, sp.unitId, sp.transform); } else { Debug.LogWarningFormat("Invalid role"); } } else { Debug.LogWarningFormat("Ignoring unit for player {0}", role); } } }
// only client private IEnumerator HandleTurn() { // TODO select with unit has the turn //int unitNumber = 0; // TODO units should be cached in client? List <Unit> units = JuloFind.allWithComponent <Unit>(); bool found = false; foreach (Unit unit in units) { if (unit.playerNetId == this.netId /* TODO && .unitNumber == unitNumber*/) { currentUnit = unit; found = true; break; } } if (found) { bool keepPlaying = true; while (keepPlaying) { if (Input.GetKeyDown(KeyCode.Return)) { keepPlaying = false; } else if (Input.GetKey("left")) { Vector3 pos = currentUnit.transform.position; currentUnit.transform.position = new Vector3(pos.x - moveSpeed * Time.deltaTime, pos.y, pos.z); } else if (Input.GetKey("right")) { Vector3 pos = currentUnit.transform.position; currentUnit.transform.position = new Vector3(pos.x + moveSpeed * Time.deltaTime, pos.y, pos.z); } yield return(null); } } else { JuloDebug.Log("Unit not found"); yield return(new WaitForSeconds(1.5f)); } //JuloDebug.Log("Turn is over"); CmdEndTurn(); yield return(null); }
//public void OnEnable() private void Start() { //We cache the Hash to the "Open" Parameter, so we can feed to Animator.SetBool. isOpenParameterId = Animator.StringToHash(isOpenParameterName); // hide all panels foreach (Panel panel in JuloFind.allDescendants <Panel>(this)) { if (panel.gameObject.activeSelf) { panel.gameObject.SetActive(false); } } if (initiallyOpen != null) { OpenPanel(initiallyOpen); } }