コード例 #1
0
        static void Gizmo(Cover cover, GizmoType type)
        {
            var isSelected = (type & GizmoType.Selected) != 0;
            var alpha      = isSelected ? 0.9f : 0.5f;

            var collider = cover.GetComponent <BoxCollider>();

            if (collider != null)
            {
                Gizmos.color  = new Color(204 / 255f, 147 / 255f, 89f / 255f, alpha);
                Gizmos.matrix = cover.transform.localToWorldMatrix;
                Gizmos.DrawCube(collider.center, collider.size);

                const float depth  = 0.2f;
                const float height = 0.1f;

                var coverDepth  = Vector3.Distance(cover.transform.TransformPoint(0, 0, 0), cover.transform.TransformPoint(0, 0, collider.size.z));
                var coverHeight = Vector3.Distance(cover.transform.TransformPoint(0, 0, 0), cover.transform.TransformPoint(0, collider.size.y, 0));

                Gizmos.matrix = Matrix4x4.Translate(new Vector3(0, -coverHeight * 0.5f + height * 0.5f, 0) - cover.Forward * (coverDepth * 0.5f + depth * 0.5f)) *
                                cover.transform.localToWorldMatrix *
                                Matrix4x4.Scale(new Vector3(1, height / coverHeight, depth / coverDepth));
                Gizmos.DrawCube(collider.center, collider.size);
            }

            Gizmos.matrix = Matrix4x4.identity;
        }