/// <summary>
        /// Updates the contents of the prefab with the contents of the provided prefab instance. If the provided object
        /// is not a prefab instance nothing happens.
        /// </summary>
        /// <param name="obj">Prefab instance whose prefab to update.</param>
        /// <param name="refreshScene">If true, all prefab instances in the current scene will be updated so they consistent
        ///                            with the newly saved data.</param>
        public static void ApplyPrefab(SceneObject obj, bool refreshScene = true)
        {
            if (obj == null)
            {
                return;
            }

            if (refreshScene)
            {
                SceneObject root = Scene.Root;
                if (root != null)
                {
                    Internal_RecordPrefabDiff(root.GetCachedPtr());
                }
            }

            IntPtr objPtr = obj.GetCachedPtr();

            Internal_ApplyPrefab(objPtr);

            if (refreshScene)
            {
                SceneObject root = Scene.Root;
                if (root != null)
                {
                    Internal_UpdateFromPrefab(root.GetCachedPtr());
                }
            }
        }
Example #2
0
 /// <summary>
 /// Records a state of the entire scene object at a specific point and allows you to restore it to its original
 /// values as needed.
 /// </summary>
 /// <param name="so">Scene object to record.</param>
 /// <param name="recordHierarchy">If true all children of this object will also be recorded.</param>
 /// <param name="description">Optional description of what exactly the command does.</param>
 public static void RecordSO(SceneObject so, bool recordHierarchy = false, string description = "")
 {
     if (so != null)
     {
         Internal_RecordSO(so.GetCachedPtr(), description);
     }
 }
Example #3
0
 /// <summary>
 /// Deletes a scene object. Undo operation recorded in global undo/redo stack.
 /// </summary>
 /// <param name="so">Scene object to delete.</param>
 /// <param name="description">Optional description of what exactly the command does.</param>
 public static void DeleteSO(SceneObject so, string description = "")
 {
     if (so != null)
     {
         Internal_DeleteSO(so.GetCachedPtr(), description);
     }
 }
Example #4
0
        /// <summary>
        /// Changes the parent of a set of scene objects. Undo operation recorded in global undo/redo stack.
        /// </summary>
        /// <param name="so">Scene objects to change the parent of.</param>
        /// <param name="parent">New parent.</param>
        /// <param name="description">Optional description of what exactly the command does.</param>
        public static void ReparentSO(SceneObject[] so, SceneObject parent, string description = "")
        {
            if (so != null)
            {
                List <IntPtr> soPtrs = new List <IntPtr>();
                for (int i = 0; i < so.Length; i++)
                {
                    if (so[i] != null)
                    {
                        soPtrs.Add(so[i].GetCachedPtr());
                    }
                }

                if (soPtrs.Count > 0)
                {
                    IntPtr parentPtr = IntPtr.Zero;
                    if (parent != null)
                    {
                        parentPtr = parent.GetCachedPtr();
                    }

                    Internal_ReparentSOMulti(soPtrs.ToArray(), parentPtr, description);
                }
            }
        }
Example #5
0
        /// <summary>
        /// Creates new a scene object by cloning an existing object.
        /// </summary>
        /// <param name="so">Scene object to clone.</param>
        /// <param name="description">Optional description of what exactly the command does.</param>
        /// <returns>Cloned scene object.</returns>
        public static SceneObject CloneSO(SceneObject so, string description = "")
        {
            if (so != null)
                return Internal_CloneSO(so.GetCachedPtr(), description);

            return null;
        }
Example #6
0
 /// <summary>
 /// Updates the transform of the GUI widget with the latest transform from the parent SceneObject.
 /// </summary>
 /// <param name="parentSO">Scene object the GUI widget component is attached to.</param>
 internal void UpdateTransform(SceneObject parentSO)
 {
     if (parentSO != null)
     {
         Internal_UpdateTransform(mCachedPtr, parentSO.GetCachedPtr());
     }
 }
Example #7
0
 /// <summary>
 /// Breaks the prefab link on the provided scene object and makes the operation undo-able. Undo operation recorded
 /// in global undo/redo stack.
 /// See <see cref="PrefabUtility.BreakPrefab"/>.
 /// </summary>
 /// <param name="so">Scene object whose prefab link to break.</param>
 /// <param name="description">Optional description of what exactly the command does.</param>
 public static void BreakPrefab(SceneObject so, string description = "")
 {
     if (so != null)
     {
         Internal_BreakPrefab(so.GetCachedPtr(), description);
     }
 }
Example #8
0
        /// <summary>
        /// Returns the root object of the prefab instance that this object belongs to, if any. 
        /// </summary>
        /// <param name="obj">Scene object to retrieve the prefab parent for.</param>
        /// <returns>Prefab parent of the provided object, or null if the object is not part of a prefab instance.</returns>
        public static SceneObject GetPrefabParent(SceneObject obj)
        {
            if (obj == null)
                return null;

            IntPtr objPtr = obj.GetCachedPtr();
            return Internal_GetPrefabParent(objPtr);
        }
