Пример #1
0
        private static void TransformHandles(SuperPlane aPlane, Vector3 rtb, Vector3 lbf)
        {
            Vector3 snap = EditorTools.GetUnitySnap();

            EditorTools.capDir = Matrix4x4.TRS(Vector3.zero, aPlane.transform.rotation, Vector3.one);

            Handles.color = Color.Lerp(Color.red, Color.white, 0.5f);
            SuperCubeEditorUtil.Handle(PivotType.Right, aPlane.transform, true, false, false, snap, ref lbf, ref rtb, EditorTools.BarCapZ);
            SuperCubeEditorUtil.Handle(PivotType.Left, aPlane.transform, true, false, false, snap, ref lbf, ref rtb, EditorTools.BarCapZ);

            Handles.color = Color.Lerp(Color.blue, Color.white, 0.5f);
            SuperCubeEditorUtil.Handle(PivotType.Front, aPlane.transform, false, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapX);
            SuperCubeEditorUtil.Handle(PivotType.Back, aPlane.transform, false, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapX);

            Handles.color = Color.Lerp(Color.Lerp(Color.red, Color.white, 0.5f), Color.Lerp(Color.blue, Color.white, 0.5f), .5f);
            SuperCubeEditorUtil.Handle(PivotType.Back | PivotType.Right, aPlane.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapXZ);
            SuperCubeEditorUtil.Handle(PivotType.Back | PivotType.Left, aPlane.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapXZ);
            SuperCubeEditorUtil.Handle(PivotType.Front | PivotType.Right, aPlane.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapXZ);
            SuperCubeEditorUtil.Handle(PivotType.Front | PivotType.Left, aPlane.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapXZ);

            // Check if there was an edit, and update the mesh!
            Vector3 newExtents = new Vector3(Mathf.Abs(rtb.x - lbf.x), Mathf.Abs(rtb.y - lbf.y), Mathf.Abs(rtb.z - lbf.z));

            if (aPlane.Extents != newExtents)
            {
                aPlane.transform.position += aPlane.transform.TransformDirection(lbf + new Vector3((rtb.x - lbf.x) / 2, (rtb.y - lbf.y) / 2, (rtb.z - lbf.z) / 2));
                aPlane.Extents             = newExtents;
                aPlane.Build(true);
            }
        }
