void OnJoinedRoom() { if (serverOwner) { this.GetComponent <WorldManager> ().SpawnWorld(); } // Add player GameObject playerController = (GameObject)Instantiate(playerControllerPrefab, Vector3.up * 601, Quaternion.identity); GameObject playerModel = PhotonNetwork.Instantiate("PlayerModel", playerController.transform.position, Quaternion.identity, 0); // Connect model to controller so others can see position. SyncTransform sync = playerController.GetComponent <SyncTransform>(); sync.child = playerModel.transform; // Set your name on the hat for other players to see. playerModel.GetComponent <PhotonView>().RPC("SetNameTag", PhotonTargets.AllBuffered, playerName); // Disable hat rendering locally. foreach (MeshRenderer r in playerModel.GetComponentsInChildren <MeshRenderer>()) { r.enabled = false; } }
// Start is called before the first frame update public override void OnAwake() { base.OnAwake(); animator = transform.GetNestedComponentInChildren <Animator, NetObject>(true); syncAnimator = transform.GetNestedComponentInChildren <SyncAnimator, NetObject>(true); syncTransform = GetComponent <SyncTransform>(); syncLauncher = transform.GetNestedComponentInChildren <SyncCannon, NetObject>(true); syncHitscan = transform.GetNestedComponentInChildren <SyncContactScan, NetObject>(true); }
public static void SetTransform(Transform transform, SyncTransform uTransform) { var pos = uTransform.Position; transform.localPosition = new Vector3(pos.X, pos.Y, pos.Z); var rot = uTransform.Rotation; transform.localRotation = new Quaternion(rot.X, rot.Y, rot.Z, rot.W); var scl = uTransform.Scale; transform.localScale = new Vector3(scl.X, scl.Y, scl.Z); }
void SetUpSyncTransform(GameObject gameObject, SyncTransform syncTransform, bool initialiseValues) { // Initialise scale, position, rotation (NB: scale doesn't change in this // code base right now). if (initialiseValues) { syncTransform.Scale.Value = gameObject.transform.localScale; syncTransform.Position.Value = gameObject.transform.localPosition; syncTransform.Rotation.Value = gameObject.transform.localRotation; } // Ensure that the object is moveable gameObject.EnsureComponent <UserMoveable>(); // Ensure that the transforms synchronize themselves. var synchronizer = gameObject.EnsureComponent <TransformSynchronizer>(); synchronizer.TransformDataModel = syncTransform; }
public static SyncTransform AddDefaultSyncTransform() { var selection = Selection.activeGameObject; if (!selection) { Debug.LogWarning("No Object Selected."); return(null); } SyncTransform st = selection.GetComponent <SyncTransform>(); if (!st) { st = selection.AddComponent <SyncTransform>(); } return(st); }
void ConfigureSocket() { socket.On("register", (e) => { Debug.Log("[Register] Registrando PlayerLocal"); RegisterState state = JsonConvert.DeserializeObject <RegisterState>(e.data.ToString()); foreach (Client c in state.clients) { InstantiateClient(c); } id = state.myID; }); socket.On("ddd", (e) => { Debug.Log("[DisconectClient] Disconectando cliente: " + e.data); }); socket.On("newClient", (e) => { Client newClient = JsonConvert.DeserializeObject <Client>(e.data.ToString()); if (clients.ContainsKey(newClient.id) == false) { Debug.Log("[NewClient] Registrando Cliente: " + newClient.id); InstantiateClient(newClient); } }); socket.On("updateRemotePosition", (e) => { SyncTransform sync = JsonConvert.DeserializeObject <SyncTransform>(e.data.ToString()); if (sync.id != id) { GameObject syncClient = clients[sync.id]; syncClient.transform.position = sync.position; syncClient.transform.eulerAngles = sync.rotation; //Debug.Log("[UpdateRemotePosition] Update Position from " + sync.id); } }); }
//public static SyncTransform AddDefaultSyncTransform() //{ // var selection = Selection.activeGameObject; // if (!selection) // { // Debug.LogWarning("No Object Selected."); // return null; // } // SyncTransform st = selection.GetComponent<SyncTransform>(); // if (!st) // st = selection.AddComponent<SyncTransform>(); // return st; //} //public static SyncTransform AddDefaultSyncTransform(Transform t) //{ // if (ReferenceEquals(t, null)) // t = Selection.activeTransform; // if (ReferenceEquals(t, null)) // return null; // SyncTransform st = t.GetComponent<SyncTransform>(); // if (!st) // st = t.gameObject.AddComponent<SyncTransform>(); // return st; //} public static SyncTransform AddDefaultDisabledSyncTransform(Transform t) { if (ReferenceEquals(t, null)) { t = Selection.activeTransform; } if (ReferenceEquals(t, null)) { return(null); } SyncTransform st = t.GetComponent <SyncTransform>(); if (!st) { st = t.gameObject.AddComponent <SyncTransform>(); Debug.Log("Added SyncTransform to " + t.name); var tc = st.transformCrusher; var pc = tc.PosCrusher; var rc = tc.RotCrusher; var sc = tc.SclCrusher; pc.XCrusher.Enabled = false; pc.YCrusher.Enabled = false; pc.ZCrusher.Enabled = false; rc.TRSType = TRSType.Euler; rc.XCrusher.Enabled = false; rc.YCrusher.Enabled = false; rc.ZCrusher.Enabled = false; sc.uniformAxes = ElementCrusher.UniformAxes.NonUniform; sc.XCrusher.Enabled = false; sc.YCrusher.Enabled = false; sc.ZCrusher.Enabled = false; } return(st); }
public void UpdateLocalPositon(string id, Transform syncTransform) { SyncTransform sync = new SyncTransform(id, syncTransform.position, syncTransform.eulerAngles); socket.Emit("updatePosition", new JSONObject(JsonConvert.SerializeObject(sync))); }