DoInstantiate() private method

private DoInstantiate ( ExitGames.Client.Photon.Hashtable evData, PhotonPlayer, photonPlayer, GameObject resourceGameObject ) : GameObject
evData ExitGames.Client.Photon.Hashtable
photonPlayer PhotonPlayer,
resourceGameObject GameObject
return GameObject
Esempio n. 1
0
    public static GameObject Instantiate(string prefabName, Vector3 position, Quaternion rotation, int group, object[] data)
    {
        GameObject obj2;

        if (!connected || (InstantiateInRoomOnly && !inRoom))
        {
            UnityEngine.Debug.LogError(string.Concat(new object[] { "Failed to Instantiate prefab: ", prefabName, ". Client should be in a room. Current connectionStateDetailed: ", connectionStatesDetailed }));
            return(null);
        }
        if (prefabName == "TITAN_VER3.1")
        {
            obj2 = Cach.TITAN_VER3_1 != null ? Cach.TITAN_VER3_1 : Cach.TITAN_VER3_1 = (GameObject)Resources.Load("TITAN_VER3.1");
        }
        else if (prefabName == "hook")
        {
            obj2 = Cach.hook != null ? Cach.hook : Cach.hook = (GameObject)Resources.Load("hook");
        }
        else if (prefabName == "AOTTG_HERO 1")
        {
            obj2 = Cach.AOTTG_HERO_1 != null ? Cach.AOTTG_HERO_1 : Cach.AOTTG_HERO_1 = (GameObject)Resources.Load("AOTTG_HERO 1");
        }
        else if (prefabName.StartsWith("RCAsset/"))
        {
            obj2 = CyanMod.CacheGameResources.RCLoad <GameObject>(prefabName.Substring(8));
        }
        else
        {
            obj2 = CyanMod.CacheGameResources.Load <GameObject>(prefabName);
        }
        if (obj2 == null)
        {
            UnityEngine.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)
        {
            UnityEngine.Debug.LogError("Failed to Instantiate prefab:" + prefabName + ". Prefab must have a PhotonView component.");
            return(null);
        }
        if (isMasterClient && InRoomChat.IsPausedFlayer && (prefabName == "FX/flareBullet2") && Time.timeScale > 0.9f)
        {
            FengGameManagerMKII.instance.FlayerPauseRecompil();
        }
        int[] viewIDs = new int[obj2.GetComponentsInChildren <PhotonView>(true).Length];
        for (int i = 0; i < viewIDs.Length; i++)
        {
            viewIDs[i] = AllocateViewID(player.ID);
        }
        return(networkingPeer.DoInstantiate(networkingPeer.SendInstantiate(prefabName, position, rotation, group, viewIDs, data, false), networkingPeer.mLocalActor, obj2));
    }
Esempio 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("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);
        }

        var viewIDs = new int[obj2.GetPhotonViewsInChildren().Length];

        for (var i = 0; i < viewIDs.Length; i++)
        {
            viewIDs[i] = AllocateViewID(player.ID);
        }

        var evData = networkingPeer.SendInstantiate(prefabName, position, rotation, @group, viewIDs, data, false);

        return(networkingPeer.DoInstantiate(evData, networkingPeer.mLocalActor, obj2));
    }
Esempio n. 3
0
    /// <summary>
    /// Instantiate a prefab over the network. This prefab needs to be located in the root of a "Resources" folder.
    /// </summary>
    /// <param name="prefab"></param>
    /// <param name="position"></param>
    /// <param name="rotation"></param>
    /// <param name="group"></param>
    /// <param name="data">optional instantiation data. This will be saved to it's PhotonView</param>
    /// <returns>The new instance.</returns>
    public static GameObject Instantiate(Object prefab, Vector3 position, Quaternion rotation, int group, object[] data)
    {
        if (!VerifyCanUseNetwork())
        {
            return(null);
        }

        GameObject prefabGo = (GameObject)Resources.Load(prefab.name, typeof(GameObject));

        if (prefabGo == null)
        {
            Debug.LogError("PhotonNetwork error: Could not Instantiate the prefab [" + prefab.name + "]. Please verify you have this gameobject in a Resources folder (and not in a subfolder)");
            return(null);
        }

        Component[]    views   = (Component[])prefabGo.GetComponentsInChildren <PhotonView>(true);
        PhotonViewID[] viewIDs = new PhotonViewID[views.Length];
        for (int i = 0; i < viewIDs.Length; i++)
        {
            viewIDs[i] = AllocateViewID();
        }

        // Send to others, create info
        Hashtable instantiateEvent = networkingPeer.SendInstantiate(prefab.name, position, rotation, group, viewIDs, data);

        // Instantiate the GO locally (but the same way as if it was done via event). This will also cache the instantiationId
        return(networkingPeer.DoInstantiate(instantiateEvent, networkingPeer.mLocalActor, prefabGo));
    }
Esempio n. 4
0
    public static GameObject InstantiateSceneObject(string prefabName, Vector3 position, Quaternion rotation, int group, object[] data)
    {
        if (!connected || (InstantiateInRoomOnly && !inRoom))
        {
            Debug.LogError(string.Concat(new object[]
            {
                "Failed to InstantiateSceneObject prefab: ",
                prefabName,
                ". Client should be in a room. Current connectionStateDetailed: ",
                connectionStateDetailed
            }));
            return(null);
        }
        if (!IsMasterClient)
        {
            Debug.LogError("Failed to InstantiateSceneObject prefab: " + prefabName + ". Client is not the MasterClient in this room.");
            return(null);
        }
        GameObject gameObject = (GameObject)Optimization.Caching.CacheResources.Load(prefabName);

        if (gameObject == null)
        {
            Debug.LogError("Failed to InstantiateSceneObject prefab: " + prefabName + ". Verify the Prefab is in a Resources folder (and not in a subfolder)");
            return(null);
        }
        if (gameObject.GetComponent <PhotonView>() == null)
        {
            Debug.LogError("Failed to InstantiateSceneObject prefab:" + prefabName + ". Prefab must have a PhotonView component.");
            return(null);
        }
        Component[] photonViewsInChildren = gameObject.GetPhotonViewsInChildren();
        int[]       array = AllocateSceneViewIDs(photonViewsInChildren.Length);
        if (array == null)
        {
            Debug.LogError(string.Concat(new object[]
            {
                "Failed to InstantiateSceneObject prefab: ",
                prefabName,
                ". No ViewIDs are free to use. Max is: ",
                MAX_VIEW_IDS
            }));
            return(null);
        }
        Hashtable evData = networkingPeer.SendInstantiate(prefabName, position, rotation, group, array, data, true);

        return(networkingPeer.DoInstantiate(evData, networkingPeer.mLocalActor, gameObject));
    }