Exemplo n.º 1
0
        public static LinkedMemberInfo Create(Object unityObject, MemberInfo[] parents)
        {
            var hierarchy = LinkedMemberHierarchy.Get(unityObject);
            LinkedMemberInfo memberInfo = null;

            for (int n = 0, lastIndex = parents.Length - 1; n <= lastIndex; n++)
            {
                var current   = parents[n];
                var fieldInfo = current as FieldInfo;
                if (fieldInfo != null)
                {
                    memberInfo = hierarchy.Get(memberInfo, fieldInfo);
                    continue;
                }
                var propertyInfo = current as PropertyInfo;
                if (propertyInfo != null)
                {
                    memberInfo = hierarchy.Get(memberInfo, propertyInfo);
                    continue;
                }

                var methodInfo = current as MethodInfo;
                if (methodInfo != null)
                {
                    memberInfo = hierarchy.Get(memberInfo, methodInfo);
                    continue;
                }

                Debug.LogError("LinkedMemberInfo.Create - MemberInfo #" + n + " type unsupported: " + StringUtils.ToString(current.GetType()));
            }
            return(memberInfo);
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        protected override void DoBuildMembers()
        {
                        #if DEV_MODE && DEBUG_BUILD_MEMBERS
            Debug.Log(Msg(ToString(), ".DoBuildMembers with hasResult=", hasResult, ", hasParameters=", hasParameters, ", isGeneric=", isGeneric));
                        #endif

            if (!hasResult && !hasParameters && !isGeneric)
            {
                DrawerArrayPool.Resize(ref members, 0);
            }
            else
            {
                int size = 0;
                if (hasResult)
                {
                    size++;
                }
                if (isGeneric)
                {
                    size++;
                }
                if (hasParameters)
                {
                    size++;
                }
                DrawerArrayPool.Resize(ref members, size);

                bool readOnly = ReadOnly;

                int index = 0;
                if (isGeneric)
                {
                    members[0] = GenericsDrawer.Create(memberInfo, this, GUIContentPool.Create("Generics"), readOnly);
                    index++;
                }

                if (hasParameters)
                {
                    members[index] = ParameterDrawer.Create(MethodInfo.GetParameters(), memberInfo, this, GUIContentPool.Create("Parameters"), readOnly);
                    index++;
                }

                if (hasResult)
                {
                    string tooltip = LinkedMemberInfo.TooltipDatabase.GetTooltipFromParent(MethodInfo.ReturnParameter, memberInfo, "Returns");
                    if (tooltip.Length == 0)
                    {
                        tooltip = "Value returned by method.";
                    }

                    var resultMemberInfo = resultMemberHierarchy.Get(null, typeof(MethodDrawer).GetField("result", BindingFlags.Instance | BindingFlags.NonPublic), LinkedMemberParent.ClassInstance, null);
                    members[index] = DrawerProvider.GetForField(result, Type, resultMemberInfo, this, GUIContentPool.Create("Result", tooltip), readOnly);
                }
            }
        }
Exemplo n.º 3
0
        public static LinkedMemberInfo Deserialize(byte[] bytes)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            UnityEngine.Debug.Assert(bytes != null);
                        #endif

            using (var stream = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                stream.Write(bytes, 0, bytes.Length);
                stream.Seek(0, SeekOrigin.Begin);
                SerializableMemberInfo deserialized;
                deserialized = formatter.Deserialize(stream) as SerializableMemberInfo;
                int count   = deserialized.targetReferences.Length;
                var targets = ArrayPool <Object> .Create(count);

                for (int n = count - 1; n >= 0; n--)
                {
                    targets[n] = ObjectIds.GetTarget(deserialized.targetReferences[n]);
                }

                var hierarchy = LinkedMemberHierarchy.Get(targets);

                LinkedMemberInfo result = null;
                var memberStack         = deserialized.memberStack;

                // TO DO: serialize parent info better for more reliable fetching

                for (int n = memberStack.Count - 1; n >= 0; n--)
                {
                    var member = memberStack.Pop();
                    result = member.Deserialize(hierarchy);
                }
                return(result);
            }
        }
Exemplo n.º 4
0
            public LinkedMemberInfo Deserialize(LinkedMemberHierarchy hierarchy)
            {
                LinkedMemberInfo parent = null;
                var parentType          = parentChainIsBroken ? LinkedMemberParent.Missing : LinkedMemberParent.UnityObject;

                if (parentName != null)
                {
                    var allInfos = hierarchy.Members;
                    for (int n = allInfos.Count - 1; n >= 0; n--)
                    {
                        if (string.Equals(allInfos[n].Name, parentName))
                        {
                            parent = allInfos[n];
                            if (parent.IsStatic)
                            {
                                parentType = LinkedMemberParent.Static;
                            }
                            else
                            {
                                parentType = LinkedMemberParent.LinkedMemberInfo;
                            }
                            break;
                        }
                    }

                                        #if DEV_MODE && PI_ASSERTATIONS
                    UnityEngine.Debug.Assert(parent != null, "SerializableMemberInfo.Deserialize: unable to find parent by name \"" + parentName + "\"");
                                        #endif
                }

                LinkedMemberInfo result;

                switch (linkedMemberType)
                {
                case LinkedMemberType.Field:
                    result = hierarchy.Get(parent, attributeProvider as FieldInfo, parentType);
                    break;

                case LinkedMemberType.CollectionMember:
                    var getMember = getDelegateSerialized.Deserialize <GetCollectionMember>();
                    var setMember = setDelegateSerialized.Deserialize <SetCollectionMember>();
                                                #if DEV_MODE && PI_ASSERTATIONS
                    UnityEngine.Debug.Assert(getMember != null || setMember != null, "CollectionMember with type=" + StringUtils.ToStringSansNamespace(type) + " and parentName=\"" + parentName + "\" get and set were null with getDelegateSerialized=" + getDelegateSerialized);
                                                #endif
                    result = hierarchy.GetCollectionMember(parent, type, collectionIndex, getMember, setMember);
                    break;

                case LinkedMemberType.Property:
                case LinkedMemberType.Indexer:
                    result = hierarchy.Get(parent, attributeProvider as PropertyInfo, parentType);
                    break;

                case LinkedMemberType.Method:
                    result = hierarchy.Get(parent, attributeProvider as MethodInfo, parentType);
                    break;

                case LinkedMemberType.Parameter:
                    result = hierarchy.Get(parent, attributeProvider as ParameterInfo);
                    break;

                case LinkedMemberType.GenericTypeArgument:
                    result = hierarchy.Get(parent, attributeProvider as Type, collectionIndex);
                    break;

                case LinkedMemberType.CollectionResizer:
                    var get = getDelegateSerialized.Deserialize <GetSize>();
                    var set = setDelegateSerialized.Deserialize <SetSize>();
                    result = hierarchy.GetCollectionResizer(parent, type, get, set);
                    break;

                default:
                    throw new NotSupportedException("Deserializing LinkedMemberInfo of type " + linkedMemberType);
                }

                                #if UNITY_EDITOR
                if (serializedPropertyFullPath != null)
                {
                    result.SetSerializedProperty(hierarchy.SerializedObject.FindProperty(serializedPropertyFullPath));
                }
                                #endif

                return(result);
            }