Esempio n. 1
0
        private void __Remove(Node node)
        {
            ServerObject instance = node == null ? null : node.GetComponent <ServerObject>();

            Assert.IsNotNull(instance);
            if (instance == null || instance == this)
            {
                return;
            }

            Server host = __node == null ? null : __node.host as Server;

            Assert.IsNotNull(host);
            if (host == null)
            {
                return;
            }

            Server.Node temp;
            bool        result = host.GetNode(__node.index, out temp);

            Assert.IsTrue(result);
            if (!result)
            {
                return;
            }

            if (temp.connectionId >= 0)
            {
                --instance.__refCount;

                if (instance.__refCount == 0 && instance.onDisable != null)
                {
                    instance.onDisable();
                }

                --__refCount;
                if (__refCount == 0 && onDisable != null)
                {
                    onDisable();
                }
            }
            else
            {
                if (!host.GetNode(node.index, out temp))
                {
                    return;
                }

                if (temp.connectionId >= 0)
                {
                    --__refCount;
                    if (__refCount == 0 && onDisable != null)
                    {
                        onDisable();
                    }

                    --instance.__refCount;
                }
            }
        }
Esempio n. 2
0
        private void __Add(Node node)
        {
            ServerObject instance = node == null ? null : node.GetComponent <ServerObject>();

            Assert.IsNotNull(instance);
            if (instance == null || instance == this)
            {
                return;
            }

            Server host = __node == null ? null : __node.host as Server;

            Assert.IsNotNull(host);
            if (host == null)
            {
                return;
            }

            short index = __node.index;

            Server.Node temp;
            bool        result = host.GetNode(index, out temp);

            Assert.IsTrue(result);
            if (!result)
            {
                return;
            }

            if (temp.connectionId >= 0)
            {
                if (__refCount == 0 && onEnable != null)
                {
                    onEnable();
                }

                ++__refCount;

                if (instance.__refCount == 0 && instance.onEnable != null)
                {
                    instance.onEnable();
                }

                ++instance.__refCount;

                Delegate[] invocationList = instance.onInit == null ? null : instance.onInit.GetInvocationList();
                if (invocationList != null)
                {
                    Func <NetworkWriter, short> onInit;
                    foreach (Delegate invocation in invocationList)
                    {
                        onInit = invocation as Func <NetworkWriter, short>;
                        if (onInit != null)
                        {
                            host.Send(
                                temp.connectionId,
                                node.index,
                                onInit(instance.RpcStart()),
                                instance.__writer.AsArray(),
                                instance.__writer.Position);
                        }
                    }
                }
            }
            else
            {
                if (!host.GetNode(node.index, out temp))
                {
                    return;
                }

                if (temp.connectionId >= 0)
                {
                    if (__refCount == 0 && onEnable != null)
                    {
                        onEnable();
                    }

                    ++__refCount;

                    ++instance.__refCount;

                    Delegate[] invocationList = this.onInit == null ? null : this.onInit.GetInvocationList();
                    if (invocationList != null)
                    {
                        Func <NetworkWriter, short> onInit;
                        foreach (Delegate invocation in invocationList)
                        {
                            onInit = invocation as Func <NetworkWriter, short>;
                            if (onInit != null)
                            {
                                host.Send(
                                    temp.connectionId,
                                    index,
                                    onInit(RpcStart()),
                                    __writer.AsArray(),
                                    __writer.Position);
                            }
                        }
                    }
                }
            }
        }