示例#1
0
        public static async ETVoid Login(LoginViewComponent self, string account, string password)
        {
            #region 客户端给服务器发送登陆信息
            // 创建一个ETModel层的Session
            ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);

            Log.Info("服务器地址 : " + GlobalConfigComponent.Instance.GlobalProto.Address);
            // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息
            Session   realmSession = ComponentFactory.Create <Session, ETModel.Session>(session);
            R2C_Login r2CLogin     = (R2C_Login)await realmSession.Call(new C2R_Login()
            {
                Account = account, Password = password
            });

            realmSession.Dispose();

            #endregion

            if (r2CLogin.Error != ErrorCode.ERR_Success)
            {
                SetErrorPrompt(self, Message.Get(r2CLogin.ErrorMessageId));
                return;
            }


            #region 客户端根据服务器下发的网关地址连接网关

            Log.Info("服务器下发的网关地址 : " + r2CLogin.Address);
            Log.Info("服务器下发的网关验证码 : " + r2CLogin.Key);

            // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中
            ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address);
            ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession;

            // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中
            Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession);



            G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate()
            {
                Key = r2CLogin.Key
            });

            Log.Info("登陆gate成功!");

            #endregion

            // 创建Player
            Player player = ETModel.ComponentFactory.CreateWithId <Player>(g2CLoginGate.PlayerId);

            PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent <PlayerComponent>();

            playerComponent.MyPlayer = player;

            // 测试消息有成员是class类型
            G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo)await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo());


            // 加载Unit资源
            ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();

            // 加载场景资源
            await resourcesComponent.LoadBundleAsync("start.unity3d");

            // 切换到Battle场景
            using (SceneChangeComponent sceneChangeComponent = Game.Scene.AddComponent <SceneChangeComponent>())
            {
                await sceneChangeComponent.ChangeSceneAsync(SceneType.Start);
            }

            // 逻辑层不应该去调用UI,逻辑层只关心逻辑并且抛出事件,由UI层自己去订阅事件,而且注意事件名字
            // 很多人容易把这个事件取名成LoginFinishiCreateLobbyUI,这是不对的,事件抛出去不可能知道谁订阅了这个事件,
            // 也不会知道别人订阅这个事件是干什么的,这里只知道我Login Finish
            //Game.EventSystem.Run(EventIdType.LoginFinish);
            Game.EventSystem.Run(EventIdType.LoginHasFinish);
        }
示例#2
0
 public static FUILoadingProgressBar CreateInstance()
 {
     return(ComponentFactory.Create <FUILoadingProgressBar, GObject>(CreateGObject()));
 }
示例#3
0
        public static void CreateM5V5Game()
        {
            M5V5Game m5V5Game = ComponentFactory.Create <M5V5Game>();

            Game.Scene.AddComponent <M5V5GameComponent, M5V5Game>(m5V5Game);
        }
示例#4
0
 public static FUILoading Create(GObject go)
 {
     return(ComponentFactory.Create <FUILoading, GObject>(go));
 }
 private static IComponent Destination() => ComponentFactory.Create(DestinationName);
示例#6
0
        public void Test()
        {
            ComponentFactory factory   = new ComponentFactory();
            Component        corporate = factory.Create <Composite>("corporate"); // 1

            factory.Create <Leaf>(corporate, "president");                        // 2 (1)
            factory.Create <Leaf>(corporate, "vice president");                   // 3 (2)
            Component sales  = factory.Create <Composite>(corporate, "sales");    // 4
            Component market = factory.Create <Composite>(corporate, "market");   // 5

            factory.Create <Leaf>(sales, "joe");                                  // 6 (3)
            factory.Create <Leaf>(sales, "bob");                                  // 7 (4)
            factory.Create <Leaf>(market, "judi");                                // 8 (5)
            Component branch = factory.Create <Composite>(corporate, "branch");   // 9

            factory.Create <Leaf>(branch, "manager");                             // 10(6)
            factory.Create <Leaf>(branch, "peter");                               // 11(7)

            IEnumerable <Component> matchSet = corporate.Enumerate(new LeafMatchRule());
            IList <Component>       leaves   = new List <Component>(matchSet);

            Assert.AreEqual <int>(7, leaves.Count);
            IList <Component> another = new List <Component>(corporate.Enumerate());

            Assert.AreEqual <int>(11, another.Count);
        }
 private static IComponent Component() => ComponentFactory.Create(ComponentName);
示例#8
0
 public static IComponent   ExternalBefore() => ComponentFactory.Create(ExternalBeforeName);
示例#9
0
 /// <summary>
 /// 创建热更新层会话
 /// </summary>
 public Session CreateHotfixSession(ETModel.Session session)
 {
     return(ComponentFactory.Create <Session, ETModel.Session>(session));
 }
