private void handleDragInteraction(Rect position, AudioTrack track, Vector2 translation, Vector2 scale)
    {
        Rect controlBackground = new Rect(0, 0, position.width, position.height);

        switch (Event.current.type)
        {
        case EventType.DragUpdated:
            if (controlBackground.Contains(Event.current.mousePosition))
            {
                bool     audioFound = false;
                Object[] objRefs    = DragAndDrop.objectReferences;
                for (int i = 0; i < objRefs.Length; i++)
                {
                    AudioClip clip = objRefs[i] as AudioClip;
                    if (clip != null)
                    {
                        audioFound = true;
                        break;
                    }
                }
                if (audioFound)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                    Event.current.Use();
                }
            }
            break;

        case EventType.DragPerform:
            if (controlBackground.Contains(Event.current.mousePosition))
            {
                AudioClip clip    = null;
                Object[]  objRefs = DragAndDrop.objectReferences;
                for (int i = 0; i < objRefs.Length; i++)
                {
                    AudioClip audioClip = objRefs[i] as AudioClip;
                    if (audioClip != null)
                    {
                        clip = audioClip;
                        break;
                    }
                }
                if (clip != null)
                {
                    float       fireTime = (Event.current.mousePosition.x - translation.x) / scale.x;
                    CinemaAudio ca       = CutsceneItemFactory.CreateCinemaAudio(track, clip, fireTime);
                    Undo.RegisterCreatedObjectUndo(ca, string.Format("Created {0}", ca.name));
                    Event.current.Use();
                }
            }
            break;
        }
    }
    protected override void updateHeaderControl3(UnityEngine.Rect position)
    {
        AudioTrack track = TargetTrack.Behaviour as AudioTrack;

        if (track == null)
        {
            return;
        }

        Color temp = GUI.color;

        GUI.color = (track.AudioClips.Length > 0) ? Color.green : Color.red;

        int controlID = GUIUtility.GetControlID(track.GetInstanceID(), FocusType.Passive, position);

        if (GUI.Button(position, string.Empty, TrackGroupControl.styles.addIcon))
        {
            EditorGUIUtility.ShowObjectPicker <AudioClip>(null, false, string.Empty, controlID);
        }

        if (Event.current.type == EventType.ExecuteCommand && Event.current.commandName == "ObjectSelectorClosed")
        {
            if (EditorGUIUtility.GetObjectPickerControlID() == controlID)
            {
                Object    pickedObject = EditorGUIUtility.GetObjectPickerObject();
                AudioClip clip         = (pickedObject as AudioClip);
                if (clip != null)
                {
                    CinemaAudio ca = CutsceneItemFactory.CreateCinemaAudio(track, clip, state.ScrubberPosition);
                    Undo.RegisterCreatedObjectUndo(ca, string.Format("Created {0}", ca.name));
                }
                Event.current.Use();
            }
        }
        GUI.color = temp;
    }
示例#3
0
    private void handleDragInteraction(Rect position, AudioTrack track, Vector2 translation, Vector2 scale)
    {
        Rect controlBackground = new Rect(0, 0, position.width, position.height);

        switch (Event.current.type)
        {
        case EventType.DragUpdated:
            if (controlBackground.Contains(Event.current.mousePosition))
            {
                bool audioFound = false;
                {
                    // foreach(var objectReference in DragAndDrop.objectReferences)
                    var __enumerator1 = (DragAndDrop.objectReferences).GetEnumerator();
                    while (__enumerator1.MoveNext())
                    {
                        var objectReference = (Object)__enumerator1.Current;
                        {
                            AudioClip clip = objectReference as AudioClip;
                            if (clip != null)
                            {
                                audioFound = true;
                                break;
                            }
                        }
                    }
                }
                if (audioFound)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                    Event.current.Use();
                }
            }
            break;

        case EventType.DragPerform:
            if (controlBackground.Contains(Event.current.mousePosition))
            {
                AudioClip clip = null;
                {
                    // foreach(var objectReference in DragAndDrop.objectReferences)
                    var __enumerator2 = (DragAndDrop.objectReferences).GetEnumerator();
                    while (__enumerator2.MoveNext())
                    {
                        var objectReference = (Object)__enumerator2.Current;
                        {
                            AudioClip audioClip = objectReference as AudioClip;
                            if (audioClip != null)
                            {
                                clip = audioClip;
                                break;
                            }
                        }
                    }
                }
                if (clip != null)
                {
                    float       fireTime = (Event.current.mousePosition.x - translation.x) / scale.x;
                    CinemaAudio ca       = CutsceneItemFactory.CreateCinemaAudio(track, clip, fireTime);
                    Undo.RegisterCreatedObjectUndo(ca, string.Format("Created {0}", ca.name));
                    Event.current.Use();
                }
            }
            break;
        }
    }