Ejemplo n.º 1
0
 void UpdateClass(string[] classes)
 {
     for(int i = 0; i < classes.Length; i++) {
         Type type = WrapReflectionTools.GetType(classes[i]);
         OnlyRemoveClass(WrapReflectionTools.GetWrapFolderName(type), WrapReflectionTools.GetWrapFileName(type));
         OnlyAddClass(type);
     }
     UpdateWrapCore();// 有可能WrapCore被改坏了,还是更新一下
     AssetDatabase.Refresh();
 }
Ejemplo n.º 2
0
    void OnlyAddClass(string fullname)
    {
        Type type = WrapReflectionTools.GetType(fullname);

        if(type == null) {
            Debug.LogWarning("No Such Type : " + fullname);
            return;
        }
        OnlyAddClass(type);
    }
Ejemplo n.º 3
0
 void RemoveClass(string[] classes)
 {
     for(int i = 0; i < classes.Length; i++) {
         Type type = WrapReflectionTools.GetType(classes[i]);
         OnlyRemoveClass(WrapReflectionTools.GetWrapFolderName(type), WrapReflectionTools.GetWrapFileName(type));
     }
     ReloadWrap();
     UpdateWrapCore();
     //Remove完毕ReloadDataBase,会编译代码
     AssetDatabase.Refresh();
 }
Ejemplo n.º 4
0
    //分为3部分:System(不会变),Unity(更新Unity版本时变),Custom(Assembly-CSharp里,每次改代码时变)
    public static string[] RegisterTypeToString(List <Type> systemTypes, List <Type> unityTypes, List <Type> customTypes)
    {
        string systemType = "";
        string unityType  = "";
        string customType = "";

        for (int i = 0; i < systemTypes.Count; i++)
        {
            string trueName = WrapReflectionTools.GetTrueName(systemTypes[i]);

            if (WrapReflectionTools.IsStaticClass(systemTypes[i]))
            {
                systemType += "CQuark.AppDomain.RegisterType (typeof(" + trueName + "), \"" + trueName + "\");";
            }
            else
            {
                systemType += "CQuark.AppDomain.RegisterType<" + trueName + "> ();";
            }
            systemType += "\n";
        }
        for (int i = 0; i < unityTypes.Count; i++)
        {
            string trueName = WrapReflectionTools.GetTrueName(unityTypes[i]);

            if (WrapReflectionTools.IsStaticClass(unityTypes[i]))
            {
                unityType += "CQuark.AppDomain.RegisterType (typeof(" + trueName + "), \"" + trueName + "\");";
            }
            else
            {
                unityType += "CQuark.AppDomain.RegisterType<" + trueName + "> ();";
            }
            unityType += "\n";
        }
        for (int i = 0; i < customTypes.Count; i++)
        {
            string trueName = WrapReflectionTools.GetTrueName(customTypes[i]);

            if (WrapReflectionTools.IsStaticClass(customTypes[i]))
            {
                customType += "CQuark.AppDomain.RegisterType (typeof(" + trueName + "), \"" + trueName + "\");";
            }
            else
            {
                customType += "CQuark.AppDomain.RegisterType<" + trueName + "> ();";
            }
            customType += "\n";
        }
        return(new string[] { systemType, unityType, customType });
    }
Ejemplo n.º 5
0
 void UpdateRegisterTypes()
 {
     List<Type> systemType = new List<Type>();
     List<Type> unityType = new List<Type>();
     List<Type> customType = new List<Type>();
     WrapReflectionTools.GetAllTypes(systemType, unityType, customType);
     string[] output = WrapTextTools.RegisterTypeToString(systemType, unityType, customType);
     //TODO
     string text = File.ReadAllText(WrapConfigFolder + "/RegisterTypesTemplate.txt", System.Text.Encoding.UTF8);// (Resources.Load("WrapPartTemplate") as TextAsset).text;
     text = text.Replace("{RegisterSystemTypes}", output[0]);
     text = text.Replace("{RegisterUnityTypes}", output[1]);
     text = text.Replace("{RegisterCustomTypes}", output[2]);
     if(!Directory.Exists(RegisterGenFolder)){
         Directory.CreateDirectory(RegisterGenFolder);
     }
     WrapTextTools.WriteAllText(RegisterGenFolder, "RegisterTypes.cs", text);
     AssetDatabase.Refresh();
 }
