示例#1
0
        static void ModelInit(CodeGenerator gen, DataContext rootContext, gamedef.CodeGenModule module)
        {
            switch (module.ModelGen)
            {
            case gamedef.ModelGenType.MGT_Singleton:
            {
                gen.PrintLine("_Model = Framework.ModelManager.Instance.Get<", ModelTemplate.ClassName(rootContext), ">();");
                gen.PrintLine();
            }
            break;

            case gamedef.ModelGenType.MGT_Instance:
            {
                gen.PrintLine("_Model = new ", ModelTemplate.ClassName(rootContext), "();");
                gen.PrintLine();
            }
            break;
            }
        }
示例#2
0
        public static void ClassBody(CodeGenerator gen, DataContext rootContext, List <DataContext> propContextList, gamedef.CodeGenModule module)
        {
            gen.PrintLine("// Generated by github.com/davyxu/cellorigin");
            gen.PrintLine("using UnityEngine;");
            gen.PrintLine("using UnityEngine.UI;");
            gen.PrintLine("using System;");
            gen.PrintLine();

            gen.PrintLine("partial class ", ClassName(rootContext), " : Framework.BasePresenter");
            gen.PrintLine("{");
            gen.In();

            gen.PrintLine(ModelTemplate.ClassName(rootContext), " _Model;");
            gen.PrintLine();

            // 网络Peer声明
            foreach (gamedef.CodeGenPeer peer in module.Peer)
            {
                NetworkDeclare(gen, peer);
            }

            if (module.ModelGen != gamedef.ModelGenType.MGT_Manual)
            {
                // 属性声明
                foreach (DataContext propContext in propContextList)
                {
                    PropertyBody(gen, rootContext, propContext);
                }
            }


            gen.PrintLine("public void Init( )");
            gen.PrintLine("{");
            gen.In();


            ModelInit(gen, rootContext, module);

            if (module.ModelGen != gamedef.ModelGenType.MGT_Manual)
            {
                foreach (DataContext propContext in propContextList)
                {
                    PropertyInit(gen, rootContext, propContext);
                }
            }


            // 网络获取及消息绑定


            foreach (gamedef.CodeGenPeer peer in module.Peer)
            {
                NetworkRegisterBody(gen, peer);
            }


            gen.Out();
            gen.PrintLine("}"); // Bind
            gen.PrintLine();

            foreach (DataContext propContext in propContextList)
            {
                CommandBody(gen, rootContext, propContext);
            }

            foreach (gamedef.CodeGenPeer peer in module.Peer)
            {
                foreach (string msgType in peer.RecvMessage)
                {
                    NetworkCallbackBody(gen, rootContext, peer, msgType);
                }
            }

            gen.Out();
            gen.PrintLine("}"); // Class
        }