コード例 #1
0
 /// <summary>
 /// コピー履歴表示
 /// </summary>
 void ShowCopyHistory(float secPerFrame)
 {
     if (AnimationExtensionData.EventCopyHistory.Count <= 0)
     {
         return;
     }
     EditorGUILayout.Space();
     EditorGUILayout.LabelField("コピー履歴");
     for (var eventIdx = 0; eventIdx < AnimationExtensionData.EventCopyHistory.Count; ++eventIdx)
     {
         var eventInfo = AnimationExtensionData.EventCopyHistory[eventIdx];
         EditorGUILayout.BeginHorizontal(GUI.skin.box);
         GUILayout.Button(string.Empty, GUI.skin.label, GUILayout.Width(20));
         GUILayout.Button(string.Empty, GUI.skin.label, GUILayout.Width(20));
         // コピー中イベントにする
         if (GUILayout.Button("C", GUILayout.Width(20)))
         {
             AnimationExtensionData.CopyEventInfo(fromEventInfo: eventInfo);
         }
         EditorGUILayout.LabelField(string.IsNullOrEmpty(eventInfo.functionName) ? "(指定なし)" : eventInfo.functionName, GUILayout.MaxWidth(150));
         EditorGUILayout.LabelField(SecToFrame(eventInfo.time, secPerFrame).ToString(), GUILayout.MaxWidth(100));
         EditorGUILayout.LabelField(eventInfo.intParameter.ToString(), GUILayout.MaxWidth(100));
         EditorGUILayout.LabelField(eventInfo.floatParameter.ToString(), GUILayout.MaxWidth(100));
         GUILayout.Label(eventInfo.stringParameter);
         EditorGUILayout.EndHorizontal();
     }
 }
コード例 #2
0
    void OnGUI()
    {
        if (RootObject == null)
        {
            return;
        }
        FunctionSearchText = EditorGUILayout.TextField("関数名検索", FunctionSearchText);
        var targetMethods = new List <MethodInfo>(CallableMethods);

        if (string.IsNullOrEmpty(FunctionSearchText) == false)
        {
            targetMethods = targetMethods.Where(method => method.Name.ToLower().Contains(FunctionSearchText.ToLower())).ToList();
        }

        var animEvents = AnimationUtility.GetAnimationEvents(AnimClip);
        var animEvent  = animEvents[EventIndex];
        var funcIdx    = -1;

        if (string.IsNullOrEmpty(animEvent.functionName) == false)
        {
            funcIdx = targetMethods.FindIndex(method => method.Name == animEvent.functionName);
        }
        var selectFuncIdx = EditorGUILayout.Popup(funcIdx, targetMethods.Select(method => FormatCallableMethodName(method)).ToArray());

        if (selectFuncIdx == -1)
        {
            selectFuncIdx = targetMethods.Count();
        }
        // 関数が変わったら、パラメータ初期化
        if (funcIdx != selectFuncIdx)
        {
            animEvent.intParameter             = 0;
            animEvent.floatParameter           = 0.0f;
            animEvent.stringParameter          = string.Empty;
            animEvent.objectReferenceParameter = null;
            funcIdx = selectFuncIdx;
        }
        if (funcIdx >= 0 && funcIdx < targetMethods.Count)
        {
            animEvent.functionName = targetMethods[funcIdx].Name;
            ShowParameter(animEvent, targetMethods[funcIdx]);
        }

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("コピー"))
        {
            AnimationExtensionData.CopyEventInfo(fromEventInfo: animEvent);
        }
        if (GUILayout.Button("ペースト"))
        {
            Undo.RecordObject(AnimClip, "paste event info");
            AnimationExtensionData.PasteEventInfo(toEventInfo: animEvent);
        }
        EditorGUILayout.EndHorizontal();

        AnimationUtility.SetAnimationEvents(AnimClip, animEvents);
    }
