コード例 #1
0
    static int OnAfterDeserialize(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        ISerializationCallbackReceiver obj = LuaScriptMgr.GetNetObject <ISerializationCallbackReceiver>(L, 1);

        obj.OnAfterDeserialize();
        return(0);
    }
コード例 #2
0
        /// <summary>
        /// Entry-point for deserializing data from an previously serialized xml formatted string.
        /// </summary>
        /// <param name="xml"></param>
        /// <param name="maxSupportedVer"></param>
        /// <returns></returns>
        public static object Deserialize(string xml, int maxSupportedVer, ITypeConverter typeConverter, bool isSerializerCallback = false)
        {
            var deserializer = new XmlDeserializer(typeConverter);

            deserializer.Doc.LoadXml(xml);
            deserializer.DeferredIds = new Dictionary <int, List <DeferedReferenceMap> >();

            //preload built-in unity resources manifest lookup
            if (!isSerializerCallback)
            {
                GameObject builtinGo = Resources.Load("BuiltinResources") as GameObject;
                SerializerBase.UnityResources = builtinGo.GetComponent <BuiltinResources>();
            }
            deserializer.SetupStandardSurrogates();

            //run the deserializer
            string version = deserializer.Doc.DocumentElement.GetAttribute("version");

            if (maxSupportedVer < Convert.ToInt32(version))
            {
                throw new InvalidVersionException();
            }
            string culture = deserializer.Doc.DocumentElement.GetAttribute("culture");

            deserializer.cult = new CultureInfo(culture);

            object o = deserializer.DeserializeCore(deserializer.Doc.DocumentElement);

            deserializer.AssignDeferedData();

            ISerializationCallbackReceiver callback = o as ISerializationCallbackReceiver;

            if (callback != null)
            {
                callback.OnAfterDeserialize();
            }


            //remove temporary information
            deserializer.ClearCache();
            SerializerBase.UnityResources = null;
            if (!isSerializerCallback)
            {
                Resources.UnloadUnusedAssets();//we may have loaded some manifests during serialization. Release now
            }
            return(o);
        }
    public static int OnAfterDeserialize(IntPtr l)
    {
        int result;

        try
        {
            ISerializationCallbackReceiver serializationCallbackReceiver = (ISerializationCallbackReceiver)LuaObject.checkSelf(l);
            serializationCallbackReceiver.OnAfterDeserialize();
            LuaObject.pushValue(l, true);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
コード例 #4
0
      public void ScanObject(UnityEngine.Object obj)
      {
          ISerializationCallbackReceiver receiver = obj as ISerializationCallbackReceiver;

          if (receiver != null)
          {
              bool formerForceEditorModeSerialization = UnitySerializationUtility.ForceEditorModeSerialization;

              try
              {
                  UnitySerializationUtility.ForceEditorModeSerialization = true;
                  this.allowRegisteringScannedTypes = true;
                  receiver.OnBeforeSerialize();
              }
              finally
              {
                  this.allowRegisteringScannedTypes = false;
                  UnitySerializationUtility.ForceEditorModeSerialization = formerForceEditorModeSerialization;
              }
          }
      }
コード例 #5
0
        public static void UpdatePrefabInstancePropertyModifications(UnityEngine.Object prefabInstance, bool withUndo)
        {
            if (prefabInstance == null)
            {
                throw new ArgumentNullException("prefabInstance");
            }
            if (!(prefabInstance is ISupportsPrefabSerialization))
            {
                throw new ArgumentException("Type must implement ISupportsPrefabSerialization");
            }
            if (!(prefabInstance is ISerializationCallbackReceiver))
            {
                throw new ArgumentException("Type must implement ISerializationCallbackReceiver");
            }
            if (!OdinPrefabSerializationEditorUtility.ObjectIsPrefabInstance(prefabInstance))
            {
                throw new ArgumentException("Value must be a prefab instance");
            }

            Action action = null;

            EditorApplication.HierarchyWindowItemCallback hierarchyCallback = (arg1, arg2) => action();
            EditorApplication.ProjectWindowItemCallback   projectCallback   = (arg1, arg2) => action();
            SceneView.OnSceneFunc sceneCallback = (arg) => action();

            EditorApplication.hierarchyWindowItemOnGUI += hierarchyCallback;
            EditorApplication.projectWindowItemOnGUI   += projectCallback;
            SceneView.onSceneGUIDelegate += sceneCallback;

            action = () =>
            {
                EditorApplication.hierarchyWindowItemOnGUI -= hierarchyCallback;
                EditorApplication.projectWindowItemOnGUI   -= projectCallback;
                SceneView.onSceneGUIDelegate -= sceneCallback;

                // Clear out pre-existing modifications, as they can actually mess this up
                {
                    ISupportsPrefabSerialization supporter = (ISupportsPrefabSerialization)prefabInstance;

                    if (supporter.SerializationData.PrefabModifications != null)
                    {
                        supporter.SerializationData.PrefabModifications.Clear();
                    }

                    if (supporter.SerializationData.PrefabModificationsReferencedUnityObjects != null)
                    {
                        supporter.SerializationData.PrefabModificationsReferencedUnityObjects.Clear();
                    }

                    UnitySerializationUtility.PrefabModificationCache.CachePrefabModifications(prefabInstance, new List <PrefabModification>());
                }

                try
                {
                    if (prefabInstance == null)
                    {
                        // Ignore - the object has been destroyed since the method was invoked.
                        return;
                    }

                    if (Event.current == null)
                    {
                        throw new InvalidOperationException("Delayed property modification delegate can only be called during the GUI event loop; Event.current must be accessible.");
                    }

                    try
                    {
                        PrefabUtility.RecordPrefabInstancePropertyModifications(prefabInstance);
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError("Exception occurred while calling Unity's PrefabUtility.RecordPrefabInstancePropertyModifications:");
                        Debug.LogException(ex);
                    }

                    var tree = PropertyTree.Create(prefabInstance);

                    tree.DrawMonoScriptObjectField = false;

                    bool isRepaint = Event.current.type == EventType.Repaint;

                    if (!isRepaint)
                    {
                        GUIHelper.PushEventType(EventType.Repaint);
                    }

                    InspectorUtilities.BeginDrawPropertyTree(tree, withUndo);

                    foreach (var property in tree.EnumerateTree(true))
                    {
                        if (property.ValueEntry == null)
                        {
                            continue;
                        }
                        if (!property.SupportsPrefabModifications)
                        {
                            continue;
                        }

                        property.Update(true);

                        if (!(property.ChildResolver is IKeyValueMapResolver))
                        {
                            continue;
                        }

                        if (property.ValueEntry.DictionaryChangedFromPrefab)
                        {
                            tree.PrefabModificationHandler.RegisterPrefabDictionaryDeltaModification(property, 0);
                        }
                        else
                        {
                            var prefabProperty = tree.PrefabModificationHandler.PrefabPropertyTree.GetPropertyAtPath(property.Path);

                            if (prefabProperty == null)
                            {
                                continue;
                            }
                            if (prefabProperty.ValueEntry == null)
                            {
                                continue;
                            }
                            if (!property.SupportsPrefabModifications)
                            {
                                continue;
                            }
                            if (!(property.ChildResolver is IKeyValueMapResolver))
                            {
                                continue;
                            }

                            tree.PrefabModificationHandler.RegisterPrefabDictionaryDeltaModification(property, 0);
                        }
                    }

                    InspectorUtilities.EndDrawPropertyTree(tree);

                    if (!isRepaint)
                    {
                        GUIHelper.PopEventType();
                    }

                    ISerializationCallbackReceiver receiver = (ISerializationCallbackReceiver)prefabInstance;
                    receiver.OnBeforeSerialize();
                    receiver.OnAfterDeserialize();
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                }
            };

            foreach (SceneView scene in SceneView.sceneViews)
            {
                scene.Repaint();
            }
        }
コード例 #6
0
        public static void UpdatePrefabInstancePropertyModifications(UnityEngine.Object prefabInstance, bool withUndo)
        {
            var prefabType = PrefabUtility.GetPrefabType(prefabInstance);

            //Assert.IsTrue(prefabInstance != null, "Argument is null");
            //Assert.IsTrue(prefabInstance is ISupportsPrefabSerialization, "Type must implement ISupportsPrefabSerialization");
            //Assert.IsTrue(prefabInstance is ISerializationCallbackReceiver, "Type must implement ISerializationCallbackReceiver");
            //Assert.IsTrue(prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.ModelPrefabInstance, "Value must be a prefab instance");

            if (prefabInstance == null)
            {
                throw new ArgumentNullException("prefabInstance");
            }
            if (!(prefabInstance is ISupportsPrefabSerialization))
            {
                throw new ArgumentException("Type must implement ISupportsPrefabSerialization");
            }
            if (!(prefabInstance is ISerializationCallbackReceiver))
            {
                throw new ArgumentException("Type must implement ISerializationCallbackReceiver");
            }
            if (!(prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.ModelPrefabInstance))
            {
                throw new ArgumentException("Value must be a prefab instance");
            }

            Action action = null;

            EditorApplication.HierarchyWindowItemCallback hierarchyCallback = (arg1, arg2) => action();
            EditorApplication.ProjectWindowItemCallback   projectCallback   = (arg1, arg2) => action();
            SceneView.OnSceneFunc sceneCallback = (arg) => action();

            EditorApplication.hierarchyWindowItemOnGUI += hierarchyCallback;
            EditorApplication.projectWindowItemOnGUI   += projectCallback;
            SceneView.onSceneGUIDelegate += sceneCallback;

            action = () =>
            {
                EditorApplication.hierarchyWindowItemOnGUI -= hierarchyCallback;
                EditorApplication.projectWindowItemOnGUI   -= projectCallback;
                SceneView.onSceneGUIDelegate -= sceneCallback;

                try
                {
                    //Assert.IsTrue(prefabInstance != null, "Invalid Argument: The prefab instance to update modifications for has been destroyed before updating could start.");
                    //Assert.IsNotNull(Event.current, "Can only be called during the GUI event loop; Event.current must be accessible.");

                    //if (prefabInstance == null) throw new InvalidOperationException("The prefab instance to update modifications for has been destroyed before updating could start.");

                    if (prefabInstance == null)
                    {
                        // Ignore - the object has been destroyed since the method was invoked.
                        return;
                    }

                    if (Event.current == null)
                    {
                        throw new InvalidOperationException("Delayed property modification delegate can only be called during the GUI event loop; Event.current must be accessible.");
                    }

                    try
                    {
                        PrefabUtility.RecordPrefabInstancePropertyModifications(prefabInstance);
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError("Exception occurred while calling Unity's PrefabUtility.RecordPrefabInstancePropertyModifications:");
                        Debug.LogException(ex);
                    }

                    var tree = PropertyTree.Create(prefabInstance);

                    //if (tree == null) Debug.LogError("Tree is null");

                    tree.DrawMonoScriptObjectField = false;

                    bool isRepaint = Event.current.type == EventType.Repaint;

                    if (!isRepaint)
                    {
                        GUIHelper.PushEventType(EventType.Repaint);
                    }

                    InspectorUtilities.BeginDrawPropertyTree(tree, withUndo);

                    foreach (var property in tree.EnumerateTree(true))
                    {
                        //if (property == null) Debug.LogError("Property is null");

                        if (property.ValueEntry == null)
                        {
                            continue;
                        }
                        if (property.ValueEntry.GetDictionaryHandler() == null)
                        {
                            continue;
                        }

                        if (property.ValueEntry.DictionaryChangedFromPrefab)
                        {
                            tree.RegisterPrefabDictionaryDeltaModification(property, 0);
                        }
                        else
                        {
                            var prefabProperty = tree.PrefabPropertyTree.GetPropertyAtPath(property.Path);

                            if (prefabProperty == null)
                            {
                                continue;
                            }
                            if (prefabProperty.ValueEntry == null)
                            {
                                continue;
                            }
                            if (prefabProperty.ValueEntry.GetDictionaryHandler() == null)
                            {
                                continue;
                            }

                            //if (property.Children == null) Debug.LogError("Property children is null");
                            //if (prefabProperty.Children == null) Debug.LogError("Prefab property children is null");

                            if (property.Children.Count != prefabProperty.Children.Count)
                            {
                                tree.RegisterPrefabDictionaryDeltaModification(property, 0);
                            }
                        }
                    }

                    InspectorUtilities.EndDrawPropertyTree(tree);

                    if (!isRepaint)
                    {
                        GUIHelper.PopEventType();
                    }

                    ISerializationCallbackReceiver receiver = (prefabInstance as ISerializationCallbackReceiver);
                    if (receiver == null)
                    {
                        Debug.LogError("Receiver is null");
                    }
                    receiver.OnBeforeSerialize();
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                }
            };

            foreach (SceneView scene in SceneView.sceneViews)
            {
                scene.Repaint();
            }
        }