Exemplo n.º 1
0
    static int AppendMethod(MethodDefinition method)
    {
        string                    methodSignature      = GetMethodSignature(method);
        string                    methodFullSignature  = method.FullName;
        InjectedMethodInfo        newInfo              = new InjectedMethodInfo();
        string                    typeName             = ToLuaInjectionHelper.GetTypeName(method.DeclaringType, true);
        List <InjectedMethodInfo> typeMethodIndexGroup = null;

        bridgeInfo.TryGetValue(typeName, out typeMethodIndexGroup);

        if (typeMethodIndexGroup == null)
        {
            typeMethodIndexGroup        = new List <InjectedMethodInfo>();
            newInfo.methodPublishedName = method.Name;
            bridgeInfo.Add(typeName, typeMethodIndexGroup);
        }
        else
        {
            InjectedMethodInfo existInfo = typeMethodIndexGroup.Find(info => info.methodOverloadSignature == methodSignature);

            if (existInfo == null)
            {
                existInfo = typeMethodIndexGroup.Find(info => info.methodName == method.Name);
                if (existInfo != null)
                {
                    newInfo.methodPublishedName   = methodSignature;
                    existInfo.methodPublishedName = existInfo.methodOverloadSignature;
                }
                else
                {
                    newInfo.methodPublishedName = method.Name;
                }
            }
            else
            {
                if (existInfo.methodFullSignature != methodFullSignature)
                {
                    Debug.LogError(typeName + "." + existInfo.methodPublishedName + " 签名跟历史签名不一致,无法增量,Injection中断,请修改函数签名、或者直接删掉InjectionBridgeEditorInfo.xml(该操作会导致无法兼容线上版的包体,需要强制换包)!");
                    EditorPrefs.SetInt(Application.dataPath + "WaitForInjection", 0);
                    return(-1);
                }
                return(existInfo.methodIndex);
            }
        }

        newInfo.methodName = method.Name;
        newInfo.methodOverloadSignature = methodSignature;
        newInfo.methodFullSignature     = methodFullSignature;
        newInfo.methodIndex             = ++methodCounter;
        typeMethodIndexGroup.Add(newInfo);

        return(methodCounter);
    }
Exemplo n.º 2
0
    static string GetMethodSignature(MethodDefinition method)
    {
        StringBuilder paramsTypeNameBuilder = StringBuilderCache.Acquire();

        paramsTypeNameBuilder.Append(method.Name);

        foreach (var param in method.Parameters)
        {
            paramsTypeNameBuilder
            .Append("-")
            .Append(ToLuaInjectionHelper.GetTypeName(param.ParameterType));
        }

        return(StringBuilderCache.GetStringAndRelease(paramsTypeNameBuilder));
    }