public void LoadShip(string prefab_name, string object_name) { GameObject Ship = Instantiate(Resources.Load(prefab_name, typeof(GameObject)), this.gameObject.transform) as GameObject; channel s = Ship.GetComponent <channel>(); Ship.GetComponent <puppet>().InitTransform(Ship.transform.localPosition, Ship.transform.localRotation);// rotation); network n = GameObject.FindObjectOfType <network>(); int unikID = 1; if (!Channel.GetNetwork().IsClient()) { unikID = GetComponent <server>().GetFreeID(); } int t = n.AddGameObjectToChannel(Ship, unikID); s.SetNetwork(n); s.SetChannel(t); Channel.RegisterEntity(Ship, s.GetChannel()); object_name += "_" + t; Ship.name = object_name; Ship.GetComponent <ship>().Init(this.gameObject); ShipList[s.GetChannel()] = Ship; }
public void SpawnPlayer(int contID, bool IsClient, bool ownPlayer, Vector3 position, Quaternion rotation, float time) { Vector3 re = rotation.eulerAngles; GameObject Player = Instantiate(Resources.Load("Prefabs/Player", typeof(GameObject)), transform) as GameObject; Player.transform.localPosition = position; Player.transform.localRotation = rotation; Channel.RegisterEntity(Player, contID); if (IsClient && ownPlayer) { Transform t = Player.transform.FindChild("Camera"); myCam = t.gameObject; t.gameObject.SetActive(true); Player.AddComponent <puppetcontrol>(); Player.GetComponent <puppet>().InitTransform(position, rotation);// rotation); puppetcontrol f = Player.GetComponent <puppetcontrol>(); f.SetChannel(Channel); // f.AddObjectToInteract(this.gameObject); GameObject GUI = GameObject.Find("GUI"); if (GUI != null) { GUI.GetComponent <gui>().PushUserInterface(Player); } } else { Player.AddComponent <puppet>(); Player.GetComponent <puppet>().InitTransform(position, rotation);// rotation); } Player.GetComponent <puppet>().SetTransform(position, rotation, puppet.trans_flag_position | puppet.trans_flag_rotation, time); if (Player) { Debug.Log("Enter Ship (" + Channel.GetChannel() + ")" + " player " + contID + " pos: " + position + " rot:" + re.x + "," + re.y + "," + re.z); } if (IsClient == false) { network_data.create_player m = new network_data.create_player(); m.set(contID, Channel.GetChannel()); m.position = position; m.rotation = rotation; byte[] data = network_utils.nData.Instance.SerializeMsg <network_data.create_player>(m); Channel.SendToChannel(ref data); List <byte[]> datalist = new List <byte[]>(); IDictionaryEnumerator r = Channel.FirstEntity(); while (r.MoveNext()) { if (contID != (int)r.Key) { m.set((int)r.Key, Channel.GetChannel()); m.position = ((GameObject)r.Value).transform.localPosition; m.rotation = ((GameObject)r.Value).transform.localRotation; byte[] data1 = network_utils.nData.Instance.SerializeMsg <network_data.create_player>(m); Channel.GetNetwork().Send(contID, data1); } } foreach (KeyValuePair <int, trigger> j in Triggers) { trigger t = (trigger)j.Value; t.SendTriggerTo(contID); } } }