Beispiel #1
0
//----------------------------------------------------------------------------------------------------------------------    
    /// <inheritdoc/>
    public override ClipDrawOptions GetClipOptions(TimelineClip clip) {
        ClipDrawOptions         clipOptions = base.GetClipOptions(clip);
        SceneCachePlayableAsset asset       = clip.asset as SceneCachePlayableAsset;
        if (null == asset) {
            Debug.LogError("Asset is not a SceneCachePlayableAsset: " + clip.asset);
            return clipOptions;
        }
        
        SceneCacheClipData clipData = asset.GetBoundClipData();
        if (null == clipData) 
            return clipOptions;

        SceneCachePlayer scPlayer = asset.GetSceneCachePlayer();
        if (null == scPlayer) {
            clipOptions.errorText = NO_SCENE_CACHE_ASSIGNED_ERROR;
            return clipOptions;
        }

        LimitedAnimationController overrideLimitedAnimationController =asset.GetOverrideLimitedAnimationController();
        
        if (!scPlayer.IsLimitedAnimationOverrideable() && overrideLimitedAnimationController.IsEnabled()) {
            clipOptions.errorText = UNABLE_TO_OVERRIDE_LIMITED_ANIMATION_ERROR;
            return clipOptions;
        }

        clipOptions.tooltip = scPlayer.GetSceneCacheFilePath();

        return clipOptions;
    } 
Beispiel #2
0
//----------------------------------------------------------------------------------------------------------------------

        bool DrawCacheFile(SceneCachePlayer t)
        {
            t.ShowCacheFileInInspector(EditorGUILayout.Foldout(t.IsCacheFileShownInInspector(), "File", true, GetDefaultFoldoutStyle()));
            if (!t.IsCacheFileShownInInspector())
            {
                return(false);
            }

            bool changed = false;

            //Show Selector GUI. Check if we should reopen
            string fullPath           = t.GetSceneCacheFilePath();
            string prevNormalizedPath = AssetEditorUtility.NormalizePath(fullPath);

            string newNormalizedPath = EditorGUIDrawerUtility.DrawFileSelectorGUI("Cache File Path", "MeshSync",
                                                                                  prevNormalizedPath, "sc", OnSceneCacheFileReload);

            newNormalizedPath = AssetEditorUtility.NormalizePath(newNormalizedPath);

            if (newNormalizedPath != prevNormalizedPath)
            {
                ChangeSceneCacheFileInInspector(t, newNormalizedPath);
            }

            if (!string.IsNullOrEmpty(fullPath) && !fullPath.StartsWith(Application.streamingAssetsPath))
            {
                GUILayout.BeginHorizontal();
                const float BUTTON_WIDTH = 50.0f;
                if (GUILayout.Button("Copy", GUILayout.Width(BUTTON_WIDTH)))
                {
                    string dstPath = Misc.CopyFileToStreamingAssets(fullPath);
                    ChangeSceneCacheFileInInspector(t, dstPath);
                }
                GUILayout.Label("Scene Cache file to StreamingAssets");
                EditorGUILayout.LabelField("(RECOMMENDED)", EditorStyles.boldLabel);
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                GUILayout.Space(15);
            }
            EditorGUILayout.Space();

            //[TODO-sin: 2022-3-14] This may cause crash when sliding the values back and forth. Find out why
            // preload
            {
                // changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "SceneCache: Preload",
                //     guiFunc: () => (EditorGUILayout.IntSlider("Preload Length", t.GetPreloadLength(), 0, t.frameCount)),
                //     updateFunc: (int preloadLength) => { t.SetPreloadLength(preloadLength); });
            }

            return(changed);
        }
//----------------------------------------------------------------------------------------------------------------------

        static TestDataComponents ChangeSceneCacheFileAndVerify(SceneCachePlayer player, string scPath)
        {
            SceneCachePlayerEditorUtility.ChangeSceneCacheFile(player, scPath);
            string savedScFilePath = player.GetSceneCacheFilePath();

            Assert.AreEqual(AssetEditorUtility.NormalizePath(scPath), savedScFilePath);
            Assert.IsTrue(AssetEditorUtility.IsPathNormalized(savedScFilePath), $"{savedScFilePath} is not normalized");
            Assert.IsTrue(player.transform.childCount > 0);

            TestDataComponents ret = new TestDataComponents(
                player.GetComponentInChildren <Camera>(),
                player.GetComponentInChildren <Light>(),
                player.GetComponentInChildren <MeshRenderer>()
                );

            Assert.IsNotNull(ret.cam);
            Assert.IsNotNull(ret.light);
            Assert.IsNotNull(ret.meshRenderer);
            return(ret);
        }
