Пример #1
0
        // Mostly copy paste of above adapted for just checking the types in `params` args
        private int ScoreMethodParamArgPair(System.Type methodParam, System.Type argType)
        {
            // This doesn't yet handle implicit user defined casts... there are probably other things this should handle too.
            int score = 1000000;

            if (methodParam == argType)
            {
                score = 0;
            }
            else if (methodParam.IsValidNumericImplicitCastTargetType() && argType.IsValidNumericImplictCastSourceType())
            {
                score = UdonSharpUtils.GetImplicitNumericCastDistance(methodParam, argType);
            }
            else if (methodParam == typeof(object))
            {
                score = 30; // We want to avoid object args as much as possible
            }
            else if (argType.IsSubclassOf(methodParam))
            {
                // Count the distance in the inheritance

                System.Type currentType = argType;

                score = 0;
                while (currentType != methodParam && score < 20)
                {
                    score++;
                    currentType = currentType.BaseType;
                }
            }

            return(score);
        }