Exemple #1
0
        static ResolveResult Resolve(DelayedLink link, Dictionary <string, UObject> objects)
        {
            if (link.AbsoluteObjectReference.StartsWith("SBParticles", StringComparison.Ordinal))
            {
                return(ResolveResult.Skipped);
            }
            if (link.AbsoluteObjectReference.StartsWith("GlobalsTX", StringComparison.Ordinal))
            {
                return(ResolveResult.Skipped);
            }
            UObject imported;

            if (objects.TryGetValue(link.AbsoluteObjectReference, out imported))
            {
                try
                {
                    link.Assign(imported);
                    return(ResolveResult.Success);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                    return(ResolveResult.Error);
                }
            }
            if (link.IsTypeReference)
            {
                var type = ReflectionHelper.GetTypeFromName(link.AbsoluteObjectReference);
                if (type != null)
                {
                    try
                    {
                        link.Assign(type);
                        return(ResolveResult.Success);
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                        return(ResolveResult.Error);
                    }
                }
            }
            Debug.LogError(string.Format("Could not find imported object: {0} for {1}", link.AbsoluteObjectReference, link));
            return(ResolveResult.NotFound);
        }
Exemple #2
0
        public static void TrySetValue(object target, FieldInfo targetField, object propValue, int arrayIndex, IResourceLocator resourceLocator)
        {
            var link = propValue as DelayedLink;

            if (link != null)
            {
                link.FieldReference  = targetField;
                link.TargetReference = target;
                link.IndexReference  = arrayIndex;
                if (CanSkip(link.SkipTestClassReference) || CanSkip(link.AbsoluteClassPath))
                {
                    return;
                }
                UObject subject;
                if (resourceLocator.TryFindObject(link.AbsoluteObjectReference, out subject))
                {
                    link.Assign(subject);
                    return;
                }
                if (link.FieldReference.FieldType == typeof(TypeDescription) ||
                    (link.FieldReference.FieldType.IsArray && link.FieldReference.FieldType.GetElementType() == typeof(TypeDescription)) ||
                    (link.FieldReference.FieldType.IsGenericType && link.FieldReference.FieldType.GetGenericTypeDefinition() == typeof(List <>) && link.FieldReference.FieldType.GetGenericArguments()[0] == typeof(TypeDescription))
                    )
                {
                    var t = GetTypeFromName(link.AbsoluteObjectReference);
                    if (t != null)
                    {
                        link.Assign(new TypeDescription(link.AbsoluteObjectReference));
                        return;
                    }
                    Debug.LogWarning("Couldn't find type: " + link.AbsoluteObjectReference);
                    return;
                }
                Debug.LogError(string.Format("Couldn't find linked object: {0} for {1} (field:{2})", link.AbsoluteObjectReference, link.TargetReference, link.FieldReference));
            }
            else
            {
                link = new DelayedLink()
                {
                    FieldReference         = targetField,
                    TargetReference        = target,
                    IndexReference         = arrayIndex,
                    SkipTestClassReference = targetField.FieldType.FullName
                };
                link.Assign(propValue);
            }
        }