//----------------------------------------------------------------------------------------------------------------------

        bool DrawCacheSettings(SceneCachePlayer t)
        {
            bool     changed   = false;
            GUIStyle styleFold = EditorStyles.foldout;

            styleFold.fontStyle = FontStyle.Bold;

            t.foldCacheSettings = EditorGUILayout.Foldout(t.foldCacheSettings, "Player", true, styleFold);
            if (t.foldCacheSettings)
            {
                //Show Selector GUI. Check if we should reopen
                string fullPath           = t.GetSceneCacheFilePath();
                string prevNormalizedPath = AssetEditorUtility.NormalizePath(fullPath);

                string newNormalizedPath = EditorGUIDrawerUtility.DrawFileSelectorGUI("Cache File Path", "MeshSync",
                                                                                      prevNormalizedPath, "sc", OnSceneCacheFileReload);
                newNormalizedPath = AssetEditorUtility.NormalizePath(newNormalizedPath);

                if (newNormalizedPath != prevNormalizedPath)
                {
                    ChangeSceneCacheFileInInspector(t, newNormalizedPath);
                }

                if (!string.IsNullOrEmpty(fullPath) && !fullPath.StartsWith(Application.streamingAssetsPath))
                {
                    GUILayout.BeginHorizontal();
                    const float BUTTON_WIDTH = 50.0f;
                    if (GUILayout.Button("Copy", GUILayout.Width(BUTTON_WIDTH)))
                    {
                        string dstPath = Misc.CopyFileToStreamingAssets(fullPath);
                        ChangeSceneCacheFileInInspector(t, dstPath);
                    }
                    GUILayout.Label("Scene Cache file to StreamingAssets");
                    EditorGUILayout.LabelField("(RECOMMENDED)", EditorStyles.boldLabel);
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                    GUILayout.Space(15);
                }
                EditorGUILayout.Space();

                //Time Unit
                changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "SceneCache: Time Unit",
                                                                  guiFunc: () => (SceneCachePlayer.TimeUnit)EditorGUILayout.Popup("Time Unit",
                                                                                                                                  (int)t.GetTimeUnit(), TIME_UNIT_ENUMS),
                                                                  updateFunc: (SceneCachePlayer.TimeUnit timeUnit) => {
                    t.SetTimeUnit(timeUnit);
                    t.ResetTimeAnimation();
                }
                                                                  );


                SceneCachePlayer.TimeUnit selectedTimeUnit = t.GetTimeUnit();

                if (selectedTimeUnit == SceneCachePlayer.TimeUnit.Seconds)
                {
                    changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "SceneCache: Time",
                                                                      guiFunc: () => (EditorGUILayout.FloatField("Time", t.GetTime())),
                                                                      updateFunc: (float time) => { t.SetTime(time); });

                    changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "SceneCache: Interpolation",
                                                                      guiFunc: () => (EditorGUILayout.Toggle("Interpolation", t.GetInterpolation())),
                                                                      updateFunc: (bool toggle) => { t.SetInterpolation(toggle); });
                }
                else if (selectedTimeUnit == SceneCachePlayer.TimeUnit.Frames)
                {
                    changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "SceneCache: Base Frame",
                                                                      guiFunc: () => ((SceneCachePlayer.BaseFrame)EditorGUILayout.Popup("Base Frame", (int)t.GetBaseFrame(), BASE_FRAME_ENUMS)),
                                                                      updateFunc: (SceneCachePlayer.BaseFrame baseFrame) => {
                        t.SetBaseFrame(baseFrame);
                        t.ResetTimeAnimation();
                    });

                    changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "SceneCache: Frame",
                                                                      guiFunc: () => (EditorGUILayout.IntField("Frame", t.GetFrame())),
                                                                      updateFunc: (int frame) => { t.SetFrame(frame); });
                }

                // preload
                {
                    changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "SceneCache: Preload",
                                                                      guiFunc: () => (EditorGUILayout.IntSlider("Preload Length", t.GetPreloadLength(), 0, t.frameCount)),
                                                                      updateFunc: (int preloadLength) => { t.SetPreloadLength(preloadLength); });
                }

                EditorGUILayout.Space();
            }

            return(changed);
        }
