Example #1
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);
            }
        }