Пример #1
0
void DoTrackContextMenu(Event e, Rect clipsPosRect, float cursorTime)
{
    if (e.type == EventType.ContextClick && clipsPosRect.Contains(e.mousePosition))
    {
        var attachableTypeInfos = new List <EditorTools.TypeMetaInfo>();

        var existing       = actions.FirstOrDefault();
        var existingCatAtt = existing != null?existing.GetType().GetCustomAttributes(typeof(CategoryAttribute), true).FirstOrDefault() as CategoryAttribute : null;

        foreach (var info in EditorTools.GetTypeMetaDerivedFrom(typeof(ActionClip)))
        {
            if (!info.attachableTypes.Contains(this.GetType()))
            {
                continue;
            }

            if (existingCatAtt != null)
            {
                if (existingCatAtt.category == info.category)
                {
                    attachableTypeInfos.Add(info);
                }
            }
            else
            {
                attachableTypeInfos.Add(info);
            }
        }

        if (attachableTypeInfos.Count > 0)
        {
            var menu = new UnityEditor.GenericMenu();
            foreach (var _info in attachableTypeInfos)
            {
                var info     = _info;
                var category = string.IsNullOrEmpty(info.category)? string.Empty : (info.category + "/");
                var tName    = info.name;
                menu.AddItem(new GUIContent(category + tName), false, () => { AddAction(info.type, cursorTime); });
            }

            var copyType = CutsceneUtility.GetCopyType();
            if (copyType != null && attachableTypeInfos.Select(i => i.type).Contains(copyType))
            {
                menu.AddSeparator("/");
                menu.AddItem(new GUIContent(string.Format("Paste Clip ({0})", copyType.Name)), false, () => { CutsceneUtility.PasteClip(this, cursorTime); });
            }

            menu.ShowAsContext();
            e.Use();
        }
    }
}
Пример #2
0
        //Show basic stuff
        static void ShowPreliminaryInspector()
        {
            var type        = CutsceneUtility.selectedObject.GetType();
            var nameAtt     = type.GetCustomAttributes(typeof(NameAttribute), false).FirstOrDefault() as NameAttribute;
            var name        = nameAtt != null ? nameAtt.name : type.Name.SplitCamelCase();
            var withinRange = cutscene.currentTime > 0 && cutscene.currentTime >= CutsceneUtility.selectedObject.startTime && cutscene.currentTime <= CutsceneUtility.selectedObject.endTime;
            var keyable     = CutsceneUtility.selectedObject is IKeyable && (CutsceneUtility.selectedObject as IKeyable).animationData != null && (CutsceneUtility.selectedObject as IKeyable).animationData.isValid;
            var isActive    = CutsceneUtility.selectedObject.isActive;

            GUI.color = new Color(0, 0, 0, 0.2f);
            GUILayout.BeginHorizontal(Slate.Styles.headerBoxStyle);
            GUI.color = Color.white;
            GUILayout.Label(string.Format("<b><size=18>{0}{1}</size></b>", withinRange && keyable && isActive ? "<color=#eb5b50>●</color> " : "", name));
            GUI.backgroundColor = default(Color);
            var clip = CutsceneUtility.selectedObject as ActionClip;

            if (clip != null && GUILayout.Button(Styles.gearIcon, GUILayout.Width(40)))
            {
                var menu = new GenericMenu();
                menu.AddItem(new GUIContent("Copy Values"), false, () => { CutsceneUtility.CopyClipValues(clip); });
                menu.AddItem(new GUIContent("Paste Values"), false, () => { CutsceneUtility.PasteClipValues(clip); });
                menu.ShowAsContext();
            }
            GUI.backgroundColor = Color.white;
            GUILayout.EndHorizontal();

            if (Prefs.showDescriptions)
            {
                var descAtt     = type.GetCustomAttributes(typeof(DescriptionAttribute), true).FirstOrDefault() as DescriptionAttribute;
                var description = descAtt != null ? descAtt.description : null;
                if (!string.IsNullOrEmpty(description))
                {
                    EditorGUILayout.HelpBox(description, MessageType.None);
                }
            }

            GUILayout.Space(2);
        }