//----------------------------------------------------------------------------------------------------------------------

        private static bool DrawSceneCacheImportSettings(SceneCachePlayer t)
        {
            bool changed = false;
            MeshSyncPlayerConfig playerConfig = t.GetConfigV();

            t.foldImportSettings = EditorGUILayout.Foldout(t.foldImportSettings, "Import Settings", true, GetBoldFoldoutStyle());
            if (t.foldImportSettings)
            {
                IHasModelImporterSettings importer         = AssetImporter.GetAtPath(t.GetSceneCacheFilePath()) as IHasModelImporterSettings;
                ModelImporterSettings     importerSettings = playerConfig.GetModelImporterSettings();

                if (null == importer)
                {
                    MeshSyncInspectorUtility.DrawModelImporterSettingsGUI(t, importerSettings);
                }
                else
                {
                    bool isOverride = t.IsModelImporterSettingsOverridden();

                    EditorGUILayout.BeginHorizontal();
                    EditorGUIDrawerUtility.DrawUndoableGUI(t, "Override",
                                                           guiFunc: () => GUILayout.Toggle(isOverride, "", GUILayout.MaxWidth(15.0f)),
                                                           updateFunc: (bool overrideValue) => { t.OverrideModelImporterSettings(overrideValue); });

                    using (new EditorGUI.DisabledScope(!isOverride)) {
                        EditorGUIDrawerUtility.DrawUndoableGUI(t, "Create Materials",
                                                               guiFunc: () => (bool)EditorGUILayout.Toggle("Create Materials", importerSettings.CreateMaterials),
                                                               updateFunc: (bool createMat) => { importerSettings.CreateMaterials = createMat; });
                    }

                    EditorGUILayout.EndHorizontal();

                    using (new EditorGUI.DisabledScope(!isOverride)) {
                        ++EditorGUI.indentLevel;
                        MeshSyncInspectorUtility.DrawModelImporterMaterialSearchMode(t, importerSettings);
                        --EditorGUI.indentLevel;
                    }
                }



                changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "MeshSync: Animation Interpolation",
                                                                  guiFunc: () => EditorGUILayout.Popup(new GUIContent("Animation Interpolation"),
                                                                                                       playerConfig.AnimationInterpolation, MeshSyncEditorConstants.ANIMATION_INTERPOLATION_ENUMS),
                                                                  updateFunc: (int val) => { playerConfig.AnimationInterpolation = val; }
                                                                  );


                changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "MeshSync: Keyframe Reduction",
                                                                  guiFunc: () => EditorGUILayout.Toggle("Keyframe Reduction", playerConfig.KeyframeReduction),
                                                                  updateFunc: (bool toggle) => { playerConfig.KeyframeReduction = toggle; }
                                                                  );

                if (playerConfig.KeyframeReduction)
                {
                    EditorGUI.indentLevel++;

                    changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "MeshSync: Threshold",
                                                                      guiFunc: () => EditorGUILayout.FloatField("Threshold", playerConfig.ReductionThreshold),
                                                                      updateFunc: (float val) => { playerConfig.ReductionThreshold = val; }
                                                                      );

                    changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "MeshSync: Erase Flat Curves",
                                                                      guiFunc: () => EditorGUILayout.Toggle("Erase Flat Curves", playerConfig.ReductionEraseFlatCurves),
                                                                      updateFunc: (bool toggle) => { playerConfig.ReductionEraseFlatCurves = toggle; }
                                                                      );
                    EditorGUI.indentLevel--;
                }

                changed |= EditorGUIDrawerUtility.DrawUndoableGUI(t, "MeshSync: Z-Up Correction",
                                                                  guiFunc: () => EditorGUILayout.Popup(new GUIContent("Z-Up Correction"), playerConfig.ZUpCorrection,
                                                                                                       MeshSyncEditorConstants.Z_UP_CORRECTION_ENUMS),
                                                                  updateFunc: (int val) => { playerConfig.ZUpCorrection = val; }
                                                                  );

                EditorGUILayout.Space();
            }

            return(changed);
        }
Beispiel #6
0
 internal static void ReloadSceneCacheFile(SceneCachePlayer cachePlayer) {
     string sceneCacheFilePath = cachePlayer.GetSceneCacheFilePath();        
     ChangeSceneCacheFile(cachePlayer, sceneCacheFilePath);
     
 }