Example #1
0
        private GenericMenu MenuForEventTimeLine(JTimelineBase line, JEventTrack track)
        {
            GenericMenu contextMenu = new GenericMenu();
            float       newTime     = (((UnityEngine.Event.current.mousePosition.x + XScroll) / DisplayArea.width) * line.Sequence.Duration) / XScale;

            contextMenu.AddItem(new GUIContent("AddNewEventTimeline"),
                                false, (obj) => AddNewEventTrack(((JTimelineBase)((object[])obj)[0])),
                                new object[] { line });

            string baseAdd = "Add Event/";

            var baseType = typeof(JEventBase);
            var types    = USEditorUtility.GetAllSubTypes(baseType).Where(type => type.IsSubclassOf(baseType));

            foreach (Type type in types)
            {
                string fullAdd          = baseAdd;
                var    customAttributes = type.GetCustomAttributes(true).Where(attr => attr is JEventAttribute).Cast <JEventAttribute>();
                foreach (JEventAttribute customAttribute in customAttributes)
                {
                    fullAdd += customAttribute.EventPath;
                }
                contextMenu.AddItem(new GUIContent(fullAdd),
                                    false, (obj) => AddNewTrackEvent(((JEventTrack)((object[])obj)[0]), ((float)((object[])obj)[1]), ((Type)((object[])obj)[2])),
                                    new object[] { track, newTime, type });
            }


            contextMenu.AddItem(new GUIContent("DeleteEventLine"),
                                false, (obj) => RemoveEventTrack(((JEventTrack)((object[])obj)[0])),
                                new object[] { track });

            return(contextMenu);
        }
Example #2
0
 public void ResetSelection()
 {
     if (SelectedObjects != null && SelectedObjects.Count > 0)
     {
         USEditorUtility.RemoveFromUnitySelection(SelectedObjects);
         SelectedObjects.Clear();
         SourcePositions.Clear();
     }
 }
Example #3
0
        public void HandleEvent(EventType eventType, int button, Vector2 mousePosition)
        {
            hasObjectsUnderMouse = false;

            List <UnityEngine.Object> allObjectsUnderMouse = new List <UnityEngine.Object>();

            foreach (KeyValuePair <UnityEngine.Object, List <JClipRenderData> > kvp in timelineClipRenderDataMap)
            {
                foreach (JClipRenderData renderclip in kvp.Value)
                {
                    if (IsBoxSelecting && HasStartedDrag)
                    {
                        Rect temp = SelectionArea;
                        temp.y += ScrollInfo.currentScroll.y;
                        if (USEditorUtility.DoRectsOverlap(temp, renderclip.renderRect))
                        {
                            allObjectsUnderMouse.Add(renderclip);
                        }
                    }
                    else
                    {
                        if (renderclip.renderRect.Contains(mousePosition))
                        {
                            allObjectsUnderMouse.Add(renderclip);
                        }
                    }
                }
            }
            if (allObjectsUnderMouse.Count > 0)
            {
                hasObjectsUnderMouse = true;
            }

            switch (eventType)
            {
            case EventType.MouseDown:
            {
                HasProcessedInitialDrag = false;
                IsDragging        = false;
                IsBoxSelecting    = false;
                DragStartPosition = mousePosition;

                if (!hasObjectsUnderMouse && UnityEngine.Event.current.button == 0)
                {
                    IsBoxSelecting = true;
                }
                if (hasObjectsUnderMouse && UnityEngine.Event.current.button == 0)
                {
                    IsDragging = true;
                }
                if (IsDragging && UnityEngine.Event.current.alt && UnityEngine.Event.current.control)
                {
                    IsDuplicating = true;
                }

                // if we have no objects under our mouse, then we are likely trying to clear our selection
                if (!hasObjectsUnderMouse && (!UnityEngine.Event.current.control && !UnityEngine.Event.current.command))
                {
                    ResetSelection();
                }

                if (!UnityEngine.Event.current.control && !UnityEngine.Event.current.command)
                {
                    Selection.activeGameObject = null;
                    Selection.activeObject     = null;
                    Selection.activeTransform  = null;
                    Selection.objects          = new UnityEngine.Object[] { };
                }

                HasStartedDrag = false;
                SequenceWindow.Repaint();
            }
            break;

            case EventType.MouseDrag:
            {
                if (!HasStartedDrag)
                {
                    HasStartedDrag = true;
                }

                SequenceWindow.Repaint();
            }
            break;

            case EventType.MouseUp:
            {
                HasProcessedInitialDrag = false;
                IsBoxSelecting          = false;
                IsDragging    = false;
                IsDuplicating = false;
                HasDuplicated = false;
                SequenceWindow.Repaint();
            }
            break;
            }

            //单选
            if ((!UnityEngine.Event.current.control && !UnityEngine.Event.current.command) && hasObjectsUnderMouse && !HasStartedDrag && ((eventType == EventType.MouseUp && button == 0) || (eventType == EventType.MouseDown && button == 1)))
            {
                EditorGUI.FocusTextInControl("");
                ResetSelection();
                OnSelectedObjects(allObjectsUnderMouse);

                if (SelectedObjects.Count == 1)
                {
                    //单选 处理更类型的属性显示
                    var selectobj = SelectedObjects[0] as JClipRenderData;
                    OnSingleClipSelected(selectobj);
                }
            }
            else
            //多选 添加和删除
            if ((UnityEngine.Event.current.control || UnityEngine.Event.current.command) && hasObjectsUnderMouse && !HasStartedDrag && eventType == EventType.MouseUp)
            {
                foreach (var selectedObject in allObjectsUnderMouse)
                {
                    if (!SelectedObjects.Contains(selectedObject))
                    {
                        OnSelectedObjects(new List <UnityEngine.Object> {
                            selectedObject
                        });
                    }
                    else
                    {
                        OnDeSelectedObjects(new List <UnityEngine.Object> {
                            selectedObject
                        });
                    }
                }
            }
            else if (IsBoxSelecting && HasStartedDrag)
            {
                OnSelectedObjects(allObjectsUnderMouse);
            }
            //移动
            if (IsDragging && HasStartedDrag)
            {
                if (allObjectsUnderMouse.Count == 1)
                {
                    if (!selectedObjects.Contains(allObjectsUnderMouse[0]))
                    {
                        ResetSelection();
                    }
                }
                OnSelectedObjects(allObjectsUnderMouse);
                DragStartPosition = new Vector2(DragStartPosition.x, DragStartPosition.y);
                Vector2 mouseDelta = UnityEngine.Event.current.mousePosition - DragStartPosition;

                if (!HasProcessedInitialDrag)
                {
                    StartDraggingObjects();
                    HasProcessedInitialDrag = true;
                }
                ProcessDraggingObjects(mouseDelta);
                if (IsDuplicating && !HasDuplicated)
                {
                }
                else
                {
                    ///  ProcessDraggingObjects(mouseDelta);
                }
            }
        }