public Object[] Deserialize()
        {
                        #if DEV_MODE && DEBUG_ENABLED
            Debug.Log("Deserializing InspectorSerializedState from " + inspected.Length + " inspected...");
                        #endif

            int count      = inspected.Length;
            var references = new Object[count];
            for (int n = count - 1; n >= 0; n--)
            {
                var target = ObjectIds.GetTarget(inspected[n]);
                if (target != null)
                {
                    references[n] = target;
                }
                else
                {
                                        #if DEV_MODE
                    Debug.LogWarning("InspectorSerializedState inspected[" + n + "] reference could not be re-established. This is expected behaviour if the target has been destroyed.");
                                        #endif
                    references = references.RemoveAt(n);
                }
            }
            return(references);
        }
Example #2
0
        public void DeserializeOverride(BinaryFormatter formatter, MemoryStream stream)
        {
            // 1: Editor count
            int editorCount = (int)formatter.Deserialize(stream);

            Setup(editorCount);

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(cachedEditors.Count == 0, StringUtils.ToStringSansNamespace(GetType()) + ".DeserializeOverride called with " + cachedEditors.Count + " cachedEditors:\n" + StringUtils.ToString(cachedEditors, "\n"));
                        #endif

            // 2: instance IDs for Editors
            for (int n = 0; n < editorCount; n++)
            {
                int instanceId = (int)formatter.Deserialize(stream);
                var editor     = ObjectIds.GetTarget(instanceId) as Editor;
                if (editor != null)
                {
                    if (!Validate(editor))
                    {
                                                #if DEV_MODE
                        Debug.LogWarning("cachedEditors.Add - Disposing editor which failed validation: " + GetKey(editor).GetHashCode() + ", " + editor.GetType().Name + StringUtils.ToString(editor.targets) + " with instanceId " + instanceId);
                                                #endif
                        Dispose(ref editor);
                        continue;
                    }

                    try
                    {
                        cachedEditors.Add(GetKey(editor), editor);
                                                #if DEV_MODE && DEBUG_DESERIALIZE
                        Debug.Log("Editors - Deserialized Editor " + GetKey(editor).GetHashCode() + " for " + editor.GetType().Name + StringUtils.ToString(editor.targets) + " with instanceId " + instanceId);
                                                #endif
                    }
                    catch (ArgumentException)                    //TEMP
                    {
                                                #if DEV_MODE
                        var key = GetKey(editor);
                        var conflictingEditor = cachedEditors[GetKey(editor)];
                        Debug.LogError("cachedEditors.Add - Already contained key " + key.GetHashCode() + " (instanceId=" + instanceId + ")"
                                       + "\nFailed To Add: " + (editor == null ? "null" : editor.GetType().Name + " with targets " + StringUtils.ToString(editor.targets))
                                       + "\nExisting: " + (conflictingEditor == null ? "null" : conflictingEditor.GetType().Name + " with targets " + StringUtils.ToString(conflictingEditor.targets))
                                       + "\ncachedEditors:\n" + StringUtils.ToString(cachedEditors, "\n"));
                                                #endif
                    }
                }
            }

                        #if DEV_MODE && DEBUG_DESERIALIZE
            Debug.Log(StringUtils.ToStringSansNamespace(GetType()) + " - Deserialized " + cachedEditors.Count + " cachedEditors:\n" + StringUtils.ToString(cachedEditors, "\n"));
                        #endif
        }
        public InspectorSerializedState(InspectorState inspectorState)
        {
            var targets = inspectorState.inspected;

            int count = targets.Length;

                        #if DEV_MODE && DEBUG_ENABLED
            Debug.Log("Creating InspectorSerializedState from " + targets.Length + " targets: " + StringUtils.ToString(targets));
                        #endif

            var references = new int[count];
            for (int n = count - 1; n >= 0; n--)
            {
                var target = targets[n];
                if (target == null)
                {
                                        #if DEV_MODE
                    Debug.LogWarning("InspectorSerializedState inspected[" + n + "] reference was null! Will skip serializing.");
                                        #endif

                    references = references.RemoveAt(n);
                }
                else
                {
                    references[n] = ObjectIds.Get(target);

                                        #if DEV_MODE
                    Debug.Assert(ObjectIds.GetTarget(references[n]) == target);
                                        #endif
                }
            }
            inspected = references;

            viewLocked = inspectorState.ViewIsLocked;

            scrollPos = inspectorState.ScrollPos;

            filter = inspectorState.filter.RawInput;
        }
Example #4
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);
            }
        }