예제 #1
0
    public static void Generate()
    {
        if (type.IsInterface && type != typeof(System.Collections.IEnumerator))
        {
            return;
        }

        Debugger.Log("Begin Generate lua Wrap for class {0}", className);

        if (wrapClassName == "")
        {
            wrapClassName = className;
        }
        exportName = wrapClassName + "Wrap";

        AutoCompleteExport.AddExportClass(exportName, type);

        if (type.IsEnum)
        {
            GenEnum();
        }
        else
        {
            InitMethods();
            InitField();
        }

        AutoCompleteExport.ExportClass(exportName);
        AutoCompleteExport.ExportFile(exportName);
    }
예제 #2
0
    public static void CreateAutoComplete()
    {
        Debug.Log("CreateAutoComplete");
        if (EditorApplication.isCompiling)
        {
            EditorUtility.DisplayDialog("警告", "请等待编辑器完成编译再执行此功能", "确定");
            return;
        }

        if (!File.Exists(CustomSettings.saveDir))
        {
            Directory.CreateDirectory(CustomSettings.saveDir);
        }

        List <ToLuaMenu.BindType> allTypes = new List <ToLuaMenu.BindType>();

        allTypes.Clear();
        ToLuaMenu.BindType[] typeList = CustomSettings.customTypeList;

        ToLuaMenu.BindType[] list = GenBindTypes(typeList);
        ToLuaExport.allTypes.AddRange(ToLuaMenu.baseType);

        for (int i = 0; i < list.Length; i++)
        {
            ToLuaExport.allTypes.Add(list[i].type);
        }

        for (int i = 0; i < list.Length; i++)
        {
            ToLuaExport.type = list[i].type;
            Clear();
            className     = list[i].name;
            type          = list[i].type;
            isStaticClass = list[i].IsStatic;
            baseType      = list[i].baseType;
            wrapClassName = list[i].wrapName;
            Generate();
        }

        if (ExportSetting.ZipFile)
        {
            AutoCompleteExport.ZipAutoCompletionToFile();
            Rolance.FileHelper.Instance.DelFile();
        }

        Debug.Log("Generate lua binding files over");
        Rolance.FileHelper.Instance.Clear();
        AutoCompleteExport.Clear();
        ToLuaExport.allTypes.Clear();
        allTypes.Clear();
        AssetDatabase.Refresh();
    }
예제 #3
0
    static void InitField()
    {
        fields = type.GetFields(BindingFlags.GetField | BindingFlags.SetField | BindingFlags.Instance | binding);

        List <FieldInfo> fieldList = new List <FieldInfo>();

        fieldList.AddRange(fields);

        for (int i = 0; i < fieldList.Count; i++)
        {
            AutoCompleteExport.AddExportProperty(exportName, fieldList[i]);
        }
    }
예제 #4
0
    static void InitMethods()
    {
        bool flag = false;

        if (baseType != null || isStaticClass)
        {
            binding |= BindingFlags.DeclaredOnly;
            flag     = true;
        }

        List <MethodInfo> list = new List <MethodInfo>();

        list.AddRange(type.GetMethods(BindingFlags.Instance | binding));

        Type tempType = type.BaseType;

        while (tempType.BaseType != null)
        {
            list.AddRange(tempType.GetMethods(BindingFlags.Instance | binding));
            tempType = tempType.BaseType;
        }

        for (int i = list.Count - 1; i >= 0; --i)
        {
            //去掉操作符函数
            if (list[i].Name.StartsWith("op_") || list[i].Name.StartsWith("add_") || list[i].Name.StartsWith("remove_"))
            {
                if (!IsNeedOp(list[i].Name))
                {
                    list.RemoveAt(i);
                }

                continue;
            }

            //扔掉 unity3d 废弃的函数
            if (ToLuaExport.IsObsolete(list[i]))
            {
                list.RemoveAt(i);
            }
            else
            {
                AutoCompleteExport.AddExportMethod(exportName, list[i]);
            }
        }
    }
예제 #5
0
    static void GenEnum()
    {
        fields = type.GetFields(BindingFlags.GetField | BindingFlags.Public | BindingFlags.Static);
        List <FieldInfo> list = new List <FieldInfo>(fields);

        for (int i = list.Count - 1; i > 0; i--)
        {
            if (ToLuaExport.IsObsolete(list[i]))
            {
                list.RemoveAt(i);
            }
        }

        fields = list.ToArray();
        for (int i = 0; i < fields.Length; i++)
        {
            AutoCompleteExport.AddExportEnum(exportName, fields[i]);
        }
    }