コード例 #1
0
ファイル: AMTimeline.cs プロジェクト: nathanfunk/MateAnimator
    public static bool showEasePicker(AMTrack track, AMKey key, AnimatorData aData, float x = -1f, float y = -1f, float width = -1f)
    {
        bool didUpdate = false;
        if(x >= 0f && y >= 0f && width >= 0f) {
            width--;
            float height = 22f;
            Rect rectLabel = new Rect(x, y - 1f, 40f, height);
            GUI.Label(rectLabel, "Ease");
            Rect rectPopup = new Rect(rectLabel.x + rectLabel.width + 2f, y + 3f, width - rectLabel.width - width_button_delete - 3f, height);

            int nease = EditorGUI.Popup(rectPopup, key.easeType, easeTypeNames);
            if(key.easeType != nease) {
                recordUndoTrackAndKeys(track, false, "Change Ease");
                key.setEaseType(nease);
                // update cache when modifying varaibles
                track.updateCache();
                AMCodeView.refresh();
                // preview new position
                aData.getCurrentTake().previewFrame(aData.getCurrentTake().selectedFrame);
                // save data
                EditorUtility.SetDirty(track);
                setDirtyKeys(track);
                // refresh component
                didUpdate = true;
                // refresh values
                AMEasePicker.refreshValues();
            }

            Rect rectButton = new Rect(width - width_button_delete + 1f, y, width_button_delete, width_button_delete);
            if(GUI.Button(rectButton, getSkinTextureStyleState("popup").background, GUI.skin.GetStyle("ButtonImage"))) {
                AMEasePicker.setValues(/*aData,*/key, track);
                EditorWindow.GetWindow(typeof(AMEasePicker));
            }

            //display specific variable for certain tweens
            //TODO: only show this for specific tweens
            if(!key.hasCustomEase()) {
                y += rectButton.height + 4;
                Rect rectAmp = new Rect(x, y, 200f, height);
                key.amplitude = EditorGUI.FloatField(rectAmp, "Amplitude", key.amplitude);

                y += rectAmp.height + 4;
                Rect rectPer = new Rect(x, y, 200f, height);
                key.period = EditorGUI.FloatField(rectPer, "Period", key.period);
            }
        }
        else {
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            GUILayout.Space(1f);
            GUILayout.Label("Ease");
            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            GUILayout.Space(3f);
            int nease = EditorGUILayout.Popup(key.easeType, easeTypeNames);
            if(key.easeType != nease) {
                recordUndoTrackAndKeys(track, false, "Change Ease");
                key.setEaseType(nease);
                // update cache when modifying varaibles
                track.updateCache();
                AMCodeView.refresh();
                // preview new position
                aData.getCurrentTake().previewFrame(aData.getCurrentTake().selectedFrame);
                // save data
                EditorUtility.SetDirty(track);
                setDirtyKeys(track);
                // refresh component
                didUpdate = true;
                // refresh values
                AMEasePicker.refreshValues();
            }
            GUILayout.EndVertical();
            if(GUILayout.Button(getSkinTextureStyleState("popup").background, GUI.skin.GetStyle("ButtonImage"), GUILayout.Width(width_button_delete), GUILayout.Height(width_button_delete))) {
                AMEasePicker.setValues(/*aData,*/key, track);
                EditorWindow.GetWindow(typeof(AMEasePicker));
            }
            GUILayout.Space(1f);
            GUILayout.EndHorizontal();

            //display specific variable for certain tweens
            //TODO: only show this for specific tweens
            if(!key.hasCustomEase()) {
                key.amplitude = EditorGUILayout.FloatField("Amplitude", key.amplitude);

                key.period = EditorGUILayout.FloatField("Period", key.period);
            }
        }
        return didUpdate;
    }
