public RegisterPhotonView ( PhotonView, netView ) : void | ||
netView | PhotonView, | |
Résultat | void |
public void RegisterPhotonView(PhotonView netView)
{
if (!Application.isPlaying)
{
this.photonViewList = new Dictionary<int, PhotonView>();
return;
}
if (netView.viewID == 0)
{
// don't register views with ID 0 (not initialized). they register when a ID is assigned later on
Debug.Log("PhotonView register is ignored, because viewID is 0. No id assigned yet to: " + netView);
return;
}
if (this.photonViewList.ContainsKey(netView.viewID))
{
// if some other view is in the list already, we got a problem. it might be undestructible. print out error
if (netView != photonViewList[netView.viewID])
{
Debug.LogError(string.Format("PhotonView ID duplicate found: {0}. New: {1} old: {2}. Maybe one wasn't destroyed on scene load?! Check for 'DontDestroyOnLoad'. Destroying old entry, adding new.", netView.viewID, netView, photonViewList[netView.viewID]));
}
else
{
return;
}
this.RemoveInstantiatedGO(photonViewList[netView.viewID].gameObject, true);
}
// Debug.Log("adding view to known list: " + netView);
this.photonViewList.Add(netView.viewID, netView);
//Debug.LogError("view being added. " + netView); // Exit Games internal log
if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
{
Debug.Log("Registered PhotonView: " + netView.viewID);
}
}
private GameObject SetViewIDs(ref GameObject go) { NetworkingPeer networkingPeer = PhotonNetwork.networkingPeer; PhotonView[] views = go.GetPhotonViewsInChildren(); //Debug.Log("Found " + views.Length + " photon views in " + go.name + " object and its children"); int[] viewIDs = new int[views.Length]; for (int i = 0; i < viewIDs.Length; i++) // ignore the main gameobject { //Debug.Log("Instantiate prefabName: " + prefabName + " player.ID: " + player.ID); viewIDs[i] = PhotonNetwork.AllocateViewID(); //Debug.Log("Allocated an id of " + viewIDs[i]); views[i].viewID = viewIDs[i]; views[i].instantiationId = viewIDs[i]; //Debug.Log("Assigning view id of " + viewIDs[i] + ", so now the view id is " + go.GetPhotonView().viewID + " for gameobject " + go.name); networkingPeer.RegisterPhotonView(views[i]); } return(go); }