コード例 #1
0
ファイル: TimeLine.cs プロジェクト: chav0/cockroach
        void Init()
        {
            if (id == -1)
            {
                id = EditorGUIExtra.GetPermanentControlID();
            }

            if (m_TimeArea == null)
            {
                m_TimeArea = new TimeArea(false);
                m_TimeArea.hRangeLocked    = false;
                m_TimeArea.vRangeLocked    = false;
                m_TimeArea.hSlider         = false;
                m_TimeArea.vSlider         = false;
                m_TimeArea.margin          = 10f;
                m_TimeArea.scaleWithWindow = true;
                m_TimeArea.hTicks.SetTickModulosForFrameRate(30f);
                m_TimeArea.OnEnable();
            }

            if (styles == null)
            {
                styles = new Timeline.Styles();
            }
        }
コード例 #2
0
        public void DrawMajorTicks(Rect position, float frameRate)
        {
            Color color = Handles.color;

            GUI.BeginGroup(position);
            if (Event.current.type != EventType.Repaint)
            {
                GUI.EndGroup();
                return;
            }

            TimeArea.InitStyles();
            this.SetTickMarkerRanges();
            this.hTicks.SetTickStrengths(3f, 80f, true);
            Color textColor = TimeArea.styles.TimelineTick.normal.textColor;

            textColor.a   = 0.1f;
            Handles.color = textColor;
            for (int i = 0; i < this.hTicks.tickLevels; i++)
            {
                float num = this.hTicks.GetStrengthOfLevel(i) * 0.9f;
                if (num > 0.5f)
                {
                    float[] ticksAtLevel = this.hTicks.GetTicksAtLevel(i, true);
                    for (int j = 0; j < ticksAtLevel.Length; j++)
                    {
                        if (ticksAtLevel[j] >= 0f)
                        {
                            int   num2 = Mathf.RoundToInt(ticksAtLevel[j] * frameRate);
                            float x    = this.FrameToPixel((float)num2, frameRate, position);
                            Handles.DrawLine(new Vector3(x, 0f, 0f), new Vector3(x, position.height, 0f));
                        }
                    }
                }
            }

            GUI.EndGroup();
            Handles.color = color;
        }
コード例 #3
0
        public TimeArea.TimeRulerDragMode BrowseRuler(Rect position, int id, ref float time, float frameRate, bool pickAnywhere, GUIStyle thumbStyle)
        {
            Event current   = Event.current;
            Rect  position2 = position;

            if (time != -1f)
            {
                position2.x     = Mathf.Round(base.TimeToPixel(time, position)) - (float)thumbStyle.overflow.left;
                position2.width = thumbStyle.fixedWidth + (float)thumbStyle.overflow.horizontal;
            }
            switch (current.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (position2.Contains(current.mousePosition))
                {
                    GUIUtility.hotControl = id;
                    TimeArea.s_PickOffset = current.mousePosition.x - base.TimeToPixel(time, position);
                    current.Use();
                    return(TimeArea.TimeRulerDragMode.Start);
                }
                if (pickAnywhere && position.Contains(current.mousePosition))
                {
                    GUIUtility.hotControl = id;
                    float num = TimeArea.SnapTimeToWholeFPS(base.PixelToTime(current.mousePosition.x, position), frameRate);
                    TimeArea.s_OriginalTime = time;
                    if (num != time)
                    {
                        GUI.changed = true;
                    }
                    time = num;
                    TimeArea.s_PickOffset = 0f;
                    current.Use();
                    return(TimeArea.TimeRulerDragMode.Start);
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id)
                {
                    GUIUtility.hotControl = 0;
                    current.Use();
                    return(TimeArea.TimeRulerDragMode.End);
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    float num2 = TimeArea.SnapTimeToWholeFPS(base.PixelToTime(current.mousePosition.x - TimeArea.s_PickOffset, position), frameRate);
                    if (num2 != time)
                    {
                        GUI.changed = true;
                    }
                    time = num2;
                    current.Use();
                    return(TimeArea.TimeRulerDragMode.Dragging);
                }
                break;

            case EventType.KeyDown:
                if (GUIUtility.hotControl == id && current.keyCode == KeyCode.Escape)
                {
                    if (time != TimeArea.s_OriginalTime)
                    {
                        GUI.changed = true;
                    }
                    time = TimeArea.s_OriginalTime;
                    GUIUtility.hotControl = 0;
                    current.Use();
                    return(TimeArea.TimeRulerDragMode.Cancel);
                }
                break;

            case EventType.Repaint:
                if (time != -1f)
                {
                    bool flag = position.Contains(current.mousePosition);
                    position2.x += (float)thumbStyle.overflow.left;
                    thumbStyle.Draw(position2, id == GUIUtility.hotControl, flag || id == GUIUtility.hotControl, false, false);
                }
                break;
            }
            return(TimeArea.TimeRulerDragMode.None);
        }
