public static void AddAudioEvent(AnimationClip clip, AnimationSoundTag soundTag)
        {
            AnimationEvent evt = new AnimationEvent();

            evt.time            = Mathf.Max(soundTag.time, 0);
            evt.functionName    = "OnPlaySoundEvent";
            evt.stringParameter = soundTag.sound.name;
            clip.AddEvent(evt);
        }
示例#2
0
        bool DrawAnimationDropbox(AnimationConfigOverride slot)
        {
            bool hasSlot = false;

            Rect       myRect  = GUILayoutUtility.GetRect(0, 0, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
            GUIContent content = new GUIContent(slot.Config.animation ? slot.Config.animation.name : "Unassigned");


            GUI.Box(myRect, content, UIUtil.BoxStyle);
            if (myRect.Contains(Event.current.mousePosition))
            {
                if (Event.current.type == EventType.DragUpdated)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    Event.current.Use();
                }
                else if (Event.current.type == EventType.DragPerform)
                {
                    if (DragAndDrop.objectReferences.Length > 0)
                    {
                        object reference = DragAndDrop.objectReferences[0];
                        if (reference is AnimationClip)
                        {
                            slot.preset           = null;
                            slot.Config.animation = reference as AnimationClip;
                            EditorUtility.SetDirty(config);
                        }
                        else if (reference is AnimationConfigPreset)
                        {
                            slot.preset = reference as AnimationConfigPreset;
                            EditorUtility.SetDirty(config);
                        }
                        else if (reference is AudioClip)
                        {
                            var  audio   = reference as AudioClip;
                            bool hasFile = false;
                            var  tags    = slot.Config.soundTags;
                            AnimationSoundTag[] newTags = new AnimationSoundTag[tags.Length + 1];
                            for (int i = 0; i < tags.Length; i++)
                            {
                                if (tags[i].sound.name == audio.name)
                                {
                                    hasFile = true;
                                }
                                newTags[i] = tags[i];
                            }

                            if (!hasFile)
                            {
                                newTags[tags.Length] = new AnimationSoundTag()
                                {
                                    sound = audio
                                };
                                slot.Config.soundTags = newTags;
                                EditorUtility.SetDirty(config);
                            }
                        }
                    }

                    Event.current.Use();
                }
                else if (Event.current.type == EventType.MouseDown)
                {
                    Event.current.Use();

                    if (slot == selectedSlot)
                    {
                        selectedSlot = null;
                    }
                    else
                    {
                        if (null != selectedSlot)
                        {
                            onUnselectedSlot?.Invoke(slot);
                        }
                        selectedSlot = slot;
                        onSelectedSlot?.Invoke(slot);
                    }

                    return(true);
                }
            }

            return(false);
        }