void Start() { io = GameObject.Find("SocketIOController").GetComponent <SocketIOController>(); io.On("connect", (SocketIOEvent e) => { Debug.Log("SocketIO connected"); io.Emit("test-event1"); TestObject t = new TestObject(); t.test = 123; t.test2 = "test1"; io.Emit("test-event2", JsonUtility.ToJson(t)); TestObject t2 = new TestObject(); t2.test = 1234; t2.test2 = "test2"; io.Emit("test-event3", JsonUtility.ToJson(t2), (string data) => { Debug.Log(data); }); }); io.On("allPlayersPositions", (SocketIOEvent ev) => { Debug.Log("allPlayersPositions received"); Debug.Log(ev.data.ToString()); PlayersList playersList = new PlayersList(); playersList = JsonUtility.FromJson <PlayersList>(ev.data); foreach (Players player in playersList.Players) { Debug.Log(player.playerId); Debug.Log(player.pos); string playerName = "Player" + player.playerId; GameObject playerInstance = Instantiate(playerPrefab, player.pos, Quaternion.identity); playerInstance.name = playerName; playerInstance.tag = "Player"; /*LocalPlayer localPlayer = playerInstance.GetComponent<LocalPlayer>(); * localPlayer.playerId = player.playerId; */ } }); // delete an instance of the disconnected player io.On("playerDisconnected", (SocketIOEvent ev) => { string playerId = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId; string playerName = "Player" + playerId; Destroy(GameObject.Find(playerName)); }); io.On("spawnPlayer", (SocketIOEvent ev) => { playerSpawn.GetComponent <SpawnPlayer>().spawnLocalPlayer(); }); io.On("moveInput", (SocketIOEvent ev) => { Debug.Log("moveInput received : " + ev.data.ToString()); Movement movement = JsonUtility.FromJson <Movement>(ev.data); string playerName = "Player" + movement.playerId; GameObject.Find(playerName).GetComponent <PlayerState>().moveInput = movement.moveInput; }); io.On("playerMoved", (SocketIOEvent ev) => { Debug.Log("playerMoved received : " + ev.data.ToString()); PlayerPos playerPos = JsonUtility.FromJson <PlayerPos>(ev.data); string playerId = playerPos.playerId; string playerName = "Player" + playerId; Debug.Log(playerName); GameObject playerToMove = GameObject.Find(playerName); if (playerToMove == null) { playerToMove = Instantiate(playerPrefab, playerPos.pos, Quaternion.identity); playerToMove.name = playerName; playerToMove.tag = "Player"; playerToMove.GetComponent <LocalPlayer>().setPlayerId(playerId); } // TODO: playerToMove.Move(player.pos); playerToMove.transform.position = playerPos.pos; Debug.Log("playerPos.pos"); Debug.Log(playerPos.pos); /*if(playerToMove != null){ * playerToMove.transform.position = playerPos.pos; * } * else{ * Debug.Log("cannot find the playerToMove!"); * }*/ }); io.On("playerRotated", (SocketIOEvent ev) => { Debug.Log("playerRotated received : " + ev.data.ToString()); PlayerPos playerPos = JsonUtility.FromJson <PlayerPos>(ev.data); string playerId = playerPos.playerId; string playerName = "Player" + playerId; Debug.Log(playerName); GameObject playerToMove = GameObject.Find(playerName); playerToMove.transform.eulerAngles = playerPos.pos; Debug.Log("playerPos.pos"); Debug.Log(playerPos.pos); }); io.On("velocityChanged", (SocketIOEvent ev) => { Debug.Log("velocityChanged received : " + ev.data.ToString()); PlayerVelocity playerVelocity = JsonUtility.FromJson <PlayerVelocity>(ev.data); string playerId = playerVelocity.playerId; string playerName = "Player" + playerId; Debug.Log(playerName); GameObject playerToMove = GameObject.Find(playerName); playerToMove.GetComponent <PlayerController>().ComputeVelocity(playerVelocity.velocity); /*if (playerVelocity.velocity.x == 0) * { * playerToMove.GetComponent<Animator>.SetBool("IsRunning", false); * } * else * { * playerToMove.GetComponent<Animator>.SetBool("IsRunning", true); * }*/ Debug.Log("playerVelocity.velocity"); Debug.Log(playerVelocity.velocity); }); io.On("playerAttack", (SocketIOEvent ev) => { Debug.Log("playerAttack received"); string playerId = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId; string playerName = "Player" + playerId; GameObject playerInstance = GameObject.Find(playerName); playerInstance.GetComponent <PlayerState>().isAttacking = true; playerInstance.GetComponent <Animator>().SetTrigger("Attack"); }); io.On("playerEndAttack", (SocketIOEvent ev) => { Debug.Log("playerAttack received"); string playerId = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId; string playerName = "Player" + playerId; GameObject.Find(playerName).GetComponent <PlayerState>().isAttacking = false; }); io.On("jump", (SocketIOEvent ev) => { Debug.Log("jump received"); string playerId = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId; string playerName = "Player" + playerId; GameObject.Find(playerName).GetComponent <PlayerState>().jump = true; }); io.On("playerKilled", (SocketIOEvent ev) => { Debug.Log("another player killed by a player"); string playerId = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId; string playerName = "Player" + playerId; Destroy(GameObject.Find(playerName)); }); io.On("playerDeathByDeathFloor", (SocketIOEvent ev) => { Debug.Log("another player killed by death floor"); string playerId = JsonUtility.FromJson <PlayerIdJSON>(ev.data).playerId; string playerName = "Player" + playerId; Destroy(GameObject.Find(playerName)); }); /*io.On("anotherPlayerConnected", (SocketIOEvent e) => { * Debug.Log(e.data); * Instantiate(myPrefab, new Vector3(0, 0, 0), Quaternion.identity); * });*/ io.Connect(); io.On("test-event", (SocketIOEvent e) => { Debug.Log(e.data); }); }
// Use this for initialization void Start() { playerPos = PlayerPos.GetInstance(); }
// Start is called before the first frame update void Start() { rb = GetComponent <Rigidbody2D>(); ps = GetComponent <PlayerPos>(); }
void Start() { playerPos = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerPos>(); DeactivateClearedMenu(); }
void Awake() { gameMaster = GameObject.FindGameObjectWithTag("Game").GetComponent <GameMaster>(); PlayerPosition = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerPos>(); }
// Start is called before the first frame update void Start() { playerPos = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerPos>(); }
void Main(string args) { debug("BEGIN"); if (args.Trim().Length > 0) { GROUP_TAG = args; } debug("Groupname: " + GROUP_TAG); List <IMyTerminalBlock> Blocks = new List <IMyTerminalBlock>(); GridTerminalSystem.GetBlocksOfType <IMyRemoteControl>(Blocks, (x => x.IsWorking && x.CubeGrid.Equals(Me.CubeGrid))); if (Blocks.Count > 0) { IMyRemoteControl RC = Blocks[0] as IMyRemoteControl; debug("Using Remotecontrol: " + RC.CustomName); List <IMyBlockGroup> Groups = new List <IMyBlockGroup>(); GridTerminalSystem.GetBlockGroups(Groups); Blocks.Clear(); for (int i = 0; i < Groups.Count; i++) { if (Groups[i].Name.Contains(GROUP_TAG)) { for (int j = 0; j < Groups[i].Blocks.Count; j++) { if ( ((Groups[i].Blocks[j] is IMyRadioAntenna) || (Groups[i].Blocks[j] is IMyBeacon)) && Groups[i].Blocks[j].IsFunctional && Groups[i].Blocks[j].CubeGrid.Equals(Me.CubeGrid) ) { Blocks.Add(Groups[i].Blocks[j]); } } } } Vector3D PlayerPos; Vector3D PbPos = RC.GetPosition(); RC.GetNearestPlayer(out PlayerPos); debug("Nearest Player: (" + String.Format("{0:0}", Vector3D.Distance(PlayerPos, PbPos)) + " m)" + PlayerPos.ToString()); debug("Functional Antennas/Beacons: " + Blocks.Count.ToString()); for (int i = 0; i < Blocks.Count; i++) { IMyTerminalBlock RA = Blocks[i] as IMyTerminalBlock; int d_pos = RA.CustomName.IndexOf("DEBUG"); string d_name = RA.CustomName.Trim(); if (d_pos > -1) { d_name = RA.CustomName.Substring(0, d_pos).Trim(); RA.SetCustomName(d_name); } double radius = 0.0; if (RA is IMyRadioAntenna) { radius = Convert.ToDouble((RA as IMyRadioAntenna).Radius); } else if (RA is IMyBeacon) { radius = Convert.ToDouble((RA as IMyBeacon).Radius); } double cutOffPoint = radius * CUT_OFF_FACTOR; double distance = Vector3D.Distance(PlayerPos, PbPos); string info = "% (radius: " + String.Format("{0:0}", radius) + " m; cut-off point: " + String.Format("{0:0}", cutOffPoint) + " m; distance: " + String.Format("{0:0}", distance) + " m)"; if (distance < cutOffPoint) { info = "Enable: " + info; // RA.ApplyAction("OnOff_On"); } else { info = "Disable '" + info; // RA.ApplyAction("OnOff_Off"); } Echo(info.Replace("%", RA.CustomName)); if (DEBUG) { d_pos = RA.CustomName.IndexOf("DEBUG"); d_name = RA.CustomName.Trim(); if (d_pos > -1) { d_name = RA.CustomName.Substring(0, d_pos).Trim(); } RA.SetCustomName(d_name + " DEBUG: " + info.Replace("%", "")); } } } else { debug("Remote Control not found."); } debug("END"); }