Example #9
0
        /// <summary>
        /// Breaks the link between a prefab instance and its prefab. Object will retain all current values but will
        /// no longer be influenced by modifications to its parent prefab.
        /// </summary>
        /// <param name="obj">Prefab instance whose link to break.</param>
        public static void BreakPrefab(SceneObject obj)
        {
            if (obj == null)
                return;

            IntPtr objPtr = obj.GetCachedPtr();
            Internal_BreakPrefab(objPtr);
        }
        /// <summary>
        /// Records the current state of the provided scene object.
        /// </summary>
        /// <param name="so">Scene object to record the state for.</param>
        /// <param name="hierarchy">If true, state will be recorded for the scene object and all of its children. Otherwise
        ///                         the state will only be recorded for the provided scene object.</param>
        public SerializedSceneObject(SceneObject so, bool hierarchy)
        {
            IntPtr soPtr = IntPtr.Zero;
            if (so != null)
                soPtr = so.GetCachedPtr();

            Internal_CreateInstance(this, soPtr, hierarchy);
        }
Example #11
0
        public NativeRenderable(SceneObject sceneObject)
        {
            IntPtr sceneObjPtr = IntPtr.Zero;
            if (sceneObject != null)
                sceneObjPtr = sceneObject.GetCachedPtr();

            Internal_Create(this, sceneObjPtr);
        }
Example #12
0
        public NativeRigidbody(SceneObject linkedSO)
        {
            IntPtr linkedSOPtr = IntPtr.Zero;
            if (linkedSO != null)
                linkedSOPtr = linkedSO.GetCachedPtr();

            Internal_CreateInstance(this, linkedSOPtr);
        }
Example #13
0
        /// <summary>
        /// Checks if a scene object has a prefab link. Scene objects with a prefab link will be automatically updated
        /// when their prefab changes in order to reflect its changes.
        /// </summary>
        /// <param name="obj">Scene object to check if it has a prefab link.</param>
        /// <returns>True if the object is a prefab instance (has a prefab link), false otherwise.</returns>
        public static bool IsPrefabInstance(SceneObject obj)
        {
            if (obj == null)
                return false;

            IntPtr objPtr = obj.GetCachedPtr();
            return Internal_HasPrefabLink(objPtr);
        }
Example #14
0
        /// <summary>
        /// Creates new a scene object by cloning an existing object. Undo operation recorded in global undo/redo stack.
        /// </summary>
        /// <param name="so">Scene object to clone.</param>
        /// <param name="description">Optional description of what exactly the command does.</param>
        /// <returns>Cloned scene object.</returns>
        public static SceneObject CloneSO(SceneObject so, string description = "")
        {
            if (so != null)
            {
                return(Internal_CloneSO(so.GetCachedPtr(), description));
            }

            return(null);
        }
Example #15
0
        /// <summary>
        /// Returns the UUID of the prefab attached to the provided scene object. Only works on root prefab objects.
        /// </summary>
        /// <param name="obj">Scene object to retrieve the prefab UUID for.</param>
        /// <returns>Prefab UUID if the object is part of a prefab, null otherwise. </returns>
        public static string GetPrefabUUID(SceneObject obj)
        {
            if (obj == null)
            {
                return(null);
            }

            IntPtr objPtr = obj.GetCachedPtr();

            return(Internal_GetPrefabUUID(objPtr));
        }
Example #16
0
        /// <summary>
        /// Remove any instance specific changes to the object or its hierarchy from the provided prefab instance and
        /// restore it to the exact copy of the linked prefab.
        /// </summary>
        /// <param name="obj">Prefab instance to revert to original state.</param>
        public static void RevertPrefab(SceneObject obj)
        {
            if (obj == null)
            {
                return;
            }

            IntPtr objPtr = obj.GetCachedPtr();

            Internal_RevertPrefab(objPtr);
        }
Example #17
0
        /// <summary>
        /// Checks if a scene object has a prefab link. Scene objects with a prefab link will be automatically updated
        /// when their prefab changes in order to reflect its changes.
        /// </summary>
        /// <param name="obj">Scene object to check if it has a prefab link.</param>
        /// <returns>True if the object is a prefab instance (has a prefab link), false otherwise.</returns>
        public static bool IsPrefabInstance(SceneObject obj)
        {
            if (obj == null)
            {
                return(false);
            }

            IntPtr objPtr = obj.GetCachedPtr();

            return(Internal_HasPrefabLink(objPtr));
        }
