Ejemplo n.º 1
0
        public static RMPNetworkView Replicate(string prefabName, RMPPeer to = null)
        {
            if (!NetworkService.IsServer)
            {
                Debug.LogError("Only server can replicate RMP object. Replication aborted.");
                return(null);
            }

            var target = System.Array.Find(_instance._replicateTable, prefab => prefab.name.Equals(prefabName));

            if (target != null)
            {
                // view 의 Awake 가 호출되고 새 guid 가 부여됨.
                var instance = Instantiate(target);
                // 직렬화 되지 않는 멤버변수는 instantiate 할 때 복사되지 않음.
                instance.ReplicationTableIndex = target.ReplicationTableIndex;

                // null 일 경우 모두에게, 아닐 경우 해당 세션에게만.
                if (to == null)
                {
                    var cls = RMPPeer.ClientPeers;
                    if (cls != null)
                    {
                        foreach (var peer in cls.Values)
                        {
                            peer.SendReplicate(instance);
                        }
                    }
                }
                else
                {
                    to.SendReplicate(instance);
                }

                return(instance);
            }
            else
            {
                Debug.LogError(string.Format("Replicate target not found by its name \'{0}\'.", prefabName));
                return(null);
            }
        }
Ejemplo n.º 2
0
        public static RMPNetworkView Replicate(int index, RMPPeer to = null)
        {
            if (!NetworkService.IsServer)
            {
                Debug.LogError("Only server can replicate RMP object. Replication aborted.");
                return(null);
            }

            try
            {
                var target   = _instance._replicateTable[index];
                var instance = Instantiate(target);
                instance.ReplicationTableIndex = target.ReplicationTableIndex;

                if (to == null)
                {
                    var cls = RMPPeer.ClientPeers;
                    if (cls != null)
                    {
                        foreach (var peer in cls.Values)
                        {
                            peer.SendReplicate(instance);
                        }
                    }
                }
                else
                {
                    to.SendReplicate(instance);
                }

                return(instance);
            }
            catch (Exception error)
            {
                Debug.LogError(error);
                return(null);
            }
        }
Ejemplo n.º 3
0
        public static void Replicate(RMPNetworkView view, RMPPeer to = null)
        {
            if (!NetworkService.IsServer)
            {
                Debug.LogError("Only server can replicate RMP object. Replication aborted.");
                return;
            }

            if (to == null)
            {
                var cls = RMPPeer.ClientPeers;
                if (cls != null)
                {
                    foreach (var peer in cls.Values)
                    {
                        peer.SendReplicate(view);
                    }
                }
            }
            else
            {
                to.SendReplicate(view);
            }
        }