//----------------------------------------------------------------------------------------------------------------------
        void ShowReloadSelectedSceneCacheFilesGUI()
        {
            float itemHeight = EditorGUIUtility.singleLineHeight;

            //Button
            EditorGUILayout.BeginHorizontal(GUILayout.Height(itemHeight));
            if (GUILayout.Button("Reload Selected Scene Cache Files", GUILayout.Width(250f), GUILayout.Height(itemHeight)))
            {
                foreach (SceneCachePlayer player in m_targets)
                {
                    string sceneCacheFilePath = player.GetSceneCacheFilePath();
                    SceneCachePlayerEditorUtility.ChangeSceneCacheFile(player, sceneCacheFilePath);
                }
            }
            EditorGUILayout.EndHorizontal();

            //[TODO-sin: 2020-9-28] use ScrollView
            foreach (SceneCachePlayer player in m_targets)
            {
                EditorGUILayout.BeginHorizontal(GUILayout.Height(itemHeight));
                GUILayout.Space(30);
                if (player.gameObject.IsPrefab())
                {
                    GameObject prefab     = PrefabUtility.GetCorrespondingObjectFromOriginalSource(player.gameObject);
                    string     prefabPath = AssetDatabase.GetAssetPath(prefab);
                    EditorGUILayout.LabelField(prefabPath);
                }
                else
                {
                    EditorGUILayout.LabelField(player.name);
                }
                EditorGUILayout.EndHorizontal();
            }
        }
        static void CreateSceneCachePlayerMenu(MenuCommand menuCommand)
        {
            string sceneCacheFilePath = EditorUtility.OpenFilePanelWithFilters("Select Cache File", "",
                                                                               new string[] { "All supported files", "sc", "All files", "*" });

            if (string.IsNullOrEmpty(sceneCacheFilePath))
            {
                return;
            }

            //Prefab and assets path
            MeshSyncRuntimeSettings runtimeSettings = MeshSyncRuntimeSettings.GetOrCreateSettings();

            string scOutputPath   = runtimeSettings.GetSceneCacheOutputPath();
            string prefabFileName = Path.GetFileNameWithoutExtension(sceneCacheFilePath);
            string prefabPath     = $"{scOutputPath}/{prefabFileName}.prefab";
            string assetsFolder   = Path.Combine(scOutputPath, prefabFileName);

            bool created = SceneCachePlayerEditorUtility.CreateSceneCachePlayerAndPrefab(sceneCacheFilePath, prefabPath,
                                                                                         assetsFolder, out SceneCachePlayer player, out GameObject prefab);


            if (!created)
            {
                EditorUtility.DisplayDialog("MeshSync"
                                            , "Failed to open " + sceneCacheFilePath
                                            + ". Possible reasons: file format version does not match, or the file is not scene cache."
                                            , "Ok"
                                            );
            }
        }
//----------------------------------------------------------------------------------------------------------------------
    
    private void DrawLimitedAnimationGUI(SceneCachePlayableAsset scPlayableAsset) {
        SceneCachePlayer scPlayer = scPlayableAsset.GetSceneCachePlayer();
        
        bool disableScope = null == scPlayer;
        
        if (null != scPlayer) {
            disableScope |= (!scPlayer.IsLimitedAnimationOverrideable());
        }

        if (disableScope) {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.HelpBox(
                "Disabled because Limited Animation settings on the SceneCache GameObject is enabled, or the playback mode is set to interpolate", 
                MessageType.Warning
            );
            if (GUILayout.Button("Fix", GUILayout.Width(64), GUILayout.Height(36))) {
                scPlayer.AllowLimitedAnimationOverride();
                Repaint();
            }
            EditorGUILayout.EndHorizontal();
            
        }

        using (new EditorGUI.DisabledScope(disableScope)) {
            SceneCachePlayerEditorUtility.DrawLimitedAnimationGUI(scPlayableAsset.GetOverrideLimitedAnimationController(),
                m_scPlayableAsset, scPlayer);
        }
        
    }
//----------------------------------------------------------------------------------------------------------------------
        void OnSceneCacheFileReload()
        {
            string sceneCacheFilePath = m_sceneCachePlayer.GetSceneCacheFilePath();

            SceneCachePlayerEditorUtility.ChangeSceneCacheFile(m_sceneCachePlayer, sceneCacheFilePath);
            GUIUtility.ExitGUI();
        }
