publicclassRaycastTarget : Graphic { // Additionally, If you need a Raycast target that is not a rectangle, you can implement bool Raycast(Vector2 sp, Camera eventCamera) method from Graphic. publicoverridevoidSetMaterialDirty() { return; } publicoverridevoidSetVerticesDirty() { return; } /// Probably not necessary since the chain of calls `Rebuild()`->`UpdateGeometry()`->`DoMeshGeneration()`->`OnPopulateMesh()` won't happen; so here really just as a fail-safe. protectedoverridevoidOnPopulateMesh(VertexHelper vh) { vh.Clear(); return; }
#if UNITY_EDITOR
privatevoidOnDrawGizmos() { if (!this.enabled) return RectTransform rectTransform = this.transform as RectTransform; Color wireColor = Color.yellow; if (this.isActiveAndEnabled) wireColor.a *= 0.7f // Padding to be applied to the masking // X = Left, Y = Bottom, Z = Right, W = Top // if you wanna make it bigger, then the all value shouble be negative Vector4 padding = this.raycastPadding * -1.0f; Matrix4x4 localToWorld = rectTransform.localToWorldMatrix Vector3 topLeft = SomeUtils.GetOffsetLocalPosition(rectTransform, SomeUtils.UIOffsetType.TopLeft); Vector3 topRight = SomeUtils.GetOffsetLocalPosition(rectTransform, SomeUtils.UIOffsetType.TopRight); Vector3 bottomLeft = SomeUtils.GetOffsetLocalPosition(rectTransform, SomeUtils.UIOffsetType.BottomLeft); Vector3 bottomRight = SomeUtils.GetOffsetLocalPosition(rectTransform, SomeUtils.UIOffsetType.BottomRight) topLeft = localToWorld.MultiplyPoint(topLeft + (Vector3.left * padding.x) + (Vector3.up * padding.w)); topRight = localToWorld.MultiplyPoint(topRight + (Vector3.right * padding.z) + (Vector3.up * padding.w)); bottomLeft = localToWorld.MultiplyPoint(bottomLeft + (Vector3.left * padding.x) + (Vector3.down * padding.y)); bottomRight = localToWorld.MultiplyPoint(bottomRight + (Vector3.right * padding.z) + (Vector3.down * padding.y)) Color tempColor = Gizmos.color; Gizmos.color = wireColor Gizmos.DrawLine(topLeft, topRight); Gizmos.DrawLine(topLeft, bottomLeft); Gizmos.DrawLine(bottomRight, topRight); Gizmos.DrawLine(bottomRight, bottomLeft); Gizmos.color = tempColor }