AllocateSceneViewID









How do I use Allocate Scene View I D
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


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
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
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() == null)
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     }

AllocateSceneViewID 178 lượt xem

Gõ tìm kiếm nhanh...