Ejemplo n.º 6
0
    void OnlyAddClass(Type type)
    {
        List<string> _typeDic = new List<string>();
        string classFullName = WrapReflectionTools.GetTrueName(type);
        if(!WrapTextTools.IsSupported(classFullName))
            return;
        if(_classBlackList.Contains(classFullName))
            return;

        string assemblyName = WrapReflectionTools.GetWrapFolderName(type);
        string classname = WrapReflectionTools.GetWrapFileName(type);

        string manifest = "";//一个记事本,用来保存哪些内容做了Wrap

        //变量或属性
        List<Property> savePropertys = WrapReflectionTools.GetPropertys(type, ref manifest, _memberBlackList);
        string[] propertyPartStr = WrapTextTools.Propertys2PartStr(classFullName, savePropertys);

        //构造函数
        List<Method> constructMethods = WrapReflectionTools.GetConstructor(type, ref manifest);
        string wrapNew = WrapTextTools.Constructor2PartStr(classFullName, constructMethods);
        WrapTextTools.CallTypes2TypeStr(classFullName, constructMethods, _typeDic);

        //静态方法(最后的参数是忽略属性,因为属性也是一种方法)
        List<Method> staticMethods = WrapReflectionTools.GetStaticMethods(type, ref manifest, savePropertys, _memberBlackList);
        string wrapSCall = WrapTextTools.SCall2PartStr(classFullName, staticMethods);
        WrapTextTools.CallTypes2TypeStr(classFullName, staticMethods, _typeDic);

        //成员方法
        List<Method> memberMethods = WrapReflectionTools.GetInstanceMethods(type, ref manifest, savePropertys, _memberBlackList);
        string wrapMCall = WrapTextTools.MCall2PartStr(classFullName, memberMethods);
        WrapTextTools.CallTypes2TypeStr(classFullName, memberMethods, _typeDic);

        //索引
        List<Method> indexMethods = WrapReflectionTools.GetIndex(type, ref manifest);
        string[] wrapIndex = WrapTextTools.Index2PartStr(classFullName, indexMethods);

        //运算符(数学运算和逻辑运算)
        List<Method> opMethods = WrapReflectionTools.GetOp(type, ref manifest);
        string[] wrapOp = WrapTextTools.Op2PartStr(opMethods);

        UpdateWrapPart(assemblyName, classname, manifest, _typeDic, propertyPartStr,
            wrapNew, wrapSCall, wrapMCall, wrapIndex, wrapOp);
    }
Ejemplo n.º 7
0
    public void WrapCommon()
    {
        //最后导出的内容是: BaseType + (All-Non-Namespace + WhiteList) - BlackList
        //导出的时候同时注册
        //基本类型(int,bool,string等)
        //        OnlyAddClass("", "double");
        //        OnlyAddClass("", "float");
        //        OnlyAddClass("", "long");
        //        OnlyAddClass("", "ulong");
        //        OnlyAddClass("", "int");
        //        OnlyAddClass("", "uint");
        //        OnlyAddClass("", "short");
        //        OnlyAddClass("", "ushort");
        //        OnlyAddClass("", "byte");
        //        OnlyAddClass("", "sbyte");
        //        OnlyAddClass("", "char");
        //        OnlyAddClass("", "object");
        //        OnlyAddClass("", "bool");
        //        OnlyAddClass("", "string");

        //项目里没有Namespace的所有类, 减去黑名单
        if (m_wrapNonNameSpaceClass) {
            Type[] types = WrapReflectionTools.GetTypesByNamespace ("");
            if (types != null) {
                for (int i = 0; i < types.Length; i++) {
                    OnlyAddClass (types [i]);
                }
            }
        }

        for (int i = 0; i < _whiteList.Count; i++) {
            OnlyAddClass(_whiteList[i]);
        }

        ReloadWrap();
        UpdateWrapCore();
        //Add完毕ReloadDataBase,会编译代码
        AssetDatabase.Refresh();
    }
Ejemplo n.º 8
0
    //Wrap一个自己输入的内容,需要判断是一个类还是一个命名空间
    public void WrapCustom(string text)
    {
        Type type = WrapReflectionTools.GetType(text);

        //输入的是一个类
        if(type != null) {
            string assemblyName = WrapReflectionTools.GetWrapFolderName(type);
            string className = WrapReflectionTools.GetWrapFileName(type);
            WrapClass wc = GetWrapClass(assemblyName);
            if(wc == null) {
                wc = new WrapClass(assemblyName);
                AddClass(type);
            }
            else {
                if(!wc.m_classes.Contains(className))
                    AddClass(type);
                else
                    UpdateClass(new string[]{text});
            }
        }
        //输入的是一个命名空间
        else{
            Type[] types = WrapReflectionTools.GetTypesByNamespace(text);
            if(types != null) {
                for(int i = 0; i < types.Length; i++) {
        //					Debug.Log(types[i].ToString());
                    AddClass(types[i]);
                }
            }
        }

        ReloadWrap();
        UpdateWrapCore();
        //Add完毕ReloadDataBase,会编译代码
        AssetDatabase.Refresh();
    }