Exemplo n.º 1
0
 public void AddGenericArguments(TDType rootType, TypeResolverGroup typeResolverGroup, params string[] strings)
 {
     if (!GeneratedGenericArguments)
     {
         foreach (var genericArgument in strings)
         {
             GenericArguments.Add(
                 UdonTypeExporter.GetOrCreateTDType(rootType, genericArgument, typeResolverGroup));
             GeneratedGenericArguments = true;
         }
     }
 }
Exemplo n.º 2
0
 private static void AddInputs(Class Class, Method method)
 {
     for (int i = 0; i < method.Inputs.Count; i++)
     {
         TDType input = method.Inputs[i];
         Class.Methods.Append(input);                                                                                                     //Type name
         Class.Methods.Append(
             $" {UdonTypeExporter.RemoveTypeSpecialCharacters(UdonTypeExporter.FirstCharacterToLower(input.UdonName), true, true)}_{i}"); //Parameter name
         if (i != method.Inputs.Count - 1)
         {
             Class.Methods.Append(", ");
         }
     }
 }
Exemplo n.º 3
0
 public static void AddTypeInterfaces(this Type type, HashSet <string> interfaces,
                                      TypeResolverGroup typeResolverGroup)
 {
     if (type == null)
     {
         return;
     }
     foreach (var Interface in type.GetInterfaces())
     {
         if (typeResolverGroup.GetTypeFromTypeString(UdonTypeExporter.GenerateUdonName(Interface)) != null)
         {
             interfaces.Add(UdonTypeExporter.GetTypeFullName(Interface));
             Interface.AddTypeInterfaces(interfaces, typeResolverGroup);
         }
     }
 }
Exemplo n.º 4
0
    private static string RecurseInheritedType(Type originalType, Type type, TypeResolverGroup typeResolverGroup)
    {
        if (type == null || type == typeof(object))
        {
            return("");
        }
        if (originalType == type)
        {
            return(RecurseInheritedType(originalType, type.BaseType, typeResolverGroup));
        }

        if (typeResolverGroup.GetTypeFromTypeString(UdonTypeExporter.GenerateUdonName(type)) != null)
        {
            return(UdonTypeExporter.GetTypeFullName(type));
        }

        if (type.BaseType != null)
        {
            return(RecurseInheritedType(originalType, type.BaseType, typeResolverGroup));
        }

        return("");
    }
