示例#1
0
        public virtual void Connect(ConnectionConfig config)
        {
            if (config is ReceptionistConfig)
            {
                if (UseDynamicId)
                {
                    WorkerId = GenerateDynamicWorkerId();
                }

                Connection = ConnectionUtility.ConnectToSpatial((ReceptionistConfig)config, GetWorkerType,
                                                                WorkerId);
            }
            else if (config is LocatorConfig)
            {
                Connection = ConnectionUtility.LocatorConnectToSpatial((LocatorConfig)config, GetWorkerType);
            }
            else
            {
                throw new InvalidConfigurationException($"Invalid connection config was provided: '{config}' Only" +
                                                        "ReceptionistConfig and LocatorConfig are supported.");
            }

            Application.quitting += () =>
            {
                ConnectionUtility.Disconnect(Connection);
                Connection = null;
            };

            View.Connect();
        }
示例#2
0
文件: Worker.cs 项目: PushoN/UnityGDK
 public void Dispose()
 {
     EntityMapping.Clear();
     World?.Dispose();
     World = null;
     OnDisconnect?.Invoke(this);
     ConnectionUtility.Disconnect(Connection);
     Connection?.Dispose();
     Connection = null;
 }
示例#3
0
文件: Worker.cs 项目: PushoN/UnityGDK
        private Worker(ConnectionConfig config, ILogDispatcher logDispatcher, Vector3 origin)
        {
            Origin   = origin;
            WorkerId = string.IsNullOrEmpty(config.WorkerId)
                ? $"{config.WorkerType}-{Guid.NewGuid()}"
                : config.WorkerId;

            Connection               = ConnectionUtility.Connect(config, WorkerId);
            LogDispatcher            = logDispatcher;
            WorkerType               = config.WorkerType;
            logDispatcher.Connection = Connection;

            World = new World(WorkerId);
            World.CreateManager <WorkerSystem>(this);
            var entityManager = World.GetOrCreateManager <EntityManager>();

            WorkerEntity = entityManager.CreateEntity(typeof(OnConnected), typeof(WorkerEntityTag));
            OnConnect?.Invoke(this);
        }