Example #18
0
        /// <summary>
        /// Returns the root object of the prefab instance that this object belongs to, if any.
        /// </summary>
        /// <param name="obj">Scene object to retrieve the prefab parent for.</param>
        /// <returns>Prefab parent of the provided object, or null if the object is not part of a prefab instance.</returns>
        public static SceneObject GetPrefabParent(SceneObject obj)
        {
            if (obj == null)
            {
                return(null);
            }

            IntPtr objPtr = obj.GetCachedPtr();

            return(Internal_GetPrefabParent(objPtr));
        }
        /// <summary>
        /// Records the current state of the provided scene object.
        /// </summary>
        /// <param name="so">Scene object to record the state for.</param>
        /// <param name="hierarchy">If true, state will be recorded for the scene object and all of its children. Otherwise
        ///                         the state will only be recorded for the provided scene object.</param>
        public SerializedSceneObject(SceneObject so, bool hierarchy)
        {
            IntPtr soPtr = IntPtr.Zero;

            if (so != null)
            {
                soPtr = so.GetCachedPtr();
            }

            Internal_CreateInstance(this, soPtr, hierarchy);
        }
Example #20
0
        /// <summary>
        /// Checks is the provided scene object internal (hidden from normal user, used by internal engine systems).
        /// </summary>
        /// <param name="so">Scene object to check.</param>
        /// <returns>True if internal, false otherwise. </returns>
        public static bool IsInternal(SceneObject so)
        {
            if (so == null)
            {
                return(false);
            }

            IntPtr objPtr = so.GetCachedPtr();

            return(Internal_IsInternal(objPtr));
        }
Example #21
0
        /// <summary>
        /// Changes the parent of the scene object. Undo operation recorded in global undo/redo stack.
        /// </summary>
        /// <param name="so">Scene object to change the parent of.</param>
        /// <param name="parent">New parent.</param>
        /// <param name="description">Optional description of what exactly the command does.</param>
        public static void ReparentSO(SceneObject so, SceneObject parent, string description = "")
        {
            if (so != null)
            {
                IntPtr parentPtr = IntPtr.Zero;
                if (parent != null)
                {
                    parentPtr = parent.GetCachedPtr();
                }

                Internal_ReparentSO(so.GetCachedPtr(), parentPtr, description);
            }
        }
Example #22
0
        /// <summary>
        /// Returns the UUID of the prefab attached to the provided scene object. Only works on root prefab objects.
        /// </summary>
        /// <param name="obj">Scene object to retrieve the prefab UUID for.</param>
        /// <returns>Prefab UUID if the object is part of a prefab, null otherwise. </returns>
        public static UUID GetPrefabUUID(SceneObject obj)
        {
            if (obj == null)
            {
                return(UUID.Empty);
            }

            IntPtr objPtr = obj.GetCachedPtr();

            UUID uuid;

            Internal_GetPrefabUUID(objPtr, out uuid);

            return(uuid);
        }
Example #23
0
        /// <summary>
        /// Updates the contents of the prefab with the contents of the provided prefab instance. If the provided object
        /// is not a prefab instance nothing happens.
        /// </summary>
        /// <param name="obj">Prefab instance whose prefab to update.</param>
        /// <param name="refreshScene">If true, all prefab instances in the current scene will be updated so they consistent
        ///                            with the newly saved data.</param>
        public static void ApplyPrefab(SceneObject obj, bool refreshScene = true)
        {
            if (obj == null)
            {
                return;
            }

            SceneObject prefabInstanceRoot = GetPrefabParent(obj);

            if (prefabInstanceRoot == null)
            {
                return;
            }

            if (refreshScene)
            {
                SceneObject root = Scene.Root;
                if (root != null)
                {
                    Internal_RecordPrefabDiff(root.GetCachedPtr());
                }
            }

            UUID   prefabUUID = GetPrefabUUID(prefabInstanceRoot);
            string prefabPath = ProjectLibrary.GetPath(prefabUUID);
            Prefab prefab     = ProjectLibrary.Load <Prefab>(prefabPath);

            if (prefab != null)
            {
                IntPtr soPtr     = prefabInstanceRoot.GetCachedPtr();
                IntPtr prefabPtr = prefab.GetCachedPtr();

                Internal_ApplyPrefab(soPtr, prefabPtr);
                ProjectLibrary.Save(prefab);
            }

            if (refreshScene)
            {
                SceneObject root = Scene.Root;
                if (root != null)
                {
                    Internal_UpdateFromPrefab(root.GetCachedPtr());
                }
            }
        }
Example #24
0
 /// <summary>
 /// Deletes a scene object.
 /// </summary>
 /// <param name="so">Scene object to delete.</param>
 /// <param name="description">Optional description of what exactly the command does.</param>
 public static void DeleteSO(SceneObject so, string description = "")
 {
     if (so != null)
         Internal_DeleteSO(so.GetCachedPtr(), description);
 }
