Beispiel #1
0
    static void DynamicGroup()
    {
        //No need to init it double times
        if (moreGroup == null)
        {
            moreGroup = new TouchBar.Group("slidersGroup", 6);

            slider = moreGroup.AddSlider("slider", 0, 10, 3, (double value) => {
                Debug.Log("On Slider change [value:" + value.ToString() + "]");
            });

            //Close group button
            moreGroup.AddImageButton("close", "/Editor/UniTouchBar/Icons/close.png", "", () => {
                if (moreGroup != null) //Shit happens - shouldn't but in case of!.
                {
                    moreGroup.Hide();
                }
            });

            //Let's add and show!
            TouchBar.AddGroup(moreGroup);
            //We can hide buttons
            moreGroup.OnHidden += () => {
                showSliderButton.Show();
            };
            moreGroup.OnShow += () => {
                showSliderButton.Hide();
            };
        }

        moreGroup.Show();
    }
    static void TouchBar_Manager_OnReady()
    {
        TouchBar.Manager.OnReady -= TouchBar_Manager_OnReady;
        EditorApplication.update += EditorApplication_Update;
        group = new TouchBar.Group("animation", 4);

        segments = group.AddSegments("segments", 5);

        recordButton = group.AddImageButton("record", "/Editor/UniTouchBar/Icons/record.png", "", () => {
            if (AnimatorEditor.GetFlag("recording"))
            {
                //STOP
                System.Type.GetType("UnityEditorInternal.AnimationWindowState, UnityEditor.dll").GetMethod("StopRecording").Invoke(AnimatorEditor.stateWindow, null);
                recordButton.UpdateImage("/Editor/UniTouchBar/Icons/record.png");
            }
            else
            {
                //START
                System.Type.GetType("UnityEditorInternal.AnimationWindowState, UnityEditor.dll").GetMethod("StartRecording").Invoke(AnimatorEditor.stateWindow, null);
                recordButton.UpdateImage("/Editor/UniTouchBar/Icons/recording.png");
            }
            AnimatorEditor.Repaint();
        });

        slider = group.AddSlider("slider", 0, 100, 1, (double obj) => {
            try {
                object[] parameters = new object[] {
                    (float)obj
                };
                System.Type.GetType("UnityEditorInternal.IAnimationWindowControl, UnityEditor.dll").GetMethod("GoToTime").Invoke(AnimatorEditor.controlInterface, parameters);
                AnimatorEditor.Repaint();
            } catch (System.Exception ex) {
                TouchBar.Log(ex);
            }

            ///TouchBar.Log(System.Type.GetType("UnityEditorInternal.AnimationWindowState, UnityEditor.dll").GetProperty("maxTime").GetValue(AnimatorEditor.stateWindow, null));
        });
        TouchBar.AddGroup(group);
        segments.SetOptionWithImage(0, "/Editor/UniTouchBar/Icons/segment_rewind_back.png", () => {
            System.Type.GetType("UnityEditorInternal.IAnimationWindowControl, UnityEditor.dll").GetMethod("GoToFirstKeyframe").Invoke(AnimatorEditor.controlInterface, null);
            AnimatorEditor.Repaint();
            AnimatorTouchBar.SegmentClick();
        });
        segments.SetOptionWithImage(1, "/Editor/UniTouchBar/Icons/segment_step_back.png", () => {
            System.Type.GetType("UnityEditorInternal.IAnimationWindowControl, UnityEditor.dll").GetMethod("GoToPreviousKeyframe").Invoke(AnimatorEditor.controlInterface, null);
            AnimatorEditor.Repaint();
            AnimatorTouchBar.SegmentClick();
        });
        segments.SetOptionWithImage(2, "/Editor/UniTouchBar/Icons/segment_play.png", () => {
            if (AnimatorEditor.GetFlag("playing"))
            {
                //STOP
                segments.Select(-1);
                System.Type.GetType("UnityEditorInternal.AnimationWindowState, UnityEditor.dll").GetMethod("StopPlayback").Invoke(AnimatorEditor.stateWindow, null);
            }
            else
            {
                //START
                segments.Select(2);
                System.Type.GetType("UnityEditorInternal.AnimationWindowState, UnityEditor.dll").GetMethod("StartPlayback").Invoke(AnimatorEditor.stateWindow, null);
            }
            AnimatorEditor.Repaint();
        });
        segments.SetOptionWithImage(3, "/Editor/UniTouchBar/Icons/segment_step.png", () => {
            System.Type.GetType("UnityEditorInternal.IAnimationWindowControl, UnityEditor.dll").GetMethod("GoToNextKeyframe").Invoke(AnimatorEditor.controlInterface, null);
            AnimatorEditor.Repaint();
            AnimatorTouchBar.SegmentClick();
        });
        segments.SetOptionWithImage(4, "/Editor/UniTouchBar/Icons/segment_rewind.png", () => {
            System.Type.GetType("UnityEditorInternal.IAnimationWindowControl, UnityEditor.dll").GetMethod("GoToLastKeyframe").Invoke(AnimatorEditor.controlInterface, null);
            AnimatorEditor.Repaint();
            AnimatorTouchBar.SegmentClick();
        });

        group.ShowOnWindow(TouchBar.Windows.Animation);
        group.ShowOnWindow(TouchBar.Windows.Scene);
        group.OnShow += () => {
            AnimatorEditor.Clean();
            //            TouchBar.Log("Hello");
            loaded = true;
            if (AnimatorEditor.window == null)
            {
                group.Hide();
                loaded = false;
            }

            if ((EditorWindow.focusedWindow != null) && (EditorWindow.focusedWindow.titleContent.text == "Scene"))
            {
            }
        };
    }