SendInstantiate() private method

private SendInstantiate ( string prefabName, Vector3 position, Quaternion rotation, int group, int viewIDs, object data, bool isGlobalObject ) : ExitGames.Client.Photon.Hashtable
prefabName string
position Vector3
rotation Quaternion
group int
viewIDs int
data object
isGlobalObject bool
return ExitGames.Client.Photon.Hashtable
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))
        {
            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));
    }
Ejemplo n.º 3
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));
    }
Ejemplo n.º 4
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));
    }
Ejemplo n.º 5
0
    public static GameObject Instantiate(string prefabName, Vector3 position, Quaternion rotation, int group, object[] data)
    {
        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);
        }
        GameObject gameObject = prefabName.StartsWith("RCAsset/") ? Optimization.Caching.CacheResources.RCLoad(prefabName) : (GameObject)Optimization.Caching.CacheResources.Load(prefabName);

        //      if (!UsePrefabCache || !PrefabCache.TryGetValue(prefabName, out gameObject))
        //{
        //	gameObject =
        //	if (UsePrefabCache)
        //	{
        //		PrefabCache.Add(prefabName, gameObject);
        //	}
        //}
        if (gameObject == null)
        {
            Debug.LogError("Failed to Instantiate 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 Instantiate prefab:" + prefabName + ". Prefab must have a PhotonView component.");
            return(null);
        }
        Component[] photonViewsInChildren = gameObject.GetPhotonViewsInChildren();
        int[]       array = new int[photonViewsInChildren.Length];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = AllocateViewID(player.ID);
        }
        networkingPeer.SendInstantiate(prefabName, position, rotation, group, array, data, false);
        return(Optimization.Caching.Pool.NetworkInstantiate(prefabName, position, rotation, array[0], array, networkingPeer.currentLevelPrefix, group, data));
        //Hashtable evData = networkingPeer.SendInstantiate(prefabName, position, rotation, group, array, data, false);
        //return networkingPeer.DoInstantiate(evData, networkingPeer.mLocalActor, gameObject);
    }