コード例 #2
0
    void OnGUI()
    {
        this.title = "Ease: " + (oData.time_numbering ? AMTimeline.frameToTime(key.frame, (float)aData.getCurrentTake().frameRate) + " s" : key.frame.ToString());
        AMTimeline.loadSkin(oData, ref skin, ref cachedSkinName, position);
        bool updateEasingCurve = false;

        GUIStyle styleBox = new GUIStyle(GUI.skin.button);

        styleBox.normal = GUI.skin.button.active;
        styleBox.hover  = styleBox.normal;
        styleBox.border = GUI.skin.button.border;
        GUILayout.BeginArea(new Rect(5f, 5f, position.width - 10f, position.height - 10f));
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("", styleBox, GUILayout.Width(500f), GUILayout.Height(100f)))
        {
            selectedSpeedIndex = (selectedSpeedIndex + 1) % speedValues.Length;
            percent            = waitPercent * -1f;
        }

        GUILayout.EndHorizontal();

        GUILayout.Space(5f);
        GUILayout.BeginHorizontal();
        int  prevCategory         = category;
        bool updatedSelectedIndex = false;

        if (setCategory(GUILayout.SelectionGrid(category, categories, (position.width >= 715f ? 12 : 6), GUILayout.Width(position.width - 16f))))
        {
            selectedIndex = getSelectedEaseIndex(prevCategory, selectedIndex);
            selectedIndex = getCategoryIndexForEase(selectedIndex);
            if (selectedIndex < 0)
            {
                selectedIndex        = 0;
                percent              = waitPercent * -1f;
                updatedSelectedIndex = true;
            }
        }
        GUILayout.EndHorizontal();
        GUILayout.Space(5f);

        GUILayout.BeginVertical(GUILayout.Height(233f));
        if (updatedSelectedIndex || setSelectedIndex(GUILayout.SelectionGrid(selectedIndex, easeTypesFiltered[category].ToArray(), 3)))
        {
            percent           = waitPercent * -1f;
            updateEasingCurve = true;
            if (getSelectedEaseName(category, selectedIndex) == "Custom")
            {
                isCustomEase = true;
                if (key.customEase.Count > 0)
                {
                    curve = key.getCustomEaseCurve();
                }
                else
                {
                    setEasingCurve();
                }
            }
            else
            {
                isCustomEase = false;
            }
        }
        GUILayout.EndVertical();
        GUILayout.Space(5f);
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Apply"))
        {
            bool shouldUpdateCache = false;
            if (isCustomEase)
            {
                key.setCustomEase(curve);
                shouldUpdateCache = true;
            }
            if (key.setEaseType(getSelectedEaseIndex(category, selectedIndex)))
            {
                shouldUpdateCache = true;
            }
            if (shouldUpdateCache)
            {
                // update cache when modifying varaibles
                track.updateCache();
                AMCodeView.refresh();
                // preview new position
                aData.getCurrentTake().previewFrame(aData.getCurrentTake().selectedFrame);
                // save data
                EditorUtility.SetDirty(aData);
            }
            this.Close();
        }
        if (GUILayout.Button("Cancel"))
        {
            this.Close();
        }
        GUILayout.EndHorizontal();
        GUILayout.EndArea();

        // orb texture
        GUI.DrawTexture(new Rect(x_pos, 15f, 80f, 80f), tex_orb);
        // speed label
        GUIStyle styleLabelRight = new GUIStyle(GUI.skin.label);

        styleLabelRight.alignment        = TextAnchor.MiddleRight;
        styleLabelRight.normal.textColor = Color.white;
        EditorGUI.DropShadowLabel(new Rect(475f, 5f, 25f, 25f), speedNames[selectedSpeedIndex], styleLabelRight);
        // draw border
        GUI.color = GUI.skin.window.normal.textColor;
        GUI.DrawTexture(new Rect(0f, 0f, 7f, 110f), EditorGUIUtility.whiteTexture);
        GUI.DrawTexture(new Rect(position.width - 209f, 0f, 208f, 110f), EditorGUIUtility.whiteTexture);
        GUI.color = Color.white;

        // curve field
        if (updateEasingCurve)
        {
            setEasingCurve();
        }
        else if (!isCustomEase && didChangeCurve())
        {
            isCustomEase  = true;
            selectedIndex = getCategoryIndexForEaseName("Custom");
            if (selectedIndex < 0)
            {
                category      = 0;
                selectedIndex = getCategoryIndexForEaseName("Custom");
            }
        }
        curve = EditorGUI.CurveField(new Rect(500f, 5f, 208f, 100f), curve, Color.blue, new Rect(0f, -0.5f, 1f, 2.0f));
    }
