Пример #1
0
        void Build(DOMCommand command)
        {
            Assert.IsFalse(string.IsNullOrEmpty(command.name), "name is required for <command />");

            var pptName = NameUtility.SlugifyConstName(command.name);

            var parametricArgs = string.Empty;

            if (command.args != null && command.args.Length > 0)
            {
                var builder = new StringBuilder();
                builder.Append("<");
                for (int i = 0; i < command.args.Length; i++)
                {
                    if (i > 0)
                    {
                        builder.Append(", ");
                    }
                    builder.Append(command.args[i].type);
                }
                builder.Append(">");
                parametricArgs = builder.ToString();
            }

            m_Class.AddField(
                new CSField(
                    Scope.Private,
                    pptName,
                    "IClassMethod" + parametricArgs,
                    "new DynamicClassMethod" + parametricArgs + "(\"" + command.name + "\")",
                    CSField.Modifier.Static | CSField.Modifier.Readonly));
        }
Пример #2
0
        void VisitIn(DOMField field)
        {
            Assert.IsFalse(string.IsNullOrEmpty(field.type), "type is required for <field />");
            Assert.IsFalse(string.IsNullOrEmpty(field.name), "name is required for <field />");

            m_Class.AddField(new CSField(Scope.Private, field.name, field.type, field.@default));
        }
Пример #3
0
        void VisitIn(DOMCommand command)
        {
            Assert.IsFalse(string.IsNullOrEmpty(command.name), "name is required for <command />");

            var parametricArgs0 = string.Empty;
            var parametricArgs1 = string.Empty;

            if (command.args != null && command.args.Length > 0)
            {
                var parametricTypes = command.args.Select(a => a.type).ToArray();
                parametricArgs0 = "<" + string.Join(", ", parametricTypes) + ">";
                parametricArgs1 = ", " + string.Join(", ", parametricTypes);
            }

            m_PropertyClass.AddField(
                new CSField(
                    Scope.Public,
                    NameUtility.SlugifyConstName(command.name),
                    "IClassMethod" + parametricArgs0, "new StaticClassMethod<" + m_Class.name + parametricArgs1 + ">(\"" + command.name + "\")",
                    CSField.Modifier.Static | CSField.Modifier.Readonly));
        }
Пример #4
0
        string WriteChild(string tag, string @class, DOMElement elt)
        {
            var instanceId = GetIdForTag(tag);
            var fieldName  = GetFieldNameFor(instanceId);

            m_Class.AddField(new CSField(Scope.Private, fieldName, @class));
            m_BuildMethod.AddBodyLine(string.Format("{0} = new {1}();", fieldName, @class));
            m_BuildMethod.AddBodyLine(string.Format(m_WriteChildFormatStack.Peek(), fieldName, m_WriteChildFormatStack.Peek()));

            WriteSetOrBind(fieldName, @class, "widthOverride", elt.widthOverride);
            WriteSetOrBind(fieldName, @class, "heightOverride", elt.heightOverride);

            return(fieldName);
        }
Пример #5
0
    //通过类名和csv文本,返回cs文件的内容(一个C#类的定义)
    private static CSClass GetText(string className, string sourceText)
    {
        string[] lineList = sourceText.Split('\n');
        string[] keyList  = ParseLine(lineList[0].Trim());
        string[] typeList = ParseLine(lineList[1].Trim());

        CSClass cs = new CSClass(className);

        for (int i = 0, n = keyList.Length; i < n; i++)
        {
            cs.AddField(keyList[i], typeList[i]);
        }

        return(cs);
    }
Пример #6
0
        private void VisitIn(DOMDocument document)
        {
            // Create window method
            var createWindowMethod = new CSMethod(Scope.Internal, m_Class.name, "CreateWindow", CSMethod.Modifier.Static)
                                     .AddBodyLine("var window = GetWindow<" + m_Class.name + ">();");

            if (!string.IsNullOrEmpty(document.title))
            {
                createWindowMethod.AddBodyLine("window.titleContent = new GUIContent(\"" + document.title + "\");");
            }
            createWindowMethod.AddBodyLine("return window;");

            m_Class.AddMethod(createWindowMethod);

            m_HasService = false;
            m_HasRoot    = false;

            if (!string.IsNullOrEmpty(document.serviceClass))
            {
                m_HasService = true;
                m_Class.AddField(new CSField(Scope.Private, "m_Service", document.serviceClass));
                m_AwakeMethod.AddBodyLine("m_Service = new " + document.serviceClass + "();");

                var exposedClass = string.IsNullOrEmpty(document.exposedServiceClass)
                    ? document.serviceClass
                    : document.exposedServiceClass;

                m_Class.AddProperty(new CSProperty(Scope.Public, "service", exposedClass)
                                    .SetGetter("return m_Service;"));
            }

            if (!string.IsNullOrEmpty(document.rootClass))
            {
                m_HasRoot = true;
                m_Class.AddField(new CSField(Scope.Private, "m_Root", document.rootClass));
                m_AwakeMethod.AddBodyLine("m_Root = new " + document.rootClass + "();");
            }

            if (m_HasRoot)
            {
                m_AwakeMethod.AddBodyLine("m_Root.parent = new VisualElementRoot();");
                m_AwakeMethod.AddBodyLine("m_Root.RepaintRequested += Repaint;");
                m_OnDestroyMethod.AddBodyLine("m_Root.RepaintRequested -= Repaint;");
                m_OnDestroyMethod.AddBodyLine("m_Root.Dispose();");
                m_OnDestroyMethod.AddBodyLine("m_Root = null;");
                if (m_HasService)
                {
                    m_AwakeMethod.AddBodyLine("m_Root.dataContext = m_Service.vm;");
                }

                m_Class.AddMethod(new CSMethod(Scope.Private, "void", "OnGUI")
                                  .AddBodyLine("m_Root.OnGUI();"));
            }
            if (m_HasService)
            {
                m_AwakeMethod.AddBodyLine("m_Service.vm.PropertyChanged += VmOnPropertyChanged;");
                m_AwakeMethod.AddBodyLine("m_Service.vm.SetPropertyChanged((ClassProperty)null);");
                m_OnDestroyMethod.AddBodyLine("m_Service.vm.PropertyChanged -= VmOnPropertyChanged;");
            }
            if (m_HasRoot || m_HasService)
            {
                var onEnableMethod = new CSMethod(Scope.Private, "void", "OnEnable");
                var cond           = "m_Service == null || m_Root == null";
                if (!m_HasRoot)
                {
                    cond = "m_Service == null";
                }
                if (!m_HasService)
                {
                    cond = "m_Root == null";
                }

                onEnableMethod.AddBodyLine("if (" + cond + ")");
                onEnableMethod.AddBodyLine("    Awake();");
                m_Class.AddMethod(onEnableMethod);
            }
        }