コード例 #3
0
    /// <summary>
    /// AnimationClipに関連付いているイベント情報一覧表示
    /// </summary>
    void ShowAnimationClipEventList(AnimationClip clip)
    {
        var secPerFrame = 1 / clip.frameRate;

        EditorGUILayout.LabelField("イベントリスト");
        EditorGUILayout.BeginHorizontal();
        // 新規イベント追加
        if (GUILayout.Button("+", GUILayout.Width(20)))
        {
            Undo.RecordObject(this, "add new event info");
            var eventList = TargetEvents.ToList();
            eventList.Add(new AnimationEvent());
            TargetEvents = eventList.OrderBy(event_info => event_info.time).ToArray();
            IsDirty      = true;
        }
        GUILayout.Button(string.Empty, GUI.skin.label, GUILayout.Width(20));
        GUILayout.Button(string.Empty, GUI.skin.label, GUILayout.Width(20));
        EditorGUILayout.LabelField("関数名", GUILayout.MaxWidth(150));
        EditorGUILayout.LabelField("frame(" + clip.frameRate + ")", GUILayout.MaxWidth(100));
        EditorGUILayout.LabelField("整数値", GUILayout.MaxWidth(100));
        EditorGUILayout.LabelField("数値(小数点)", GUILayout.MaxWidth(100));
        EditorGUILayout.LabelField("文字列");
        EditorGUILayout.EndHorizontal();
        var deleteIdx = -1;

        for (var eventIdx = 0; eventIdx < TargetEvents.Length; ++eventIdx)
        {
            var eventInfo = TargetEvents[eventIdx];
            EditorGUILayout.BeginHorizontal(GUI.skin.box);
            GUI.color = Color.red;
            // イベント削除
            if (GUILayout.Button("―", GUILayout.Width(20)))
            {
                deleteIdx = eventIdx;
            }
            GUI.color = Color.white;
            // コピー中イベントを貼り付け
            if (GUILayout.Button("P", GUILayout.Width(20)))
            {
                if (AnimationExtensionData.EventInfoInCopy != null)
                {
                    // Undoされない…
                    // Undo.RecordObject(this, "paste event info");
                    AnimationExtensionData.PasteEventInfo(toEventInfo: eventInfo);
                    IsDirty = true;
                }
            }
            // コピー中イベントにする
            if (GUILayout.Button("C", GUILayout.Width(20)))
            {
                AnimationExtensionData.CopyEventInfo(fromEventInfo: eventInfo);
            }
            EditorGUILayout.LabelField(string.IsNullOrEmpty(eventInfo.functionName) ? "(指定なし)" : eventInfo.functionName, GUILayout.MaxWidth(150));
            var frame    = eventInfo.time <= 0.0f ? 0 : SecToFrame(eventInfo.time, secPerFrame);
            var inputInt = EditorGUILayout.IntField(frame, GUILayout.MinWidth(100), GUILayout.MaxWidth(100));
            if (inputInt != frame)
            {
                eventInfo.time = inputInt * secPerFrame;
                IsDirty        = true;
            }
            inputInt = EditorGUILayout.IntField(eventInfo.intParameter, GUILayout.MinWidth(100), GUILayout.MaxWidth(100));
            if (inputInt != eventInfo.intParameter)
            {
                eventInfo.intParameter = inputInt;
                IsDirty = true;
            }
            var inputFloat = EditorGUILayout.FloatField(eventInfo.floatParameter, GUILayout.MinWidth(100), GUILayout.MaxWidth(100));
            if (inputFloat != eventInfo.floatParameter)
            {
                eventInfo.floatParameter = inputFloat;
                IsDirty = true;
            }
            var inputString = GUILayout.TextField(eventInfo.stringParameter);
            if (inputString != eventInfo.stringParameter)
            {
                eventInfo.stringParameter = inputString;
                IsDirty = true;
            }
            EditorGUILayout.EndHorizontal();
        }
        if (deleteIdx != -1)
        {
            Undo.RecordObject(this, "delete event info");
            var eventList = TargetEvents.ToList();
            eventList.RemoveAt(deleteIdx);
            TargetEvents = eventList.ToArray();
            deleteIdx    = -1;
            IsDirty      = true;
        }
        // 変更時のみボタンを有効に
        GUI.enabled = IsDirty;
        if (GUILayout.Button("適用", GUILayout.MaxWidth(50)))
        {
            Undo.RecordObject(clip, "apply event info");
            TargetEvents = TargetEvents.OrderBy(event_info => event_info.time).ToArray();
            AnimationUtility.SetAnimationEvents(clip, TargetEvents);
            IsDirty = false;

            // 他ウィンドウの再描画を促す
            var animEventWindows = Resources.FindObjectsOfTypeAll <AnimationEventWindow>();
            foreach (var window in animEventWindows)
            {
                window.Repaint();
            }
            var animationWindowType = Types.GetType("UnityEditor.AnimationWindow", "UnityEditor.dll");
            var animWindows         = Resources.FindObjectsOfTypeAll(animationWindowType) as EditorWindow[];
            foreach (var window in animWindows)
            {
                window.Repaint();
            }
        }
        GUI.enabled = true;
    }