Inheritance: UnityEngine.MonoBehaviour
 private void OnDestroy()
 {
     if (s_instance == this)
     {
         s_instance       = null;
         s_instanceExists = false;
     }
 }
 private void OnDestroy()
 {
     if (s_instance == this)
     {
         s_instance = null;
         s_instanceExists = false;
     }
 }
 private void Awake()
 {
     if (s_instance)
     {
         DestroyImmediate(this);
     }
     else
     {
         s_instance = this;
         s_instanceExists = true;
     }
 }
        public static bool TryInit()
        {
            if (s_instanceExists)
                return false;

            s_instanceExists = true;

            var go = new GameObject("_ChannelEventDispatcher");
            s_instance = go.AddComponent<ChannelEventDispatcher>();
            DontDestroyOnLoad(go);
            return true;
        }
 private void Awake()
 {
     if (s_instance)
     {
         DestroyImmediate(this);
     }
     else
     {
         s_instance       = this;
         s_instanceExists = true;
     }
 }
        public static Communicator Create()
        {
            ChannelEventDispatcher.TryInit();

            var communicator = new Communicator();

            communicator.ChannelFactory.TaskFactory = new UnitySlimTaskFactory {
                Owner = ChannelEventDispatcher.Instance
            };
            ((ObserverRegistry)communicator.ObserverRegistry).EventPoster = c => ChannelEventDispatcher.Post(c, null);

            return(communicator);
        }
        public static bool TryInit()
        {
            if (s_instanceExists)
            {
                return(false);
            }

            s_instanceExists = true;

            var go = new GameObject("_ChannelEventDispatcher");

            s_instance = go.AddComponent <ChannelEventDispatcher>();
            DontDestroyOnLoad(go);
            return(true);
        }
示例#8
0
        public static ChannelFactory Build(IPacketSerializer packetSerializer = null, IPEndPoint endPoint = null, Func <ILog> createChannelLogger = null)
        {
            ChannelEventDispatcher.TryInit();

            if (packetSerializer == null)
            {
                packetSerializer = PacketSerializer.CreatePacketSerializer();
            }

            var channelFactory = new ChannelFactory
            {
                Type                = ChannelType.Tcp,
                ConnectEndPoint     = endPoint,
                CreateChannelLogger = createChannelLogger,
                TaskFactory         = new UnitySlimTaskFactory {
                    Owner = ChannelEventDispatcher.Instance
                },
                ObserverEventPoster = c => ChannelEventDispatcher.Post(c, null),
                PacketSerializer    = packetSerializer
            };

            return(channelFactory);
        }