Пример #2
0
        private static bool TransformHandles(SuperCube aBox, Vector3 aRtb, Vector3 aLbf)
        {
            Vector3 rtb     = aRtb;
            Vector3 lbf     = aLbf;
            Vector3 snap    = EditorTools.GetUnitySnap();
            bool    rebuild = false;

            EditorTools.capDir = Matrix4x4.TRS(Vector3.zero, aBox.transform.rotation, Vector3.one);

            // Bottom
            Handles.color = Color.Lerp(Color.green, Color.white, 0.5f);
            SuperCubeEditorUtil.Handle(PivotType.Bottom, aBox.transform, false, true, false, snap, ref lbf, ref rtb, EditorTools.ArrowCapYN);
            Handles.color = Color.Lerp(Color.red, Color.white, 0.5f);
            SuperCubeEditorUtil.Handle(PivotType.Right, aBox.transform, true, false, false, snap, ref lbf, ref rtb, EditorTools.ArrowCapXP);
            SuperCubeEditorUtil.Handle(PivotType.Left, aBox.transform, true, false, false, snap, ref lbf, ref rtb, EditorTools.ArrowCapXN);
            Handles.color = Color.Lerp(Color.blue, Color.white, 0.5f);
            SuperCubeEditorUtil.Handle(PivotType.Back, aBox.transform, false, false, true, snap, ref lbf, ref rtb, EditorTools.ArrowCapZP);
            SuperCubeEditorUtil.Handle(PivotType.Front, aBox.transform, false, false, true, snap, ref lbf, ref rtb, EditorTools.ArrowCapZN);
            Handles.color = Color.Lerp(Color.green, Color.white, 0.5f);
            SuperCubeEditorUtil.Handle(PivotType.Top, aBox.transform, false, true, false, snap, ref lbf, ref rtb, EditorTools.ArrowCapYP);

            if (!SuperCubeSettings.HideYRing)
            {
                Handles.color = Color.Lerp(Color.Lerp(Color.red, Color.white, 0.5f), Color.Lerp(Color.blue, Color.white, 0.5f), .5f);
                SuperCubeEditorUtil.Handle(PivotType.Back | PivotType.Right, aBox.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapY);
                SuperCubeEditorUtil.Handle(PivotType.Back | PivotType.Left, aBox.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapY);
                SuperCubeEditorUtil.Handle(PivotType.Front | PivotType.Right, aBox.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapY);
                SuperCubeEditorUtil.Handle(PivotType.Front | PivotType.Left, aBox.transform, true, false, true, snap, ref lbf, ref rtb, EditorTools.BarCapY);
            }

            if (!SuperCubeSettings.HideZRing)
            {
                Handles.color = Color.Lerp(Color.Lerp(Color.red, Color.white, 0.5f), Color.Lerp(Color.green, Color.white, 0.5f), .5f);
                SuperCubeEditorUtil.Handle(PivotType.Left | PivotType.Top, aBox.transform, true, true, false, snap, ref lbf, ref rtb, EditorTools.BarCapZ);
                SuperCubeEditorUtil.Handle(PivotType.Left | PivotType.Bottom, aBox.transform, true, true, false, snap, ref lbf, ref rtb, EditorTools.BarCapZ);
                SuperCubeEditorUtil.Handle(PivotType.Right | PivotType.Top, aBox.transform, true, true, false, snap, ref lbf, ref rtb, EditorTools.BarCapZ);
                SuperCubeEditorUtil.Handle(PivotType.Right | PivotType.Bottom, aBox.transform, true, true, false, snap, ref lbf, ref rtb, EditorTools.BarCapZ);
            }

            if (!SuperCubeSettings.HideXRing)
            {
                Handles.color = Color.Lerp(Color.Lerp(Color.blue, Color.white, 0.5f), Color.Lerp(Color.green, Color.white, 0.5f), .5f);
                SuperCubeEditorUtil.Handle(PivotType.Front | PivotType.Top, aBox.transform, false, true, true, snap, ref lbf, ref rtb, EditorTools.BarCapX);
                SuperCubeEditorUtil.Handle(PivotType.Front | PivotType.Bottom, aBox.transform, false, true, true, snap, ref lbf, ref rtb, EditorTools.BarCapX);
                SuperCubeEditorUtil.Handle(PivotType.Back | PivotType.Top, aBox.transform, false, true, true, snap, ref lbf, ref rtb, EditorTools.BarCapX);
                SuperCubeEditorUtil.Handle(PivotType.Back | PivotType.Bottom, aBox.transform, false, true, true, snap, ref lbf, ref rtb, EditorTools.BarCapX);
            }

            // Check if there was an edit, and notify an update to the mesh!
            Vector3 newExtents = new Vector3(Mathf.Abs(rtb.x - lbf.x), Mathf.Abs(rtb.y - lbf.y), Mathf.Abs(rtb.z - lbf.z));

            if (aBox.SliceFaces)
            {
                float maxSize = SuperCubeSettings.MaxSize;
                if (newExtents.x > maxSize)
                {
                    newExtents.x = aBox.Extents.x; lbf.x = aLbf.x; rtb.x = aRtb.x;
                }
                if (newExtents.y > maxSize)
                {
                    newExtents.y = aBox.Extents.y; lbf.y = aLbf.y; rtb.y = aRtb.y;
                }
                if (newExtents.z > maxSize)
                {
                    newExtents.z = aBox.Extents.z; lbf.z = aLbf.z; rtb.z = aRtb.z;
                }
            }
            if (aBox.Extents != newExtents)
            {
                aBox.transform.position += aBox.transform.TransformDirection(lbf + new Vector3((rtb.x - lbf.x) / 2, (rtb.y - lbf.y) / 2, (rtb.z - lbf.z) / 2));
                aBox.Extents             = newExtents;
                rebuild = true;
            }

            return(rebuild);
        }