示例#10
0
        public virtual void Read(IBitReader reader, ushort version)
        {
            this._ComponentContainers.Clear();

            if (version == 2)
            {
                var componentContainerVersion = reader.ReadUInt16();

                reader.PushFrameLength(24);

                var componentContainerCount = reader.ReadUInt16();
                for (int i = 0; i < componentContainerCount; i++)
                {
                    reader.PushFrameLength(24);

                    var componentContainerId = reader.ReadUInt32();
                    ComponentContainer componentContainer = null;

                    var hasComponents = reader.ReadBoolean();
                    if (hasComponents == true)
                    {
                        componentContainer = new ComponentContainer();

                        if (componentContainerVersion >= 2)
                        {
                            componentContainer.Unknown1 = reader.ReadBoolean();
                        }

                        if (componentContainerVersion >= 3)
                        {
                            componentContainer.Unknown2 = reader.ReadString();
                        }

                        var componentCount = reader.ReadUInt16();
                        for (int j = 0; j < componentCount; j++)
                        {
                            reader.PushFrameLength(24);

                            var componentNameHash = reader.ReadUInt32();

                            var component = ComponentFactory.Create(componentNameHash);
                            if (component == null)
                            {
                                throw new InvalidOperationException();
                            }

                            component.Read(reader, componentContainerVersion);
                            componentContainer.Components.Add(component);

                            reader.PopFrameLength();
                        }
                    }

                    this._ComponentContainers.Add(componentContainerId, componentContainer);

                    reader.PopFrameLength();
                }

                reader.PopFrameLength();
            }
        }
