protected void HandleCursorPosition() { // get current hovered position on the XZ-plane Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Plane xzPlane = new Plane(Vector3.up, Vector3.zero); float distance; if (xzPlane.Raycast(ray, out distance)) { // get the hit point: Vector3 temp = ray.GetPoint(distance); // and rounding it to half units hoveredPoint = new Vector3((int)Mathf.Round(temp.x * 2), 0, (int)Mathf.Round(temp.z * 2)) / 2.0f; // stop if there is no point nearby if ((hoveredPoint - temp).magnitude > hoverPrecision) { selectionObject.gameObject.SetActive(false); return; } xBetweenFullUnits = hoveredPoint.x % 1 != 0.0f; zBetweenFullUnits = hoveredPoint.z % 1 != 0.0f; var meshFilter = selectionObject.GetComponent <MeshFilter>(); // hovering over point if (!xBetweenFullUnits && !zBetweenFullUnits) { meshFilter.mesh = pointMesh; hoverType = HoverType.Point; } // hovering over edge else if (!xBetweenFullUnits || !zBetweenFullUnits) { meshFilter.mesh = edgeMesh; hoverType = HoverType.Edge; selectionObject.transform.rotation = Quaternion.Euler(90.0f, xBetweenFullUnits ? 90.0f : 0.0f, 0); } // hovering over face else { meshFilter.mesh = faceMesh; hoverType = HoverType.Face; } // update selection object selectionObject.position = hoveredPoint; selectionObject.gameObject.SetActive(true); } }
private HoverType GetHoverType(Rect rect, float y) { HoverType hy = HoverType.Middle; float p = rect.height / 3; if (y < p + rect.y) { hy = HoverType.Top; } else if (y > 2 * p + rect.y) { hy = HoverType.Bottom; } return(hy); }
private void DragHover(Rect rect, HoverType type) { switch (type) { case HoverType.Bottom: currentShowDrag = new Rect(rect.x, rect.yMax, rect.width, offsety); break; case HoverType.Middle: currentShowDrag = new Rect(rect.xMax, rect.center.y - offsety / 2, rect.width, offsety); break; case HoverType.Top: currentShowDrag = new Rect(rect.x, rect.y - offsety, rect.width, offsety); break; } }
private void EndDrag(TreeNode hoverNode, HoverType type) { var reDrag = TreeNode.FindNodeByGuid(root, currentDrag.guid); var hove = TreeNode.FindNodeByGuid(root, hoverNode.guid); if (reDrag != null && hove != null) { switch (type) { case HoverType.Bottom: { if (CanAppend(hove.Value.Parant, currentDrag)) { int index = hove.Value.Parant.childs.IndexOf(hoverNode) + 1; if (reDrag.Value.Parant == hove.Value.Parant) { int a = reDrag.Value.Parant.childs.IndexOf(currentDrag); index = hove.Value.Parant.childs.IndexOf(hoverNode); if (a > index) { index += 1; } reDrag.Value.Parant.childs.Remove(currentDrag); hove.Value.Parant.childs.Insert(index, currentDrag); } else if (index >= 0 && index < hove.Value.Parant.childs.Count) { reDrag.Value.Parant.childs.Remove(currentDrag); hove.Value.Parant.childs.Insert(index, currentDrag); } } else { EditorApplication.Beep(); } } break; case HoverType.Middle: { if (CanAppend(hoverNode, currentDrag)) { reDrag.Value.Parant.childs.Remove(currentDrag); hoverNode.childs.Add(currentDrag); } else { EditorApplication.Beep(); } } break; case HoverType.Top: { if (CanAppend(hove.Value.Parant, currentDrag)) { int index = hove.Value.Parant.childs.IndexOf(hoverNode); if (index >= 0 && index <= hove.Value.Parant.childs.Count) { reDrag.Value.Parant.childs.Remove(currentDrag); hove.Value.Parant.childs.Insert(index, currentDrag); } } else { EditorApplication.Beep(); } } break; } } currentDrag = null; currentShowDrag = null; }
private StateOfEditor DrawNode(Rect rect, TreeNode node, StateOfEditor expanded, bool haveChild, bool isRuning, RunStatus?state) { Color color = isRuning ? Color.yellow : Color.black; Color bg = Color.white; var att = GetNodeAtt(node.GetType()); if (lastClick == node) { color = Color.green; } var name = node.GetType().Name; if (att != null) { name = att.ShorName + ":" + node.name + (state == null?"":state.Value.ToString()); bg = GetColorByShortName(att.ShorName); } if (haveChild) { expanded.Expanded = EditorGLTools.DrawExpandBox(rect, name, expanded.OnEdited?string.Empty:node.ToString(), expanded.Expanded, color, bg, isRuning ? 2 : 1); } else { EditorGLTools.DrawTitleRect(rect, name, expanded.OnEdited?string.Empty:node.ToString(), color, bg, isRuning ? 2 : 1); } if (lastClick == node) { if (GUI.Button(new Rect(rect.xMax - 50, rect.y, 50, 20), expanded.OnEdited?"Close":"Edit")) { expanded.OnEdited = !expanded.OnEdited; } } else { expanded.OnEdited = false; } if (expanded.OnEdited) { GUILayout.BeginArea(new Rect(rect.x, rect.y + 25, rect.width - 2, rect.height - 25)); expanded.scroll = GUILayout.BeginScrollView(expanded.scroll); GUILayout.BeginVertical(GUILayout.Width(rect.width - 25)); PropertyDrawer.DrawObject(node); GUILayout.EndVertical(); GUILayout.EndScrollView(); GUILayout.EndArea(); } if (currentDrag == node) { return(new StateOfEditor()); } if (Event.current.type == EventType.ContextClick) { if (rect.Contains(Event.current.mousePosition)) { GenericMenu m = new GenericMenu(); m.AddItem(new GUIContent("Delete"), false, DeleteNode, node); //m.AddSeparator (""); ProcessMenu(m, node); m.ShowAsContext(); Event.current.Use(); } } if (lastClick != node) { if (Event.current.type == EventType.MouseDown) { if (rect.Contains(Event.current.mousePosition)) { SetLastClick(node); Event.current.Use(); } } } if (Event.current.type == EventType.MouseDrag) { if (rect.Contains(Event.current.mousePosition)) { if (currentDrag != null) { if (currentDrag != node) { HoverType t = HoverType.Middle; if (node != root) { t = GetHoverType(rect, Event.current.mousePosition.y); } DragHover(rect, t); Event.current.Use(); } else { currentShowDrag = null; Event.current.Use(); } } else { BeginDrag(node); Event.current.Use(); } } } if (Event.current.type == EventType.mouseUp) { if (currentDrag != null && currentDrag != node) { if (rect.Contains(Event.current.mousePosition)) { var t = GetHoverType(rect, Event.current.mousePosition.y); EndDrag(node, t); Event.current.Use(); } } } return(expanded); }
internal void SetActiveElement(LinkBase link, NodeAnchor anchor, HoverType hover_type) { ActiveElement.Set(link, anchor); ActiveElementType = hover_type; }
internal void SetActiveElement(LinkBase link, ControlPoint control_point, HoverType hover_type) { ActiveElement.Set(link, control_point); ActiveElementType = hover_type; }
internal void SetActiveElement(LinkBase link, HoverType hover_type) { ActiveElement.Set(link); ActiveElementType = hover_type; }
internal void SetActiveElement(NodeBase node, HoverType hover_type) { ActiveElement.Set(node); ActiveElementType = hover_type; }
public virtual HoverType HandleLayout() { if (clip == null) { return(HoverType.None); } if (clip.track == null) { return(HoverType.None); } HoverType hoverType = HoverType.None; int totalWidth = Mathf.RoundToInt((GetDuration() / clip.track.sequence.duration) * containerRect.width); if (totalWidth < 5) { totalWidth = 5; } float fadeInWidth = Mathf.RoundToInt((GetFadeIn() / clip.track.sequence.duration) * containerRect.width); float fadeOutWidth = Mathf.RoundToInt((GetFadeOut() / clip.track.sequence.duration) * containerRect.width); if (updateWaveform) { int texWidth = Mathf.RoundToInt((clip.audioClip.length / clip.track.sequence.duration) * containerRect.width); GenerateWaveform(texWidth, Mathf.RoundToInt(containerRect.height)); } updateWaveform = false; float positionPercent = GetPosition() / clip.track.sequence.duration; GUI.BeginGroup(containerRect); float rectLeft = positionPercent * containerRect.width; float rectRight = positionPercent * containerRect.width + totalWidth; rect = new Rect(rectLeft, 0, totalWidth, containerRect.height - 1); bool outOfBounds = rect.x + rect.width > containerRect.width; Rect secondaryRect = new Rect((rect.x - containerRect.width), rect.y, rect.width, rect.height); Vector2 mousePos = Event.current.mousePosition; Rect leftMargin = new Rect(rectLeft - 2, 0, 8, containerRect.height - 1); Rect rightMargin = new Rect(rectRight - 6, 0, 8, containerRect.height - 1); if (Event.current.alt) { leftMargin.x += fadeInWidth; rightMargin.x -= fadeOutWidth; } if (leftMargin.x > containerRect.width) { leftMargin.x -= containerRect.width; } if (rightMargin.x > containerRect.width) { rightMargin.x -= containerRect.width; } EditorGUIUtility.AddCursorRect(leftMargin, MouseCursor.ResizeHorizontal); EditorGUIUtility.AddCursorRect(rightMargin, MouseCursor.ResizeHorizontal); if (new Rect(0, 0, containerRect.width, containerRect.height).Contains(mousePos)) { if (leftMargin.Contains(mousePos)) { EditorGUI.DrawRect(leftMargin, Color.black); if (Event.current.alt) { hoverType = HoverType.FadeLeft; } else { hoverType = HoverType.TrimLeft; } } else if (rightMargin.Contains(mousePos)) { EditorGUI.DrawRect(rightMargin, Color.black); if (Event.current.alt) { hoverType = HoverType.FadeRight; } else { hoverType = HoverType.TrimRight; } } else if (rect.Contains(mousePos) || (outOfBounds && secondaryRect.Contains(mousePos))) { hoverType = HoverType.Move; } } fadeInRect = new Rect(0, 0f, fadeInWidth, rect.height); fadeOutRect = new Rect(rect.width - fadeOutWidth, 0f, fadeOutWidth, rect.height); innerRect = new Rect(fadeInWidth, 0f, totalWidth - fadeInWidth - fadeOutWidth, rect.height); GUI.EndGroup(); return(hoverType); }