public void BeginDragDraw() { GameController.mouseDragging = true; if (ComponentSelection.selected != ComponentType.NONE) { DragType = DragType.DRAW; } else if (GameController.simState == SimState.EDITING && DragType == DragType.NONE) { SpawnDragBox(); } }
public void StopDrag() { StopAllCoroutines(); currentDragType = DragType.Scroll; isDragging = false; SetParent(); OnDragEvent?.Invoke(false); button.interactable = true; canvasGroup.blocksRaycasts = true; dragVisuals.OnDrag(false); }
public void Adjust(DragType drag) { LabelHV labelHv; Point point; Rectangle rect; if (m_bStart) { labelHv = m_StartOr; point = m_Line.m_Start; rect = m_Line.m_StartActivity.GetRect(); } else { labelHv = m_FinishOr; point = m_Line.m_Finish; rect = m_Line.m_FinishActivity.GetRect(); } if (labelHv == LabelHV.Hor) { if (point.X == rect.Left && m_bPos && drag == DragType.DragNothing) { m_Offset.X += m_Rect.Width; m_Offset.X = -m_Offset.X; m_bPos = false; } if (point.X == rect.Right && !m_bPos && drag == DragType.DragNothing) { m_Offset.X += m_Rect.Width; m_Offset.X = -m_Offset.X; m_bPos = true; } } else { if (point.Y == rect.Top && m_bPos && drag == DragType.DragNothing) { m_Offset.Y += m_Rect.Height; m_Offset.Y = -m_Offset.Y; m_bPos = false; } if (point.Y == rect.Bottom && !m_bPos && drag == DragType.DragNothing) { m_Offset.Y += m_Rect.Height; m_Offset.Y = -m_Offset.Y; m_bPos = true; } } m_Rect = new Rectangle(point.X, point.Y, point.X + m_Rect.Width, point.Y + m_Rect.Height); m_Rect.Offset(m_Offset); }
/// <summary> /// 切换拖拽状态 /// </summary> /// <param name="dragType"></param> /// <param name="targetObj"></param> public void SwitchDragType(DragType dragType, GameObject targetObj) { HighFiveItem item = null; switch (dragType) { case DragType.Gembox: //Ui上 transform.SetParent(targetObj.transform); transform.localPosition = Vector3.zero; selfRect.pivot = new Vector2(0.5f, 0.5f); //逻辑上:宝石放到宝石槽 item = GlobalVar.G_Player.GetItems()[ItemData.ID]; item.Enable(); //Ui逻辑 dragger.IsTarget = gemboxIsTarget; dragger.eventOnGetTarget = gridObj => { item.gemBoxIndex = -1; SwitchDragType(DragType.Package, gridObj); onDragStateChanged?.Invoke(); }; break; case DragType.Package: //UI显示 transform.SetParent(targetObj.transform); //逻辑上应处理的:从宝石槽中取下宝石 item = GlobalVar.G_Player.GetItems()[ItemData.ID]; item.Disable(); //ui逻辑 dragger.IsTarget = slotIsTarget; dragger.eventOnGetTarget = gemBoxObj => { item.gemBoxIndex = gemBoxObj.transform.GetSiblingIndex(); // Debug.Log($"setindex_itemId:{item.GetHashCode()},itemIndex:{item.gemBoxIndex}"); SwitchDragType(DragType.Gembox, gemBoxObj); onDragStateChanged?.Invoke(); }; break; } }
public void OnBeginDrag(PointerEventData eventData) { dragType = Input.GetMouseButton(0) ? DragType.FULL : Input.GetMouseButton(1) ? DragType.HALF : DragType.ONE; if (eventData.pointerCurrentRaycast.gameObject != null) { if (eventData.pointerCurrentRaycast.gameObject.GetComponent <Slot>() && eventData.pointerCurrentRaycast.gameObject.GetComponent <Slot>().DataItem.Item != null) { begin = eventData.pointerCurrentRaycast.gameObject.GetComponent <Slot>(); DragItem.sprite = begin.DataItem.Item.Sprite; DragItem.gameObject.SetActive(true); } } }
public override void Adjust(DragType drag) { if (drag == DragType.DragFinish) { if (m_Finish.Y > m_StartActivity.Top + m_StartActivity.Height / 2) { m_Start.Y = m_StartActivity.Bottom; } else { m_Start.Y = m_StartActivity.Top; } } else if (drag == DragType.DragStart) { if (m_Start.Y > m_FinishActivity.Top + m_FinishActivity.Height / 2) { m_Finish.Y = m_FinishActivity.Bottom; } else { m_Finish.Y = m_FinishActivity.Top; } } else { if (m_StartActivity.Top + m_StartActivity.Height / 2 > m_FinishActivity.Top + m_FinishActivity.Height / 2) { m_Start.Y = m_StartActivity.Top; m_Finish.Y = m_FinishActivity.Bottom; } else { m_Start.Y = m_StartActivity.Bottom; m_Finish.Y = m_FinishActivity.Top; } if (m_StartOffset > m_StartActivity.Width) { m_StartOffset = m_StartActivity.Width; } if (m_FinishOffset > m_FinishActivity.Width) { m_FinishOffset = m_FinishActivity.Width; } m_Start.X = m_StartActivity.Left + m_StartOffset; m_Finish.X = m_FinishActivity.Left + m_FinishOffset; } AdjustMiddle(); m_Label.Adjust(drag); }
protected void mouseDown() { mDragOriginPoint = Input.mousePosition; mPreMousePoint = mDragOriginPoint; //右クリックか左クリックか if (Input.GetMouseButtonDown(1)) { _DragType = DragType.typeTwo; } else { _DragType = DragType.typeOne; } }
public void StopDrag() { if (this._lockDrag) { return; } GuideCommand.EqualsInfo[] moveCommands = new GuideCommand.EqualsInfo[this._oldPosValues.Count]; int i = 0; if (this._currentDragType == DragType.Position || this._currentDragType == DragType.Both) { foreach (KeyValuePair <int, Vector3> kvp in this._oldPosValues) { moveCommands[i] = new GuideCommand.EqualsInfo() { dicKey = kvp.Key, oldValue = kvp.Value, newValue = Studio.Studio.Instance.dicChangeAmount[kvp.Key].pos }; ++i; } } GuideCommand.EqualsInfo[] rotateCommands = new GuideCommand.EqualsInfo[this._oldRotValues.Count + this._additionalRotationEqualsCommands.Count]; i = 0; if (this._currentDragType == DragType.Rotation || this._currentDragType == DragType.Both) { foreach (KeyValuePair <int, Vector3> kvp in this._oldRotValues) { rotateCommands[i] = new GuideCommand.EqualsInfo() { dicKey = kvp.Key, oldValue = kvp.Value, newValue = Studio.Studio.Instance.dicChangeAmount[kvp.Key].rot }; ++i; } } foreach (GuideCommand.EqualsInfo info in this._additionalRotationEqualsCommands) { rotateCommands[i] = info; ++i; } UndoRedoManager.Instance.Push(new Commands.MoveRotateEqualsCommand(moveCommands, rotateCommands)); this._currentDragType = DragType.None; this._oldPosValues.Clear(); this._oldRotValues.Clear(); this._additionalRotationEqualsCommands.Clear(); }
public void onPress() { Grid grid = Grid.Instance; grid.onGridButtonPress(position); DragBegin = position; if (GameController.simState == SimState.EDITING && ComponentSelection.selected == ComponentType.NONE && Grid.Instance.GroupSelection.PointSet.Contains(position)) { DragType = DragType.GROUPMOVE; Grid.Instance.GroupSelection.GraspPoint = position; } else { Grid.Instance.ClearGroupSelection(); } }
protected override void OnMouseDown(MouseEventArgs e) { if (e.Button == MouseButtons.Left) //左键 { bool flag = false; foreach (Control c in DesingerHost.Controls) //遍历控件容器 看是否选中其中某一控件 { Rectangle r = c.Bounds; r = DesingerHost.RectangleToScreen(r); r = this.RectangleToClient(r); Rectangle rr = r; rr.Inflate(10, 10); if (rr.Contains(e.Location)) { recter.Rect = r; _currentCtrl = c; recter.IsForm = false; flag = true; Invalidate2(false); break; } } if (!flag) //没有控件被选中,判断是否选中控件容器 { Rectangle r = DesingerHost.Bounds; r = Parent.RectangleToScreen(r); r = this.RectangleToClient(r); if (r.Contains(e.Location)) { recter.Rect = r; recter.IsForm = true; _currentCtrl = null; Invalidate2(false); } } DragType dt = recter.GetMouseDragType(e.Location); //判断是否可以进行鼠标操作 if (dt != DragType.None) { _mouseDown = true; _firstPoint = e.Location; _dragType = dt; } } base.OnMouseDown(e); }
void Update() { if (isDragging && es.IsPointerOverGameObject()) { deletionMarker.gameObject.SetActive(false); wireMarker.gameObject.SetActive(false); ghostMarker.gameObject.SetActive(false); isDragging = false; return; } if (Input.GetMouseButtonDown(0)) { if (es.IsPointerOverGameObject() || build == ComponentType.Empty) { return; } StartBuild(); } else if (Input.GetMouseButtonDown(1)) { if (es.IsPointerOverGameObject()) { return; } isDragging = true; startPos = circuit.WorldToLocal(camera.ScreenToWorldPoint(Input.mousePosition)); drag = DragType.destroy; deletionMarker.gameObject.SetActive(true); } if (isDragging) { switch (drag) { case DragType.build: DragBuild(); break; case DragType.move: DragMove(); break; case DragType.destroy: DragDelete(); break; } } }
void selectButton(Button button, Vector3 currentPos) { //check if it is in the image array that is allowed to be moved if (buttonIsAvailableInArray(button)) { //Make the image the current selected image selectedButton = button; dragType = DragType.BUTTONS; moveOffset = selectedButton.transform.position - currentPos; } else { //Clear the selected Button selectedButton = null; dragType = DragType.NONE; } }
void selectImage(Image image, Vector3 currentPos) { //check if it is in the image array that is allowed to be moved if (imageIsAvailableInArray(image)) { //Make the image the current selected image selectedUIPanels = image; dragType = DragType.IMAGES; moveOffset = selectedUIPanels.transform.position - currentPos; } else { //Clear the selected Button selectedUIPanels = null; dragType = DragType.NONE; } }
private static void CleanUp(bool deleteTempSceneObject) { if (s_SceneDragObjects != null) { if (deleteTempSceneObject) { foreach (GameObject obj2 in s_SceneDragObjects) { Object.DestroyImmediate(obj2, false); } } s_SceneDragObjects.Clear(); s_SceneDragObjects = null; } HandleUtility.ignoreRaySnapObjects = null; s_DragType = DragType.NotInitialized; }
private static void CleanUp(bool deleteTempSceneObject) { if (s_SceneDragObjects != null) { if (deleteTempSceneObject) { foreach (GameObject obj2 in s_SceneDragObjects) { UnityEngine.Object.DestroyImmediate(obj2, false); } } s_SceneDragObjects.Clear(); s_SceneDragObjects = null; } HandleUtility.ignoreRaySnapObjects = null; s_DragType = DragType.NotInitialized; }
static void CleanUp(bool deleteTempSceneObject) { if (deleteTempSceneObject) { foreach (GameObject gameObject in s_SceneDragObjects) { Object.DestroyImmediate(gameObject, false); } } if (s_SceneDragObjects != null) { s_SceneDragObjects.Clear(); s_SceneDragObjects = null; } s_DragType = DragType.NotInitialized; }
/// <summary> /// ToString method for DragType /// </summary> /// <param name="dragtype"></param> /// <returns></returns> public static string DragtypeToString(DragType dragtype) { switch (dragtype) { case DragType.HAND_RIGHT: return("Right Hand"); case DragType.HAND_LEFT: return("Left Hand"); case DragType.FOOT_LEFT: return("Left Foot"); case DragType.FOOT_RIGHT: return("Right Foot"); } return("<INVALID TYPE>"); }
public void AddListener(View targetView, DragAndDropEventHandler callback) { InternalDragAndDropEventHandler cb = (dragEvent) => { DragType type = (DragType)Interop.DragAndDrop.GetAction(dragEvent); DragEvent ev = new DragEvent(); global::System.IntPtr cPtr = Interop.DragAndDrop.GetPosition(dragEvent); ev.Position = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false); if (type == DragType.Enter) { ev.DragType = type; callback(targetView, ev); } else if (type == DragType.Leave) { ev.DragType = type; callback(targetView, ev); } else if (type == DragType.Move) { ev.DragType = type; callback(targetView, ev); } else if (type == DragType.Drop) { ev.DragType = type; ev.MimeType = Interop.DragAndDrop.GetMimeType(dragEvent); ev.Data = Interop.DragAndDrop.GetData(dragEvent); callback(targetView, ev); } }; targetEventDictionary.Add(targetView, cb); if (!Interop.DragAndDrop.AddListener(SwigCPtr, View.getCPtr(targetView), new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate <Delegate>(cb)))) { throw new InvalidOperationException("Fail to AddListener"); } }
static void ListViewCellMouseDown(int id, Event e, Rect rect, Action action, Func <bool> cellClickAction) { if (rect.Contains(e.mousePosition) && e.button == 0) { var r = new Rect(rect.xMax - dragResize, rect.y, dragResize, rect.height); if (r.Contains(e.mousePosition)) { dragTypeControl = DragType.Resize; } else { dragTypeControl = DragType.Normal; if (!cellClickAction()) { action(); } } GUIUtility.hotControl = id; Event.current.Use(); } }
public DraggedLinkElement(ProductionGraphViewer parent, NodeElement startNode, LinkType startConnectionType, Item item) : base(parent) { if (startConnectionType == LinkType.Input) { ConsumerElement = startNode; } else { SupplierElement = startNode; } StartConnectionType = startConnectionType; Item = item; if ((Control.MouseButtons & MouseButtons.Left) != 0) { DragType = DragType.MouseDown; } else { DragType = DragType.MouseUp; } }
IEnumerator Pull(DragType type) { //Vector2.zero used because child objects Tip and Tail ever must be in zero local coordinates parent object Hook Debug.Log("PULL"); //If target object is not draggable - pull up character if (type == DragType.NotDraggable) { //Player follow for tail of hook playerMovement.HookOn(tailTransform); //While tail of hook didn't reach tip position while (Vector2.MoveTowards(tailTransform.localPosition, tipTransform.localPosition, pullSpeed * Time.deltaTime) != (Vector2)tailTransform.localPosition) { yield return(new WaitForEndOfFrame()); tailTransform.localPosition = Vector2.MoveTowards(tailTransform.localPosition, tipTransform.localPosition, pullSpeed * Time.deltaTime); myTransform.localPosition = -Vector2.MoveTowards(tailTransform.localPosition, tipTransform.localPosition, pullSpeed * Time.deltaTime); } } //If target object draggable or haven't a target else { if (hookedEnemy != null) { hookedEnemy.HookOn(tipTransform); //Set target state to HookOn } //While target didn't reach tail of hook position while (Vector2.MoveTowards(parent.InverseTransformPoint(tipTransform.position), Vector2.zero, pullSpeed * Time.deltaTime) != (Vector2)tipTransform.localPosition) { yield return(new WaitForEndOfFrame()); tipTransform.localPosition = Vector2.MoveTowards(parent.InverseTransformPoint(tipTransform.position), Vector2.zero, pullSpeed * Time.deltaTime); } } Release(); pullCoroutine = null; yield return(null); }
private void Update() { bool isDown = Input.GetKey(KeyCode.Mouse0); bool isUp = Input.GetKeyUp(KeyCode.Mouse0); if (isDown == false && isDown == false) { dragType = DragType.NoTouch; } if (isDown == true && isUp == false) { dragType = DragType.Down; } if (isUp == true) { dragType = DragType.Up; } switch (dragType) { case DragType.NoTouch: break; case DragType.Down: Down(); break; case DragType.Up: Up(); break; default: break; } }
private void OnMouseDown(object sender, MouseButtonEventArgs e) { try { if (!SimulatorContainer.IsMouseCaptured) { if (e.ChangedButton == MouseButton.Left) { dragType = DragType.LOOK; } else if (e.ChangedButton == MouseButton.Right) { dragType = DragType.MOVE; } var p = e.GetPosition(SimulatorContainer); mouseStart = new Vector2((float)p.X, (float)p.Y); SimulatorContainer.CaptureMouse(); } } catch (Exception err) { GUIUtilities.ReportUnexpectedException(err); } }
public void SetDrag(DragType t, DragOrigin o, int id, int ul) { this.dragType = t; this.dragOrigin = o; this.dragID = id; this.dragLevel = ul; this.dragable = true; }
public static void HandleSpriteSceneDrag(SceneView sceneView, IEvent evt, Object[] objectReferences, string[] paths, ShowFileDialogDelegate saveFileDialog) { if (evt.type != EventType.DragUpdated && evt.type != EventType.DragPerform && evt.type != EventType.DragExited) { return; } // Return if any of the dragged objects are null, e.g. a MonoBehaviour without a managed instance if (objectReferences.Any(obj => obj == null)) { return; } // Regardless of EditorBehaviorMode or SceneView mode we don't handle if texture is dragged over a GO with renderer if (objectReferences.Length == 1 && objectReferences[0] as UnityTexture2D != null) { GameObject go = HandleUtility.PickGameObject(evt.mousePosition, true); if (go != null) { var renderer = go.GetComponent <Renderer>(); if (renderer != null && !(renderer is SpriteRenderer)) { // There is an object where the cursor is // and we are dragging a texture. Most likely user wants to // assign texture to the GO // Case 730444: Proceed only if the go has a renderer CleanUp(true); return; } } } switch (evt.type) { case (EventType.DragUpdated): DragType newDragType = evt.alt ? DragType.CreateMultiple : DragType.SpriteAnimation; if (s_DragType != newDragType || s_SceneDragObjects == null) // Either this is first time we are here OR evt.alt changed during drag { if (!ExistingAssets(objectReferences) && PathsAreValidTextures(paths)) // External drag with images that are not in the project { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; s_SceneDragObjects = new List <Object>(); s_DragType = newDragType; } else // Internal drag with assets from project { List <Sprite> assets = GetSpriteFromPathsOrObjects(objectReferences, paths, evt.type); if (assets.Count == 0) { return; } if (s_DragType != DragType.NotInitialized) // evt.alt changed during drag, so we need to cleanup and start over { CleanUp(true); } s_DragType = newDragType; CreateSceneDragObjects(assets, sceneView); IgnoreForRaycasts(s_SceneDragObjects); } } PositionSceneDragObjects(s_SceneDragObjects, sceneView, evt.mousePosition); DragAndDrop.visualMode = DragAndDropVisualMode.Copy; evt.Use(); break; case (EventType.DragPerform): List <Sprite> sprites = GetSpriteFromPathsOrObjects(objectReferences, paths, evt.type); if (sprites.Count > 0 && s_SceneDragObjects != null) { // Store current undoIndex to undo all operations done if any part of sprite creation fails int undoIndex = Undo.GetCurrentGroup(); // For external drags, we have delayed all creation to DragPerform because only now we have the imported sprite assets if (s_SceneDragObjects.Count == 0) { CreateSceneDragObjects(sprites, sceneView); PositionSceneDragObjects(s_SceneDragObjects, sceneView, evt.mousePosition); } foreach (GameObject dragGO in s_SceneDragObjects) { dragGO.hideFlags = HideFlags.None; // When in e.g Prefab Mode ensure to reparent dragged objects under the prefab root Transform defaultObjectTransform = SceneView.GetDefaultParentObjectIfSet(); if (defaultObjectTransform != null) { dragGO.transform.SetParent(defaultObjectTransform, true); } else if (sceneView.customParentForDraggedObjects != null) { dragGO.transform.SetParent(sceneView.customParentForDraggedObjects, true); } Undo.RegisterCreatedObjectUndo(dragGO, "Create Sprite"); EditorUtility.SetDirty(dragGO); } bool createGameObject = true; if (s_DragType == DragType.SpriteAnimation && sprites.Count > 1) { createGameObject = AddAnimationToGO((GameObject)s_SceneDragObjects[0], sprites.ToArray(), saveFileDialog); } if (createGameObject) { Selection.objects = s_SceneDragObjects.ToArray(); } else { // Revert all Create Sprite actions if animation failed to be created or was cancelled Undo.RevertAllDownToGroup(undoIndex); } CleanUp(!createGameObject); evt.Use(); } break; case EventType.DragExited: if (s_SceneDragObjects != null) { CleanUp(true); evt.Use(); } break; } }
private bool Equip(int id, DragType dt) { bool ok = false; if(this.combatant is Character) { EquipSet set = EquipSet.NONE; if(DragType.WEAPON.Equals(dt)) set = EquipSet.WEAPON; else if(DragType.ARMOR.Equals(dt)) set = EquipSet.ARMOR; ((Character)combatant).Equip(-1, id, set); ok = true; } return ok; }
private void HistogramView_MouseUp(object sender, MouseEventArgs e) { if (dragType != DragType.None) { dragType = DragType.None; updateTimer.Enabled = false; updateTimer.Enabled = true; } }
private void HistogramView_MouseDown(object sender, MouseEventArgs e) { //todo unhack this and move to constants if ((Math.Abs(e.X - center) < 10) && Math.Abs(e.Y - 75) < 10) { dragType = DragType.Center; } else if (Math.Abs(e.X - lowPosition) < 3) { dragType = DragType.Low; } else if (Math.Abs(e.X - highPosition) < 3) { dragType = DragType.High; } else { dragType = DragType.Range; downPosition = Math.Min(255, Math.Max(0, e.X)); HistogramView.Refresh(); } }
void VideoBox_MouseMove(object sender, MouseEventArgs e) { int arriba = int.Parse(Arriba.Text); int abajo = VideoBox.Height - int.Parse(Abajo.Text) - 1; int izquierda = int.Parse(Izquierda.Text); int derecha = VideoBox.Width - int.Parse(Derecha.Text) - 1; if (!IsPushed) { VideoBox.Cursor = Cursors.Default; if (e.X == izquierda) { tipo = DragType.W; VideoBox.Cursor = Cursors.SizeWE; if (e.Y == arriba) { VideoBox.Cursor = Cursors.SizeNWSE; tipo = DragType.NW; } if (e.Y == abajo) { tipo = DragType.SW; VideoBox.Cursor = Cursors.SizeNESW; } } if (e.X == derecha) { tipo = DragType.E; VideoBox.Cursor = Cursors.SizeWE; if (e.Y == arriba) { VideoBox.Cursor = Cursors.SizeNESW; tipo = DragType.NE; } if (e.Y == abajo) { VideoBox.Cursor = Cursors.SizeNWSE; tipo = DragType.SE; } } if ((VideoBox.Cursor == Cursors.Default) && ((e.Y == arriba) || (e.Y == abajo))) { VideoBox.Cursor = Cursors.SizeNS; if (e.Y == arriba) tipo = DragType.N; else tipo = DragType.S; } } else { switch (tipo) { case DragType.W: Izquierda.Text = e.X.ToString(); break; case DragType.NW: Izquierda.Text = e.X.ToString(); Arriba.Text = e.Y.ToString(); break; case DragType.SW: Izquierda.Text = e.X.ToString(); Abajo.Text = Convert.ToString(VideoBox.Height - e.Y); break; case DragType.N: Arriba.Text = e.Y.ToString(); break; case DragType.S: Abajo.Text = Convert.ToString(VideoBox.Height - e.Y); break; case DragType.E: Derecha.Text = Convert.ToString(VideoBox.Width - e.X); break; case DragType.NE: Arriba.Text = e.Y.ToString(); Derecha.Text = Convert.ToString(VideoBox.Width - e.X); break; case DragType.SE: Abajo.Text = Convert.ToString(VideoBox.Height - e.Y); Derecha.Text = Convert.ToString(VideoBox.Width - e.X); break; } if ((e.X < 0 || e.X >VideoBox.Width) || (e.Y < 0 || e.Y > VideoBox.Height)) FixValues(); DrawLines(); } }
void VideoBox_MouseUp(object sender, MouseEventArgs e) { IsPushed = false; VideoBox.Cursor = Cursors.Default; tipo = DragType.None; }
static void HandleSceneDrag(SceneView sceneView, Event evt, Object[] objectReferences, string[] paths) { if (evt.type != EventType.DragUpdated && evt.type != EventType.DragPerform && evt.type != EventType.DragExited) { return; } switch (evt.type) { case EventType.DragUpdated: { DragType newDragType = DragType.CreateMultiple; if (s_DragType != newDragType || s_SceneDragObjects == null) // Either this is first time we are here OR evt.alt changed during drag { if (ExistingAssets(objectReferences)) // External drag with images that are not in the project { List <SpriteShape> assets = GetSpriteShapeFromPathsOrObjects(objectReferences, paths, evt.type); if (assets.Count == 0) { return; } if (s_DragType != DragType.NotInitialized) { // evt.alt changed during drag, so we need to cleanup and start over CleanUp(true); } s_DragType = newDragType; CreateSceneDragObjects(assets); } } if (s_SceneDragObjects != null) { PositionSceneDragObjects(s_SceneDragObjects, sceneView, evt.mousePosition); DragAndDrop.visualMode = DragAndDropVisualMode.Copy; evt.Use(); } } break; case EventType.DragPerform: { List <SpriteShape> assets = GetSpriteShapeFromPathsOrObjects(objectReferences, paths, evt.type); if (assets.Count > 0 && s_SceneDragObjects != null) { // For external drags, we have delayed all creation to DragPerform because only now we have the imported sprite assets if (s_SceneDragObjects.Count == 0) { CreateSceneDragObjects(assets); PositionSceneDragObjects(s_SceneDragObjects, sceneView, evt.mousePosition); } foreach (GameObject dragGO in s_SceneDragObjects) { Undo.RegisterCreatedObjectUndo(dragGO, "Create Shape"); dragGO.hideFlags = HideFlags.None; } Selection.objects = s_SceneDragObjects.ToArray(); CleanUp(false); evt.Use(); } } break; case EventType.DragExited: { if (s_SceneDragObjects != null) { CleanUp(true); evt.Use(); } } break; } }
protected override void OnMouseMove(MouseEventArgs e) { #region 标移过形状改变 if (!_mouseDown) { DragType dt = _recter.GetMouseDragType(e.Location); switch (dt) { case DragType.Top: { Cursor = Cursors.SizeNS; break; } case DragType.RightTop: { Cursor = Cursors.SizeNESW; break; } case DragType.RightBottom: { Cursor = Cursors.SizeNWSE; break; } case DragType.Right: { Cursor = Cursors.SizeWE; break; } case DragType.LeftTop: { Cursor = Cursors.SizeNWSE; break; } case DragType.LeftBottom: { Cursor = Cursors.SizeNESW; break; } case DragType.Left: { Cursor = Cursors.SizeWE; break; } case DragType.Center: { Cursor = Cursors.SizeAll; break; } case DragType.Bottom: { Cursor = Cursors.SizeNS; break; } default: { Cursor = Cursors.Default; break; } } } #endregion #region 拖动 else { #region switch (_dragType) //改变方框位置大小 { case DragType.Top: { Point delta = new Point(e.Location.X - _firstPoint.X, e.Location.Y - _firstPoint.Y); _recter.Rect = new Rectangle(_recter.Rect.X, _recter.Rect.Y + delta.Y, _recter.Rect.Width, _recter.Rect.Height + delta.Y * (-1)); _firstPoint = e.Location; break; } case DragType.RightTop: { Point delta = new Point(e.Location.X - _firstPoint.X, e.Location.Y - _firstPoint.Y); _recter.Rect = new Rectangle(_recter.Rect.X, _recter.Rect.Y + delta.Y, _recter.Rect.Width + delta.X, _recter.Rect.Height + delta.Y * (-1)); _firstPoint = e.Location; break; } case DragType.RightBottom: { Point delta = new Point(e.Location.X - _firstPoint.X, e.Location.Y - _firstPoint.Y); _recter.Rect = new Rectangle(_recter.Rect.X, _recter.Rect.Y, _recter.Rect.Width + delta.X, _recter.Rect.Height + delta.Y); _firstPoint = e.Location; break; } case DragType.Right: { Point delta = new Point(e.Location.X - _firstPoint.X, e.Location.Y - _firstPoint.Y); _recter.Rect = new Rectangle(_recter.Rect.X, _recter.Rect.Y, _recter.Rect.Width + delta.X, _recter.Rect.Height); _firstPoint = e.Location; break; } case DragType.LeftTop: { Point delta = new Point(e.Location.X - _firstPoint.X, e.Location.Y - _firstPoint.Y); _recter.Rect = new Rectangle(_recter.Rect.X + delta.X, _recter.Rect.Y + delta.Y, _recter.Rect.Width + delta.X * (-1), _recter.Rect.Height + delta.Y * (-1)); _firstPoint = e.Location; break; } case DragType.LeftBottom: { Point delta = new Point(e.Location.X - _firstPoint.X, e.Location.Y - _firstPoint.Y); _recter.Rect = new Rectangle(_recter.Rect.X + delta.X, _recter.Rect.Y, _recter.Rect.Width + delta.X * (-1), _recter.Rect.Height + delta.Y); _firstPoint = e.Location; break; } case DragType.Left: { Point delta = new Point(e.Location.X - _firstPoint.X, e.Location.Y - _firstPoint.Y); _recter.Rect = new Rectangle(_recter.Rect.X + delta.X, _recter.Rect.Y, _recter.Rect.Width + delta.X * (-1), _recter.Rect.Height); _firstPoint = e.Location; break; } case DragType.Center: { Point delta = new Point(e.Location.X - _firstPoint.X, e.Location.Y - _firstPoint.Y); _recter.Rect = new Rectangle(_recter.Rect.X + delta.X, _recter.Rect.Y + delta.Y, _recter.Rect.Width, _recter.Rect.Height); _firstPoint = e.Location; break; } case DragType.Bottom: { Point delta = new Point(e.Location.X - _firstPoint.X, e.Location.Y - _firstPoint.Y); _recter.Rect = new Rectangle(_recter.Rect.X, _recter.Rect.Y, _recter.Rect.Width, _recter.Rect.Height + delta.Y); _firstPoint = e.Location; break; } default: { break; } } #endregion } #endregion if (_mouseDown) { Invalidate2(false); } //左键选中区域 if (_currentCtrl == null && _selectMouseDown) { _select = new Select(); Rectangle r = new Rectangle(); r.X = _firstSelectPoint.X; r.Y = _firstSelectPoint.Y; Point mouse = this.PointToClient(Control.MousePosition); if (mouse.X - _firstSelectPoint.X < 0) { r.X = mouse.X; } if (mouse.Y - _firstSelectPoint.Y < 0) { r.Y = mouse.Y; } r.Width = Math.Abs(mouse.X - _firstSelectPoint.X); r.Height = Math.Abs(mouse.Y - _firstSelectPoint.Y); _select.Rect = r; Invalidate2(false); } base.OnMouseMove(e); }
public override bool ProcessInputEvent(InputEvent evt) { bool handled = false; //bool modifierPressed = (evt.KeyData & Modifier) == Modifier; bool modifierPressed = (UserControl.ModifierKeys & Modifier) == Modifier; switch (evt.Type) { case eInputEventType.KeyDown: if (modifierPressed) { ModifierPressed = true; } break; case eInputEventType.KeyUp: if (!modifierPressed) { ModifierPressed = false; } break; case eInputEventType.MouseButtonUp: if (DragMode != DragType.None) { SelectionChanged = true; if (StartFreq == EndFreq) { StartFreq = 0; StartStrength = 0; EndFreq = 0; EndStrength = 0; Visible = false; Selected = false; } Reorder(); UpdatePositions(); DragMode = DragType.None; MainPlot.CursorType(false); } break; case eInputEventType.MouseButtonDown: if (ModifierPressed) { SelectionChanged = true; Visible = true; Selected = true; DragMode = DragType.LowerRight; handled = true; StartFreq = MainPlot.CursorFrequency; StartStrength = MainPlot.CursorStrength; EndFreq = MainPlot.CursorFrequency; EndStrength = MainPlot.CursorStrength; UpdatePositions(); MainPlot.CursorType(true); } else { /* if area selected */ if (Visible) { bool withinHor = (MainPlot.CursorFrequency >= Math.Min(StartFreq, EndFreq) && MainPlot.CursorFrequency <= Math.Max(StartFreq, EndFreq)); bool withinVert = (MainPlot.CursorStrength >= Math.Min(StartStrength, EndStrength) && MainPlot.CursorStrength <= Math.Max(StartStrength, EndStrength)); /* and cursor within area */ if (withinHor) { Visible = true; Selected = true; if (Draggable && withinVert) { int xPosCursor = (int)MainPlot.XPosFromFrequency(MainPlot.CursorFrequency); int yPosCursor = (int)MainPlot.YPosFromStrength(MainPlot.CursorStrength); int xPos1 = (int)MainPlot.XPosFromFrequency(StartFreq); int xPos2 = (int)MainPlot.XPosFromFrequency(EndFreq); int yPos1 = (int)MainPlot.YPosFromStrength(StartStrength); int yPos2 = (int)MainPlot.YPosFromStrength(EndStrength); double topDelta = Math.Abs(yPosCursor - Math.Max(yPos1, yPos2)); double bottomDelta = Math.Abs(yPosCursor - Math.Min(yPos1, yPos2)); double leftDelta = Math.Abs(xPosCursor - Math.Min(xPos1, xPos2)); double rightDelta = Math.Abs(xPosCursor - Math.Max(xPos1, xPos2)); bool topDrag = false; bool bottomDrag = false; bool leftDrag = false; bool rightDrag = false; if (topDelta < DragBorderWidth) { topDrag |= true; } if (bottomDelta < DragBorderWidth) { bottomDrag |= true; } if (leftDelta < DragBorderWidth) { leftDrag |= true; } if (rightDelta < DragBorderWidth) { rightDrag |= true; } if (topDrag) { if (leftDrag) { DragMode = DragType.UpperLeft; } else if (rightDrag) { DragMode = DragType.UpperRight; } else { DragMode = DragType.Upper; } } else if (bottomDrag) { if (leftDrag) { DragMode = DragType.LowerLeft; } else if (rightDrag) { DragMode = DragType.LowerRight; } else { DragMode = DragType.Lower; } } else { if (leftDrag) { DragMode = DragType.Left; } else if (rightDrag) { DragMode = DragType.Right; } else { DragMode = DragType.Center; } } SelectionChanged = true; DragStartFrequency = MainPlot.CursorFrequency; DragStartStrength = MainPlot.CursorStrength; handled = true; } } else { /* else only display */ Visible = true; Selected = false; } } UpdatePositions(); } break; case eInputEventType.MouseMoved: switch (DragMode) { case DragType.LowerRight: EndFreq = MainPlot.CursorFrequency; EndStrength = MainPlot.CursorStrength; break; case DragType.LowerLeft: StartFreq = MainPlot.CursorFrequency; EndStrength = MainPlot.CursorStrength; break; case DragType.Lower: EndStrength = MainPlot.CursorStrength; break; case DragType.Upper: StartStrength = MainPlot.CursorStrength; break; case DragType.UpperLeft: StartFreq = MainPlot.CursorFrequency; StartStrength = MainPlot.CursorStrength; break; case DragType.UpperRight: EndFreq = MainPlot.CursorFrequency; StartStrength = MainPlot.CursorStrength; break; case DragType.Right: EndFreq = MainPlot.CursorFrequency; break; case DragType.Left: StartFreq = MainPlot.CursorFrequency; break; case DragType.Center: long curFreq = MainPlot.CursorFrequency; double curStrength = MainPlot.CursorStrength; StartFreq -= (DragStartFrequency - curFreq); StartStrength -= (DragStartStrength - curStrength); EndFreq -= (DragStartFrequency - curFreq); EndStrength -= (DragStartStrength - curStrength); DragStartFrequency = curFreq; DragStartStrength = curStrength; break; } if (DragMode != DragType.None) { SelectionChanged = true; } if (!Selected && (FreqWidth > 0 && (MainPlot.CursorFrequency >= Math.Min(StartFreq, EndFreq) && MainPlot.CursorFrequency <= Math.Max(StartFreq, EndFreq)))) { Selected = true; SelectionChanged = true; } UpdatePositions(); break; } return(handled); }
private void OnMouseDown(object sender, MouseButtonEventArgs e) { try { if (!SimulatorContainer.IsMouseCaptured) { if (e.ChangedButton == MouseButton.Left) dragType = DragType.LOOK; else if (e.ChangedButton == MouseButton.Right) dragType = DragType.MOVE; var p = e.GetPosition(SimulatorContainer); mouseStart = new Vector2((float)p.X, (float)p.Y); SimulatorContainer.CaptureMouse(); } } catch (Exception err) { GUIUtilities.ReportUnexpectedException(err); } }
// Update is called once per frame void Update() { if (!DragEnabled) { grabbing = false; target = null; targetScript = null; return; } if (target == null) { grabbing = false; target = null; targetScript = null; } if (target != null && Input.GetKeyDown(KeyCode.Escape)) // Tinaxd Press Esc to cancel dragging { target.GetComponent <BasicUnit>().NotifyDragEnd(); grabbing = false; target = null; targetScript = null; return; } if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.transform.tag == "Unit") { target = hit.transform.gameObject; targetScript = hit.transform.GetComponent <UnitInfoTag>(); grabbing = true; targetPlane = new Plane(Vector3.up, target.transform.position); float enter = 0; targetPlane.Raycast(ray, out enter); localOrigin = ray.GetPoint(enter); targetUnit = simulator.GetUnit(targetScript.uuid); if (targetUnit.owner != simulator.isClient)//0:host 1:client { grabbing = false; target = null; targetScript = null; } else // Tinaxd show DragUI { target.GetComponent <BasicUnit>().NotifyDragStart(); } } } } if (Input.GetMouseButtonUp(0)) { if (grabbing) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); float enter = 0; targetPlane.Raycast(ray, out enter); // Debug.Log(localOrigin - ray.GetPoint(enter)); Vector3 vel = localOrigin - ray.GetPoint(enter); vel *= 2; DragType dt = DragType.NORMAL; vel = GetVelocity(vel); switch (dt) { case DragType.NORMAL: UnitMovedCmd c = new UnitMovedCmd(); c.sent = false; c.vx = vel.x; c.vz = vel.z; c.uuid = targetUnit.uuid; c.owner = simulator.isClient; simulator.commands.Add(c); break; case DragType.ARCHER: //target.GetComponent<BasicUnit>().DragMode = DragType.NORMAL; NewUnitCmd cmd = new NewUnitCmd { fromUnitId = target.GetComponent <BasicUnit>().unit.uuid, velocity = new Vector3(vel.x * 3, 0, vel.z * 3), unitType = 2, // Unit type Arrow }; simulator.commands.Add(cmd); break; case DragType.FIREBALL: //target.GetComponent<BasicUnit>().DragMode = DragType.NORMAL; NewUnitCmd cmd2 = new NewUnitCmd { fromUnitId = target.GetComponent <BasicUnit>().unit.uuid, velocity = new Vector3(vel.x * 3, 0, vel.z * 3), unitType = 3, // Unit type Fireball }; simulator.commands.Add(cmd2); break; } //targetScript.rg.AddForce(vel, ForceMode.VelocityChange); /* * CommandData c = new CommandData(); * c.sent = false; * c.when = manager.elapsedTime; * c.vx = vel.x; * c.vz = vel.z; * c.x = targetScript.transform.position.x; * c.z = targetScript.transform.position.z; * * targetScript.command = c;*/ grabbing = false; target.GetComponent <BasicUnit>().NotifyDragEnd(); // Tinaxd disable DragUI } } ballisticsSimulator.lr.enabled = grabbing; // Tinaxd update DragUI if (grabbing) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); var basicUnit = target.GetComponent <BasicUnit>(); float enter = 0; targetPlane.Raycast(ray, out enter); var point = ray.GetPoint(enter); Vector3 diff = -point + localOrigin; diff *= 2; diff = GetVelocity(diff); ballisticsSimulator.UpdateTrails(target.transform.position, diff); basicUnit.NotifyDragUpdate(point); } }
static bool CurveDisplay(IAudioEffectPlugin plugin, Rect r0, ref float threshold, ref float ratio, ref float makeupGain, ref float attackTime, ref float releaseTime, ref float knee, float sidechainLevel, float outputLevel, float blend) { Event evt = Event.current; int controlID = GUIUtility.GetControlID(FocusType.Passive); Rect r = AudioCurveRendering.BeginCurveFrame(r0); const float thresholdActiveWidth = 10f; float vuWidth = 10f; float minThreshold, maxThreshold, defThreshold; plugin.GetFloatParameterInfo(kThresholdName, out minThreshold, out maxThreshold, out defThreshold); float minRatio, maxRatio, defRatio; plugin.GetFloatParameterInfo(kRatioName, out minRatio, out maxRatio, out defRatio); float minMakeupGain, maxMakeupGain, defMakeupGain; plugin.GetFloatParameterInfo(kMakeupGainName, out minMakeupGain, out maxMakeupGain, out defMakeupGain); float minKnee, maxKnee, defKnee; plugin.GetFloatParameterInfo(kKneeName, out minKnee, out maxKnee, out defKnee); float dbRange = 100.0f, dbMin = -80.0f; float thresholdPosX = r.width * (threshold - dbMin) / dbRange; bool modifiedValue = false; switch (evt.GetTypeForControl(controlID)) { case EventType.MouseDown: if (r.Contains(Event.current.mousePosition) && evt.button == 0) { dragtype = DragType.None; GUIUtility.hotControl = controlID; EditorGUIUtility.SetWantsMouseJumping(1); evt.Use(); // Ensure visible state change on mousedown to make it clear that interaction is possible if ((Mathf.Abs(r.x + thresholdPosX - evt.mousePosition.x) >= thresholdActiveWidth)) { dragtype = (evt.mousePosition.x < r.x + thresholdPosX) ? DragType.MakeupGain : DragType.Ratio; } else { dragtype = DragType.ThresholdAndKnee; } } break; case EventType.MouseUp: if (GUIUtility.hotControl == controlID && evt.button == 0) { dragtype = DragType.None; GUIUtility.hotControl = 0; EditorGUIUtility.SetWantsMouseJumping(0); evt.Use(); } break; case EventType.MouseDrag: if (GUIUtility.hotControl == controlID) { float dragAcceleration = evt.alt ? .25f : 1f; if (dragtype == DragType.ThresholdAndKnee) { bool dragKnee = Mathf.Abs(evt.delta.x) < Mathf.Abs(evt.delta.y); if (dragKnee) { knee = Mathf.Clamp(knee + evt.delta.y * 0.5f * dragAcceleration, minKnee, maxKnee); } else { threshold = Mathf.Clamp(threshold + evt.delta.x * 0.1f * dragAcceleration, minThreshold, maxThreshold); } } else if (dragtype == DragType.Ratio) { ratio = Mathf.Clamp(ratio + evt.delta.y * (ratio > 1.0f ? 0.05f : 0.003f) * dragAcceleration, minRatio, maxRatio); } else if (dragtype == DragType.MakeupGain) { makeupGain = Mathf.Clamp(makeupGain - evt.delta.y * 0.5f * dragAcceleration, minMakeupGain, maxMakeupGain); } else { Debug.LogError("Drag: Unhandled enum"); } modifiedValue = true; evt.Use(); } break; } if (evt.type == EventType.Repaint) { // Curve HandleUtility.ApplyWireMaterial(); //float sidechainPosX = r.width * (sidechainLevel - dbMin) / dbRange; float thresholdPosY = r.height * (1.0f - ((threshold - dbMin + makeupGain) / dbRange)); Color thresholdColor = new Color(0.7f, 0.7f, 0.7f); Color sidechainColor = Color.black; float duckGradient = 1.0f / ratio; float duckThreshold = threshold; float duckSidechainLevel = sidechainLevel; float duckMakeupGain = makeupGain; float duckKnee = knee; float duckKneeC1 = (knee > 0.0f) ? ((duckGradient - 1.0f) / (4.0f * knee)) : 0.0f; float duckKneeC2 = duckThreshold - knee; // Main filled curve AudioCurveRendering.DrawFilledCurve( r, delegate(float x, out Color col) { float level = x * dbRange + dbMin; float gain = level; float t = level - duckThreshold; col = ScaleAlpha(duckSidechainLevel > level ? AudioCurveRendering.kAudioOrange : Color.grey, blend); if (t > -duckKnee && t < duckKnee) { t += duckKnee; gain = t * (duckKneeC1 * t + 1.0f) + duckKneeC2; if (dragtype == DragType.ThresholdAndKnee) { const float mult = 1.2f; col = new Color(col.r * mult, col.g * mult, col.b * mult); } } else if (t > 0.0f) { gain = duckThreshold + duckGradient * t; } return((2.0f * (gain + duckMakeupGain - dbMin) / dbRange) - 1.0f); } ); // Curve shown when modifying MakeupGain if (dragtype == DragType.MakeupGain) { AudioCurveRendering.DrawCurve( r, delegate(float x) { float level = x * dbRange + dbMin; float gain = level; float t = level - duckThreshold; if (t > -duckKnee && t < duckKnee) { t += duckKnee; gain = t * (duckKneeC1 * t + 1.0f) + duckKneeC2; } else if (t > 0.0f) { gain = duckThreshold + duckGradient * t; } return((2.0f * (gain + duckMakeupGain - dbMin) / dbRange) - 1.0f); }, Color.white ); } // Threshold text and line textStyle10.normal.textColor = ScaleAlpha(thresholdColor, blend); EditorGUI.DrawRect(new Rect(r.x + thresholdPosX, r.y, 1, r.height), textStyle10.normal.textColor); DrawText(r.x + thresholdPosX + 4, r.y + 6, string.Format(CultureInfo.InvariantCulture.NumberFormat, "Threshold: {0:F1} dB", threshold)); // Sidechain text and line textStyle10.normal.textColor = ScaleAlpha(sidechainColor, blend); DrawText(r.x + 4, r.y + r.height - 10, sidechainLevel < -80 ? "Input: None" : string.Format(CultureInfo.InvariantCulture.NumberFormat, "Input: {0:F1} dB", sidechainLevel)); if (dragtype == DragType.Ratio) { float aspect = (float)r.height / (float)r.width; Handles.DrawAAPolyLine(2.0f, new Color[] { Color.black, Color.black }, new Vector3[] { new Vector3(r.x + thresholdPosX + r.width, r.y + thresholdPosY - aspect * r.width, 0.0f), new Vector3(r.x + thresholdPosX - r.width, r.y + thresholdPosY + aspect * r.width, 0.0f) }); Handles.DrawAAPolyLine(3.0f, new Color[] { Color.white, Color.white }, new Vector3[] { new Vector3(r.x + thresholdPosX + r.width, r.y + thresholdPosY - aspect * duckGradient * r.width, 0.0f), new Vector3(r.x + thresholdPosX - r.width, r.y + thresholdPosY + aspect * duckGradient * r.width, 0.0f) }); } else if (dragtype == DragType.ThresholdAndKnee) { // Knee min and max lines float normalizedKnee1 = (threshold - knee - dbMin) / dbRange; float normalizedKnee2 = (threshold + knee - dbMin) / dbRange; float y1 = EvaluateDuckingVolume(normalizedKnee1, ratio, threshold, makeupGain, knee, dbRange, dbMin); float y2 = EvaluateDuckingVolume(normalizedKnee2, ratio, threshold, makeupGain, knee, dbRange, dbMin); float knee1PosY = r.yMax - (y1 + 1f) * 0.5f * r.height; float knee2PosY = r.yMax - (y2 + 1f) * 0.5f * r.height; EditorGUI.DrawRect(new Rect(r.x + normalizedKnee1 * r.width, knee1PosY, 1, r.height - knee1PosY), new Color(0, 0, 0, 0.5f)); EditorGUI.DrawRect(new Rect(r.x + normalizedKnee2 * r.width - 1, knee2PosY, 1, r.height - knee2PosY), new Color(0, 0, 0, 0.5f)); // Enhanced threshold EditorGUI.DrawRect(new Rect(r.x + thresholdPosX - 1, r.y, 3, r.height), Color.white); } outputLevel = (Mathf.Clamp(outputLevel - makeupGain, dbMin, dbMin + dbRange) - dbMin) / dbRange; if (EditorApplication.isPlaying) { const int margin = 2; Rect vuRect = new Rect(r.x + r.width - vuWidth + margin, r.y + margin, vuWidth - 2 * margin, r.height - 2 * margin); DrawVU(vuRect, outputLevel, blend, true); } } AudioCurveRendering.EndCurveFrame(); return(modifiedValue); }
public static guiSlot Create(Transform parent, ResourceData worker, SlotType type, DragType drag, object data = null) { GameObject obj = Instantiate<GameObject>(Resources.Load<GameObject>("Slot")); obj.transform.SetParent(parent); obj.transform.localScale = Vector3.one; guiSlot slot = obj.GetComponent<guiSlot>(); slot.Worker = worker; slot.Type = type; slot.Drag = drag; slot.Data = data; return slot; }
public void Draw(Rect viewRect, ClipViewInfo info, Navigator navigator, float totalFrame, float currentFrame, IReadOnlyList <Blackboard> blackboards) { if (Asset == null) { return; } if (SerializedObject == null) { return; } m_BlackboardList = blackboards; var beginFrame = BeginFrame; var endFrame = EndFrame; var fullRect = new Rect(info.Min, viewRect.y + 2f, info.Max - info.Min, viewRect.height - 4f); if (endFrame <= navigator.MinFrame || beginFrame >= navigator.MaxFrame) { return; } var edgeRect = Utility.CalculateEdgeRects(fullRect, 8f); EditorGUIUtility.AddCursorRect(edgeRect.left, MouseCursor.SplitResizeLeftRight); EditorGUIUtility.AddCursorRect(edgeRect.right, MouseCursor.SplitResizeLeftRight); var contentRect = new Rect(info.ContentMin + 2f, fullRect.y + 2f, info.ContentMax - info.ContentMin - 4f, fullRect.height - 4f); ClipViewUtility.DrawClip(fullRect, info, BackgroundColor); SerializedObject.Update(); DrawContents(contentRect, SerializedObject); SerializedObject.ApplyModifiedProperties(); var dragCtrlId = GUIUtility.GetControlID(FocusType.Passive); var e = Event.current; switch (e.type) { case EventType.MouseDown: { if (edgeRect.left.Contains(e.mousePosition)) { m_DragType = DragType.Min; GUIUtility.hotControl = dragCtrlId; e.Use(); break; } if (edgeRect.right.Contains(e.mousePosition)) { m_DragType = DragType.Max; GUIUtility.hotControl = dragCtrlId; e.Use(); break; } if (contentRect.Contains(e.mousePosition) && e.button == 1) { ShowContextMenu(); e.Use(); break; } if (contentRect.Contains(e.mousePosition)) { Selection.objects = new Object[] { Asset }; m_DragType = DragType.Range; GUIUtility.hotControl = dragCtrlId; e.Use(); } } break; case EventType.MouseDrag: if (dragCtrlId == GUIUtility.hotControl) { switch (m_DragType) { case DragType.Min: { var next = Utility.Remap(e.mousePosition.x, viewRect.xMin, viewRect.xMax, navigator.MinFrame, navigator.MaxFrame); BeginFrame = ClipViewUtility.Adjust(next, viewRect, navigator); BeginFrame = Mathf.Min(BeginFrame, EndFrame); BeginFrame = Mathf.Max(BeginFrame, info.StopMin); } break; case DragType.Max: { var next = Utility.Remap(e.mousePosition.x, viewRect.xMin, viewRect.xMax, navigator.MinFrame, navigator.MaxFrame); EndFrame = ClipViewUtility.Adjust(next, viewRect, navigator); EndFrame = Mathf.Max(BeginFrame, EndFrame); EndFrame = Mathf.Min(EndFrame, info.StopMax); } break; case DragType.Range: { var delta = Utility.Remap(e.delta.x, 0f, viewRect.width, 0f, navigator.Range); if (0f > delta) { if (0f > BeginFrame + delta) { delta = -BeginFrame; } } else { if (totalFrame < EndFrame + delta) { delta = totalFrame - EndFrame; } } BeginFrame += delta; EndFrame += delta; BeginFrame = Mathf.Max(BeginFrame, info.StopMin); EndFrame = Mathf.Min(EndFrame, info.StopMax); if (info.HasPrev) { EndFrame = Mathf.Max(EndFrame, info.StopMax2); } if (info.HasNext) { BeginFrame = Mathf.Min(BeginFrame, info.StopMin2); } } break; } e.Use(); } break; case EventType.MouseUp: case EventType.Ignore: if (dragCtrlId == GUIUtility.hotControl) { BeginFrame = ClipViewUtility.Adjust(BeginFrame, viewRect, navigator); EndFrame = ClipViewUtility.Adjust(EndFrame, viewRect, navigator); m_DragType = DragType.None; GUIUtility.hotControl = 0; e.Use(); } break; } }
void DrawNodes() { if (currentFlowNodes == null) { return; } bool mouseDown = false; bool hit = false; switch (Event.current.type) { case EventType.MouseDown: if (Event.current.button == 2) { hand = true; } if (Event.current.isMouse && Event.current.button == 0) { downPos = Event.current.mousePosition; dragPos = downPos; rectTool = true; mouseDown = true; Event.current.Use(); } break; case EventType.MouseMove: break; case EventType.KeyDown: if (Event.current.keyCode == KeyCode.Delete) { for (int i = 0; i < selection.Count; ++i) { DeleteFlowNode(selection[i]); selection[i] = null; } selection.Clear(); currentFlowNode = null; UpdateFlowNodes(); } break; case EventType.Repaint: if (hand) { int id = GUIUtility.GetControlID(FocusType.Passive); EditorGUIUtility.AddCursorRect(new Rect(new Vector2(0, 0), new Vector2(Screen.width, Screen.height)), MouseCursor.Pan, id); //hand = false; } if (rectTool) { Rect rect = new Rect(0, 0, 100, 200); rect.position = downPos; rect.yMax = dragPos.y; rect.xMax = dragPos.x; GUI.color = Kiz_GUIUtility.RectToolColor; GUI.DrawTexture(rect, EditorGUIUtility.whiteTexture); GUI.color = Color.white; } break; case EventType.MouseDrag: if (Event.current.button == 2) { hand = true; } else { hand = false; } if (Event.current.isMouse && Event.current.button == 0) { if (currentFlowNode != null) { if (dragPin) { } else { currentFlowNode.mPosition = Event.current.mousePosition - dragNodePos; } needRepaint = true; } LastMousePos = Event.current.mousePosition; Event.current.Use(); } if (rectTool) { dragPos = Event.current.mousePosition; } break; case EventType.MouseUp: if (Event.current.button == 2) { hand = false; } if (Event.current.isMouse && Event.current.button == 0) { dragPin = false; if (dragType == DragType.Hold) { dragType = DragType.Release; } else { currentFlowNode = null; } Event.current.Use(); } rectTool = false; break; } foreach (var node in currentFlowNodes) { Color nodeColor = selection.Contains(node) ? Color.yellow : node.LastTimeColor; // ノードの描画 using (new ColorScope(nodeColor)) { GUI.Box(node.NodeRect, node.GetType().ToString().Replace("FlowNode_", ""), Styles.Node); } float lastY = node.NodeRect.yMin; // ノブとか描画 foreach (var inputPin in node.EditorInputPins) { GUI.Box(inputPin.Rect, "◎", Styles.Pin); GUI.Label(inputPin.LabelRect, inputPin.Pin.Name, Styles.PinLabel); if (dragType == DragType.Release && !object.Equals(node, currentFlowNode)) { if (inputPin.Rect.Contains(LastMousePos)) { currentFlowNode.Join(dragPinID, node, inputPin.Pin.ID); } } lastY = inputPin.Rect.yMax + 10; node.mSize = new Vector2(Mathf.Max(node.mSize.x, inputPin.LabelRect.width + inputPin.Rect.width + 20), node.mSize.y); } // ノブとか描画 foreach (var outputPin in node.EditorOutputPins) { GUI.Box(outputPin.Rect, "◎", Styles.Pin); GUI.Label(outputPin.LabelRect, outputPin.Pin.Name, Styles.PinLabel); // あたり判定の処理 if (mouseDown && !hit) { if (outputPin.Rect.Contains(Event.current.mousePosition)) { dragNodePos = outputPin.Rect.center; currentFlowNode = node; hit = true; dragPin = true; dragType = DragType.Hold; dragPinID = outputPin.Pin.ID; rectTool = false; } } lastY = outputPin.Rect.yMax + 10; node.mSize = new Vector2(Mathf.Max(node.mSize.x, outputPin.LabelRect.width + outputPin.Rect.width + 20), node.mSize.y); } node.mSize.y = lastY - node.mPosition.y; // あたり判定の処理 if (mouseDown && !hit) { // 当たっていた if (node.NodeRect.Contains(Event.current.mousePosition)) { if (!selection.Contains(node)) { selection.Clear(); selection.Add(node); } dragNodePos = Event.current.mousePosition - node.mPosition; currentFlowNode = node; hit = true; rectTool = false; } } } if (mouseDown && !hit) { selection.Clear(); } if (dragPin) { Handles.BeginGUI(); Handles.DrawLine(dragNodePos, Event.current.mousePosition); Handles.EndGUI(); } if (dragType == DragType.Release) { dragType = DragType.Free; currentFlowNode = null; } foreach (var node in currentFlowNodes) { foreach (var link in node.NodeLinks) { var srcPin = node.EditorOutputPins.Find(pin => pin.Pin.ID == link.srcPin); var dstPin = link.dstNode.EditorInputPins.Find(pin => pin.Pin.ID == link.dstPin); Handles.BeginGUI(); bool mouseOverConnection = HitCheckConnection(Event.current.mousePosition, srcPin.Rect.center, dstPin.Rect.center); Color connectionColor = mouseOverConnection ? Kiz_GUIUtility.SelectedColor : link.LastTimeColor; DrawConnection(srcPin.Rect.center, dstPin.Rect.center, connectionColor); Handles.EndGUI(); } } }