Locate
How do I use Locate
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PhotonEditor.cs
Copy
543 protected virtual void OnGuiMainWizard()
544 {
545 GUILayout.BeginHorizontal();
546 GUILayout.FlexibleSpace();
547 GUILayout.Label(WizardIcon);
548 GUILayout.FlexibleSpace();
549 GUILayout.EndHorizontal();
550
551 EditorGUILayout.Separator();
552
553 GUILayout.Label(CurrentLang.PUNWizardLabel, EditorStyles.boldLabel);
554 if (isPunPlus)
555 {
556 GUILayout.Label(CurrentLang.MobilePunPlusExportNoteLabel);
557 }
558 else if (!InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.Android) || !InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.iOS))
559 {
560 GUILayout.Label(CurrentLang.MobileExportNoteLabel);
561 }
562 EditorGUILayout.Separator();
563
564
565 // settings button
566 GUILayout.BeginHorizontal();
567 GUILayout.Label(CurrentLang.SettingsButton, EditorStyles.boldLabel, GUILayout.Width(100));
568 if (GUILayout.Button(new GUIContent(CurrentLang.SetupButton, CurrentLang.SetupServerCloudLabel)))
569 {
570 this.InitPhotonSetupWindow();
571 }
572
573 GUILayout.EndHorizontal();
574 EditorGUILayout.Separator();
575
576
577 // find / select settings asset
578 GUILayout.BeginHorizontal();
579 GUILayout.Label(CurrentLang.SettingsFileLabel, EditorStyles.boldLabel, GUILayout.Width(100));
580 if (GUILayout.Button(new GUIContent(CurrentLang.LocateSettingsButton, CurrentLang.SettingsHighlightLabel)))
581 {
582 EditorGUIUtility.PingObject(PhotonEditor.Current);
583 }
584
585 GUILayout.EndHorizontal();
586
587
588 GUILayout.FlexibleSpace();
589
590 // converter
591 GUILayout.BeginHorizontal();
592 GUILayout.Label(CurrentLang.ConverterLabel, EditorStyles.boldLabel, GUILayout.Width(100));
593 if (GUILayout.Button(new GUIContent(CurrentLang.StartButton, CurrentLang.UNtoPUNLabel)))
594 {
595 PhotonConverter.RunConversion();
596 }
597
598 GUILayout.EndHorizontal();
599 EditorGUILayout.Separator();
600
601
602 // documentation
603 GUILayout.BeginHorizontal();
604 GUILayout.Label(CurrentLang.DocumentationLabel, EditorStyles.boldLabel, GUILayout.Width(100));
605 GUILayout.BeginVertical();
606 if (GUILayout.Button(new GUIContent(CurrentLang.OpenPDFText, CurrentLang.OpenPDFTooltip)))
607 {
608 EditorUtility.OpenWithDefaultApp(DocumentationLocation);
609 }
610
611 if (GUILayout.Button(new GUIContent(CurrentLang.OpenDevNetText, CurrentLang.OpenDevNetTooltip)))
612 {
613 EditorUtility.OpenWithDefaultApp(UrlDevNet);
614 }
615
616 if (GUILayout.Button(new GUIContent(CurrentLang.OpenCloudDashboardText, CurrentLang.OpenCloudDashboardTooltip)))
617 {
618 EditorUtility.OpenWithDefaultApp(UrlCloudDashboard + Uri.EscapeUriString(this.emailAddress));
619 }
620
621 if (GUILayout.Button(new GUIContent(CurrentLang.OpenForumText, CurrentLang.OpenForumTooltip)))
622 {
623 EditorUtility.OpenWithDefaultApp(UrlForum);
624 }
625
626 GUILayout.EndVertical();
627 GUILayout.EndHorizontal();
628 }
File name: NetworkingPeer.cs
Copy
459 private void LeftRoomCleanup()
460 {
461 bool wasInRoom = mRoomToGetInto != null;
462 // when leaving a room, we clean up depending on that room's settings.
463 bool autoCleanupSettingOfRoom = (this.mRoomToGetInto != null) ? this.mRoomToGetInto.autoCleanUp : PhotonNetwork.autoCleanUpPlayerObjects;
464
465 this.hasSwitchedMC = false;
466 this.mRoomToGetInto = null;
467 this.mActors = new Dictionary
468 this.mPlayerListCopy = new PhotonPlayer[0];
469 this.mOtherPlayerListCopy = new PhotonPlayer[0];
470 this.mMasterClient = null;
471 this.allowedReceivingGroups = new HashSet
472 this.blockSendingGroups = new HashSet
473 this.mGameList = new Dictionary
474 this.mGameListCopy = new RoomInfo[0];
475 this.isFetchingFriends = false;
476
477 this.ChangeLocalID(-1);
478
479 // Cleanup all network objects (all spawned PhotonViews, local and remote)
480 if (autoCleanupSettingOfRoom)
481 {
482 this.LocalCleanupAnythingInstantiated(true);
483 PhotonNetwork.manuallyAllocatedViewIds = new List
484 }
485
486 if (wasInRoom)
487 {
488 SendMonoMessage(PhotonNetworkingMessage.OnLeftRoom);
489 }
490 }
File name: PhotonNetwork.cs
Copy
1959 public static int AllocateViewID()
1960 {
1961 int manualId = AllocateViewID(player.ID);
1962 manuallyAllocatedViewIds.Add(manualId);
1963 return manualId;
1964 }
File name: PhotonNetwork.cs
Copy
1971 public static int AllocateSceneViewID()
1972 {
1973 if (!PhotonNetwork.isMasterClient)
1974 {
1975 Debug.LogError("Only the Master Client can AllocateSceneViewID(). Check PhotonNetwork.isMasterClient!");
1976 return -1;
1977 }
1978
1979 int manualId = AllocateViewID(0);
1980 manuallyAllocatedViewIds.Add(manualId);
1981 return manualId;
1982 }
File name: PhotonNetwork.cs
Copy
1988 public static void UnAllocateViewID(int viewID)
1989 {
1990 manuallyAllocatedViewIds.Remove(viewID);
1991
1992 if (networkingPeer.photonViewList.ContainsKey(viewID))
1993 {
1994 Debug.LogWarning(string.Format("UnAllocateViewID() should be called after the PhotonView was destroyed (GameObject.Destroy()). ViewID: {0} still found in: {1}", viewID, networkingPeer.photonViewList[viewID]));
1995 }
1996 }
File name: PhotonNetwork.cs
Copy
1999 // returns viewID (combined owner and sub id)
2000 private static int AllocateViewID(int ownerId)
2001 {
2002 if (ownerId == 0)
2003 {
2004 // we look up a fresh subId for the owner "room" (mind the "sub" in subId)
2005 int newSubId = lastUsedViewSubIdStatic;
2006 int newViewId;
2007 int ownerIdOffset = ownerId * MAX_VIEW_IDS;
2008 for (int i = 1; i < MAX_VIEW_IDS; i++)
2009 {
2010 newSubId = (newSubId + 1) % MAX_VIEW_IDS;
2011 if (newSubId == 0)
2012 {
2013 continue; // avoid using subID 0
2014 }
2015
2016 newViewId = newSubId + ownerIdOffset;
2017 if (!networkingPeer.photonViewList.ContainsKey(newViewId))
2018 {
2019 lastUsedViewSubIdStatic = newSubId;
2020 return newViewId;
2021 }
2022 }
2023
2024 // this is the error case: we didn't find any (!) free subId for this user
2025 throw new Exception(string.Format("AllocateViewID() failed. Room (user {0}) is out of 'scene' viewIDs. It seems all available are in use.", ownerId));
2026 }
2027 else
2028 {
2029 // we look up a fresh SUBid for the owner
2030 int newSubId = lastUsedViewSubId;
2031 int newViewId;
2032 int ownerIdOffset = ownerId * MAX_VIEW_IDS;
2033 for (int i = 1; i < MAX_VIEW_IDS; i++)
2034 {
2035 newSubId = (newSubId + 1) % MAX_VIEW_IDS;
2036 if (newSubId == 0)
2037 {
2038 continue; // avoid using subID 0
2039 }
2040
2041 newViewId = newSubId + ownerIdOffset;
2042 if (!networkingPeer.photonViewList.ContainsKey(newViewId) && !manuallyAllocatedViewIds.Contains(newViewId))
2043 {
2044 lastUsedViewSubId = newSubId;
2045 return newViewId;
2046 }
2047 }
2048
2049 throw new Exception(string.Format("AllocateViewID() failed. User {0} is out of subIds, as all viewIDs are used.", ownerId));
2050 }
2051 }
File name: PhotonNetwork.cs
Copy
2053 private static int[] AllocateSceneViewIDs(int countOfNewViews)
2054 {
2055 int[] viewIDs = new int[countOfNewViews];
2056 for (int view = 0; view < countOfNewViews; view++)
2057 {
2058 viewIDs[view] = AllocateViewID(0);
2059 }
2060
2061 return viewIDs;
2062 }
File name: PhotonNetwork.cs
Copy
2090 public static GameObject Instantiate(string prefabName, Vector3 position, Quaternion rotation, int group, object[] data)
2091 {
2092 if (!connected || (InstantiateInRoomOnly && !inRoom))
2093 {
2094 Debug.LogError("Failed to Instantiate prefab: " + prefabName + ". Client should be in a room. Current connectionStateDetailed: " + PhotonNetwork.connectionStateDetailed);
2095 return null;
2096 }
2097
2098 GameObject prefabGo;
2099 if (!UsePrefabCache || !PrefabCache.TryGetValue(prefabName, out prefabGo))
2100 {
2101 prefabGo = (GameObject)Resources.Load(prefabName, typeof(GameObject));
2102 if (UsePrefabCache)
2103 {
2104 PrefabCache.Add(prefabName, prefabGo);
2105 }
2106 }
2107
2108 if (prefabGo == null)
2109 {
2110 Debug.LogError("Failed to Instantiate prefab: " + prefabName + ". Verify the Prefab is in a Resources folder (and not in a subfolder)");
2111 return null;
2112 }
2113
2114 // a scene object instantiated with network visibility has to contain a PhotonView
2115 if (prefabGo.GetComponent
2116 {
2117 Debug.LogError("Failed to Instantiate prefab:" + prefabName + ". Prefab must have a PhotonView component.");
2118 return null;
2119 }
2120
2121 Component[] views = (Component[])prefabGo.GetPhotonViewsInChildren();
2122 int[] viewIDs = new int[views.Length];
2123 for (int i = 0; i < viewIDs.Length; i++)
2124 {
2125 //Debug.Log("Instantiate prefabName: " + prefabName + " player.ID: " + player.ID);
2126 viewIDs[i] = AllocateViewID(player.ID);
2127 }
2128
2129 // Send to others, create info
2130 Hashtable instantiateEvent = networkingPeer.SendInstantiate(prefabName, position, rotation, group, viewIDs, data, false);
2131
2132 // Instantiate the GO locally (but the same way as if it was done via event). This will also cache the instantiationId
2133 return networkingPeer.DoInstantiate(instantiateEvent, networkingPeer.mLocalActor, prefabGo);
2134 }
File name: PhotonNetwork.cs
Copy
2150 public static GameObject InstantiateSceneObject(string prefabName, Vector3 position, Quaternion rotation, int group, object[] data)
2151 {
2152 if (!connected || (InstantiateInRoomOnly && !inRoom))
2153 {
2154 Debug.LogError("Failed to InstantiateSceneObject prefab: " + prefabName + ". Client should be in a room. Current connectionStateDetailed: " + PhotonNetwork.connectionStateDetailed);
2155 return null;
2156 }
2157
2158 if (!isMasterClient)
2159 {
2160 Debug.LogError("Failed to InstantiateSceneObject prefab: " + prefabName + ". Client is not the MasterClient in this room.");
2161 return null;
2162 }
2163
2164 GameObject prefabGo;
2165 if (!UsePrefabCache || !PrefabCache.TryGetValue(prefabName, out prefabGo))
2166 {
2167 prefabGo = (GameObject)Resources.Load(prefabName, typeof(GameObject));
2168 if (UsePrefabCache)
2169 {
2170 PrefabCache.Add(prefabName, prefabGo);
2171 }
2172 }
2173
2174 if (prefabGo == null)
2175 {
2176 Debug.LogError("Failed to InstantiateSceneObject prefab: " + prefabName + ". Verify the Prefab is in a Resources folder (and not in a subfolder)");
2177 return null;
2178 }
2179
2180 // a scene object instantiated with network visibility has to contain a PhotonView
2181 if (prefabGo.GetComponent
2182 {
2183 Debug.LogError("Failed to InstantiateSceneObject prefab:" + prefabName + ". Prefab must have a PhotonView component.");
2184 return null;
2185 }
2186
2187 Component[] views = (Component[])prefabGo.GetPhotonViewsInChildren();
2188 int[] viewIDs = AllocateSceneViewIDs(views.Length);
2189
2190 if (viewIDs == null)
2191 {
2192 Debug.LogError("Failed to InstantiateSceneObject prefab: " + prefabName + ". No ViewIDs are free to use. Max is: " + MAX_VIEW_IDS);
2193 return null;
2194 }
2195
2196 // Send to others, create info
2197 Hashtable instantiateEvent = networkingPeer.SendInstantiate(prefabName, position, rotation, group, viewIDs, data, true);
2198
2199 // Instantiate the GO locally (but the same way as if it was done via event). This will also cache the instantiationId
2200 return networkingPeer.DoInstantiate(instantiateEvent, networkingPeer.mLocalActor, prefabGo);
2201 }
File name: PhotonView.cs
Copy
295 protected internal void OnDestroy()
296 {
297 if (!this.destroyedByPhotonNetworkOrQuit)
298 {
299 PhotonNetwork.networkingPeer.LocalCleanPhotonView(this);
300 }
301
302 if (!this.destroyedByPhotonNetworkOrQuit && !Application.isLoadingLevel)
303 {
304 if (this.instantiationId > 0)
305 {
306 // if this viewID was not manually assigned (and we're not shutting down or loading a level), you should use PhotonNetwork.Destroy() to get rid of GOs with PhotonViews
307 Debug.LogError("OnDestroy() seems to be called without PhotonNetwork.Destroy()?! GameObject: " + this.gameObject + " Application.isLoadingLevel: " + Application.isLoadingLevel);
308 }
309 else
310 {
311 // this seems to be a manually instantiated PV. if it's local, we could warn if the ID is not in the allocated-list
312 if (this.viewID <= 0)
313 {
314 Debug.LogWarning(string.Format("OnDestroy manually allocated PhotonView {0}. The viewID is 0. Was it ever (manually) set?", this));
315 }
316 else if (this.isMine && !PhotonNetwork.manuallyAllocatedViewIds.Contains(this.viewID))
317 {
318 Debug.LogWarning(string.Format("OnDestroy manually allocated PhotonView {0}. The viewID is local (isMine) but not in manuallyAllocatedViewIds list. Use UnAllocateViewID() after you destroyed the PV.", this));
319 }
320 }
321 }
322 }
Locate 106 lượt xem
Gõ tìm kiếm nhanh...