protected virtual void OnDisable() { _frontDrawer = null; _backDrawer = null; Camera.onPostRender -= onPostRender; }
protected virtual void OnEnable() { #if !UNITY_EDITOR if (!_enabledForBuild) { enabled = false; return; } #endif _frontDrawer = new RuntimeGizmoDrawer(); _backDrawer = new RuntimeGizmoDrawer(); _frontDrawer.BeginGuard(); if (_gizmoShader == null) { _gizmoShader = Shader.Find(DEFAULT_SHADER_NAME); } generateMeshes(); assignDrawerParams(); //Unsubscribe to prevent double-subscription Camera.onPostRender -= onPostRender; Camera.onPostRender += onPostRender; }
/// <summary> /// Tries to get a gizmo drawer for a given gameObject. Will fail if there is no /// gizmo manager in the scene, or if it is disabled. Will also fail if there is /// a disable RuntimeGizmoToggle as a parent of the gameObject. /// /// The gizmo matrix will be set to the identity matrix. /// The gizmo color will be set to white. /// </summary> public static bool TryGetGizmoDrawer(GameObject attatchedGameObject, out RuntimeGizmoDrawer drawer) { drawer = _backDrawer; if (drawer != null && !areGizmosDisabled(attatchedGameObject.transform)) { drawer.ResetMatrixAndColorState(); return true; } else { return false; } }
/// <summary> /// Tries to get a gizmo drawer. Will fail if there is no Gizmo manager in the /// scene, or if it is disabled. /// /// The gizmo matrix will be set to the identity matrix. /// The gizmo color will be set to white. /// </summary> public static bool TryGetGizmoDrawer(out RuntimeGizmoDrawer drawer) { drawer = _backDrawer; if (drawer != null) { drawer.ResetMatrixAndColorState(); return true; } else { return false; } }
public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer) { if (!this.enabled || !this.gameObject.activeInHierarchy) { return; } drawer.color = sphereColor; drawer.DrawPose(this.transform.ToWorldPose(), poseRadius); }
public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer) { if (!this.enabled || !this.gameObject.activeInHierarchy) { return; } drawer.DrawPose(this.transform.ToPose(), this.transform.lossyScale.x * 0.05f, drawCube: false); }
public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer) { if (!this.gameObject.activeInHierarchy || !this.enabled) { return; } drawer.color = color; drawer.DrawColliders(gameObject, useWireframe, traverseHierarchy, drawTriggers); }
protected void onPostRender(Camera camera) { if ((camera.cullingMask & gameObject.layer) == 0) { return; } #if UNITY_EDITOR //Always draw scene view //Never draw preview or reflection switch (camera.cameraType) { case CameraType.Preview: #if UNITY_2017_1_OR_NEWER case CameraType.Reflection: #endif return; case CameraType.Game: case CameraType.VR: if (!_displayInGameView) { return; } break; } #endif if (_readyForSwap) { if (OnPostRenderGizmos != null) { _backDrawer.ResetMatrixAndColorState(); OnPostRenderGizmos(_backDrawer); } RuntimeGizmoDrawer tempDrawer = _backDrawer; _backDrawer = _frontDrawer; _frontDrawer = tempDrawer; //Guard the front drawer for rendering _frontDrawer.BeginGuard(); //Unguard the back drawer to allow gizmos to be drawn to it _backDrawer.EndGuard(); _readyForSwap = false; _backDrawer.ClearAllGizmos(); } _frontDrawer.DrawAllGizmosToScreen(); }
/// <summary> /// Tries to get a gizmo drawer for a given gameObject. Will fail if there is no /// gizmo manager in the scene, or if it is disabled. Will also fail if there is /// a disable RuntimeGizmoToggle as a parent of the gameObject. /// /// The gizmo matrix will be set to the identity matrix. /// The gizmo color will be set to white. /// </summary> public static bool TryGetGizmoDrawer(GameObject attatchedGameObject, out RuntimeGizmoDrawer drawer) { drawer = _backDrawer; if (drawer != null && !areGizmosDisabled(attatchedGameObject.transform)) { drawer.ResetMatrixAndColorState(); return(true); } else { return(false); } }
/// <summary> /// Tries to get a gizmo drawer. Will fail if there is no Gizmo manager in the /// scene, or if it is disabled. /// /// The gizmo matrix will be set to the identity matrix. /// The gizmo color will be set to white. /// </summary> public static bool TryGetGizmoDrawer(out RuntimeGizmoDrawer drawer) { drawer = _backDrawer; if (drawer != null) { drawer.ResetMatrixAndColorState(); return(true); } else { return(false); } }
public static void DrawDashedLine(this RuntimeGizmos.RuntimeGizmoDrawer drawer, Vector3 a, Vector3 b, float segmentsPerMeter = 32f, float normalizedPhaseOffset = 0f) { var distance = (b - a).magnitude; var numSegments = distance * segmentsPerMeter; var segmentLength = distance / numSegments; var dir = (b - a) / distance; for (float i = normalizedPhaseOffset; i < numSegments; i += 2) { var start = a + dir * segmentLength * i; var end = a + dir * Mathf.Min(segmentLength * (i + 1), distance); drawer.DrawLine(start, end); } }
public static void DrawPose(this RuntimeGizmos.RuntimeGizmoDrawer drawer, Pose pose, float radius = 0.10f, bool drawCube = false) { drawer.PushMatrix(); drawer.matrix = Matrix4x4.TRS(pose.position, pose.rotation, Vector3.one); var origColor = drawer.color; //drawer.DrawWireSphere(Vector3.zero, radius); if (drawCube) { drawer.DrawCube(Vector3.zero, Vector3.one * radius * 0.3f); } drawer.DrawPosition(Vector3.zero, radius * 2); drawer.color = origColor; drawer.PopMatrix(); }
protected void onPostRender(Camera camera) { #if UNITY_EDITOR //Hard-coded name of the camera used to generate the pre-render view if (camera.gameObject.name == "PreRenderCamera") { return; } bool isSceneCamera = camera.gameObject.hideFlags == HideFlags.HideAndDontSave; if (!isSceneCamera && !_displayInGameView) { return; } #endif if (_readyForSwap) { if (OnPostRenderGizmos != null) { _backDrawer.ResetMatrixAndColorState(); OnPostRenderGizmos(_backDrawer); } RuntimeGizmoDrawer tempDrawer = _backDrawer; _backDrawer = _frontDrawer; _frontDrawer = tempDrawer; //Guard the front drawer for rendering _frontDrawer.BeginGuard(); //Unguard the back drawer to allow gizmos to be drawn to it _backDrawer.EndGuard(); _readyForSwap = false; _backDrawer.ClearAllGizmos(); } _frontDrawer.DrawAllGizmosToScreen(); }
public static void DrawRay(this RuntimeGizmos.RuntimeGizmoDrawer drawer, Vector3 position, Vector3 direction) { drawer.DrawLine(position, position + direction); }
public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer) { switch (gizmoType) { case GizmoType.InteractionStatus: if (_interactionBehaviour.IsBeingGrasped) { drawer.color = Color.green; } else if (GetComponent<Rigidbody>().IsSleeping()) { drawer.color = Color.gray; } else { drawer.color = Color.blue; } break; case GizmoType.ActivityDepth: drawer.color = Color.HSVToRGB(Mathf.Max(0, _timeToLive) / (_manager.MaxDepth * 2.0f), 1, 1); break; } drawer.DrawColliders(gameObject); }
public void OnDrawRuntimeGizmos(RuntimeGizmoDrawer drawer) { drawer.color = color; drawer.DrawColliders(gameObject, useWireframe, traverseHierarchy); }
public void DrawBasis(RuntimeGizmoDrawer gizmoDrawer, Vector3 origin, LeapTransform basis, float scale) { gizmoDrawer.color = Color.red; gizmoDrawer.DrawLine(origin, origin + basis.xBasis.ToVector3() * scale); gizmoDrawer.color = Color.green; gizmoDrawer.DrawLine(origin, origin + basis.yBasis.ToVector3() * scale); gizmoDrawer.color = Color.blue; gizmoDrawer.DrawLine(origin, origin + basis.zBasis.ToVector3() * scale); //Debug.DrawLine(origin, origin + basis.xBasis.ToVector3() * scale, Color.red); //Debug.DrawLine(origin, origin + basis.yBasis.ToVector3() * scale, Color.green); //Debug.DrawLine(origin, origin + basis.zBasis.ToVector3() * scale, Color.blue); }
private static bool TryGetDrawer(out Drawer drawer) { return(RuntimeGizmoManager.TryGetGizmoDrawer(out drawer)); }