Ejemplo n.º 1
0
    public static GameObject Instantiate(string prefabName, Vector3 position, Quaternion rotation, int group, object[] data)
    {
        if (!connected || (InstantiateInRoomOnly && !inRoom))
        {
            Debug.LogError("Failed to Instantiate prefab: " + prefabName + ". Client should be in a room. Current connectionStateDetailed: " + connectionStateDetailed);
            return(null);
        }
        if (!UsePrefabCache || !PrefabCache.TryGetValue(prefabName, out GameObject value))
        {
            value = ((!prefabName.StartsWith("RCAsset/")) ? ((GameObject)Resources.Load(prefabName, typeof(GameObject))) : FengGameManagerMKII.InstantiateCustomAsset(prefabName));
            if (UsePrefabCache)
            {
                PrefabCache.Add(prefabName, value);
            }
        }
        if (value == null)
        {
            Debug.LogError("Failed to Instantiate prefab: " + prefabName + ". Verify the Prefab is in a Resources folder (and not in a subfolder)");
            return(null);
        }
        if (value.GetComponent <PhotonView>() == null)
        {
            Debug.LogError("Failed to Instantiate prefab:" + prefabName + ". Prefab must have a PhotonView component.");
            return(null);
        }
        Component[] photonViewsInChildren = value.GetPhotonViewsInChildren();
        int[]       array = new int[photonViewsInChildren.Length];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = AllocateViewID(player.Id);
        }
        Hashtable evData = networkingPeer.SendInstantiate(prefabName, position, rotation, group, array, data, isGlobalObject: false);

        return(networkingPeer.DoInstantiate2(evData, networkingPeer.mLocalActor, value));
    }
Ejemplo n.º 2
0
    public static GameObject Instantiate(string prefabName, Vector3 position, Quaternion rotation, int group, object[] data)
    {
        GameObject obj2;

        if (!connected || (InstantiateInRoomOnly && !inRoom))
        {
            Debug.LogError(string.Concat(new object[] { "Failed to Instantiate prefab: ", prefabName, ". Client should be in a room. Current connectionStateDetailed: ", connectionStateDetailed }));
            return(null);
        }
        if (!UsePrefabCache || !PrefabCache.TryGetValue(prefabName, out obj2))
        {
            if (prefabName.StartsWith("RCAsset/"))
            {
                obj2 = FengGameManagerMKII.InstantiateCustomAsset(prefabName);
            }
            else
            {
                obj2 = (GameObject)Resources.Load(prefabName, typeof(GameObject));
            }
            if (UsePrefabCache)
            {
                PrefabCache.Add(prefabName, obj2);
            }
        }
        if (obj2 == null)
        {
            Debug.LogError("Failed to Instantiate prefab: " + prefabName + ". Verify the Prefab is in a Resources folder (and not in a subfolder)");
            return(null);
        }
        if (obj2.GetComponent <PhotonView>() == null)
        {
            Debug.LogError("Failed to Instantiate prefab:" + prefabName + ". Prefab must have a PhotonView component.");
            return(null);
        }
        int[] viewIDs = new int[obj2.GetPhotonViewsInChildren().Length];
        for (int i = 0; i < viewIDs.Length; i++)
        {
            viewIDs[i] = AllocateViewID(player.ID);
        }
        Hashtable evData = networkingPeer.SendInstantiate(prefabName, position, rotation, group, viewIDs, data, false);

        return(networkingPeer.DoInstantiate2(evData, networkingPeer.mLocalActor, obj2));
    }