예제 #1
0
        private static UnityObject ResolveFromTargetRelative(object target, GameObject gameObject, RuntimeMember member, RequiredFromRelativeAttribute attribute,
            Func<string, GameObject> GetOrAddRelativeAtPath,
            Func<string, GameObject> GetRelativeAtPath,
            Func<Type, Component> GetComponentInRelative)
        {
            if (member.Type == typeof(GameObject))
            {
                var path = ProcessPath(attribute.Path, member.Name);
                if (path.IsNullOrEmpty())
                    return null;

                if (attribute.Create)
                    return GetOrAddRelativeAtPath(path);

                try { return GetRelativeAtPath(path); }
                catch { return null; }
            }
            else
            {
                Component c = null;
                var path = attribute.Path;
                if (path.IsNullOrEmpty())
                {
                    c = GetComponentInRelative(member.Type);
                }
                else
                {
                    path = ProcessPath(attribute.Path, member.Name);

                    GameObject relative;

                    if (attribute.Create)
                        relative = GetOrAddRelativeAtPath(path);
                    else
                    {
                        try { relative = GetRelativeAtPath(path); }
                        catch { relative = null; }
                    }

                    if (relative == null)
                        return null;

                    c = relative.GetComponent(member.Type);
                    if (c == null && attribute.Add)
                    {
                        if (member.Type.IsAbstract)
                            Debug.Log("Can't add component `" + member.Type.Name + "` because it's abstract");
                        else
                            c = relative.AddComponent(member.Type);
                    }
                }
                return c;
            }
        }
예제 #2
0
        private static UnityObject ResolveFromTargetRelative(object target, GameObject gameObject, RuntimeMember member, RequiredFromRelativeAttribute attribute,
                                                             Func <string, GameObject> GetOrAddRelativeAtPath,
                                                             Func <string, GameObject> GetRelativeAtPath,
                                                             Func <Type, Component> GetComponentInRelative)
        {
            if (member.Type == typeof(GameObject))
            {
                var path = ProcessPath(attribute.Path, member.Name);
                if (path.IsNullOrEmpty())
                {
                    return(null);
                }

                if (attribute.Create)
                {
                    return(GetOrAddRelativeAtPath(path));
                }

                try { return(GetRelativeAtPath(path)); }
                catch { return(null); }
            }
            else
            {
                Component c    = null;
                var       path = attribute.Path;
                if (path.IsNullOrEmpty())
                {
                    c = GetComponentInRelative(member.Type);
                }
                else
                {
                    path = ProcessPath(attribute.Path, member.Name);

                    GameObject relative;

                    if (attribute.Create)
                    {
                        relative = GetOrAddRelativeAtPath(path);
                    }
                    else
                    {
                        try { relative = GetRelativeAtPath(path); }
                        catch { relative = null; }
                    }

                    if (relative == null)
                    {
                        return(null);
                    }

                    c = relative.GetComponent(member.Type);
                    if (c == null && attribute.Add)
                    {
                        if (member.Type.IsAbstract)
                        {
                            Debug.Log("Can't add component `" + member.Type.Name + "` because it's abstract");
                        }
                        else
                        {
                            c = relative.AddComponent(member.Type);
                        }
                    }
                }
                return(c);
            }
        }