Verify









How do I use Verify
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: NetworkingPeer.cs Copy
2279     internal GameObject DoInstantiate(Hashtable evData, PhotonPlayer photonPlayer, GameObject resourceGameObject)
2280     {
2281         // some values always present:
2282         string prefabName = (string)evData[(byte)0];
2283         int serverTime = (int)evData[(byte)6];
2284         int instantiationId = (int)evData[(byte)7];
2285
2286         Vector3 position;
2287         if (evData.ContainsKey((byte)1))
2288         {
2289             position = (Vector3)evData[(byte)1];
2290         }
2291         else
2292         {
2293             position = Vector3.zero;
2294         }
2295
2296         Quaternion rotation = Quaternion.identity;
2297         if (evData.ContainsKey((byte)2))
2298         {
2299             rotation = (Quaternion)evData[(byte)2];
2300         }
2301
2302         int group = 0;
2303         if (evData.ContainsKey((byte)3))
2304         {
2305             group = (int)evData[(byte)3];
2306         }
2307
2308         short objLevelPrefix = 0;
2309         if (evData.ContainsKey((byte)8))
2310         {
2311             objLevelPrefix = (short)evData[(byte)8];
2312         }
2313
2314         int[] viewsIDs;
2315         if (evData.ContainsKey((byte)4))
2316         {
2317             viewsIDs = (int[])evData[(byte)4];
2318         }
2319         else
2320         {
2321             viewsIDs = new int[1] { instantiationId };
2322         }
2323
2324         object[] incomingInstantiationData;
2325         if (evData.ContainsKey((byte)5))
2326         {
2327             incomingInstantiationData = (object[])evData[(byte)5];
2328         }
2329         else
2330         {
2331             incomingInstantiationData = null;
2332         }
2333
2334         // SetReceiving filtering
2335         if (group != 0 && !this.allowedReceivingGroups.Contains(group))
2336         {
2337             return null; // Ignore group
2338         }
2339
2340         // load prefab, if it wasn't loaded before (calling methods might do this)
2341         if (resourceGameObject == null)
2342         {
2343             if (!NetworkingPeer.UsePrefabCache || !NetworkingPeer.PrefabCache.TryGetValue(prefabName, out resourceGameObject))
2344             {
2345                 resourceGameObject = (GameObject)Resources.Load(prefabName, typeof(GameObject));
2346                 if (NetworkingPeer.UsePrefabCache)
2347                 {
2348                     NetworkingPeer.PrefabCache.Add(prefabName, resourceGameObject);
2349                 }
2350             }
2351
2352             if (resourceGameObject == null)
2353             {
2354                 Debug.LogError("PhotonNetwork error: Could not Instantiate the prefab [" + prefabName + "]. Please verify you have this gameobject in a Resources folder.");
2355                 return null;
2356             }
2357         }
2358
2359         // now modify the loaded "blueprint" object before it becomes a part of the scene (by instantiating it)
2360         PhotonView[] resourcePVs = resourceGameObject.GetPhotonViewsInChildren();
2361         if (resourcePVs.Length != viewsIDs.Length)
2362         {
2363             throw new Exception("Error in Instantiation! The resource's PhotonView count is not the same as in incoming data.");
2364         }
2365
2366         for (int i = 0; i < viewsIDs.Length; i++)
2367         {
2368             // NOTE instantiating the loaded resource will keep the viewID but would not copy instantiation data, so it's set below
2369             // so we only set the viewID and instantiationId now. the instantiationData can be fetched
2370             resourcePVs[i].viewID = viewsIDs[i];
2371             resourcePVs[i].prefix = objLevelPrefix;
2372             resourcePVs[i].instantiationId = instantiationId;
2373             resourcePVs[i].isRuntimeInstantiated = true;
2374         }
2375
2376         this.StoreInstantiationData(instantiationId, incomingInstantiationData);
2377
2378         // load the resource and set it's values before instantiating it:
2379         GameObject go = (GameObject)GameObject.Instantiate(resourceGameObject, position, rotation);
2380
2381         for (int i = 0; i < viewsIDs.Length; i++)
2382         {
2383             // NOTE instantiating the loaded resource will keep the viewID but would not copy instantiation data, so it's set below
2384             // so we only set the viewID and instantiationId now. the instantiationData can be fetched
2385             resourcePVs[i].viewID = 0;
2386             resourcePVs[i].prefix = -1;
2387             resourcePVs[i].prefixBackup = -1;
2388             resourcePVs[i].instantiationId = -1;
2389             resourcePVs[i].isRuntimeInstantiated = false;
2390         }
2391
2392         this.RemoveInstantiationData(instantiationId);
2393
2394         // Send OnPhotonInstantiate callback to newly created GO.
2395         // GO will be enabled when instantiated from Prefab and it does not matter if the script is enabled or disabled.
2396         go.SendMessage(PhotonNetworkingMessage.OnPhotonInstantiate.ToString(), new PhotonMessageInfo(photonPlayer, serverTime, null), SendMessageOptions.DontRequireReceiver);
2397         return go;
2398     }
File name: PhotonNetwork.cs Copy
302     public static bool SetMasterClient(PhotonPlayer masterClientPlayer)
303     {
304         if (!VerifyCanUseNetwork() || !isMasterClient)
305         {
306             return false;
307         }
308
309         return networkingPeer.SetMasterClient(masterClientPlayer.ID, true);
310     }
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() == null)
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() == 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     }
File name: PhotonNetwork.cs Copy
2231     public static void SendOutgoingCommands()
2232     {
2233         if (!VerifyCanUseNetwork())
2234         {
2235             return;
2236         }
2237
2238         while (networkingPeer.SendOutgoingCommands())
2239         {
2240         }
2241     }
File name: PhotonNetwork.cs Copy
2246     public static bool CloseConnection(PhotonPlayer kickPlayer)
2247     {
2248         if (!VerifyCanUseNetwork())
2249         {
2250             return false;
2251         }
2252
2253         if (!player.isMasterClient)
2254         {
2255             Debug.LogError("CloseConnection: Only the masterclient can kick another player.");
2256             return false;
2257         }
2258
2259         if (kickPlayer == null)
2260         {
2261             Debug.LogError("CloseConnection: No such player connected!");
2262             return false;
2263         }
2264
2265         RaiseEventOptions options = new RaiseEventOptions() { TargetActors = new int[] { kickPlayer.ID } };
2266         return networkingPeer.OpRaiseEvent(PunEvent.CloseConnection, null, true, options);
2267     }
File name: PhotonNetwork.cs Copy
2366     public static void DestroyPlayerObjects(int targetPlayerId)
2367     {
2368         if (!VerifyCanUseNetwork())
2369         {
2370             return;
2371         }
2372         if (player.isMasterClient || targetPlayerId == player.ID)
2373         {
2374             networkingPeer.DestroyPlayerObjects(targetPlayerId, false);
2375         }
2376         else
2377         {
2378             Debug.LogError("DestroyPlayerObjects() failed, cause players can only destroy their own GameObjects. A Master Client can destroy anyone's. This is master: " + PhotonNetwork.isMasterClient);
2379         }
2380     }
File name: PhotonNetwork.cs Copy
2422     public static void RemoveRPCs(PhotonPlayer targetPlayer)
2423     {
2424         if (!VerifyCanUseNetwork())
2425         {
2426             return;
2427         }
2428
2429         if (!targetPlayer.isLocal && !isMasterClient)
2430         {
2431             Debug.LogError("Error; Only the MasterClient can call RemoveRPCs for other players.");
2432             return;
2433         }
2434
2435         networkingPeer.OpCleanRpcBuffer(targetPlayer.ID);
2436     }
File name: PhotonNetwork.cs Copy
2447     public static void RemoveRPCs(PhotonView targetPhotonView)
2448     {
2449         if (!VerifyCanUseNetwork())
2450         {
2451             return;
2452         }
2453
2454         networkingPeer.CleanRpcBufferIfMine(targetPhotonView);
2455     }
File name: PhotonNetwork.cs Copy
2466     public static void RemoveRPCsInGroup(int targetGroup)
2467     {
2468         if (!VerifyCanUseNetwork())
2469         {
2470             return;
2471         }
2472
2473         networkingPeer.RemoveRPCsInGroup(targetGroup);
2474     }

Verify 186 lượt xem

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