// Update is called once per frame void Update() { if (NetUtilManager.OwnsObject(gameObject.name)) { if (Time.time - currentTime > 1.0f / updateFrequency) { currentTime = Time.time; NetUtilManager.SyncTransform(gameObject.name, transform); } } else { currentTime += Time.deltaTime; if (predictPosition) { transform.position = findPosition(); } if (predictRotation) { transform.rotation = findRotation(); // Quaternion.SlerpUnclamped(Quaternion.identity, deltaRotation, Time.deltaTime / deltaTime); } if (predictScale) { transform.localScale = findScale(); } } }
void NetUtilSyncTransform(object t_object) { if (NetUtilManager.OwnsObject(gameObject.name)) { return; } NetUtilSyncTransform netTransform = (NetUtilSyncTransform)t_object; if (netTransform.time < newTime) { return; } oldTime = newTime; oldPosition = newPosition; oldRotation = newRotation; oldScale = newScale; samplePosition = transform.position; sampleRotation = transform.rotation; sampleScale = transform.localScale; newTime = netTransform.time; newPosition = netTransform.position.toVector3(); newRotation = netTransform.rotation.toQuaternion(); newScale = netTransform.localScale.toVector3(); currentTime = oldTime; }
public void HostGameOnline() { NetUtilManager.Host(); name = GameObject.Find("Game Name Field").GetComponent <InputField>().text; NetUtilManager.StartAdvertiseOnline(name); GameObject.Destroy(GameObject.Find("Canvas")); }
void Start() { Application.runInBackground = true; if (!NetUtilManager.isInitialized) { NetUtilManager.Setup(); NetUtilManager.RegisterPrefabs(prefabs); } }
void Jump(object t_data) { if (!NetUtilManager.OwnsObject(gameObject.name)) { return; } bool goUp = (bool)t_data; transform.position += new Vector3(0.0f, goUp ? 2.0f : -2.0f, 0.0f); }
void NetUtilInitialize(object t_data) { ProjectileInfo info = (ProjectileInfo)t_data; velocity = info.velocity.toVector3(); if (info.isOwnedByHost && NetUtilManager.isHost && !NetUtilManager.OwnsObject(gameObject.name)) { DebugConsole.Log("requesting " + gameObject.name); NetUtilManager.RequestObject(gameObject.name); } }
void Update() { // if not local, stop execution if (!NetUtilManager.OwnsObject(gameObject.name)) { return; } // if local, simulate player if (Input.GetKey("w")) { transform.position += transform.forward * 5.0f * Time.deltaTime; } if (Input.GetKey("a")) { transform.position -= transform.right * 5.0f * Time.deltaTime; } if (Input.GetKey("s")) { transform.position -= transform.forward * 5.0f * Time.deltaTime; } if (Input.GetKey("d")) { transform.position += transform.right * 5.0f * Time.deltaTime; } if (Input.GetKey("right")) { transform.Rotate(0.0f, Time.deltaTime * 90.0f, 0.0f); } if (Input.GetKey("left")) { transform.Rotate(0.0f, Time.deltaTime * -90.0f, 0.0f); } if (Input.GetKeyDown("up")) { NetUtilManager.SendPrioritySync(new NetUtilCustomMessage(lastProjectile, "Jump", true)); } if (Input.GetKeyDown("down")) { NetUtilManager.SendPrioritySync(new NetUtilCustomMessage(lastProjectile, "Jump", false)); } if (Input.GetKeyDown("space")) { ProjectileInfo info = new ProjectileInfo(); info.isOwnedByHost = true; info.velocity = new NetUtilVector3(transform.forward * 15.0f); lastProjectile = NetUtilManager.CreateObject("projectile", transform.position + transform.forward, transform.rotation, info); } }
void Update() { if (NetUtilManager.isSetup) { NetUtilManager.Update(); } if (NetUtilManager.isConnected) { if (localPlayers.Count <= 0) { string name = NetUtilManager.CreateObject("player", Vector3.zero, Quaternion.identity, ""); localPlayers.Add(NetUtilManager.GetObject(name)); } } }
void Update() { if (!NetUtilManager.OwnsObject(gameObject.name)) { return; } transform.position += velocity * Time.deltaTime; transform.rotation *= Quaternion.AngleAxis(Time.deltaTime * 360.0f, velocity.normalized); transform.localScale = Vector3.one + Vector3.one * Mathf.Cos(Time.time) * 0.5f; age += Time.deltaTime; if (age > 5.0f) { NetUtilManager.DestroyObject(gameObject.name); Debug.Log("kill"); } }
public void RefreshList() { NetUtilGameInfo[] gameList = NetUtilManager.GetGameList(); int index = 0; foreach (NetUtilGameInfo game in gameList) { GameObject button = GameObject.Instantiate(buttonPrefab, GameObject.Find("Canvas").transform); button.transform.position += new Vector3(0.0f, -30.0f, 0.0f) * ++index; button.GetComponentInChildren <Text>().text = game.name + " (" + game.playerCount + " / " + game.playerLimit + ")"; button.GetComponent <Button>().onClick.AddListener(() => { NetUtilManager.Connect(game.ip, game.port); GameObject.Destroy(GameObject.Find("Canvas")); }); } }