示例#11
0
        static void Main(string[] args)
        {
            // 异步方法全部会回掉到主线程
            OneThreadSynchronizationContext contex = new OneThreadSynchronizationContext();

            SynchronizationContext.SetSynchronizationContext(contex);

            //AssemblyTypes(typeof(Game).Assembly);
            //AssemblyTypes(typeof(StageScene).Assembly);

            Game.EventSystem.Add(DLLType.Model, typeof(Stage).Assembly);


            Component willRemove = null;

            Stage stage1 = ComponentFactory.CreateWithId <Stage, ulong, string>(1, 1001, "关卡一");
            Stage stage2 = ComponentFactory.CreateWithId <Stage, ulong, string>(2, 1002, "关卡二");

            stage1.AddComponent <UnitMoveSystem>();
            stage2.AddComponent <UnitMoveSystem>();

            War.StageManager.Add(stage1);
            War.StageManager.Add(stage2);

            Unit unit = ComponentFactory.CreateWithParent <Unit, string>(stage1, "单位1");

            unit.AddComponent <UnitMoveComponent>();
            stage1.AddUnit(unit);

            unit = ComponentFactory.Create <Unit, string>("单位2");
            unit.AddComponent <UnitMoveComponent>();
            stage1.AddUnit(unit);

            willRemove = unit;


            unit = ComponentFactory.Create <Unit, string>("单位B1");
            unit.AddComponent <UnitMoveComponent>();
            stage2.AddUnit(unit);


            while (true)
            {
                try
                {
                    contex.Update();
                    Game.EventSystem.Update();

                    if (willRemove != null)
                    {
                        willRemove.Dispose();
                        willRemove = null;

                        unit = ComponentFactory.CreateWithParent <Unit, string>(stage1, "单位A11");
                        unit.AddComponent <UnitMoveComponent>();
                        stage1.AddUnit(unit);

                        unit = ComponentFactory.CreateWithParent <Unit, string>(stage1, "单位A12");
                        unit.AddComponent <UnitMoveComponent>();
                        stage1.AddUnit(unit);
                    }

                    Log.Info("--------------------");
                    Thread.Sleep(2000);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
            }
        }
示例#12
0
 public static IComponent   InternalComponent() => ComponentFactory.Create(InternalComponentName);
示例#13
0
 public static IComponent   ExternalAfter() => ComponentFactory.Create(ExternalAfterName);
示例#14
0
 public static FUILoadingProgressBar Create(GObject go)
 {
     return(ComponentFactory.Create <FUILoadingProgressBar, GObject>(go));
 }
 private static IComponent Source() => ComponentFactory.Create(SourceName);
示例#16
0
        public void Test()
        {
            ComponentFactory factory   = new ComponentFactory();
            Component        corporate = factory.Create <Composite>("corporate"); // 1

            factory.Create <Leaf>(corporate, "president");                        // 2
            factory.Create <Leaf>(corporate, "vice president");                   // 3
            Component sales  = factory.Create <Composite>(corporate, "sales");    // 4
            Component market = factory.Create <Composite>(corporate, "market");   // 5

            factory.Create <Leaf>(sales, "joe");                                  // 6
            factory.Create <Leaf>(sales, "bob");                                  // 7
            factory.Create <Leaf>(market, "judi");                                // 8
            Component branch = factory.Create <Composite>(corporate, "branch");   // 9

            factory.Create <Leaf>(branch, "manager");                             // 10
            factory.Create <Leaf>(branch, "peter");                               // 11
            IList <string> names = new List <string>(corporate.GetNameList());

            // 验证确实可以把所有节点的名称(含子孙节点)遍历出来
            Assert.AreEqual <int>(11, names.Count);
            foreach (string item in corporate.GetNameList())
            {
                Trace.WriteLine(item);
            }
        }
示例#17
0
    public void setupBoard(string filePath)
    {
        JObject boardJson;

        using (StreamReader reader = File.OpenText(filePath))
        {
            boardJson = (JObject)JToken.ReadFrom(new JsonTextReader(reader));
            board.GetComponent <BoardDataHandler>().setBoardJson(boardJson);
        }

        //Debug.Log(boardJson.GetValue("Components"));
        // string type = (string)boardJson.GetValue("modeType");
        string boardName    = (string)boardJson.GetValue("boardName");
        Text   boadNameText = GameObject.Find("BoardName").GetComponent <Text>();

        boadNameText.text = boardName;

        int numberOfComponent = (int)boardJson.GetValue("numberOfComponents");

        Debug.Log("numberOfComponent = " + numberOfComponent);
        for (int i = 0; i < numberOfComponent; i++)
        {
            JObject       componentData   = (JObject)boardJson.GetValue("components")[i].DeepClone();
            string        initData        = componentData.ToString();
            string        componentName   = (string)componentData.GetValue("componentType");
            string        uiComponentName = (string)componentData.GetValue("componentType") + (string)componentData.GetValue("id");
            string        type            = (string)componentData.GetValue("modeType");
            ComponentBase comp            = ComponentFactory.Create(componentName, componentData);
            GameObject    component       = null;

            switch (componentName)
            {
            case "resistor":
                component = (GameObject)Instantiate(prefabResistor);
                if (type == "fix")
                {
                    getChildObject(component, "ValueText").GetComponent <Text>().text = Util.changeUnit(comp.value, componentName);                            //comp.value.ToString();
                }
                else
                {
                    Resistor resistor = (Resistor)comp;
                    getChildObject(component, "ValueText").GetComponent <Text>().text = Util.changeUnit(resistor.minValue + (resistor.value * resistor.stepResistance), "resistor");                        //.ToString();
                }
                break;

            case "capacitor":
                component = (GameObject)Instantiate(prefabCapacitor);
                getChildObject(component, "ValueText").GetComponent <Text>().text = Util.changeUnit(comp.value, componentName);                       //comp.value.ToString();
                break;

            case "inductor":
                component = (GameObject)Instantiate(prefabInductor);
                getChildObject(component, "ValueText").GetComponent <Text>().text = Util.changeUnit(comp.value, componentName);                       //comp.value.ToString();
                break;

            case "wire":
                component = (GameObject)Instantiate(prefabWire);
                //getChildObject(component, "ValueText").GetComponent<Text>().text = "";comp.value.ToString();
                break;

            case "led":
                component = (GameObject)Instantiate(prefabLed);
                //getChildObject(component, "ValueText").GetComponent<Text>().text = comp.value.ToString();
                break;

            case "switch":
                component = (GameObject)Instantiate(prefabSwitch);
                //getChildObject(component, "ValueText").GetComponent<Text>().text = comp.value.ToString();
                break;

            case "photoresistor":
                component = (GameObject)Instantiate(prefabPhotoresistor);
                //getChildObject(component, "ValueText").GetComponent<Text>().text = comp.value.ToString();
                break;

            case "diode":
                component = (GameObject)Instantiate(prefabDiode);
                getChildObject(component, "ValueText").GetComponent <Text>().text = Util.changeUnit(comp.value, componentName);
                break;

            case "zenerdiode":
                component = (GameObject)Instantiate(prefabZenerdiode);
                getChildObject(component, "ValueText").GetComponent <Text>().text = Util.changeUnit(comp.value, componentName);
                break;

            case "ADC":                     // voltmeter
                component = (GameObject)Instantiate(prefabVoltmeter);
                getChildObject(component, "ValueText").GetComponent <Text>().text = Util.changeUnit(comp.value, componentName);
                break;

            case "AWG":                         // function generator
                component = (GameObject)Instantiate(prefabFunctionGenerator);
                //getChildObject(component, "ValueText").GetComponent<Text>().text = Util.changeUnit(comp.value, componentName);
                break;

            default:
                component = (GameObject)Instantiate(prefabEtc);
                getChildObject(component, "ValueText").GetComponent <Text>().text = Util.changeUnit(comp.value, componentName);
                break;
            }

            if (component)
            {
                component.tag  = "component";
                component.name = uiComponentName;
                component.transform.SetParent(ParentPanel, false);
                if (i < 4)
                {
                    component.transform.position = new Vector3(265, ParentPanel.transform.position.y + 10, -80 - i * 110);
                }
                else
                {
                    component.transform.position = new Vector3(415, ParentPanel.transform.position.y + 10, -80 - (i - 4) * 110);
                }
                component.transform.localScale = new Vector3(0.6f, 0.6f, 1);
                component.GetComponent <Component>().setComponentData(comp);
                component.GetComponent <Component>().setComponentInitData(initData);
            }
        }
    }