internal void ResourceNetworkInstantiate(GameObject resourceLoadedObject, bool visibleToAll, Player owner) { var loadedView = resourceLoadedObject.GetComponent <NetworkView>(); NetworkView.RegisterNewView(ref loadedView); if (owner != null && owner.CurrentRoom == this) { loadedView.owner = owner; } else { loadedView.owner = Player.Server; } m_Actors.Add(loadedView); SendNetworkInstantiate(loadedView.Connections, resourceLoadedObject); }
/// <summary> /// Instantiate an object over the network /// </summary> /// <param name="resourcePath">Path to the resource on the client</param> /// <param name="position"></param> /// <param name="rotation"></param> /// <param name="owner"></param> /// <param name="visibleToAll">if false, the object is only visible to the owner. Additional visiblity is achieved via setting the subscriptions on the networkview </param> /// <returns></returns> public GameObject NetworkInstantiate(string resourcePath, Vector3 position, Quaternion rotation, Player owner, bool visibleToAll = true) { //TODO: actually get the object out of the resource path... var gobj = GameState.CreateGameObject(position, rotation); gobj.Room = this; gobj.Resource = resourcePath; var netview = gobj.GetComponent <NetworkView>() ?? gobj.AddComponent <NetworkView>(); NetworkView.RegisterNewView(ref netview); netview.owner = owner; m_Actors.Add(netview); SendNetworkInstantiate(netview.Connections, gobj); return(gobj); }