Пример #3
0
        ///The gear context menu for all parameters
        public static void DoParamGearContextMenu(AnimatedParameter animParam, IKeyable keyable)
        {
            var keyableTime = keyable.RootTimeToLocalTime();
            var hasKeyNow   = animParam.HasKey(keyableTime);
            var hasAnyKey   = animParam.HasAnyKey();

            var menu = new GenericMenu();

            if (animParam.enabled)
            {
                if (hasKeyNow)
                {
                    menu.AddDisabledItem(new GUIContent("Add Key"));
                    menu.AddItem(new GUIContent("Remove Key"), false, () => { animParam.RemoveKey(keyableTime); });
                }
                else
                {
                    menu.AddItem(new GUIContent("Add Key"), false, () => { animParam.SetKeyCurrent(keyableTime); });
                    menu.AddDisabledItem(new GUIContent("Remove Key"));
                }

                if (hasAnyKey)
                {
                    menu.AddItem(new GUIContent("Pre Wrap Mode/Clamp"), false, () => { animParam.SetPreWrapMode(WrapMode.ClampForever); });
                    menu.AddItem(new GUIContent("Pre Wrap Mode/Loop"), false, () => { animParam.SetPreWrapMode(WrapMode.Loop); });
                    menu.AddItem(new GUIContent("Pre Wrap Mode/PingPong"), false, () => { animParam.SetPreWrapMode(WrapMode.PingPong); });

                    menu.AddItem(new GUIContent("Post Wrap Mode/Clamp"), false, () => { animParam.SetPostWrapMode(WrapMode.ClampForever); });
                    menu.AddItem(new GUIContent("Post Wrap Mode/Loop"), false, () => { animParam.SetPostWrapMode(WrapMode.Loop); });
                    menu.AddItem(new GUIContent("Post Wrap Mode/PingPong"), false, () => { animParam.SetPostWrapMode(WrapMode.PingPong); });
                }
                else
                {
                    menu.AddDisabledItem(new GUIContent("Pre Wrap Mode"));
                    menu.AddDisabledItem(new GUIContent("Post Wrap Mode"));
                }

#if SLATE_USE_EXPRESSIONS
                if (!animParam.hasActiveExpression)
                {
                    menu.AddItem(new GUIContent("Set Expression"), false, () => { animParam.scriptExpression = "value"; });
                    menu.AddDisabledItem(new GUIContent("Remove Expression"));
                }
                else
                {
                    menu.AddDisabledItem(new GUIContent("Set Expression"));
                    menu.AddItem(new GUIContent("Remove Expression"), false, () => { animParam.scriptExpression = null; });
                }
#endif
            }

            menu.AddItem(new GUIContent(animParam.enabled ? "Disable" : "Enable"), false, () => { animParam.SetEnabled(!animParam.enabled, keyableTime); });

            menu.AddSeparator("/");
            if (hasAnyKey)
            {
                menu.AddItem(new GUIContent("Remove Animation"), false, () =>
                {
                    if (EditorUtility.DisplayDialog("Reset Animation", "All animation keys will be removed for this parameter.\nAre you sure?", "Yes", "No"))
                    {
                        if (animParam.isExternal)
                        {
                            animParam.RestoreSnapshot();
                        }
                        animParam.Reset();
                        if (animParam.isExternal)
                        {
                            animParam.SetSnapshot();
                        }
                    }
                });
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Remove Animation"));
            }

            if (animParam.isExternal)
            {
                menu.AddItem(new GUIContent("Remove Parameter"), false, () =>
                {
                    if (EditorUtility.DisplayDialog("Remove Parameter", "Completely Remove Parameter.\nAre you sure?", "Yes", "No"))
                    {
                        animParam.RestoreSnapshot();
                        keyable.animationData.RemoveParameter(animParam);
                        CutsceneUtility.RefreshAllAnimationEditorsOf(keyable.animationData);
                    }
                });
            }

            menu.ShowAsContext();
            Event.current.Use();
        }