Exemplo n.º 5
0
    private static void AddUdonMethod(Class Class, Method method, bool extensionClass, string rawFullName,
                                      string prefix = "")
    {
        var returnType = method.Output.ToString();

        if (returnType == "System.Void")
        {
            returnType = "void";
        }
        if (method.MethodType == "op")
        {
            bool atLeastOneInputIsContainedType =
                false;                                   //For some reason there are operators defined in classes which are from their inherited class
            bool atLeastOneInOutIsContainedType = false; //Check output too
            foreach (var methodInput in method.Inputs)
            {
                if (methodInput == Class.Type)
                {
                    atLeastOneInputIsContainedType = true;
                }
            }

            if (method.Output == Class.Type)
            {
                atLeastOneInOutIsContainedType = true;
            }

            if (method.MethodName == "Implicit")
            {
                if (atLeastOneInOutIsContainedType)
                {
                    //[UdonMethod("VRCSDK3ComponentsVRCAudioBank.__op_Implicit__UnityEngineObject__SystemBoolean")]
                    //public static extern implicit operator System.Boolean(UnityEngine.Object unityEngineObject_0);
                    Class.Methods.AppendLine($"\t[UdonMethod(\"{method.FullUdonExternString}\")]");
                    Class.Methods.Append($"\tpublic static extern implicit operator {returnType}(");
                    AddInputs(Class, method);
                    Class.Methods.AppendLine($");");
                }
                else
                {
                    return;
                }
            }
            else if (atLeastOneInputIsContainedType &&
                     !(method.MethodName == "ConditionalXor" || //These can't be overloaded.
                       method.MethodName == "ConditionalOr" ||
                       method.MethodName == "ConditionalAnd"))
            {
                string operatorToken = null;
                switch (method.MethodName)
                {
                case "Addition":
                    operatorToken = "+";
                    break;

                case "UnaryMinus":
                case "Subtraction":
                    operatorToken = "-";
                    break;

                case "Multiply":
                case "Multiplication":
                    operatorToken = "*";
                    break;

                case "Division":
                    operatorToken = "/";
                    break;

                case "Equality":
                    operatorToken = "==";
                    break;

                case "Inequality":
                    operatorToken = "!=";
                    break;

                case "LessThan":
                    operatorToken = "<";
                    break;

                case "GreaterThan":
                    operatorToken = ">";
                    break;

                case "LessThanOrEqual":
                    operatorToken = "<=";
                    break;

                case "GreaterThanOrEqual":
                    operatorToken = ">=";
                    break;

                case "LeftShift":
                    operatorToken = "<<";
                    break;

                case "RightShift":
                    operatorToken = ">>";
                    break;

                case "LogicalAnd":
                    operatorToken = "&";
                    break;

                case "LogicalOr":
                    operatorToken = "|";
                    break;

                case "LogicalXor":
                    operatorToken = "^";
                    break;

                case "UnaryNegation":
                    operatorToken = "!";
                    break;

                case "Remainder":
                    operatorToken = "%";
                    break;

                default:
                    Debug.LogError($"Unhandled op {method.MethodName}");
                    break;
                }

                Class.Methods.AppendLine($"\t[UdonMethod(\"{method.FullUdonExternString}\")]");
                Class.Methods.Append($"\tpublic static extern {returnType} operator {operatorToken}(");
                if (method.MethodName == "LeftShift" || method.MethodName == "RightShift")
                {
                    //Overloaded shift operator must have the type of the first operand be the containing type, and the type of the second operand must be int
                    Class.Methods.Append(method.Inputs[0]);
                    Class.Methods.Append(" ");
                    Class.Methods.Append(
                        $"{UdonTypeExporter.RemoveTypeSpecialCharacters(UdonTypeExporter.FirstCharacterToLower(method.Inputs[0].UdonName), true, true)}_0");
                    Class.Methods.Append(", System.Int32 systemInt32_1");
                }
                else
                {
                    AddInputs(Class, method);
                }

                Class.Methods.AppendLine(");");
                return;
            }
        }

        if ((method.MethodType == "get" || method.MethodType == "set") && !Class.IsExtentionClass)
        {
            Field field;
            if (Class.Fields.Contains(new Field {
                FieldName = method.MethodName
            }))
            {
                field = Class.Fields.First(t => t.FieldName == method.MethodName);
            }
            else
            {
                field = new Field {
                    FieldName = method.MethodName
                };
            }

            if (method.MethodType == "get")
            {
                field.GetMethod = method;
            }
            else
            {
                field.SetMethod = method;
            }

            Class.Fields.Add(field);
            return;
        }

        Class.Methods.AppendLine($"\t[UdonMethod(\"{method.FullUdonExternString}\")]");

        if (!Class.IsInterface)
        {
            Class.Methods.Append($"\tpublic ");
        }

        if (method.IsStatic || extensionClass)
        {
            Class.Methods.Append("static ");
        }

        if (!Class.IsInterface)
        {
            Class.Methods.Append($"extern ");
        }
        //Normal method
        Class.Methods.Append(returnType);
        Class.Methods.Append(" ");
        Class.Methods.Append(prefix);
        if (method.MethodType == "add")
        {
            Class.Methods.Append("add_");
        }
        if (method.MethodType == "remove")
        {
            Class.Methods.Append("remove_");
        }
        Class.Methods.Append($"{method.MethodName}(");
        if (extensionClass)
        {
            Class.Methods.Append($"this {rawFullName} __instance__");
            if (method.Inputs.Count > 0)
            {
                Class.Methods.Append(", ");
            }
        }

        AddInputs(Class, method);

        Class.Methods.AppendLine(");");
    }