コード例 #4
0
        public void TimeRuler(Rect position, float frameRate)
        {
            Color color = GUI.color;

            GUI.BeginGroup(position);
            if (Event.current.type != EventType.Repaint)
            {
                GUI.EndGroup();
                return;
            }
            TimeArea.InitStyles();
            HandlesExtra.ApplyWireMaterial();
            GL.Begin(1);
            Color backgroundColor = GUI.backgroundColor;

            this.SetTickMarkerRanges();
            this.hTicks.SetTickStrengths(3f, 80f, true);
            Color textColor = TimeArea.styles.TimelineTick.normal.textColor;

            textColor.a = 0.75f;
            for (int i = 0; i < this.hTicks.tickLevels; i++)
            {
                float   num          = this.hTicks.GetStrengthOfLevel(i) * 0.9f;
                float[] ticksAtLevel = this.hTicks.GetTicksAtLevel(i, true);
                for (int j = 0; j < ticksAtLevel.Length; j++)
                {
                    if (ticksAtLevel[j] >= base.hRangeMin && ticksAtLevel[j] <= base.hRangeMax)
                    {
                        int   num2 = Mathf.RoundToInt(ticksAtLevel[j] * frameRate);
                        float num3 = position.height * Mathf.Min(1f, num) * 0.7f;
                        float num4 = this.FrameToPixel((float)num2, frameRate, position);
                        GL.Color(new Color(1f, 1f, 1f, num / 0.5f) * textColor);
                        GL.Vertex(new Vector3(num4, position.height - num3 + 0.5f, 0f));
                        GL.Vertex(new Vector3(num4, position.height - 0.5f, 0f));
                        if (num > 0.5f)
                        {
                            GL.Color(new Color(1f, 1f, 1f, num / 0.5f - 1f) * textColor);
                            GL.Vertex(new Vector3(num4 + 1f, position.height - num3 + 0.5f, 0f));
                            GL.Vertex(new Vector3(num4 + 1f, position.height - 0.5f, 0f));
                        }
                    }
                }
            }
            GL.End();
            int levelWithMinSeparation = this.hTicks.GetLevelWithMinSeparation(40f);

            float[] ticksAtLevel2 = this.hTicks.GetTicksAtLevel(levelWithMinSeparation, false);
            for (int k = 0; k < ticksAtLevel2.Length; k++)
            {
                if (ticksAtLevel2[k] >= base.hRangeMin && ticksAtLevel2[k] <= base.hRangeMax)
                {
                    int    num5 = Mathf.RoundToInt(ticksAtLevel2[k] * frameRate);
                    float  num6 = Mathf.Floor(this.FrameToPixel((float)num5, frameRate, base.rect));
                    string text = this.FormatFrame(num5, frameRate);
                    GUI.Label(new Rect(num6 + 3f, -3f, 40f, 20f), text, TimeArea.styles.TimelineTick);
                }
            }
            GUI.EndGroup();
            GUI.backgroundColor = backgroundColor;
            GUI.color           = color;
        }