void OnSceneGUI() { Handles.color = targetColor; Handles.SphereCap(0, script.transform.position, Quaternion.identity, size); DrawChildrenRecursive(script.transform); if (script.pivot != null) { Handles.color = pivotColor; GUI.color = pivotColor; Handles.SphereCap(0, script.pivot.position, Quaternion.identity, size); Vector3 twistAxisWorld = script.pivot.rotation * script.twistAxis.normalized * size * 40; Handles.DrawLine(script.pivot.position, script.pivot.position + twistAxisWorld); Handles.SphereCap(0, script.pivot.position + twistAxisWorld, Quaternion.identity, size); Handles.CircleCap(0, script.pivot.position, Quaternion.LookRotation(twistAxisWorld), size * 20); Handles.Label(script.pivot.position + twistAxisWorld, twistAxisLabel); } Handles.color = Color.white; GUI.color = Color.white; }
protected void OnSceneGUI() { if (!this.m_DisplayGeometry) { return; } UICircularRaycastFilter filter = this.target as UICircularRaycastFilter; RectTransform rt = filter.transform as RectTransform; if (filter.operationalRadius == 0f) { return; } float radius = filter.operationalRadius; Vector3 offset = new Vector3(rt.rect.center.x, rt.rect.center.y, 0f) + new Vector3(filter.offset.x, filter.offset.y, 0f); Canvas canvas = UIUtility.FindInParents <Canvas>(filter.gameObject); if (canvas != null) { radius *= canvas.scaleFactor; offset *= canvas.scaleFactor; } Handles.color = Color.green; Handles.CircleCap(0, filter.transform.position + offset, filter.transform.rotation, radius); }
//---------------------------------------------------------------------------- public void _PrimitiveCylinder(ref float radius, ref float height, Vector3 center, Quaternion rotation) { Vector3 topCenter = center + new Vector3(0f, height / 2f, 0f); Vector3 lowCenter = center - new Vector3(0f, height / 2f, 0f); Vector3 dir = topCenter - center; dir = rotation * dir; topCenter = center + dir; dir = lowCenter - center; dir = rotation * dir; lowCenter = center + dir; #if UNITY_5_6_OR_NEWER Handles.CircleHandleCap(0, topCenter, rotation * Quaternion.FromToRotation(Vector3.forward, Vector3.up), radius, EventType.Repaint); Handles.CircleHandleCap(0, lowCenter, rotation * Quaternion.FromToRotation(Vector3.forward, Vector3.up), radius, EventType.Repaint); #else Handles.CircleCap(0, topCenter, rotation * Quaternion.FromToRotation(Vector3.forward, Vector3.up), radius); Handles.CircleCap(0, lowCenter, rotation * Quaternion.FromToRotation(Vector3.forward, Vector3.up), radius); #endif Handles.DrawLine(topCenter + rotation * new Vector3(radius, 0f, 0f), lowCenter + rotation * new Vector3(radius, 0f, 0f)); Handles.DrawLine(topCenter - rotation * new Vector3(radius, 0f, 0f), lowCenter - rotation * new Vector3(radius, 0f, 0f)); Handles.DrawLine(topCenter + rotation * new Vector3(0f, 0f, radius), lowCenter + rotation * new Vector3(0f, 0f, radius)); Handles.DrawLine(topCenter - rotation * new Vector3(0f, 0f, radius), lowCenter - rotation * new Vector3(0f, 0f, radius)); }
public void OnSceneGUI() { var trigger = (TriggerBase)target; if (trigger.rangeHandler != null && trigger.rangeHandler.Equals(null) == false) { return; } var discColor = _outOfRangeColor; if (Application.isPlaying && trigger.inRange) { discColor = _inRangeColor; } if (GeneralSettingsManager.instance != null && GeneralSettingsManager.instance.settings != null) { var useRange = GeneralSettingsManager.instance.settings.triggerUseDistance; Handles.color = discColor; var euler = trigger.transform.rotation.eulerAngles; euler.x += 90.0f; Handles.DrawSolidDisc(trigger.transform.position, Vector3.up, useRange); discColor.a += 0.2f; Handles.color = discColor; Handles.CircleCap(0, trigger.transform.position, Quaternion.Euler(euler), useRange); } }
//绘制网格 private void RedrawNavMesh() { //遍历顶点 GameObject obj = mb.gameObject; int count = obj.transform.childCount; for (int i = 0; i < count; i++) { Transform child = obj.transform.GetChild(i); int countG = child.childCount; Vector3[] verts = new Vector3[countG]; List <Vector3> posList = new List <Vector3>(); for (int j = 0; j < countG; j++) { Vector3 pos = child.GetChild(j).transform.position; posList.Add(pos); //标记顶点 Handles.color = Color.red * 0.7f; Handles.CircleCap(0, pos, Quaternion.identity, HandleUtility.GetHandleSize(pos) * minRadis); Handles.color = Color.white; } //创建网格 CreateMesh(child, posList); } }
private void DrawGizmos() { #if UNITY_EDITOR if (DoDrawGizmos) { Matrix4x4 trs = Matrix4x4.TRS(transform.position, Quaternion.identity, Vector3.one); Handles.matrix *= trs; Handles.color = Color.cyan; Handles.DrawLines(new Vector3 [] { p0, p1, pc_a, pc_b, p0_a, p0_b, p1_a, p1_b }); Handles.CircleCap(0, p0, Quaternion.identity, 1f * Radius); Handles.CircleCap(0, p1, Quaternion.identity, 1f * Radius); Handles.color = Color.yellow; if (position_list != null) { for (int i = 0; i < position_list.Count; i++) { Vector3 p = position_list [i]; Vector3 dir = direction_list [i]; Handles.CircleCap(0, p, Quaternion.identity, .01f); Handles.ArrowCap(0, p, Quaternion.FromToRotation(-Vector3.back, dir), .1f); } } Handles.matrix *= trs.inverse; } #endif }
bool TryRotateButton(Vector3 position, float size) { size *= HandleUtility.GetHandleSize(position); var dist = Vector3.Distance(mousePosition, position); var buffer = size / 4; if (dist < size + buffer && dist > size - buffer) { if (e.type == EventType.MouseDown) { return(true); } else { mouseCursor = MouseCursor.RotateArrow; Handles.color = Color.green; } } else { Handles.color = Color.white; } Handles.CircleCap(0, position, inverseRotation, size - buffer / 2); Handles.CircleCap(0, position, inverseRotation, size + buffer / 2); return(false); }
public override void OnPreviewGUI(Rect r, GUIStyle background) { base.OnPreviewGUI(r, background); float size = 0.95f * Mathf.Min(r.width, r.height); Rect canvasRect = new Rect(r.center.x - 0.5f * size, r.center.y - 0.5f * size, size, size); CustomGestureTemplate template = target as CustomGestureTemplate; Vector2 center = canvasRect.center; float scale = 0.95f * size; Handles.color = Color.white; for (int i = 1; i < template.PointCount; ++i) { Vector2 p1 = template.GetPosition(i - 1); Vector2 p2 = template.GetPosition(i); p1.y = -p1.y; p2.y = -p2.y; p1 = center + scale * p1; p2 = center + scale * p2; if (canvasRect.width > 100) { float handleSize = canvasRect.width / 200.0f; Handles.CircleCap(0, p1, Quaternion.identity, handleSize); } Handles.DrawLine(p1, p2); } }
void DrawCircularGizmo() { #if UNITY_EDITOR Handles.color = Color.cyan; Handles.CircleCap(0, transform.position, transform.rotation * Quaternion.Euler(90.0f, 0.0f, 0.0f), size / 2.0f); #endif }
protected void DrawPointMassSceneGUI() { mainEditor.DrawPointMasses(body, true); Vector3 pos; //hovered over point mass in editor if(drawIndex >= 0 && drawIndex < body.PointMassCount && body.getPointMass(drawIndex).body != null) { pos = new Vector3(body.Shape.getVertex(drawIndex).x, body.Shape.getVertex(drawIndex).y, 0f); pos = body.transform.TransformPoint(pos); Handles.color = Color.cyan; Handles.DotCap(3, pos, Quaternion.identity, HandleUtility.GetHandleSize(pos) * 0.075f); } //selected point mass in editor if(editIndex != -1 && editIndex < body.PointMassCount && body.getPointMass(editIndex).body != null) { pos = new Vector3(body.Shape.getVertex(editIndex).x, body.Shape.getVertex(editIndex).y, 0f); pos = body.transform.TransformPoint(pos); Handles.color = Color.green; Handles.DotCap(3, pos, Quaternion.identity, HandleUtility.GetHandleSize(pos) * 0.075f); } //logic to add a new internal pointmass if(newSubComponentState == AddSubComponentState.initiated) { int controlID = GUIUtility.GetControlID(GetHashCode(), FocusType.Passive); if(Event.current.type == EventType.Layout) HandleUtility.AddDefaultControl(controlID); pos = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition).origin; //need where this ray intersects the zplane Plane plane = new Plane(Vector3.forward, new Vector3(0, 0, body.transform.position.z)); Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); float dist = 0f; plane.Raycast(ray, out dist); pos = ray.GetPoint(dist); Vector3 mousePosWorld = new Vector3(pos.x, pos.y, body.transform.position.z); Handles.color = Color.blue; Handles.CircleCap(3, mousePosWorld, Quaternion.identity, HandleUtility.GetHandleSize(mousePosWorld) * 0.15f); if(Event.current.type == EventType.MouseUp) { //body.addInternalPointMass(new JelloPointMass(body.Mass, mousePosWorld, body, false), false); body.smartAddInternalPointMass(new JelloPointMass(body.Mass, mousePosWorld, body, false), false, JelloBody.ShapeSettingOptions.MovePointMasses, mainEditor.smartShapeSettingOptions); EditorUtility.SetDirty(body); newSubComponentState = AddSubComponentState.inactive; } SceneView.RepaintAll(); } }
void OnSceneGUI(SceneView sceneView) { var selection = Selection.activeGameObject as GameObject; if (selection == null) { return; } var cameraTransform = SceneView.currentDrawingSceneView.camera.transform; var rotate = cameraTransform.rotation; var cameraPos = cameraTransform.position; Color shadowCol = new Color(0.5f, 0, 0, 0.06f); foreach (var target in referenceObjectList) { var obj = SceneObjectUtility.GetGameObject(target.value); if (obj == null) { continue; } if (obj == Selection.activeGameObject) { continue; } var startPosition = selection.transform.position; var endPosition = obj.transform.position; var size = Vector3.Distance(endPosition, cameraPos) * 0.02f; if (startPosition == endPosition) { continue; } Handles.color = Color.red; var diffPos = startPosition - endPosition; var tan = new Vector3(diffPos.y, diffPos.x, diffPos.z); var startTan = startPosition; var endTan = endPosition + tan * 0.4f; Handles.CircleCap(1, endPosition, rotate, size); for (int i = 0; i < 3; i++) { Handles.DrawBezier(startPosition, endPosition, startTan, endTan, shadowCol, null, (i + 1) * 5); } Handles.DrawBezier(startPosition, endPosition, startTan, endTan, Color.red, null, 1); Handles.Label(endPosition, obj.name); } }
void OnSceneGUI() { SerializedProperty max = serializedObject.FindProperty("maxDistance"); Vector3 pos = (target as PlaySound).transform.position; Handles.color = Color.cyan; Handles.CircleCap(0, pos, Quaternion.identity, max.floatValue); }
public static void DrawCircle(Vector3 position, Quaternion rotation, float radius) { #if UNITY_5_5_OR_NEWER Handles.CircleHandleCap(0, position, rotation, radius, EventType.Repaint); #else Handles.CircleCap(0, position, rotation, radius); #endif }
public static void DrawCircleCap(int controlID, Vector3 position, Quaternion rotation, float size) { #if UNITY_2017_1_OR_NEWER Handles.CircleHandleCap(controlID, position, rotation, size, EventType.Repaint); #else Handles.CircleCap(controlID, position, rotation, size); #endif }
public void OnDrawGizmos() { float size = 0.05f; transform.position = new Vector3(transform.position.x, 0, transform.position.z); Handles.color = Color.white; Handles.CircleCap(0, transform.position, Quaternion.LookRotation(Vector3.up, Vector3.right), size); }
public void OnDrawGizmos() { Handles.Label(transform.position, "IsGrouded: " + _isGrounded.ToString() + "\nCanClimb: " + _canClimb.ToString() + "\nIsClimbing: " + _isClimbing.ToString()); if (_groundCheck != null) { Handles.color = Color.red; Handles.CircleCap(0, _groundCheck.position, _groundCheck.rotation, groundCheckRadius); } }
private static void SceneGUITiltBased() { DisplayAtPoint(); CameraPathTiltList pointList = _cameraPath.tiltList; Camera sceneCamera = Camera.current; int pointCount = pointList.realNumberOfPoints; for (int i = 0; i < pointCount; i++) { CameraPathTilt point = pointList[i]; if (_cameraPath.enableUndo) { Undo.RecordObject(point, "Modifying Tilt Point"); } if (Vector3.Dot(sceneCamera.transform.forward, point.worldPosition - sceneCamera.transform.position) < 0) { continue; } string pointLabel = point.displayName; pointLabel += "\nvalue: " + point.tilt.ToString("F1") + "\u00B0"; Handles.Label(point.worldPosition, pointLabel); float pointHandleSize = HandleUtility.GetHandleSize(point.worldPosition) * HANDLE_SCALE; bool pointIsSelected = i == selectedPointIndex; Handles.color = (pointIsSelected) ? _cameraPath.selectedPointColour : _cameraPath.unselectedPointColour; float tiltSize = 2.0f; Vector3 pointForwardDirection = _cameraPath.GetPathDirection(point.percent, false); Quaternion qTilt = Quaternion.AngleAxis(-point.tilt, pointForwardDirection); Quaternion pointForward = Quaternion.LookRotation(pointForwardDirection); Handles.CircleCap(0, point.worldPosition, pointForward, tiltSize); Vector3 horizontalLineDirection = ((qTilt * Quaternion.AngleAxis(-90, Vector3.up)) * pointForwardDirection).normalized * tiltSize; Vector3 horizontalLineStart = point.worldPosition + horizontalLineDirection; Vector3 horizontalLineEnd = point.worldPosition - horizontalLineDirection; Handles.DrawLine(horizontalLineStart, horizontalLineEnd); Vector3 verticalLineDirection = (Quaternion.AngleAxis(-90, pointForwardDirection) * horizontalLineDirection).normalized * tiltSize; Vector3 verticalLineStart = point.worldPosition + verticalLineDirection; Vector3 verticalLineEnd = point.worldPosition; Handles.DrawLine(verticalLineStart, verticalLineEnd); if (Handles.Button(point.worldPosition, Quaternion.identity, pointHandleSize, pointHandleSize, Handles.DotCap)) { ChangeSelectedPointIndex(i); GUI.changed = true; } if (i == selectedPointIndex) { CPPSlider(point); } } }
protected virtual void OnSceneGUI() { DistanceTriggerHandler trigger = target as DistanceTriggerHandler; Color color = Handles.color; Handles.color = new Color(0f, 1f, 0f, 0.3f); Handles.DrawSolidDisc(trigger.transform.position, Vector3.up, trigger.distance); Handles.color = new Color(0f, 1f, 0f, 1f); Handles.CircleCap(0, trigger.transform.position, Quaternion.Euler(Vector3.right * 90), trigger.distance); Handles.color = color; }
public void DrawHandles(bool add) { RaycastHit hit; var ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); if (Physics.Raycast(ray.origin, ray.direction, out hit, Mathf.Infinity)) { Handles.color = add ? Color.green : Color.red; Handles.CircleCap(1, hit.point, Quaternion.LookRotation(hit.normal), _gizmoRadius); } }
protected void DrawCircleCap(Vector3 position, Quaternion rotation, float size) { #if UNITY_5_5_OR_NEWER if (Event.current.type == EventType.Repaint) { Handles.CircleHandleCap(0, position, rotation, size, EventType.Repaint); } #else Handles.CircleCap(0, position, rotation, size); #endif }
public void SceneGuiLineWriter(GameObject selection) { var cameraTransform = SceneView.currentDrawingSceneView.camera.transform; var rotate = cameraTransform.rotation; var cameraPos = cameraTransform.position; Color shadowCol = new Color(0, 0, 0.5f, 0.06f); var enableTypeList = refCompItems.FindAll(item => item.isDisplay == true); var referenceList = referenceObjectList.FindAll(item => SceneObjectUtility.GetGameObject(item.value) == selection); foreach (var refs in referenceList) { if (!enableTypeList.Exists(item => item.componentType == refs.referenceComponent.GetType())) { continue; } var obj = SceneObjectUtility.GetGameObject(refs.referenceComponent); var startPosition = selection.transform.position; var endPosition = obj.transform.position; var size = Vector3.Distance(endPosition, cameraPos) * 0.02f; if (startPosition == endPosition) { continue; } Handles.color = Color.blue; var diffPos = startPosition - endPosition; var tan = new Vector3(diffPos.y, diffPos.x, diffPos.z); var startTan = startPosition; var endTan = endPosition + tan * 0.4f; Handles.CircleCap(1, endPosition, rotate, size); for (int i = 0; i < 3; i++) { Handles.DrawBezier(startPosition, endPosition, startTan, endTan, shadowCol, null, (i + 1) * 5); } Handles.DrawBezier(startPosition, endPosition, startTan, endTan, Color.blue, null, 1); Handles.Label(endPosition, obj.name); } }
void OnSceneGUI() { SimObj simObj = (SimObj)target; if (SimUtil.ShowIDs) { Handles.color = Color.white; Handles.Label((simObj.transform.position + Vector3.up * 0.1f), simObj.Type.ToString() + " : " + simObj.UniqueID.ToString(), EditorStyles.miniButton); } if (SimUtil.ShowBasePivots) { Handles.color = Color.white; Handles.CircleCap(0, simObj.transform.position, Quaternion.Euler(-90f, 0f, 0f), 0.05f); } }
public void DrawGrid(DrawInfo drawInfo) { if (m_debugGrid) { Handles.CircleCap(0, drawInfo.InvertedZoom * (new Vector3(drawInfo.CameraOffset.x, drawInfo.CameraOffset.y, 0f)), Quaternion.identity, 5); for (int x = -( int )GRID_AREA_X; x < GRID_AREA_X; x += ( int )GRID_SIZE_X) { Handles.DrawLine(drawInfo.InvertedZoom * (new Vector3(x + drawInfo.CameraOffset.x, drawInfo.CameraOffset.y - GRID_AREA_Y, 0)), drawInfo.InvertedZoom * (new Vector3(drawInfo.CameraOffset.x + x, drawInfo.CameraOffset.y + GRID_AREA_Y, 0))); } for (int y = -( int )GRID_AREA_Y; y < GRID_AREA_X; y += ( int )GRID_SIZE_Y) { Handles.DrawLine(drawInfo.InvertedZoom * (new Vector3(drawInfo.CameraOffset.x - GRID_AREA_X, drawInfo.CameraOffset.y + y, 0)), drawInfo.InvertedZoom * (new Vector3(drawInfo.CameraOffset.x + GRID_AREA_X, drawInfo.CameraOffset.y + y, 0))); } } }
void drawHandles() { RaycastHit hit; var ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); int layerMask = 1 << paintLayer; if (Physics.Raycast(ray.origin, ray.direction, out hit, Mathf.Infinity, layerMask)) { if (placementRadius != 0) { Handles.color = Color.blue; Handles.CircleCap(1, hit.point, Quaternion.LookRotation(hit.normal), placementRadius); } } SceneView.RepaintAll(); }
void DrawNewPoints() { if (points.Count > 1) { Handles.color = Color.yellow; for (int i = 1; i < points.Count; ++i) { Vector2 p1 = points[i - 1]; Vector2 p2 = points[i]; Handles.CircleCap(0, p1, Quaternion.identity, 2.0f); Handles.DrawLine(p1, p2); } } }
public override void DoPaint() { //draw current Handles.color = Color.red; for (int i = 0; i < current_pos_list_.Count - 1; ++i) { Handles.CircleCap(0, current_pos_list_[i], Quaternion.LookRotation(Vector3.up), 0.5f); } for (int i = 0; i < current_pos_list_.Count - 1; ++i) { Handles.DrawLine(current_pos_list_[i], current_pos_list_[i + 1]); } //draw info convex_.DoPaintConvex(); }
public static void DrawRangeHandler(TriggerRangeHandler rangeHandler, GizmoType gizmoType) { var color = Color.cyan; color.a = 0.2f; Handles.color = color; var euler = rangeHandler.transform.rotation.eulerAngles; euler.x += 90.0f; Handles.DrawSolidDisc(rangeHandler.transform.position, Vector3.up, rangeHandler.useRange); color.a = 1f; Handles.color = color; Handles.CircleCap(0, rangeHandler.transform.position, Quaternion.Euler(euler), rangeHandler.useRange); }
public static void WriteLine(IEnumerable <object> referenceObjectList, GameObject selection, Color mainColor, Color shaodowColor, float curve) { var cameraTransform = SceneView.currentDrawingSceneView.camera.transform; var rotate = cameraTransform.rotation; var cameraPos = cameraTransform.position; var refObjects = referenceObjectList.Select(item => ReferenceExplorerUtility.GetGameObject(item)); foreach (var targetObject in refObjects) { try { if (targetObject == null || PrefabUtility.GetPrefabType(targetObject) == PrefabType.Prefab) { continue; } var startPosition = selection.transform.position; var endPosition = targetObject.transform.position; var size = Vector3.Distance(endPosition, cameraPos) * 1f; if (startPosition == endPosition) { continue; } Handles.color = shaodowColor; var diffPos = startPosition - endPosition; var tan = new Vector3(diffPos.y, diffPos.x, diffPos.z); var startTan = startPosition; var endTan = endPosition + tan * curve; Handles.CircleCap(0, endPosition, rotate, size); for (int i = 0; i < 3; i++) { Handles.DrawBezier(startPosition, endPosition, startTan, endTan, shaodowColor, null, (i + 1) * 5); } Handles.DrawBezier(startPosition, endPosition, startTan, endTan, mainColor, null, 1); Handles.Label(endPosition, targetObject.name); } catch (MissingReferenceException) { Debug.LogWarningFormat(selection, "{0} is missing! check it!", targetObject.name); } } }
void OnSceneGUI(SceneView sceneView) { BlockSceneSelection(); UpdateInput(); //Update grass renderer UpdateSelectedRenderer(); if (grassObject == null) { return; } //Calculate ray from mouse cursor var ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); //Check if grass was hit RaycastHit hit; if (!grassPainter.GrassCollider.Raycast(ray, out hit, Mathf.Infinity)) { return; } Handles.color = new Color(1, 0, 0, 1); Handles.CircleCap(0, hit.point, Quaternion.LookRotation(Vector3.up), grassPainter.Size); //Paint if (mouseDown) { float newDist = Vector3.Distance(lastPaintPos, hit.point); //Check draw spacing if (!didDraw || newDist > grassPainter.Spacing * grassPainter.Size) { //Draw brush grassPainter.ApplyBrush(hit.point); lastPaintPos = hit.point; } didDraw = true; } SceneView.RepaintAll(); }
private void DrawPoints(CatmullRomCentripetal spline, Transform tr) { if (!ms_drawPts) { return; } Camera sceneViewCam = Camera.current; Transform camTr = sceneViewCam.transform; // draw point and selection EUtil.PushHandleColor(SplineConst.SplinePtColor); for (int i = 0; i < spline.PointCount; ++i) { if (spline.Cycle && i == spline.PointCount - 1) //don't draw button for last point if is cycle { continue; } bool isSelPoint = false; if (i == m_curPtIdx) { isSelPoint = true; EUtil.PushHandleColor(Handles.selectedColor); } Vector3 pt = tr.TransformPoint(spline[i]); if (Handles.Button(pt, camTr.rotation, ms_ptSize, ms_ptSize, Handles.DotCap)) { m_curPtIdx = i; Repaint(); } if (isSelPoint) { EUtil.PopHandleColor(); } } EUtil.PopHandleColor(); if (ms_foldoutTSlider) { Vector3 tPos = tr.TransformPoint(spline.Interp(m_tSlider)); Handles.CircleCap(GUIUtility.GetControlID(FocusType.Passive), tPos, camTr.rotation, ms_ptSize); } }