UnityEngine.Networking.ClientScene.RegisterSpawnHandler(UnityEngine.Networking.NetworkHash128, UnityEngine.Networking.SpawnDelegate, UnityEngine.Networking.UnSpawnDelegate)

Here are the examples of the csharp api UnityEngine.Networking.ClientScene.RegisterSpawnHandler(UnityEngine.Networking.NetworkHash128, UnityEngine.Networking.SpawnDelegate, UnityEngine.Networking.UnSpawnDelegate) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

19 View Source File : PlayWithReadyState.cs
License : MIT License
Project Creator : NicolasPCouts

[UnityTest]
    public IEnumerator PlayWithReadyStateTest()
    {
        NetworkClient.ShutdownAll();
        NetworkServer.Reset();

        GameObject nmObject = new GameObject();
        PlayWithReadyStateNetworkManager nmanager = nmObject.AddComponent<PlayWithReadyStateNetworkManager>();
        nmanager.networkAddress = "localhost";

        ClientScene.RegisterSpawnHandler(playerHash, PlayWithReadyStateNetworkManager.OnSpawnPlayer, PlayWithReadyStateNetworkManager.OnUnSpawnPlayer);

        NetworkServer.RegisterHandler(FromClientMsg1, OnServerFromClientMsg1);
        NetworkServer.RegisterHandler(FromClientMsg2, OnServerFromClientMsg2);
        NetworkServer.RegisterHandler(FromClientMsg3, OnServerFromClientMsg3);

        nmanager.StartServer();
        client1 = nmanager.StartClient();
        client1.RegisterHandler(MsgType.Connect, OnClient1Connect);
        client1.RegisterHandler(MsgId1, OnMsg1);
        client1.RegisterHandler(MsgId2, OnMsg2);
        client1.RegisterHandler(MsgId3, OnMsg3);

        // client2 is never ready, so should not recieve msgs
        client2 = new NetworkClient();
        client2.RegisterHandler(MsgType.Connect, OnClient2Connect);
        client2.RegisterHandler(MsgId1, OnMsg1);
        client2.RegisterHandler(MsgId2, OnMsg2);
        client2.RegisterHandler(MsgId3, OnMsg3);
        client2.RegisterHandler(MsgType.NotReady, OnNotReady);

        replacedert.IsTrue(NetworkServer.active, "Server is not started");
        replacedert.IsTrue(NetworkClient.active, "Client is not started");

        client2.Connect(NetworkManager.singleton.networkAddress, NetworkManager.singleton.networkPort);

        yield return null;

        while (!isDone)
        {
            yield return null;
        }

        Collectionreplacedert.AreEqual(resultListOfCallbacks, actualListOfCallbacks, "Wrong order of callbacks or some callback is missing");

        nmanager.StopServer();
        nmanager.StopClient();
        NetworkClient.ShutdownAll();
        UnityEngine.Object.Destroy(nmObject);
    }

19 View Source File : CommandsAndRPCCallsWork.cs
License : MIT License
Project Creator : NicolasPCouts

[UnityTest]
    public IEnumerator CommandsAndRPCCallsWorkTest()
    {
        NetworkClient.ShutdownAll();
        NetworkServer.Reset();

        ConnectionConfig config = new ConnectionConfig();
        config.AddChannel(QosType.ReliableSequenced);// this test requires correct sequence of packets.
        config.AddChannel(QosType.Unreliable);

        myClient = new NetworkClient();
        if (!myClient.Configure(config, 10))
        {
            replacedert.Fail("Client configure failed");
        }

        NetworkServer.RegisterHandler(MsgType.AddPlayer, OnAddPlayer);
        myClient.RegisterHandler(MsgType.Connect, OnClientConnected);
        myClient.RegisterHandler(MsgType.Error, OnClientError);
        ClientScene.RegisterSpawnHandler(playerHash, OnSpawnPlayer, OnUnSpawnPlayer);

        int retries = 0;
        while (!NetworkServer.Listen("127.0.0.1", ++kListenPort))
        {
            replacedert.IsTrue(retries++ < 10, "Couldn't Listen for more than 10 retries");
        }

        myClient.Connect("127.0.0.1", kListenPort);

        while (!isTestDone)
        {
            yield return null;
        }
    }

