Example #1
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;
    }
Example #2
0
//----------------------------------------------------------------------------------------------------------------------
    
    /// <inheritdoc/>
    public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) {
        base.DrawBackground(clip, region);
        
        SceneCachePlayableAsset asset = clip.asset as SceneCachePlayableAsset;
        if (null == asset) {
            Debug.LogError("Asset is not a SceneCachePlayableAsset: " + clip.asset);
            return;
        }
        
        SceneCacheClipData clipData = asset.GetBoundClipData();
        if (null == clipData)
            return;

        LimitedAnimationController limitedAnimationController = asset.GetOverrideLimitedAnimationController();
        if (!limitedAnimationController.IsEnabled()) {
            return;
        }

        int numFrames = limitedAnimationController.GetNumFramesToHold();
        int offset    = limitedAnimationController.GetFrameOffset();
            
        GUIStyle style = new GUIStyle(GUI.skin.label) {
            alignment = TextAnchor.LowerRight,
            normal    = {
                textColor = new Color(0.3f,0.9f,0.3f),
            }
        };
        GUIContent laContent = new GUIContent($"Limited: {numFrames}, {offset}");
        
        Vector2 laContentSize = style.CalcSize(laContent);
        Rect rect = region.position;
        if (rect.width <= laContentSize.x * 2) //2: arbitrary
            return;
        
        EditorGUI.LabelField(rect, laContent, style);

        
    }
//----------------------------------------------------------------------------------------------------------------------

        private static void AssertLimitedAnimationControllerFields(LimitedAnimationController limitedAnimationController,
                                                                   int numFramesToHold, int frameOffset)
        {
            Assert.AreEqual(numFramesToHold, limitedAnimationController.GetNumFramesToHold());
            Assert.AreEqual(frameOffset, limitedAnimationController.GetFrameOffset());
        }