Exemple #1
0
        public static void SaveProject()
        {
            OnProjectSave?.Invoke();

            // Apply changes to any animation clips edited using the animation editor
            foreach (var KVP in persistentData.dirtyAnimClips)
            {
                KVP.Value.SaveToClip();
            }

            // Save all dirty resources to disk
            foreach (var KVP in persistentData.dirtyResources)
            {
                UUID   resourceUUID = KVP.Key;
                string path         = ProjectLibrary.GetPath(resourceUUID);
                if (!IsNative(path))
                {
                    continue; // Imported resources can't be changed
                }
                Resource resource = ProjectLibrary.Load <Resource>(path);

                if (resource != null)
                {
                    ProjectLibrary.Save(resource);
                }
            }

            persistentData.dirtyAnimClips.Clear();
            persistentData.dirtyResources.Clear();
            SetStatusProject(false);

            Internal_SaveProject();
        }
        /// <summary>
        /// Saves the animation curves and events stored in this object, into the associated animation clip resource.
        /// Relevant animation clip resource must already be created and exist in the project library.
        /// </summary>
        public void SaveToClip()
        {
            if (!isImported)
            {
                EditorAnimClipData editorAnimClipData;
                Apply(out editorAnimClipData);

                string resourcePath = ProjectLibrary.GetPath(clip);
                ProjectLibrary.Save(clip);

                ProjectLibrary.SetEditorData(resourcePath, editorAnimClipData);
            }
            else
            {
                string       resourcePath = ProjectLibrary.GetPath(clip);
                LibraryEntry entry        = ProjectLibrary.GetEntry(resourcePath);

                if (entry != null && entry.Type == LibraryEntryType.File)
                {
                    FileEntry         fileEntry         = (FileEntry)entry;
                    MeshImportOptions meshImportOptions = (MeshImportOptions)fileEntry.Options;

                    string clipName = PathEx.GetTail(resourcePath);

                    List <ImportedAnimationEvents> newEvents = new List <ImportedAnimationEvents>();
                    newEvents.AddRange(meshImportOptions.AnimationEvents);

                    bool isExisting = false;
                    for (int i = 0; i < newEvents.Count; i++)
                    {
                        if (newEvents[i].Name == clipName)
                        {
                            newEvents[i].Events = events;
                            isExisting          = true;
                            break;
                        }
                    }

                    if (!isExisting)
                    {
                        ImportedAnimationEvents newEntry = new ImportedAnimationEvents();
                        newEntry.Name   = clipName;
                        newEntry.Events = events;

                        newEvents.Add(newEntry);
                    }

                    meshImportOptions.AnimationEvents = newEvents.ToArray();

                    ProjectLibrary.Reimport(resourcePath, meshImportOptions, true);
                }
            }
        }
        /// <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());
                }
            }
        }