19 View Source File : MatchModeCTF.cs
License : MIT License
Project Creator : overload-development-community

private static void Postfix()
        {
            // for some reason using enreplacedy_item_security_key directly doesn't work well in MP,
            // so take the relatively simple cloak powerup and give it the appearance and type of a security key
            GameObject prefab = PrefabManager.item_prefabs[(int)ItemPrefab.enreplacedy_item_cloak];
            var prefabkeyA2 = PrefabManager.item_prefabs[(int)ItemPrefab.enreplacedy_item_security_key].GetChildByName("keyA2");
            for (int i = 0; i < CTF.TeamCount; i++)
            {
                GameObject flag = UnityEngine.Object.Instantiate(prefab, Vector3.zero, Quaternion.idenreplacedy);
                UnityEngine.Object.Destroy(flag.GetChildByName("cloak_ball (1)"));
                var color = CTF.FlagColor(i);
                var lightColor = MPTeams.TeamColor(MPTeams.AllTeams[i], 5);
                Material newMat = null;
                var keyA2 = UnityEngine.Object.Instantiate(prefabkeyA2, flag.transform);
                foreach (var rend in keyA2.GetComponentsInChildren<MeshRenderer>())
                {
                    if (newMat == null) {
                        newMat = new Material(rend.sharedMaterial.shader);
                        newMat.CopyPropertiesFromMaterial(rend.sharedMaterial);
                        newMat.SetColor("_Color", color);
                        newMat.SetColor("_EmissionColor", color);
                    }
                    rend.sharedMaterial = newMat;
                }
                var light = flag.GetChildByName("_light").GetComponent<Light>();
                light.color = lightColor;
                //light.intensity = 4.455539f;
                light.intensity = 2f;
                light.range = 4f;
                light.bounceIntensity = 0f;
                keyA2.GetChildByName("inner_ring001").GetComponent<HighlighterConstant>().color = color;
                var partRend = keyA2.GetChildByName("outer_ring_004").GetChildByName("_particle1").GetComponent<ParticleSystemRenderer>();
                var newPartMat = new Material(partRend.sharedMaterial.shader);
                newPartMat.CopyPropertiesFromMaterial(partRend.sharedMaterial);
                newPartMat.SetColor("_CoreColor", color);
                newPartMat.SetColor("_TintColor", color);
                partRend.sharedMaterial = newPartMat;

                if (flag == null)
                {
                    Debug.LogWarningFormat("CTF: Failed to instantiate prefab: {0} in RegisterSpawnHandlers", prefab.name);
                    return;
                }
                var replacedetId = CTF.FlagreplacedetId(i);
                var netId = flag.GetComponent<NetworkIdenreplacedy>();
                _NetworkIdenreplacedy_m_replacedetId_Field.SetValue(netId, replacedetId);
                UnityEngine.Object.DontDestroyOnLoad(flag);
                flag.SetActive(false);
                var item = flag.GetComponent<Item>();
                //item.m_current_segment = -1;
                //item.m_stationary = false;
                item.m_index = i;
                //item.m_light_flicker = 0;
                item.m_type = ItemType.KEY_SECURITY;
                item.m_rotate_speed =  180f;
                item.m_light_flicker = 0.2f;
                //flag.tag = "Item";
                //flag.GetComponent<NetworkIdenreplacedy>().a
                CTF.FlagObjs.Add(flag);
                //Debug.Log("Flag " + i + " color " + color + " replacedetid " + flag.GetComponent<NetworkIdenreplacedy>().replacedetId);
                m_registered_prefabs.Add(replacedetId, flag);
                ClientScene.RegisterSpawnHandler(replacedetId, NetworkSpawnItemHandler, NetworkUnspawnItemHandler);
            }
            Debug.Log("CTF: Created " + CTF.FlagObjs.Count + " flag prefabs");
        }