private static Vector2 Snap(Vector2 aOriginalPoint, Vector2 aNewPoint, Matrix4x4 aTransform, Matrix4x4 aInvTransform, PathSnap aSnapMode = PathSnap.Unity) { Vector2 result = aNewPoint; if (!Event.current.control) { return(result); } Vector3 snap = EditorTools.GetUnitySnap(); if (aSnapMode == PathSnap.Local) { result = SnapVector(aNewPoint, snap); } if (aSnapMode == PathSnap.World) { result = aInvTransform.MultiplyPoint(SnapVector(aTransform.MultiplyPoint(aNewPoint), snap)); } if (aSnapMode == PathSnap.Relative) { result = aOriginalPoint + SnapVector(aNewPoint - aOriginalPoint, snap); } return(result); }
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); } }
private static void CreateSuperCube() { GameObject obj = new GameObject("SuperCube"); obj.AddComponent <BoxCollider>(); obj.AddComponent <SuperCube>().Build(true); obj.GetComponent <Renderer>().sharedMaterial = EditorTools.GetDefaultMaterial(); Vector3 snap = EditorTools.GetUnitySnap(); obj.transform.position = SuperCubeEditorUtil.SnapVector(SuperCubeEditorUtil.GetSpawnPos() + new Vector3(0, 0.5f, 0), snap); Selection.activeGameObject = obj; EditorGUIUtility.PingObject(obj); }
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); }