Beispiel #1
0
        ///     2 ------------- 3
        ///   /               /
        ///  1 ------------ 4
        public static GravityOverrideQuad DrawQuadWithBorders(ExtQuad quad, GravityOverrideQuad quadGravity, Color color, out bool hasChanged)
        {
            hasChanged = false;
            bool changed = hasChanged;

            float sizeLine  = quad.LocalScale.magnitude / 35;
            float sizePoint = quad.LocalScale.magnitude / 30;

            Color colorFace = new Color(color.r, color.g, color.b, color.a * 0.5f);
            Color colorLine = new Color(color.r, color.g, color.b, color.a * 0.8f);

            quadGravity.Face1 = DrawQuadFace(quad, quadGravity.Face1, quad.AllowBottom, colorFace, out changed);     hasChanged = (changed) ? true : hasChanged;

            quadGravity.Line1 = ExtGravityOverrideEditor.DrawLineTrunk(quadGravity.Line1, quad.P1, quad.P2, colorLine, sizeLine, out changed);    hasChanged = (changed) ? true : hasChanged;
            quadGravity.Line2 = ExtGravityOverrideEditor.DrawLineTrunk(quadGravity.Line2, quad.P2, quad.P3, colorLine, sizeLine, out changed);    hasChanged = (changed) ? true : hasChanged;
            quadGravity.Line3 = ExtGravityOverrideEditor.DrawLineTrunk(quadGravity.Line3, quad.P3, quad.P4, colorLine, sizeLine, out changed);    hasChanged = (changed) ? true : hasChanged;
            quadGravity.Line4 = ExtGravityOverrideEditor.DrawLineTrunk(quadGravity.Line4, quad.P4, quad.P1, colorLine, sizeLine, out changed);    hasChanged = (changed) ? true : hasChanged;

            quadGravity.Point1 = ExtGravityOverrideEditor.DrawPoint(quadGravity.Point1, quad.P1, color, sizePoint, out changed);  hasChanged = (changed) ? true : hasChanged;
            quadGravity.Point2 = ExtGravityOverrideEditor.DrawPoint(quadGravity.Point2, quad.P2, color, sizePoint, out changed);  hasChanged = (changed) ? true : hasChanged;
            quadGravity.Point3 = ExtGravityOverrideEditor.DrawPoint(quadGravity.Point3, quad.P3, color, sizePoint, out changed);  hasChanged = (changed) ? true : hasChanged;
            quadGravity.Point4 = ExtGravityOverrideEditor.DrawPoint(quadGravity.Point4, quad.P4, color, sizePoint, out changed);  hasChanged = (changed) ? true : hasChanged;

            return(quadGravity);
        }
Beispiel #2
0
        public static bool DrawQuadFace(ExtQuad quad, bool face, bool allowBottom, Color color, out bool hasChanged)
        {
            hasChanged = false;

            float scaleRect = quad.LocalScale.magnitude;
            float xScale    = quad.LenghtX / 2;
            float yScale    = quad.LenghtY / 2;


            Matrix4x4 scaleMatrix = Matrix4x4.TRS(quad.Position, quad.Rotation, new Vector3(xScale, 1, yScale));

            using (new Handles.DrawingScope(scaleMatrix))
            {
                Vector3 up = scaleMatrix.ExtractRotation() * Vector3.up;
                bool    isCameraViewBehindFace = Vector3.Dot(ExtSceneView.GetSceneViewCameraTransform().forward, up) > 0 && !allowBottom;

                Handles.color = (isCameraViewBehindFace) ? new Color(color.r, color.g, color.b, color.a / 2f) : color;

                float     scale = 1f;
                Vector3[] verts = new Vector3[]
                {
                    new Vector3(-scale, 0, -scale),
                    new Vector3(-scale, 0, +scale),
                    new Vector3(+scale, 0, +scale),
                    new Vector3(+scale, 0, -scale)
                };

                if (!face)
                {
                    Handles.DrawSolidRectangleWithOutline(verts, Handles.color, Color.clear);
                }

                Quaternion rotation = Quaternion.identity * Quaternion.LookRotation(Vector3.up);


                if (!Event.current.alt && Event.current.button != 2 && Handles.Button(
                        Vector3.zero,
                        Quaternion.identity * Quaternion.LookRotation(Vector3.up),
                        1,
                        1,
                        Handles.RectangleHandleCap))
                {
                    if (isCameraViewBehindFace)
                    {
                        Debug.Log("not behind face");
                        return(false);
                    }
                    Debug.Log("face pressed");
                    face       = !face;
                    hasChanged = true;
                    Use();
                }
            }
            return(face);
        }
 public override void Construct()
 {
     _quad = new ExtQuad(transform.position,
                         transform.rotation,
                         transform.lossyScale);
 }