// Update is called once per frame void Update() { if (!Channel.GetNetwork().IsClient()) { DateTime now = new DateTime(); now = DateTime.Now; TimeSpan duration = now - last_clientupdate; if (duration > TimeSpan.FromMilliseconds(100)) { float time = Time.time; last_clientupdate = now; network_data.move_player m = new network_data.move_player(); IDictionaryEnumerator i = Channel.FirstEntity(); while (i.MoveNext()) { GameObject g = (GameObject)i.Value; m.set((int)i.Key, Channel.GetChannel()); m.position = ((GameObject)i.Value).transform.localPosition; m.velocity = ((GameObject)i.Value).GetComponent <ship>().GetVelocity(); m.rotation = ((GameObject)i.Value).transform.localRotation; m.time = time; byte[] data1 = network_utils.nData.Instance.SerializeMsg <network_data.move_player>(m); foreach (KeyValuePair <int, GameObject> gg in ShipList) { gg.Value.GetComponent <channel>().SendToChannel(ref data1); } } } } ServerTime.Update(Time.deltaTime); }
// Use this for initialization public void Init(GameObject Game) { // targetRotation = Quaternion.Euler(0,0,0); myrigidbody = transform.FindChild("Outside").GetComponent <Rigidbody>(); this.Game = Game; cockpits = transform.GetComponentsInChildren <ilink_cockpit>(); Debug.Log("found " + cockpits.Length + " cockpits"); Channel = this.GetComponent <channel>(); if (!Channel) { Debug.Log("No Channel"); } else { if (!Channel.GetNetwork()) { Debug.Log("No Network for Channel"); } } trigger[] trig = transform.GetComponentsInChildren <trigger>(); foreach (trigger ti in trig) { ti.Init(Channel); if (Triggers.ContainsKey(ti.netID)) { Debug.Log("Triggerkey " + ti.netID + "error"); } Triggers[ti.netID] = ti; if (Channel.GetNetwork().IsClient()) { Collider c = ti.GetComponent <Collider>(); if (ti.auto) { c.enabled = false; } } else { Collider c = ti.GetComponent <Collider>(); if (!ti.auto) { c.enabled = false; } } } Debug.Log("Found " + Triggers.Count + " triggers"); Debug.Log("Create ShipID " + GetChannel().GetChannel()); }
public void Init() { Channel = this.GetComponent <channel>(); if (!Channel) { Debug.Log("No Channel"); } else { if (!Channel.GetNetwork()) { Debug.Log("No Network for Channel"); } else { } } }
void OnTriggerEnter(Collider other) { if (counter == 0) { on = true; changed = true; } counter++; if (!mychannel.GetNetwork().IsClient()) { SendTrigger(-1); } }
void Update() { if (!isActiv) { return; } SetMoveVector(new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"))); UpdateCamera(); if (UI != null) { Ray ray = myCamera.GetComponent <Camera>().ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f)); RaycastHit hit; LayerMask _layerMask = 1 << 9; float dist = 1.5f; bool use_on = false; if (Physics.Raycast(ray, out hit, dist, _layerMask)) { trigger interact = hit.collider.gameObject.GetComponent <trigger>(); if (interact) { use_on = true; if (Channel.GetNetwork().IsClient()) { client c = (client)Channel.GetNetwork(); if (Input.GetKeyDown(KeyCode.F)) { interact.SendRequest(c.ingameContID); } } } else { } } Transform m = UI.transform.FindChild("Cursor_Use"); m.gameObject.SetActive(use_on); } /* if (UI != null) * { * foreach (KeyValuePair<int,GameObject> obj in ObjectToInteractWith) * { * trigger interact = obj.Value.GetComponent<ship>().MouseOver(); * if (interact != null) * { * Transform m = UI.transform.FindChild("Cursor_Use"); * m.gameObject.SetActive(true); * if (obj.Value.GetComponent<ship>().GetComponent<channel>().GetNetwork().IsClient()) * { * client c = (client)obj.Value.GetComponent<ship>().GetComponent<channel>().GetNetwork(); * if (Input.GetKeyDown(KeyCode.F)) * { * interact.SendRequest(c.ingameContID); * } * } * } * else * { * Transform m = UI.transform.FindChild("Cursor_Use"); * m.gameObject.SetActive(false); * } * } * } */ }
// Update is called once per frame void Update() { if (!Channel || !Channel.GetNetwork()) { return; } if (!Channel.GetNetwork().IsClient()) { InterpolateMovement(puppet.trans_flag_rotation); transform.localPosition += myrigidbody.gameObject.transform.localPosition; myrigidbody.gameObject.transform.localPosition = Vector3.zero; // transform.localRotation *= myrigidbody.gameObject.transform.localRotation; // myrigidbody.gameObject.transform.localRotation = Quaternion.Euler(0, 0, 0); } else { if (!IsCockpitUsedByMe()) { InterpolateMovement(puppet.trans_flag_position | puppet.trans_flag_rotation); } else { InterpolateMovement(puppet.trans_flag_position); transform.localRotation *= myrigidbody.gameObject.transform.localRotation; myrigidbody.gameObject.transform.localRotation = Quaternion.Euler(0, 0, 0); } } DateTime now = new DateTime(); now = DateTime.Now; TimeSpan duration = now - last_clientupdate; if (Channel.GetNetwork().IsClient()) { int id = Channel.GetNetwork().GetComponent <client>().ingameContID; GameObject g = Channel.GetEntity(id); if (duration > TimeSpan.FromMilliseconds(100) && g != null) { float time = Time.time; last_clientupdate = now; network_data.move_player m = new network_data.move_player(); m.set(id, Channel.GetChannel()); m.position = g.transform.localPosition; m.rotation = g.transform.localRotation; m.time = time; byte[] data1 = network_utils.nData.Instance.SerializeMsg <network_data.move_player>(m); Channel.GetNetwork().Send(id, data1); if (IsCockpitUsedByMe()) { network_data.move_player m2 = new network_data.move_player(); m2.set(ShipContID, Game.GetComponent <channel>().GetChannel()); m2.position = transform.localPosition; m2.rotation = transform.localRotation; m2.velocity = targetVelocity; m2.time = time; byte[] data = network_utils.nData.Instance.SerializeMsg <network_data.move_player>(m2); Game.GetComponent <channel>().GetNetwork().Send(GetComponent <channel>().GetChannel(), data); } } } else { if (duration > TimeSpan.FromMilliseconds(100)) { last_clientupdate = now; network_data.move_player m = new network_data.move_player(); IDictionaryEnumerator i = Channel.FirstEntity(); while (i.MoveNext()) { GameObject g = (GameObject)i.Value; m.set((int)i.Key, Channel.GetChannel()); m.position = ((GameObject)i.Value).transform.localPosition; m.rotation = ((GameObject)i.Value).transform.localRotation; byte[] data1 = network_utils.nData.Instance.SerializeMsg <network_data.move_player>(m); Channel.SendToChannel(ref data1); } } } }