RegisterPhotonView
How do I use Register Photon View
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
2688 | public void RegisterPhotonView(PhotonView netView) | 1 |
170 | PhotonNetwork.networkingPeer.RegisterPhotonView(this); | 2 |
246 | PhotonNetwork.networkingPeer.RegisterPhotonView(this); | 3 |
File name: NetworkingPeer.cs
Copy
2688 public void RegisterPhotonView(PhotonView netView)
2689 {
2690 if (!Application.isPlaying)
2691 {
2692 this.photonViewList = new Dictionary
2693 return;
2694 }
2695
2696 if (netView.viewID == 0)
2697 {
2698 // don't register views with ID 0 (not initialized). they register when a ID is assigned later on
2699 Debug.Log("PhotonView register is ignored, because viewID is 0. No id assigned yet to: " + netView);
2700 return;
2701 }
2702
2703 if (this.photonViewList.ContainsKey(netView.viewID))
2704 {
2705 // if some other view is in the list already, we got a problem. it might be undestructible. print out error
2706 if (netView != photonViewList[netView.viewID])
2707 {
2708 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]));
2709 }
2710
2711 //this.photonViewList.Remove(netView.viewID); // TODO check if we chould Destroy the GO of this view?!
2712 this.RemoveInstantiatedGO(photonViewList[netView.viewID].gameObject, true);
2713 }
2714
2715 // Debug.Log("adding view to known list: " + netView);
2716 this.photonViewList.Add(netView.viewID, netView);
2717 //Debug.LogError("view being added. " + netView); // Exit Games internal log
2718
2719 if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
2720 Debug.Log("Registered PhotonView: " + netView.viewID);
2721 }
File name: PhotonView.cs
Copy
153 {
154 get { return this.viewIdField; }
155 set
156 {
157 // if ID was 0 for an awakened PhotonView, the view should add itself into the networkingPeer.photonViewList after setup
158 bool viewMustRegister = this.didAwake && this.viewIdField == 0;
159
160 // TODO: decide if a viewID can be changed once it wasn't 0. most likely that is not a good idea
161 // check if this view is in networkingPeer.photonViewList and UPDATE said list (so we don't keep the old viewID with a reference to this object)
162 // PhotonNetwork.networkingPeer.RemovePhotonView(this, true);
163
164 this.ownerId = value / PhotonNetwork.MAX_VIEW_IDS;
165
166 this.viewIdField = value;
167
168 if (viewMustRegister)
169 {
170 PhotonNetwork.networkingPeer.RegisterPhotonView(this);
171 }
172 //Debug.Log("Set viewID: " + value + " -> owner: " + this.ownerId + " subId: " + this.subId);
173 }
174 }
File name: PhotonView.cs
Copy
243 protected internal void Awake()
244 {
245 // registration might be too late when some script (on this GO) searches this view BUT GetPhotonView() can search ALL in that case
246 PhotonNetwork.networkingPeer.RegisterPhotonView(this);
247
248 this.instantiationDataField = PhotonNetwork.networkingPeer.FetchInstantiationData(this.instantiationId);
249 this.didAwake = true;
250 }
RegisterPhotonView 156 lượt xem
Gõ tìm kiếm nhanh...