Example #25
0
 /// <summary>
 /// Creates a new prefab from the provided scene object. If the scene object has an existing prefab link it will 
 /// be broken. After the prefab is created the scene object will be automatically linked to it.
 /// </summary>
 /// <param name="so">Scene object to generate the prefab for.</param>
 public Prefab(SceneObject so)
 {
     IntPtr soPtr = so.GetCachedPtr();
     Internal_CreateInstance(this, soPtr);
 }
Example #26
0
 /// <summary>
 /// Creates a new prefab from the provided scene object. If the scene object has an existing prefab link it will 
 /// be broken. After the prefab is created the scene object will be automatically linked to it.
 /// </summary>
 /// <param name="so">Scene object to generate the prefab for.</param>
 /// <param name="isScene">Determines if the prefab represents a scene or just a generic group of objects.
 ///                       <see cref="IsScene"/></param>
 public Prefab(SceneObject so, bool isScene = true)
 {
     IntPtr soPtr = so.GetCachedPtr();
     Internal_CreateInstance(this, soPtr, isScene);
 }
Example #27
0
        /// <summary>
        /// Changes the parent of the scene object.
        /// </summary>
        /// <param name="so">Scene object to change the parent of.</param>
        /// <param name="parent">New parent.</param>
        /// <param name="description">Optional description of what exactly the command does.</param>
        public static void ReparentSO(SceneObject so, SceneObject parent, string description = "")
        {
            if (so != null)
            {
                IntPtr parentPtr = IntPtr.Zero;
                if (parent != null)
                    parentPtr = parent.GetCachedPtr();

                Internal_ReparentSO(so.GetCachedPtr(), parentPtr, description);
            }
        }
Example #28
0
        /// <summary>
        /// Changes the parent of a set of scene objects.
        /// </summary>
        /// <param name="so">Scene objects to change the parent of.</param>
        /// <param name="parent">New parent.</param>
        /// <param name="description">Optional description of what exactly the command does.</param>
        public static void ReparentSO(SceneObject[] so, SceneObject parent, string description = "")
        {
            if (so != null)
            {
                List<IntPtr> soPtrs = new List<IntPtr>();
                for (int i = 0; i < so.Length; i++)
                {
                    if (so[i] != null)
                        soPtrs.Add(so[i].GetCachedPtr());
                }

                if (soPtrs.Count > 0)
                {
                    IntPtr parentPtr = IntPtr.Zero;
                    if (parent != null)
                        parentPtr = parent.GetCachedPtr();

                    Internal_ReparentSOMulti(soPtrs.ToArray(), parentPtr, description);
                }
            }
        }
Example #29
0
 /// <summary>
 /// Breaks the prefab link on the provided scene object and makes the operation undo-able. 
 /// See <see cref="PrefabUtility.BreakPrefab"/>.
 /// </summary>
 /// <param name="so">Scene object whose prefab link to break.</param>
 /// <param name="description">Optional description of what exactly the command does.</param>
 public static void BreakPrefab(SceneObject so, string description = "")
 {
     if (so != null)
         Internal_BreakPrefab(so.GetCachedPtr(), description);
 }
Example #30
0
        /// <summary>
        /// Creates a new prefab from the provided scene object. If the scene object has an existing prefab link it will
        /// be broken. After the prefab is created the scene object will be automatically linked to it.
        /// </summary>
        /// <param name="so">Scene object to generate the prefab for.</param>
        /// <param name="isScene">Determines if the prefab represents a scene or just a generic group of objects.
        ///                       <see cref="IsScene"/></param>
        public Prefab(SceneObject so, bool isScene = true)
        {
            IntPtr soPtr = so.GetCachedPtr();

            Internal_CreateInstance(this, soPtr, isScene);
        }
Example #31
0
        /// <summary>
        /// Returns the UUID of the prefab attached to the provided scene object. Only works on root prefab objects.
        /// </summary>
        /// <param name="obj">Scene object to retrieve the prefab UUID for.</param>
        /// <returns>Prefab UUID if the object is part of a prefab, null otherwise. </returns>
        public static string GetPrefabUUID(SceneObject obj)
        {
            if (obj == null)
                return null;

            IntPtr objPtr = obj.GetCachedPtr();
            return Internal_GetPrefabUUID(objPtr);
        }
Example #32
0
 /// <summary>
 /// Records a state of the entire scene object at a specific point and allows you to restore it to its original 
 /// values as needed.
 /// </summary>
 /// <param name="so">Scene object to record.</param>
 /// <param name="recordHierarchy">If true all children of this object will also be recorded.</param>
 /// <param name="description">Optional description of what exactly the command does.</param>
 public static void RecordSO(SceneObject so, bool recordHierarchy = false, string description = "")
 {
     if (so != null)
         Internal_RecordSO(so.GetCachedPtr(), description);
 }