コード例 #3
0
ファイル: AMTimeline.cs プロジェクト: nathanfunk/MateAnimator
    void showObjectFieldFor(AMTrack amTrack, float width_track, Rect rect)
    {
        if(rect.width < 22f) return;
        // show object field for track, used in OnGUI. Needs to be updated for every track type.
        GUI.skin = null;
        EditorGUIUtility.LookLikeControls();
        // add objectfield for every track type
        // translation
        if(amTrack is AMTranslationTrack) {
            (amTrack as AMTranslationTrack).obj = (Transform)EditorGUI.ObjectField(rect, amTrack.genericObj, typeof(Transform), true/*,GUILayout.Width (width_track-padding_track*2)*/);
        }
        // rotation
        else if(amTrack is AMRotationTrack) {
            (amTrack as AMRotationTrack).obj = (Transform)EditorGUI.ObjectField(rect, amTrack.genericObj, typeof(Transform), true);
        }
        // rotation
        else if(amTrack is AMOrientationTrack) {
            if((amTrack as AMOrientationTrack).setObject((Transform)EditorGUI.ObjectField(rect, (amTrack as AMOrientationTrack).obj, typeof(Transform), true))) {
                amTrack.updateCache();
                AMCodeView.refresh();
            }
        }
        // animation
        else if(amTrack is AMAnimationTrack) {
            //GameObject _old = (amTrack as AMAnimationTrack).obj;
            if((amTrack as AMAnimationTrack).setObject((GameObject)EditorGUI.ObjectField(rect, (amTrack as AMAnimationTrack).obj, typeof(GameObject), true))) {
                //Animation _temp = (Animation)(amTrack as AMAnimationTrack).obj.GetComponent("Animation");
                if((amTrack as AMAnimationTrack).obj != null) {
                    if((amTrack as AMAnimationTrack).obj.animation == null) {
                        (amTrack as AMAnimationTrack).obj = null;
                        EditorUtility.DisplayDialog("No Animation Component", "You must add an Animation component to the GameObject before you can use it in an Animation Track.", "Okay");
                    }
                }
            }
        }
        // audio
        else if(amTrack is AMAudioTrack) {
            if((amTrack as AMAudioTrack).setAudioSource((AudioSource)EditorGUI.ObjectField(rect, (amTrack as AMAudioTrack).audioSource, typeof(AudioSource), true))) {
                if((amTrack as AMAudioTrack).audioSource != null) {
                    (amTrack as AMAudioTrack).audioSource.playOnAwake = false;
                }
            }
        }
        // property
        else if(amTrack is AMPropertyTrack) {
            GameObject propertyGameObject = (GameObject)EditorGUI.ObjectField(rect, (amTrack as AMPropertyTrack).obj, typeof(GameObject), true);
            if((amTrack as AMPropertyTrack).isObjectUnique(propertyGameObject)) {
                bool changePropertyGameObject = true;
                if((amTrack.keys.Count > 0) && (!EditorUtility.DisplayDialog("Data Will Be Lost", "You will lose all of the keyframes on track '" + amTrack.name + "' if you continue.", "Continue Anway", "Cancel"))) {
                    changePropertyGameObject = false;
                }
                if(changePropertyGameObject) {
                    Undo.RecordObject(amTrack, "Set GameObject");

                    // delete all keys
                    if(amTrack.keys.Count > 0) {
                        foreach(AMKey key in amTrack.keys)
                            Undo.DestroyObjectImmediate(key);

                        amTrack.keys = new List<AMKey>();
                        amTrack.updateCache();
                        AMCodeView.refresh();
                    }
                    (amTrack as AMPropertyTrack).setObject(propertyGameObject);

                    EditorUtility.SetDirty(amTrack);
                }
            }
        }
        // event
        else if(amTrack is AMEventTrack) {
            GameObject eventGameObject = (GameObject)EditorGUI.ObjectField(rect, (amTrack as AMEventTrack).obj, typeof(GameObject), true);
            if((amTrack as AMEventTrack).isObjectUnique(eventGameObject)) {
                bool changeEventGameObject = true;
                if((amTrack.keys.Count > 0) && (!EditorUtility.DisplayDialog("Data Will Be Lost", "You will lose all of the keyframes on track '" + amTrack.name + "' if you continue.", "Continue Anway", "Cancel"))) {
                    changeEventGameObject = false;
                }

                if(changeEventGameObject) {
                    Undo.RecordObject(amTrack, "Set GameObject");

                    // delete all keys
                    if(amTrack.keys.Count > 0) {
                        foreach(AMKey key in amTrack.keys)
                            Undo.DestroyObjectImmediate(key);

                        amTrack.keys = new List<AMKey>();
                        amTrack.updateCache();
                        AMCodeView.refresh();
                    }
                    (amTrack as AMEventTrack).setObject(eventGameObject);

                    EditorUtility.SetDirty(amTrack);
                }
            }
        }
        // set go active
        else if(amTrack is AMGOSetActiveTrack) {
            AMGOSetActiveTrack goActiveTrack = amTrack as AMGOSetActiveTrack;
            goActiveTrack.setObject((GameObject)EditorGUI.ObjectField(rect, goActiveTrack.genericObj, typeof(GameObject), true/*,GUILayout.Width (width_track-padding_track*2)*/));
        }

        GUI.skin = skin;
        EditorGUIUtility.LookLikeControls();
    }