public void OnCollapsedGUI() { GUILayout.Box("", TimelineBackground, GUILayout.MaxHeight(17.0f), GUILayout.ExpandWidth(true)); if (Event.current.type == EventType.Repaint) { DisplayArea = GUILayoutUtility.GetLastRect(); } var sortedEvents = cachedEventRenderData.OrderBy(element => element.Event.FireTime).ToList(); for (var index = 0; index < sortedEvents.Count(); index++) { var data = sortedEvents[index]; var evt = sortedEvents[index].Event; var xPos = DisplayArea.width * (evt.FireTime / Duration); data.RenderPosition = new Vector2(DisplayArea.x + ((xPos * XScale) - XScroll), DisplayArea.y); data.RenderRect = new Rect(DisplayArea.x + ((xPos * XScale) - XScroll), DisplayArea.y, 4.0f, DisplayArea.height - 1.0f); using (new Shared.GUIChangeColor(SelectedObjects.Contains(evt) ? Color.yellow : GUI.color)) data.EventEditor.DrawCollapsedEventInTimeline(data.RenderRect, DisplayArea.x, DisplayArea.width, Duration, XScale, XScroll); } HandleEvent(); }
/// <summary> /// Draws a node by the given graphics /// </summary> /// <param name="n">The node to draw</param> /// <param name="g">The graphics to use to draw the node</param> /// <param name="viewportRect">The clipping rectangle</param> private void DrawNode(Node n, Graphics g, Rectangle viewportRect) { if (n != null) { bool isNodeSelected = SelectedObjects.Contains(n); // draw the node n.Draw(g, Font, viewportRect, isNodeSelected); } }
public void OnGUI() { if (ObserverTimeline != null && ObserverTimeline.Sequence != null && ObserverTimeline.Sequence.HasSequenceBeenStarted) { Shared.TransitionHelper.ForceGameViewRepaint(); } GUILayout.Box("", TimelineBackground, GUILayout.MaxHeight(17.0f), GUILayout.ExpandWidth(true)); if (Event.current.type == EventType.Repaint) { DisplayArea = GUILayoutUtility.GetLastRect(); } var helperRect = DisplayArea; helperRect.y -= 17.0f; var validCamerasMessage = string.Empty; if (ObserverTimeline.Sequence.RunningTime > 0.0f && Camera.allCameras.Count(camera => ObserverTimeline.IsValidCamera(camera)) > 1) { validCamerasMessage = " - You have more than one active camera in your scene, is this intentional?."; } GUI.Label(helperRect, string.Format("Current Keyframe : {0} {1}", ObserverTimeline.CurrentlyActiveKeyframe != null ? ObserverTimeline.CurrentlyActiveKeyframe.KeyframeCamera.name : "null", validCamerasMessage)); var sortedKeyframes = cachedObserverRenderData.OrderBy(element => element.Keyframe.FireTime).ToList(); for (var index = 0; index < sortedKeyframes.Count(); index++) { var data = sortedKeyframes[index]; var xPos = DisplayArea.width * (data.Keyframe.FireTime / Duration); var xMaxPos = DisplayArea.width * (data.Keyframe.TransitionDuration / Duration); xMaxPos = Mathf.Clamp(xMaxPos, 4.0f, float.MaxValue); data.RenderPosition = new Vector2(DisplayArea.x + ((xPos * XScale) - XScroll), DisplayArea.y); data.RenderRect = new Rect((DisplayArea.x + ((xPos * XScale) - XScroll)) - 3.0f, DisplayArea.y, xMaxPos, DisplayArea.height - 1.0f); using (new Shared.GUIChangeColor(SelectedObjects.Contains(data.Keyframe) ? Color.yellow : GUI.color)) { GUI.Box(data.RenderRect, ""); var labelRect = data.RenderRect; labelRect.x += 4.0f; labelRect.width = 1000.0f; GUI.Label(labelRect, data.Keyframe.KeyframeCamera ? data.Keyframe.KeyframeCamera.name : "Null"); } } HandleEvent(); }
protected override void CalcSelectedObjects() { base.CalcSelectedObjects(); if (!ListView.Id.ToLower().Contains("lookup")) { var rootObjects = collection.List.OfType <ITreeNode>().Where(f => f.Parent == null || !collection.List.Contains(f.Parent)).OfType <Object>().ToList(); SelectedObjects = SelectedObjects.OfType <ITreeNode>().Where(f => f.Parent == null || !collection.List.Contains(f.Parent)).OfType <Object>().ToList(); foreach (var item in rootObjects) { CalcNestedSelectedObjects((item as ITreeNode), SelectedObjects.Contains(item)); } } }
public void OnCollapsedGUI() { if (Event.current.commandName == "UndoRedoPerformed") { ObjectPathTimeline.BuildCurveFromKeyframes(); return; } if (ObjectPathTimeline.ObjectSpline == null) { ObjectPathTimeline.BuildCurveFromKeyframes(); } cachedObjectPathRenderData[0].Keyframe = ObjectPathTimeline.FirstNode; cachedObjectPathRenderData[1].Keyframe = ObjectPathTimeline.LastNode; if (ObjectPathTimeline.ObjectSpline.SplineSolver == null) { ObjectPathTimeline.BuildCurveFromKeyframes(); } GUILayout.Box("", TimelineBackground, GUILayout.MaxHeight(17.0f), GUILayout.ExpandWidth(true)); if (Event.current.type == EventType.Repaint) { DisplayArea = GUILayoutUtility.GetLastRect(); } var startX = ConvertTimeToXPos(ObjectPathTimeline.StartTime); var endX = ConvertTimeToXPos(ObjectPathTimeline.EndTime); var splineAreaBox = new Rect(startX, DisplayArea.y, endX - startX, DisplayArea.height); GUI.Box(splineAreaBox, ""); var width = 2.0f; cachedObjectPathRenderData[0].RenderRect = new Rect(startX, DisplayArea.y, width * 2.0f, DisplayArea.height); cachedObjectPathRenderData[1].RenderRect = new Rect(endX - (width * 2.0f), DisplayArea.y, width * 2.0f, DisplayArea.height); cachedObjectPathRenderData[0].RenderPosition = new Vector2(startX, DisplayArea.y); cachedObjectPathRenderData[1].RenderPosition = new Vector2(endX, DisplayArea.y); using (new GUIChangeColor(SelectedObjects.Contains(cachedObjectPathRenderData[0].Keyframe) ? Color.yellow : GUI.color)) GUI.Box(cachedObjectPathRenderData[0].RenderRect, ""); using (new GUIChangeColor(SelectedObjects.Contains(cachedObjectPathRenderData[1].Keyframe) ? Color.yellow : GUI.color)) GUI.Box(cachedObjectPathRenderData[1].RenderRect, ""); GUI.Label(splineAreaBox, "Double Click on an existing keyframe in the Scene view to add a new one (backspace or delete to remove)."); }
void DrawCurve(USInternalCurve curve, Color curveColour) { if (curve.Keys.Count == 0) { return; } using (new HandlesChangeColor(curveColour)) { for (var keyframeIndex = 1; keyframeIndex < curve.Keys.Count; keyframeIndex++) { var keyframe = curve.Keys[keyframeIndex]; for (var segmentIndex = 1; segmentIndex < cachedKeyframePositions[keyframe].CurveSegments.Count; segmentIndex++) { AnimationCurveEditorGUIUtility.DrawLine( cachedKeyframePositions[keyframe].CurveSegments[segmentIndex - 1], cachedKeyframePositions[keyframe].CurveSegments[segmentIndex], XScroll, XScale); } } for (var keyframeIndex = 0; keyframeIndex < curve.Keys.Count; keyframeIndex++) { cachedKeyframePositions[curve.Keys[keyframeIndex]].LeftTangentColor = Color.white; cachedKeyframePositions[curve.Keys[keyframeIndex]].RightTangentColor = Color.white; if (SelectedTangent == 0) { cachedKeyframePositions[curve.Keys[keyframeIndex]].LeftTangentColor = Color.yellow; } if (SelectedTangent == 1) { cachedKeyframePositions[curve.Keys[keyframeIndex]].RightTangentColor = Color.yellow; } AnimationCurveEditorGUIUtility.KeyframeLabel( curve.Keys[keyframeIndex], cachedKeyframePositions[curve.Keys[keyframeIndex]], (keyframeIndex == 0 && curve.UseCurrentValue), XScroll, XScale); if (SelectedObjects.Count == 1 && SelectedObjects.Contains(curve.Keys[keyframeIndex])) { DrawTangent(cachedKeyframePositions[curve.Keys[keyframeIndex]], curve.Keys[keyframeIndex]); } } } }
public void OnSelectedObjects(List <UnityEngine.Object> selectedObjects) { USUndoManager.PropertyChange(this, "Select"); foreach (var selectedObject in selectedObjects) { if (!SelectedObjects.Contains(selectedObject)) { SelectedObjects.Add(selectedObject); var selection = Selection.objects != null?Selection.objects.ToList() : new List <UnityEngine.Object>(); selection.Add(selectedObject); Selection.objects = selection.ToArray(); } } }
private void MoveObject(DrawableObject @object, Point offset) { foreach (Transition trans in @object.OutTransitions) { if (!SelectedObjects.Contains(trans) && trans.StartObject == @object) { trans.MoveStart(offset); } } foreach (Transition trans in @object.InTransitions) { if (!SelectedObjects.Contains(trans)) { trans.MoveEnd(offset); } } @object.Move(offset); }
public void OnLeftDown() { Vector2 worldSpaceCursor = Camera.ScreenToWorldCoordinates(MousePosition); KeyboardState state = Keyboard.GetState(); foreach (LevelGeometry geom in Map.Geometry) { Rectangle rect = new Rectangle(geom.Position.ToPoint(), geom.Size.ToPoint()); if (rect.Contains(worldSpaceCursor)) { if (SelectedObjects.Contains(geom) == false) { SelectedObjects.Add(geom); } draggingElement = true; draggingOffst = new Vector2(worldSpaceCursor.X, worldSpaceCursor.Y); } } }
private static void PollSelection(GameWindow window, MouseState mouseState, KeyboardState keyboardState) // TODO: raycast is performed wrong on shapes' edges; check! { var startWorld = RaycastResult.StartWorld.ToBullet3(); var endWorld = RaycastResult.EndWorld.ToBullet3(); using (var raycastCallback = new ClosestRayResultCallback(ref startWorld, ref endWorld)) { PhysicsHandler.RayTestRef(ref startWorld, ref endWorld, raycastCallback); if (/*window.IsMouseButtonPressed(MouseButton.Right)*/ mouseState.IsButtonDown(MouseButton.Right) && _lastState.IsButtonUp(MouseButton.Right)) // TODO: perhaps use Window built-in method? { if (raycastCallback.HasHit) { if (!keyboardState.IsKeyDown(Key.ControlLeft) && SelectedObjects.Find(x => x != raycastCallback.CollisionObject) != null) { // Control is not pressed and other objects are already selected ---> clear selection and add the new object to the selection ClearAndAddSelection(raycastCallback.CollisionObject); } else { // add the object to the selection if it's not there yet if (!SelectedObjects.Contains(raycastCallback.CollisionObject)) { AddSelection(raycastCallback.CollisionObject); } else { RemoveSelection(raycastCallback.CollisionObject); } } } else { // no object is selected ---> clear selection ClearSelection(); } } } }
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); } } }
public void OnGUI() { if (Event.current.commandName == "UndoRedoPerformed") { return; } if (Curves == null || Curves.Count == 0) { GUILayout.Box("", TimelineBackground, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true), GUILayout.MaxHeight(MaxHeight)); if (Event.current.type == EventType.Repaint) { DisplayArea = GUILayoutUtility.GetLastRect(); } GUI.Label(DisplayArea, "Press the Animate button to start animating properties!"); return; } if (Curves.Any(curve => curve == null)) { throw new NullReferenceException("One of the curves is null, this shouldn't happen"); } if (EditorWindow == null) { throw new NullReferenceException("Editor Window must be assigned a value"); } if (RebuildCurvesOnNextGUI) { CalculateBounds(); RebuildCachedCurveInformation(); // Sometimes, depending on the update order vs the serialization order, this can be null during Undo / Redo :/ if (EditorWindow != null) { EditorWindow.Repaint(); } } RebuildCurvesOnNextGUI = false; foreach (var cachedRenderingData in cachedKeyframePositions) { if (SelectedObjects.Contains(cachedRenderingData.Key)) { cachedRenderingData.Value.IsKeyframeSelected = true; } else { cachedRenderingData.Value.IsKeyframeSelected = false; } } if (cachedKeyframePositions == null || (cachedKeyframePositions.Count == 0 && Curves.Count > 0)) { RebuildCachedCurveInformation(); } GUILayout.Box("", TimelineBackground, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true), GUILayout.MaxHeight(MaxHeight)); if (Event.current.type == EventType.Repaint) { var displayAreaRect = GUILayoutUtility.GetLastRect(); var previousDisplayArea = DisplayArea; DisplayArea = displayAreaRect; if (DisplayArea != previousDisplayArea) { RebuildCachedCurveInformation(); } } using (new GUIBeginArea(DisplayArea)) { if (Event.current.type == EventType.Repaint) { DrawGrid(); } for (var n = 0; n < Curves.Count; n++) { DrawCurve(Curves[n], AnimationCurveEditorUtility.GetCurveColor(n)); } HandleEvent(); } }
internal bool MouseDown(int x, int y, MouseButtons button, bool ctrlKey, bool altKey, bool shiftKey) // Return true if copy operation is performed { bool copyPerformed = false; if (IsCreatingMode) { if (button == MouseButtons.Left) // Add { Node addNode; if (HoveredObjects.Count > 0 && HoveredObjects[0] is Node node) { if (CreatingNodes.Contains(node)) { if (CreatingNodes.Last() == node) { CreatingNodes.RemoveAt(CreatingNodes.Count - 1); } else if (CreatingNodes.First() == node) { AddToCreatingNodes(node); SubmitCreatingNodes(); } return(false); } addNode = node; } else { Vector pos = new Vector(x, y).MapFromScreen(Scale, Origin); addNode = new Node(pos.X, pos.Y); } AddToCreatingNodes(addNode); return(false); } else if (button == MouseButtons.Right) // Exit { SubmitCreatingNodes(); return(false); } } if (altKey && PasteMode && SampleDecorator != null) // Create and paste { GraphEditManager.BeforePreformEdit(Graph, "Create Graph Elements"); Vector pos = new Vector(x, y).MapFromScreen(Scale, Origin); Node addNode = new Node(pos.X, pos.Y); addNode.Hidden = true; addNode.Decorator = SampleDecorator.Clone() as Decorator; if (!shiftKey && addNode.Decorator is TransformableDecorator transformableDecorator) { transformableDecorator.ExtraScale = (1 - Graph.MetaData.EdgeWidth) / Graph.MetaData.EdgeWidth; } GraphManipulation.AddShape(Graph, new List <Node>() { addNode }); } else if (HoveredObjects.Count > 0 && button != MouseButtons.Middle) { List <GraphElement> objectToKeep = new List <GraphElement>(); if (ctrlKey || shiftKey) { foreach (GraphElement selectedObject in SelectedObjects) { if (shiftKey || !HoveredObjects.Contains(selectedObject)) { objectToKeep.Add(selectedObject); } } } foreach (GraphElement havoredObject in HoveredObjects) { if (!SelectedObjects.Contains(havoredObject)) { objectToKeep.Add(havoredObject); } } SelectedObjects.Clear(); if (ColorPaintingMode) // Paint mode { foreach (GraphElement element in objectToKeep) { Color TryApplyColor(Color oldColor, Color newColor, string hint) { if (oldColor != newColor) { GraphEditManager.BeforePreformEdit(Graph, string.Format(Resources.Lang.Undo_Paint, hint, newColor.ToString())); } return(newColor); } if (element is Node) { if (element.Decorator is PuzzleGraph.Decorators.StartDecorator startDecorator) { if (button == MouseButtons.Right) // Color picking { PaintingModeControl.Color = startDecorator.Color; } else // Apply color { startDecorator.Color = TryApplyColor(startDecorator.Color, PaintingModeControl.Color, "start point"); } } else if (element.Decorator is PuzzleGraph.Decorators.EndDecorator endDecorator) { if (button == MouseButtons.Right) // Color picking { PaintingModeControl.Color = endDecorator.Color; } else // Apply color { endDecorator.Color = TryApplyColor(endDecorator.Color, PaintingModeControl.Color, "end point"); } } } else if (element is Face face) { if (button == MouseButtons.Right) // Color picking { PaintingModeControl.Color = face.GraphElementColor; } else // Apply color { face.GraphElementColor = TryApplyColor(face.GraphElementColor, PaintingModeControl.Color, "face"); } } else if (element is Edge edge) { if (button == MouseButtons.Right) // Color picking { PaintingModeControl.Color = edge.GraphElementColor; } else // Apply color { edge.GraphElementColor = TryApplyColor(edge.GraphElementColor, PaintingModeControl.Color, "edge"); } } } } else if (button == MouseButtons.Right) // Copy { if (objectToKeep.Count > 0) { if (ctrlKey && objectToKeep[0].Decorator is PuzzleGraph.Decorators.CombinedDecorator combinedDecorator) // Combine mode { ChooseSampleDecorator(combinedDecorator.Second, true); objectToKeep[0].Decorator = combinedDecorator.First; } else { ChooseSampleDecorator(objectToKeep[0].Decorator, true); } copyPerformed = true; } } else { if (!PasteMode) // Selection mode { SelectedObjects.AddRange(objectToKeep); if (shiftKey) { nodesToMove = new List <Node>(); foreach (GraphElement element in SelectedObjects) { if (element is Node selectedNode) { nodesToMove.Add(selectedNode); } else if (element is Edge selectedEdge) { nodesToMove.Add(selectedEdge.Start); nodesToMove.Add(selectedEdge.End); } else if (element is Face selectedFace) { nodesToMove.AddRange(selectedFace.Nodes); } } if (nodesToMove.Count > 0) { GraphEditManager.BeforePreformEdit(Graph, "Move Nodes"); ElementMoveStartPosition = new Vector(x, y); } } else { ElementMoveStartPosition = null; } } else // Paste mode { foreach (GraphElement element in objectToKeep) { if (ctrlKey && element.Decorator != null) // Combine mode { CombineDecorators(SampleDecorator, element); } else { ApplyDecoratorToObject(SampleDecorator, element); } } } } HoveredObjects.Clear(); if (SelectedObjects.Count > 0) { TetrisIndexToTemplateView(SelectedObjects[0].Decorator); } } else { mouseDownPosition = new Vector(x, y); IsDragging = true; } return(copyPerformed); }
public void OnGUI() { GUILayout.Box("", TimelineBackground, GUILayout.MaxHeight(17.0f), GUILayout.ExpandWidth(true)); if (Event.current.type == EventType.Repaint) { DisplayArea = GUILayoutUtility.GetLastRect(); } foreach (var cachedData in cachedClipRenderData) { var animationClipData = cachedData.animationClipData; using (new Shared.GUIChangeColor(SelectedObjects.Contains(animationClipData) ? Color.yellow : GUI.color)) { var startX = ConvertTimeToXPos(animationClipData.StartTime); var endX = ConvertTimeToXPos(animationClipData.StartTime + animationClipData.PlaybackDuration); var transitionX = ConvertTimeToXPos(animationClipData.StartTime + animationClipData.TransitionDuration); var handleWidth = 2.0f; cachedData.renderPosition.x = startX; cachedData.renderPosition.y = DisplayArea.y; cachedData.renderRect.x = startX; cachedData.renderRect.y = DisplayArea.y; cachedData.renderRect.width = endX - startX; cachedData.renderRect.height = DisplayArea.height; cachedData.transitionRect.x = startX; cachedData.transitionRect.y = DisplayArea.y; cachedData.transitionRect.width = transitionX - startX; cachedData.transitionRect.height = DisplayArea.height; cachedData.leftHandle.x = startX; cachedData.leftHandle.y = DisplayArea.y; cachedData.leftHandle.width = handleWidth * 2.0f; cachedData.leftHandle.height = DisplayArea.height; cachedData.rightHandle.x = endX - (handleWidth * 2.0f); cachedData.rightHandle.y = DisplayArea.y; cachedData.rightHandle.width = handleWidth * 2.0f; cachedData.rightHandle.height = DisplayArea.height; GUI.Box(cachedData.renderRect, ""); if (animationClipData.CrossFade) { GUI.Box(cachedData.transitionRect, ""); } GUI.Box(cachedData.leftHandle, ""); GUI.Box(cachedData.rightHandle, ""); cachedData.labelRect = cachedData.renderRect; cachedData.labelRect.width = DisplayArea.width; if (animationClipData.CrossFade) { cachedData.labelRect.x = cachedData.labelRect.x + (transitionX - startX); } else { cachedData.labelRect.x += 4.0f; // Nudge this along a bit so it isn't flush with the side. } GUI.Label(cachedData.labelRect, animationClipData.FriendlyName); } } HandleEvent(); }
private void SoundGUI(JTimelineSound Soundline, JSoundTrack linetrack, JClipRenderData[] renderDataList) { GenericMenu contextMenu = new GenericMenu(); ///event 右键点击 bool isContext = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 1; bool isChoose = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 0 && UnityEngine.Event.current.clickCount == 1; bool hasBox = false; Rect DisplayAreaTemp = DisplayArea; DisplayAreaTemp.x = 0; DisplayAreaTemp.y = 0; for (int j = 0; j < renderDataList.Length; j++) { JClipRenderData renderdata = renderDataList[j]; JSoundClipData SoundClipData = (JSoundClipData)renderdata.ClipData; JSoundTrack track = SoundClipData.Track; if (linetrack != track) { continue; } var startX = ConvertTimeToXPos(SoundClipData.StartTime); var endX = ConvertTimeToXPos(SoundClipData.StartTime + SoundClipData.PlaybackDuration); var transitionX = ConvertTimeToXPos(SoundClipData.StartTime + SoundClipData.TransitionDuration); var handleWidth = 2.0f; Rect renderRect = new Rect(startX, DisplayArea.y, endX - startX, DisplayArea.height); Rect transitionRect = new Rect(startX, DisplayArea.y, transitionX - startX, DisplayArea.height); Rect leftHandle = new Rect(startX, DisplayArea.y, handleWidth * 2.0f, DisplayArea.height); Rect rightHandle = new Rect(endX - (handleWidth * 2.0f), DisplayArea.y, handleWidth * 2.0f, DisplayArea.height); Rect labelRect = new Rect(); Rect renderRecttemp = renderRect; renderRecttemp.x -= DisplayArea.x; renderRecttemp.y = 0; Rect transitionRecttemp = transitionRect; transitionRecttemp.y = 0; transitionRecttemp.x -= DisplayArea.x; Rect leftHandletemp = leftHandle; leftHandletemp.y = 0; leftHandletemp.x -= DisplayArea.x; Rect rightHandletemp = rightHandle; rightHandletemp.x -= DisplayArea.x; rightHandletemp.y = 0; //GUI.color = new Color(243 / 255.0f, 154 / 255.0f, 0 / 255.0f, 1f); GUI.color = ColorTools.GetGrandientColor((float)renderdata.index / (float)CountClip); if (SelectedObjects.Contains(renderdata)) { GUI.color = ColorTools.SelectColor; } Texture2D texture = AssetPreview.GetAssetPreview(SoundClipData.Clip); if (texture != null) { GUI.DrawTexture(renderRecttemp, texture, ScaleMode.StretchToFill); } else { GUI.Box(renderRecttemp, "", USEditorUtility.NormalWhiteOutLineBG); } if (SoundClipData.CrossFade) { GUI.Box(transitionRecttemp, ""); } GUI.Box(leftHandletemp, ""); GUI.Box(rightHandletemp, ""); labelRect = renderRecttemp; labelRect.width = DisplayArea.width; renderdata.renderRect = renderRect; renderdata.labelRect = renderRect; renderdata.renderPosition = new Vector2(startX, DisplayArea.y); renderdata.transitionRect = transitionRect; renderdata.leftHandle = leftHandle; renderdata.rightHandle = rightHandle; renderdata.ClipData = SoundClipData; if (SoundClipData.CrossFade) { labelRect.x = labelRect.x + (transitionX - startX); } else { labelRect.x += 4.0f; // Nudge this along a bit so it isn't flush with the side. } GUI.color = Color.black; GUI.Label(labelRect, SoundClipData.FriendlyName); GUI.color = Color.white; if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition)) { hasBox = true; contextMenu.AddItem(new GUIContent("DeleteClip"), false, (obj) => RemoveSoundClip(((JClipRenderData)((object[])obj)[0])), new object[] { renderdata }); } if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } } if (!hasBox && isChoose && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition) && (UnityEngine.Event.current.control || UnityEngine.Event.current.command)) { //代码选中hierarchy中的对象 显示inspector 按住Ctrl or command //GameObject go = GameObject.Find(Animationline.gameObject.name); Selection.activeGameObject = Soundline.gameObject; EditorGUIUtility.PingObject(Soundline.gameObject); } if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition)) { contextMenu = MenuForSoundTimeLine(Soundline, linetrack); } if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } // Handle the case where the object picker has a value selected. if (UnityEngine.Event.current.type == EventType.ExecuteCommand && UnityEngine.Event.current.commandName == "ObjectSelectorClosed") { if (EditorGUIUtility.GetObjectPickerControlID() == controlID) { UnityEngine.Object pickedObject = EditorGUIUtility.GetObjectPickerObject(); if (pickedObject != null) { AudioClip clip = (AudioClip)pickedObject; AddNewSoundState((JTimelineSound)savedData.Line, (JSoundTrack)savedData.Track, savedData.Firetime, clip.name, clip); } UnityEngine.Event.current.Use(); } } }
private void ParticleGUI(JTimelineParticle Particleline, JParticleTrack linetrack, JClipRenderData[] renderDataList) { GenericMenu contextMenu = new GenericMenu(); ///event 右键点击 bool isContext = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 1; bool isChoose = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 0 && UnityEngine.Event.current.clickCount == 1; bool hasBox = false; Rect DisplayAreaTemp = DisplayArea; DisplayAreaTemp.x = 0; DisplayAreaTemp.y = 0; for (int j = 0; j < renderDataList.Length; j++) { JClipRenderData renderdata = renderDataList[j]; JParticleClipData particleClipData = (JParticleClipData)renderdata.ClipData; JParticleTrack track = particleClipData.Track; if (linetrack != track) { continue; } var startX = ConvertTimeToXPos(particleClipData.StartTime); var endX = ConvertTimeToXPos(particleClipData.StartTime + particleClipData.PlaybackDuration); var transitionX = ConvertTimeToXPos(particleClipData.StartTime + particleClipData.TransitionDuration); var handleWidth = 2.0f; float posy = DisplayArea.y; float height = DisplayArea.height; Rect renderRect = new Rect(startX, posy, endX - startX, height); Rect transitionRect = new Rect(startX, posy, transitionX - startX, height); Rect leftHandle = new Rect(startX, posy, handleWidth * 2.0f, height); Rect rightHandle = new Rect(endX - (handleWidth * 2.0f), posy, handleWidth * 2.0f, height); Rect labelRect = new Rect(); Rect renderRecttemp = renderRect; renderRecttemp.x -= DisplayArea.x; renderRecttemp.y = 0; Rect transitionRecttemp = transitionRect; transitionRecttemp.y = 0; transitionRecttemp.x -= DisplayArea.x; Rect leftHandletemp = leftHandle; leftHandletemp.y = 0; leftHandletemp.x -= DisplayArea.x; Rect rightHandletemp = rightHandle; rightHandletemp.x -= DisplayArea.x; rightHandletemp.y = 0; GUI.color = new Color(163 / 255.0f, 237 / 255.0f, 116 / 255.0f, 1); if (SelectedObjects.Contains(renderdata)) { GUI.color = ColorTools.SelectColor; } GUI.Box(renderRecttemp, "", USEditorUtility.NormalWhiteOutLineBG); if (particleClipData.CrossFade) { GUI.Box(transitionRecttemp, ""); } GUI.Box(leftHandletemp, ""); GUI.Box(rightHandletemp, ""); labelRect = renderRecttemp; labelRect.width = DisplayArea.width; renderdata.renderRect = renderRect; renderdata.labelRect = renderRect; renderdata.renderPosition = new Vector2(startX, height); renderdata.transitionRect = transitionRect; renderdata.leftHandle = leftHandle; renderdata.rightHandle = rightHandle; renderdata.ClipData = particleClipData; if (particleClipData.CrossFade) { labelRect.x = labelRect.x + (transitionX - startX); } else { labelRect.x += 4.0f; // Nudge this along a bit so it isn't flush with the side. } GUI.color = Color.black; GUI.Label(labelRect, particleClipData.FriendlyName); GUI.color = Color.white; if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition)) { hasBox = true; contextMenu.AddItem(new GUIContent("DeleteClip"), false, (obj) => RemoveParticleClip(((JClipRenderData)((object[])obj)[0])), new object[] { renderdata }); } if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } } if (!hasBox && isChoose && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition) && (UnityEngine.Event.current.control || UnityEngine.Event.current.command)) { //代码选中hierarchy中的对象 显示inspector 按住Ctrl or command //GameObject go = GameObject.Find(Animationline.gameObject.name); Selection.activeGameObject = Particleline.gameObject; EditorGUIUtility.PingObject(Particleline.gameObject); } if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition)) { contextMenu = MenuForParticleTimeLine(Particleline, linetrack); } if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } }
void Update() { Vector3 pos; RaycastHit2D hit; RTSObject[] hits = null; if (Input.GetMouseButton(0) || Input.GetMouseButton(1)) { pos = Input.mousePosition; pos = Camera.main.ScreenToWorldPoint(pos); hit = Physics2D.Raycast(pos, -Vector2.zero); RTSObject rtsHit = null; if (hit) { rtsHit = hit.transform.GetComponent <RTSObject>(); } if (rtsHit) { hits = new RTSObject[1] { rtsHit } } ; // Objects that were clicked / were included in the selection box } // Select, Reselect, Deselect, and Unselect Orders if (hits != null && Input.GetMouseButtonDown(0)) { if (Input.GetKey(KeyCode.LeftShift)) { if (hits.Length == 1 && selectedObjects.Contains(hits[0])) { onDeselectOrder(hits); } else { onSelectOrder(hits); } return; } onReselectOrder(hits); return; } else if (hits == null && Input.GetMouseButtonDown(0)) { onUnselectOrder(); return; } // Move, Build, Gather, and Attack Orders if (hits != null && Input.GetMouseButtonDown(1)) { if (Input.GetKey(KeyCode.LeftShift)) { switch (hits[0].GetRTSObjectType()) { case RTSObjectType.ResourceDeposit: onGatherOrder(OrderAction.Additive, hits[0] as ResourceDeposit); break; } } else { switch (hits[0].GetRTSObjectType()) { case RTSObjectType.ResourceDeposit: onGatherOrder(OrderAction.Singular, hits[0] as ResourceDeposit); break; } } return; } else if (hits == null && Input.GetMouseButtonDown(1)) { if (Input.GetKey(KeyCode.LeftShift)) { onMoveOrder(OrderAction.Additive); } else { onMoveOrder(OrderAction.Singular); } return; } if (Input.GetKey(KeyCode.Delete)) { onDeleteOrder(); } }
public void MoveObjects(Point dest) { var movedList = new List <DrawableObject>(); Point offset; offset = new Point(dest.X - MovingPoint.X, dest.Y - MovingPoint.Y); foreach (DrawableObject obj in SelectedObjects) { if (obj is Transition) { Transition trans = (Transition)obj; if (trans.StartObject == null && trans.EndObject == null) { if (!movedList.Contains(trans)) { trans.Move(offset); movedList.Add(trans); } } else { if (trans.StartObject != null) { if (!SelectedObjects.Contains(trans.StartObject)) { if (!movedList.Contains(trans.StartObject)) { MoveObject(trans.StartObject, offset); movedList.Add(trans.StartObject); } } if (!movedList.Contains(trans)) { trans.MoveStart(offset); } } else { if (!SelectedObjects.Contains(trans.StartObject)) { trans.MoveStart(offset); } } if (trans.EndObject != null) { if (!SelectedObjects.Contains(trans.EndObject)) { if (!movedList.Contains(trans.EndObject)) { MoveObject(trans.EndObject, offset); movedList.Add(trans.EndObject); } } if (!movedList.Contains(trans)) { trans.MoveEnd(offset); } } else { if (!SelectedObjects.Contains(trans.EndObject)) { trans.MoveEnd(offset); } } } } else { if (!movedList.Contains(obj)) { MoveObject(obj, offset); movedList.Add(obj); } } } MovingPoint = dest; }
private void TransformGUI(JTimelineBase timeline, JTransformTrack track, JClipRenderData[] renderDataList) { GenericMenu contextMenu = new GenericMenu(); ///event 右键点击 bool isContext = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 1 && UnityEngine.Event.current.clickCount == 1; bool isChoose = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 0 && UnityEngine.Event.current.clickCount == 1; bool isDouble = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 0 && UnityEngine.Event.current.clickCount == 2; bool hasBox = false; Rect DisplayAreaTemp = DisplayArea; DisplayAreaTemp.x = 0; DisplayAreaTemp.y = 0; var linestartX = ConvertTimeToXPos(track.StartTime); var lineendX = ConvertTimeToXPos(track.EndTime); Rect linerenderRect = new Rect(linestartX, DisplayArea.y, lineendX - linestartX, DisplayArea.height); Rect linerenderRectTemp = linerenderRect; linerenderRectTemp.x -= DisplayArea.x; linerenderRectTemp.y = 0; GUI.color = new Color(85 / 255.0f, 47 / 255.0f, 176 / 255.0f, 1f); GUI.Box(linerenderRectTemp, "", USEditorUtility.NormalWhiteOutLineBG); GUI.color = Color.white; for (int j = 0; j < renderDataList.Length; j++) { JClipRenderData renderdata = renderDataList[j]; JSplineKeyframe key = (JSplineKeyframe)renderdata.ClipData; var startX = ConvertTimeToXPos(key.StartTime); var handleWidth = 5.0f; Rect renderRect = new Rect(startX - handleWidth, DisplayArea.y, handleWidth * 2, DisplayArea.height); Rect renderRectTemp = renderRect; renderRectTemp.x -= DisplayArea.x; renderRectTemp.y = 0; Rect labelRect = new Rect(); GUI.color = new Color(255 / 255.0f, 122 / 255.0f, 105 / 255.0f, 1); if (SelectedObjects.Contains(renderdata)) { GUI.color = ColorTools.SelectColor; } GUI.Box(renderRectTemp, "", USEditorUtility.NormalWhiteOutLineBG); labelRect = renderRectTemp; renderdata.renderRect = renderRect; renderdata.labelRect = renderRect; renderdata.renderPosition = new Vector2(startX - handleWidth, DisplayArea.y); renderdata.ClipData = key; GUI.color = Color.black; GUI.Label(labelRect, "" + track.Keyframes.IndexOf(key), USEditorUtility.USeqSkin.label); GUI.color = Color.white; if (isContext && renderRectTemp.Contains(UnityEngine.Event.current.mousePosition)) { hasBox = true; contextMenu.AddItem(new GUIContent("DeleteKeyFrame"), false, (obj) => RemoveKeyFrame(((JClipRenderData)((object[])obj)[0])), new object[] { renderdata }); } if (hasBox && isContext && renderRectTemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } } if (!hasBox && isChoose && linerenderRectTemp.Contains(UnityEngine.Event.current.mousePosition) && (UnityEngine.Event.current.control || UnityEngine.Event.current.command)) { //代码选中hierarchy中的对象 显示inspector 按住Ctrl or command //GameObject go = GameObject.Find(tline.gameObject.name); Selection.activeObject = track; EditorGUIUtility.PingObject(track); } if (!hasBox && isContext && linerenderRectTemp.Contains(UnityEngine.Event.current.mousePosition)) { contextMenu = MenuForTransformTimeLine(timeline, track); } if (!hasBox && isContext && linerenderRectTemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } if (!hasBox && isDouble && linerenderRectTemp.Contains(UnityEngine.Event.current.mousePosition)) { int index = 1; float newTime = (((UnityEngine.Event.current.mousePosition.x + XScroll) / DisplayArea.width) * timeline.Sequence.Duration) / XScale; for (int i = 1; i < track.Keyframes.Count; i++) { if (newTime <= track.Keyframes[i].StartTime) { index = i; break; } } AddNewKeyFrame(track, newTime, index); } }