/// <summary> /// Draws a "Box" gizmo /// </summary> /// <param name="component">The target component</param> /// <param name="alpha">The base opacity</param> private static void DrawBox(AuraVolume component, float alpha) { float thickness = CustomGizmo.pixelWidth; Color color = CustomGizmo.color; color.a *= alpha; CustomGizmo.DrawCube(component.transform.localToWorldMatrix, color, thickness); float xPos = (1.0f - component.volumeShape.fading.xPositiveCubeFade) * 2 - 1; float xNeg = component.volumeShape.fading.xNegativeCubeFade * 2 - 1; float yPos = (1.0f - component.volumeShape.fading.yPositiveCubeFade) * 2 - 1; float yNeg = component.volumeShape.fading.yNegativeCubeFade * 2 - 1; float zPos = (1.0f - component.volumeShape.fading.zPositiveCubeFade) * 2 - 1; float zNeg = component.volumeShape.fading.zNegativeCubeFade * 2 - 1; Vector3 customPointA = new Vector3(xNeg, yPos, zNeg) * 0.5f; Vector3 customPointB = new Vector3(xPos, yPos, zNeg) * 0.5f; Vector3 customPointC = new Vector3(xPos, yNeg, zNeg) * 0.5f; Vector3 customPointD = new Vector3(xNeg, yNeg, zNeg) * 0.5f; Vector3 customPointE = new Vector3(xNeg, yPos, zPos) * 0.5f; Vector3 customPointF = new Vector3(xPos, yPos, zPos) * 0.5f; Vector3 customPointG = new Vector3(xPos, yNeg, zPos) * 0.5f; Vector3 customPointH = new Vector3(xNeg, yNeg, zPos) * 0.5f; CustomGizmo.DrawLineSegment(CustomGizmo.cubeCornerA, new Vector3(xNeg, yPos, zNeg) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(CustomGizmo.cubeCornerB, new Vector3(xPos, yPos, zNeg) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(CustomGizmo.cubeCornerC, new Vector3(xPos, yNeg, zNeg) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(CustomGizmo.cubeCornerD, new Vector3(xNeg, yNeg, zNeg) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(CustomGizmo.cubeCornerE, new Vector3(xNeg, yPos, zPos) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(CustomGizmo.cubeCornerF, new Vector3(xPos, yPos, zPos) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(CustomGizmo.cubeCornerG, new Vector3(xPos, yNeg, zPos) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(CustomGizmo.cubeCornerH, new Vector3(xNeg, yNeg, zPos) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(customPointA, customPointB, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(customPointB, customPointC, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(customPointC, customPointD, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(customPointD, customPointA, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(customPointE, customPointF, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(customPointF, customPointG, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(customPointG, customPointH, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(customPointH, customPointE, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(customPointE, customPointF, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(customPointA, customPointE, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(customPointB, customPointF, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(customPointC, customPointG, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(customPointD, customPointH, component.transform.localToWorldMatrix, color, thickness); }
/// <summary> /// Draws a "Cone" gizmo /// </summary> /// <param name="component">The target component</param> /// <param name="alpha">The base opacity</param> private static void DrawCone(AuraVolume component, float alpha) { float thickness = CustomGizmo.pixelWidth; Color color = CustomGizmo.color; color.a *= alpha; CustomGizmo.DrawCone(component.transform.localToWorldMatrix, color, thickness); float z = 1.0f - component.volumeShape.fading.distanceConeFade; float xy = Mathf.Lerp(0, 1.0f - component.volumeShape.fading.angularConeFade, z); CustomGizmo.DrawLineSegment(new Vector3(0.0f, 0.5f, 1), new Vector3(0, xy * 0.5f, z), component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(new Vector3(0.0f, -0.5f, 1), new Vector3(0, -xy * 0.5f, z), component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(new Vector3(0.5f, 0.0f, 1), new Vector3(xy * 0.5f, 0.0f, z), component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(new Vector3(-0.5f, 0.0f, 1), new Vector3(-xy * 0.5f, 0.0f, z), component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawCone(component.transform.localToWorldMatrix, Vector3.zero, Quaternion.identity, new Vector3(xy, xy, z), color, thickness); }
/// <summary> /// Draws a "Sphere" gizmo /// </summary> /// <param name="component">The target component</param> /// <param name="alpha">The base opacity</param> private static void DrawSphere(AuraVolume component, float alpha) { float thickness = CustomGizmo.pixelWidth; Color color = CustomGizmo.color; color.a *= alpha; CustomGizmo.DrawSphere(component.transform.localToWorldMatrix, color, CustomGizmo.pixelWidth); float x = 1.0f - component.volumeShape.fading.distanceSphereFade; CustomGizmo.DrawLineSegment(Vector3.up * 0.5f, Vector3.up * x * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(Vector3.down * 0.5f, Vector3.down * x * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(Vector3.left * 0.5f, Vector3.left * x * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(Vector3.right * 0.5f, Vector3.right * x * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(Vector3.back * 0.5f, Vector3.back * x * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(Vector3.forward * 0.5f, Vector3.forward * x * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawSphere(component.transform.localToWorldMatrix, Vector3.zero, Quaternion.identity, Vector3.one * x, color, thickness); }
/// <summary> /// Draws the gizmo /// </summary> /// <param name="component">The target component</param> /// <param name="opacity">The gizmo opacity</param> private static void DrawGizmo(AuraLight component, float opacity) { Color color = CustomGizmo.color; color.a = CustomGizmo.color.a * opacity; switch (component.Type) { case LightType.Directional: { float size = HandleUtility.GetHandleSize(component.transform.position); const int stepAmount = 8; const float width = 1.0f; const float length = 3.0f; CustomGizmo.DrawCircle(Matrix4x4.TRS(component.transform.position, component.transform.rotation * Quaternion.AngleAxis(90, Vector3.right), Vector3.one * size * width), color, CustomGizmo.pixelWidth); for (int i = 0; i < stepAmount; ++i) { float ratio = (float)i / (float)stepAmount * 2.0f * Mathf.PI; Vector3 localStartPosition = new Vector3(Mathf.Sin(ratio), Mathf.Cos(ratio), 0) * size * width * 0.5f; Vector3 transformedStartPosition = component.transform.localToWorldMatrix.MultiplyPoint(localStartPosition); CustomGizmo.DrawLineSegment(transformedStartPosition, transformedStartPosition + component.transform.forward * size * length, color, CustomGizmo.pixelWidth); } } break; case LightType.Spot: { float angleToWidth = Mathf.Tan(component.GetComponent <Light>().spotAngle *Mathf.Deg2Rad * 0.5f) * 2.0f * component.GetComponent <Light>().range; CustomGizmo.DrawCone(Matrix4x4.TRS(component.transform.position, component.transform.rotation, new Vector3(angleToWidth, angleToWidth, component.GetComponent <Light>().range)), color, CustomGizmo.pixelWidth); } break; case LightType.Point: { CustomGizmo.DrawSphere(Matrix4x4.TRS(component.transform.position, component.transform.rotation, Vector3.one * component.GetComponent <Light>().range * 2.0f), color, CustomGizmo.pixelWidth); } break; } }
/// <summary> /// Draws a "Cylinder" gizmo /// </summary> /// <param name="component">The target component</param> /// <param name="alpha">The base opacity</param> private static void DrawCylinder(AuraVolume component, float alpha) { float thickness = CustomGizmo.pixelWidth; Color color = CustomGizmo.color; color.a *= alpha; CustomGizmo.DrawCylinder(component.transform.localToWorldMatrix, color, thickness); float x = 1.0f - component.volumeShape.fading.widthCylinderFade; float yPos = (1.0f - component.volumeShape.fading.yPositiveCylinderFade) * 2 - 1; float yNeg = component.volumeShape.fading.yNegativeCylinderFade * 2 - 1; CustomGizmo.DrawLineSegment(new Vector3(0.5f, 0.5f, 0), new Vector3(x, yPos, 0) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(new Vector3(-0.5f, 0.5f, 0), new Vector3(-x, yPos, 0) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(new Vector3(0.5f, -0.5f, 0), new Vector3(x, yNeg, 0) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(new Vector3(-0.5f, -0.5f, 0), new Vector3(-x, yNeg, 0) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(new Vector3(0.0f, 0.5f, 0.5f), new Vector3(0, yPos, x) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(new Vector3(0.0f, 0.5f, -0.5f), new Vector3(0, yPos, -x) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(new Vector3(0.0f, -0.5f, 0.5f), new Vector3(0, yNeg, x) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawLineSegment(new Vector3(0.0f, -0.5f, -0.5f), new Vector3(0, yNeg, -x) * 0.5f, component.transform.localToWorldMatrix, color, thickness); CustomGizmo.DrawCylinder(component.transform.localToWorldMatrix, (Vector3.up * ((1.0f - component.volumeShape.fading.yPositiveCylinderFade) + component.volumeShape.fading.yNegativeCylinderFade) * 0.5f) - Vector3.up * 0.5f, Quaternion.identity, new Vector3(x, 1.0f - component.volumeShape.fading.yPositiveCylinderFade - component.volumeShape.fading.yNegativeCylinderFade, x), color, thickness); }