Beispiel #1
0
        private void OnStart()
        {
            ExcelManager.InitLoader(name =>
            {
                Stream stream = null;
                var refSet    = ResourcesManager.GetUnmanagedRefSet("configuration");
                {
                    var asset = ResourcesManager.LoadAsset <TextAsset>(name, refSet);
                    stream    = new System.IO.MemoryStream(asset.bytes);
                }
                refSet.Release();

                return(stream);
            });
            ExcelManager.LoadAll();

            this.world = GBox.Make <IWorld>();

            this.observer      = this.world.AddSystem <MessageSystem>();
            this.windowManager = this.world.AddSystem <WindowSystem>();
            this.world.AddSystem <RenderSystem>();
            this.world.AddSystem <CameraSystem>();
            var room = this.world.AddSystem <RoomSystem>();

            this.world.AddSystem <AudioSystem>();

            this.game = this.world.CreateEntity();
            var ctx = this.game.AddTrait <Context>();

            ctx.World = this.world;
            ctx.Room  = room;
            var machine = this.game.AddControl <StateMachine>();

            machine.ChangeState(new LoginState());
        }
Beispiel #2
0
        public override void OnInit(IEntityContainer container)
        {
            var channelManager = GBox.Make <IChannelManager>();

            channelManager.Extend("kongfu", (nsp) =>
            {
                var socket = GBox.Make <ISocketManager>().Create(nsp);
                return(new Channel(socket, new Fragment()));
            });
        }
Beispiel #3
0
        public override void OnInit(IEntityContainer container)
        {
            var factory = new PrefabFactory();

            this.pool = GBox.Make <IRecycleManager>().Create(factory, factory);

            var m = container.NewMatcher();

            m.HasTrait <Renderer>().ExceptTag(Renderer.Loaded);
            this.filter = container.GetFilter(this, TupleType.Job, m);
        }
Beispiel #4
0
        public void Connect(string net, string ip, int port)
        {
            //Disconnect();
            if (network != null)
            {
                StopHeart();

                network.OnPacket    -= OnPacket;
                network.OnConnected -= Connected;
                network.OnClosed    -= Closed;
                network.OnError     -= Error;

                network.Disconnect();

                network = null;

                //recvMsgList = null;
                //tmpMsgList = null;
                bConnected = false;
                entityDict.Clear();
            }

            try
            {
                if (net == "tcp")
                {
                    network = GBox.Make <INetworkManager>().Create("cratos", "cratos.tcp://" + ip + ":" + port);
                }
                else if (net == "kcp")
                {
                    network = GBox.Make <INetworkManager>().Create("cratos", "cratos.kcp://" + ip + ":" + port + "?datashards=3&parityshards=2");
                }
                network.OnConnected += Connected;
                network.OnClosed    += Closed;
                network.OnError     += Error;

                tmpMsgList  = new List <object>();
                recvMsgList = new List <object>();
                eventList   = new List <EventData>();

                network.OnPacket += OnPacket;
                network.SetPlugins(packer);
                network.Connect();
            }
            catch (Exception e)
            {
                if (WhenError != null)
                {
                    WhenError.Invoke(e);
                }
            }
        }
        /// <summary>
        /// 注册服务
        /// </summary>
        public override void Init()
        {
            var channelExtend = GBox.Make <IChannelManager>();

            channelExtend.Extend("cratos", (nsp) =>
            {
                var socketFactory = GBox.Make <ISocketManager>();
                var socket        = socketFactory.Create(nsp);
                return(new Channel.Channel(socket, new GaiaFragment()));
            });

            MMStreamPool.Init();

            //GBox.Singleton<Room>().Alias<IRoom>();
        }
Beispiel #6
0
        /// <summary>
        /// 加载Unity组件的服务提供者
        /// </summary>
        private void LoadUnityComponentProvider()
        {
            if (!LoadFromComponents)
            {
                return;
            }

            var root = GBox.Make <Component>();

            if (root == null)
            {
                return;
            }

            RegisterProviders(root.GetComponentsInChildren <IServiceProvider>());
        }
Beispiel #7
0
        /// <summary>
        /// 项目入口
        /// </summary>
        protected override void OnStartCompleted()
        {
            // Game entry, Your code starts writing here
            // called this function after, use GBox.Make function to get service
            // ex: var service = GBox.Make<IYourService>();

            Debug.Log("OnStartCompleted");

            Debug.Log("Hello GameBox, Debug Level: " + GBox.Make <DebugLevels>());
            GBox.Watch <DebugLevels>(newLevel =>
            {
                Debug.Log("Change debug level: " + newLevel);
            });

            // 游戏初始化
            Kongfu.Game.Start();
        }
Beispiel #8
0
        public void Enter(string ip, int port)
        {
            if (null != this.network)
            {
                this.network.Disconnect();
                this.network = null;
            }

            var nsp = "kongfu.tcp://" + ip + ":" + port;

            this.network              = GBox.Make <INetworkManager>().Create("kongfu.game", nsp);
            this.network.OnConnected += OnConnected;
            this.network.OnClosed    += OnClosed;
            this.network.OnError     += OnError;
            this.network.OnPacket    += OnReceive;
            this.network.SetPlugins(this);
            this.network.Connect();
        }