//----------------------------------------------------------------------------------------------------------------------

        public override void OnImportAsset(AssetImportContext ctx)
        {
            //Ignore assets outside Assets folder (for example: Packages, etc)
            if (!ctx.assetPath.StartsWith("Assets/"))
            {
                return;
            }

            GameObject       go     = new GameObject();
            SceneCachePlayer player = go.AddComponent <SceneCachePlayer>();

            SceneCachePlayerEditorUtility.ChangeSceneCacheFile(player, ctx.assetPath);

            string objectName = Path.GetFileNameWithoutExtension(ctx.assetPath);

            go.name = objectName;

            ctx.AddObjectToAsset(objectName, go);
            ctx.SetMainObject(go);
        }
Example #6
0
//----------------------------------------------------------------------------------------------------------------------
        private static bool DrawPlaybackMode(SceneCachePlayer t)
        {
            t.ShowPlaybackInInspector(EditorGUILayout.Foldout(t.IsPlaybackInInspectorShown(), "Playback", true, GetDefaultFoldoutStyle()));
            if (!t.IsPlaybackInInspectorShown())
            {
                return(false);
            }

            bool changed = false;

            changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "SceneCache: Playback Mode",
                                                              guiFunc: () =>
                                                              (SceneCachePlaybackMode)EditorGUILayout.EnumPopup("Playback Mode", t.GetPlaybackMode()),
                                                              updateFunc: (SceneCachePlaybackMode mode) => {
                t.SetPlaybackMode(mode);
                SceneCachePlayerEditorUtility.RefreshSceneCache(t);
            }
                                                              );

            ++EditorGUI.indentLevel;
            changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "SceneCache: Time",
                                                              guiFunc: () => (EditorGUILayout.FloatField("Time", t.GetTime())),
                                                              updateFunc: (float time) => { t.SetTime(Mathf.Max(0, time)); });

            using (new EditorGUI.DisabledScope(t.GetPlaybackMode() == SceneCachePlaybackMode.Interpolate)) {
                changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "SceneCache: Frame",
                                                                  guiFunc: () => (EditorGUILayout.IntField("Frame", t.GetFrame())),
                                                                  updateFunc: (int frame) => { t.SetTimeByFrame(Mathf.Max(0, frame)); });
            }
            --EditorGUI.indentLevel;

            using (new EditorGUI.DisabledScope(t.GetPlaybackMode() == SceneCachePlaybackMode.Interpolate)) {
                changed |= SceneCachePlayerEditorUtility.DrawLimitedAnimationGUI(t.GetLimitedAnimationController(), t, t);
            }

            EditorGUILayout.Space();

            return(changed);
        }
Example #7
0
//----------------------------------------------------------------------------------------------------------------------    
    
    internal static bool DrawLimitedAnimationGUI(LimitedAnimationController ctrl, 
        Object target, SceneCachePlayer sc) 
    {
        bool         changed   = false;
        const string UNDO_TEXT = "SceneCache: Limited Animation";
        
        //Limited Animation
        changed |= EditorGUIDrawerUtility.DrawUndoableGUI(target, UNDO_TEXT,
            guiFunc: () => (EditorGUILayout.Toggle("Limited Animation", ctrl.IsEnabled())),
            updateFunc: (bool limitedAnimation) => {
                ctrl.SetEnabled(limitedAnimation);
                SceneCachePlayerEditorUtility.RefreshSceneCache(sc);
            });

        ++EditorGUI.indentLevel;
        using (new EditorGUI.DisabledScope(!ctrl.IsEnabled())) {
            changed |= EditorGUIDrawerUtility.DrawUndoableGUI(target, UNDO_TEXT,
                guiFunc: () => (
                    EditorGUILayout.IntField("Num Frames to Hold", ctrl.GetNumFramesToHold())
                ),
                updateFunc: (int frames) => {
                    ctrl.SetNumFramesToHold(frames);
                    SceneCachePlayerEditorUtility.RefreshSceneCache(sc);
                });
            changed |= EditorGUIDrawerUtility.DrawUndoableGUI(target, UNDO_TEXT,
                guiFunc: () => (
                    EditorGUILayout.IntField("Frame Offset", ctrl.GetFrameOffset())
                ),
                updateFunc: (int offset) => {
                    ctrl.SetFrameOffset(offset);
                    SceneCachePlayerEditorUtility.RefreshSceneCache(sc);
                });
        }

        --EditorGUI.indentLevel;

        EditorGUILayout.Space();
        return changed;
    }
//----------------------------------------------------------------------------------------------------------------------
        private static void ChangeSceneCacheFileInInspector(SceneCachePlayer cachePlayer, string sceneCacheFilePath)
        {
            SceneCachePlayerEditorUtility.ChangeSceneCacheFile(cachePlayer, sceneCacheFilePath);
        }
//----------------------------------------------------------------------------------------------------------------------
        void OnSceneCacheFileReload()
        {
            SceneCachePlayerEditorUtility.ReloadSceneCacheFile(m_sceneCachePlayer);
        }