Esempio n. 1
0
    private void GetLuaModelScript(MLuaUICom comRef, LuaDocumentNode document, string savePath)
    {
        document.Load(savePath);
        var modelName = comRef.ModelName ?? $"{gameObject.name}Model";

        document.AddRequire(new LuaRequireNode("Data/BaseModel"));
        document.AddRequire(new LuaRequireNode("Event/EventDispacher"));
        document.ModelNode          = new LuaModelNode("Data");
        document.ClassName          = modelName;
        document.ClassInitStatement = new LuaScriptStatementNode($"class(\"{modelName}\", super)");
        document.AddField(new LuaFieldNode("super", LuaMemberType.Local, new LuaScriptStatementNode("Data.BaseModel")));

        var eventNameFieldName = $"{modelName}.{comRef.DataName.ToUpper()}";

        var property = new LuaPropertyNode(comRef.DataName, LuaMemberType.Local);

        property.setStatementNodes.Add(new LuaScriptStatementNode($"if self._{comRef.DataName} == {comRef.DataName} then return end"));
        property.setStatementNodes.Add(new LuaScriptStatementNode(property.defualtSetStatement));
        property.setStatementNodes.Add(new LuaScriptStatementNode($"{eventNameFieldName}:Dispatch(Data.onDataChange, {comRef.DataName})"));
        document.AddProperty(property);


        var eventNameField = new LuaFieldNode(eventNameFieldName, LuaMemberType.Global, new LuaScriptStatementNode($"EventDispatcher.new()"));

        document.AddField(eventNameField);

        document.AddFunction(new LuaFunctionNode("ctor", LuaMemberType.Local, null, new List <LuaBaseStatementNode>()
        {
            new LuaScriptStatementNode($"super.ctor(self, CtrlNames.{gameObject.name})")
        }));

        MFileEx.SaveText(document.ToString(), savePath);
    }
Esempio n. 2
0
    //对组件的名字进行检测
    //当名字没有相同的时候通过检测
    public static void NameRepetitionDetection(MLuaUICom[] coms, MLuaUIGroup[] groups)
    {
        Dictionary <string, List <int> > cacheName = new Dictionary <string, List <int> >();

        for (int i = 0; i < coms.Length; i++)
        {
            MLuaUICom com = coms[i];
            if (com.IsArray)
            {
                if (!cacheName.ContainsKey(com.Name))
                {
                    cacheName[com.Name] = new List <int>();
                    cacheName[com.Name].Add(i);
                }
            }
            else
            {
                if (!cacheName.ContainsKey(com.Name))
                {
                    cacheName[com.Name] = new List <int>();
                }
                cacheName[com.Name].Add(i);
            }
        }
        for (int i = 0; i < groups.Length; i++)
        {
            MLuaUIGroup group = groups[i];
            if (!cacheName.ContainsKey(group.Name))
            {
                cacheName[group.Name] = new List <int>();
            }
            cacheName[group.Name].Add(i + 20000);
            NameRepetitionDetection(group.ComRefs, group.Groups);
        }

        bool          isPassDetection = true;
        StringBuilder builder         = new StringBuilder();

        foreach (var item in cacheName)
        {
            if (item.Value.Count > 1)
            {
                builder.Append(item.Key);
                builder.Append(":\n");
                for (int i = 0; i < item.Value.Count; i++)
                {
                    int index = item.Value[i];
                    if (index >= 20000)
                    {
                        builder.Append("  Groups:");
                        index -= 20000;
                    }
                    else
                    {
                        builder.Append("  ComRefs:");
                    }
                    builder.Append(index);
                    builder.Append("\n");
                }
                isPassDetection = false;
            }
        }

        if (!isPassDetection)
        {
            EditorUtility.DisplayDialog("有名字重复的组件,请解决", builder.ToString(), "确定");
        }
    }