コード例 #1
0
            GameObject RestoreGameObject(SerializedGameObject serializedGameObject)
            {
                GameObject gameObject = new GameObject();

                Undo.RegisterCreatedObjectUndo(gameObject, "Create");

                deserializedObjects.Add(gameObject);
                deserializedGameObjects.Add(new DeserializedGameObject(serializedGameObject, gameObject));
                EditorJsonUtility.FromJsonOverwrite(serializedGameObject.serializedData, gameObject);
                RestoreObjectReference(serializedGameObject.savedInstanceIDs, gameObject);

                RestoreComponents(gameObject, serializedGameObject.serializedComponents);
                return(gameObject);
            }
コード例 #2
0
            private void SerializeGameObject(GameObject gameObject)
            {
                var parent = gameObject.transform.parent;
                SerializedGameObject sgo = new SerializedGameObject
                {
                    serializedData   = EditorJsonUtility.ToJson(gameObject, false),
                    savedInstanceIDs = GetInstanceReferenceIDs(gameObject),
                    scenePath        = gameObject.scene.path,
                    hasParent        = parent != null
                };

                sgo.parentID     = sgo.hasParent ? parent.GetInstanceID() : 0;
                sgo.siblingIndex = gameObject.transform.GetSiblingIndex();

                sgo.childCount        = gameObject.transform.childCount;
                sgo.indexOfFirstChild = serializedSelection.serializedGameObjects.Count + 1;

                foreach (var component in gameObject.GetComponents <Component>())
                {
                    if (component == null)
                    {
                        continue;
                    }
                    var serializedComponent = SerializeComponent(component);
                    sgo.serializedComponents.Add(serializedComponent);
                }

                serializedSelection.serializedGameObjects.Add(sgo);

                if (gameObject.isStatic)
                {
                    serializedSelection.foundStatic = true;
                    Debug.LogWarning("PlayModeSaver tried to serialize static GameObject " + gameObject +
                                     ". This is not allowed.");
                }

                foreach (Transform child in gameObject.transform)
                {
                    SerializeGameObject(child.gameObject);
                }
            }
コード例 #3
0
 public DeserializedGameObject(SerializedGameObject serializedGameObject, GameObject gameObject)
 {
     this.serializedGameObject = serializedGameObject;
     this.gameObject           = gameObject;
 }