Exemplo n.º 1
0
        static void PropertyBody(CodeGenerator gen, DataContext rootContext, DataContext ctx)
        {
            switch (ctx.Type)
            {
            case WidgetType.ScrollRect:
            {
                gen.PrintLine("public Framework.ObservableCollection<int, ", ClassItemName(ctx), "> ", Property(ctx), " { get; set; }");
            }
            break;

            case WidgetType.Text:
            case WidgetType.InputField:
            {
                if (HasPropertyChangedNotify(ctx))
                {
                    gen.PrintLine("public Action ", Event(ctx), ";");
                }

                gen.PrintLine("public ", PropertyType(ctx), " ", Property(ctx));
                gen.PrintLine("{");
                gen.In();

                gen.PrintLine("get");
                gen.PrintLine("{");
                gen.In();
                gen.PrintLine("return _Model.", Property(ctx), ";");
                gen.Out();
                gen.PrintLine("}");         // get


                gen.PrintLine("set");
                gen.PrintLine("{");
                gen.In();
                gen.PrintLine("_Model.", Property(ctx), " = value;");

                gen.PrintLine();

                // 有Presenter同步到View时, 调用通知
                if (HasPropertyChangedNotify(ctx))
                {
                    gen.PrintLine("if ( ", Event(ctx), " != null )");
                    gen.PrintLine("{");
                    gen.In();
                    gen.PrintLine(Event(ctx), "();");
                    gen.Out();
                    gen.PrintLine("}");         // set
                }


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


                gen.Out();
                gen.PrintLine("}");         // Property
            }
            break;

            default:
                return;
            }

            gen.PrintLine();
        }
Exemplo n.º 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
        }
Exemplo n.º 3
0
 public static void Save(CodeGenerator gen, DataContext rootContext)
 {
     CodeUtility.WriteFile(FullFileName(rootContext), gen.ToString());
 }
Exemplo n.º 4
0
 static void NetworkDeclare(CodeGenerator gen, gamedef.CodeGenPeer peer)
 {
     gen.PrintLine("NetworkPeer ", NetworkPeerInstance(peer), ";");
     gen.PrintLine();
 }