private static List <Mesh> GenerateQuad(Vector2 topLeft, Vector2 topRight, Vector2 bottomLeft, Vector2 bottomRight) { Mesh mesh = new Mesh(); List <Mesh> meshList = new List <Mesh>(); mesh.vertices = new Vector3[] { VectorEx.Vec2ToVec3(topLeft), VectorEx.Vec2ToVec3(topRight), VectorEx.Vec2ToVec3(bottomRight), VectorEx.Vec2ToVec3(bottomLeft) }; mesh.uv = new Vector2[] { topLeft, topRight, bottomRight, bottomLeft }; mesh.triangles = new int[] { 0, 1, 3, 1, 2, 3 }; meshList.Add(mesh); return(meshList); }
void LateUpdate() { Vector2 playerDirection = VectorEx.Vec3ToVec2(playerTransform.position - transform.position).normalized; float playerDistance = Vector3.Distance(playerTransform.position, transform.position); Vector2 newPos = playerDirection * Easing.easeInExpo(0f, 0.50f, Mathf.InverseLerp(4f, 1f, playerDistance)); meshTransform.localPosition = VectorEx.Vec2ToVec3(newPos); }
void OnSceneGUI() { Transform targetTransform = editorTarget.transform; if (type == Type.PLANE) { Vector3[] outlinePoints = new Vector3[] { new Vector3(editorTarget.planeOutline.xMin, 0f, editorTarget.planeOutline.yMin), // Bottom left new Vector3(editorTarget.planeOutline.xMax, 0f, editorTarget.planeOutline.yMin), // Bottom right new Vector3(editorTarget.planeOutline.xMax, 0f, editorTarget.planeOutline.yMax), // Top right new Vector3(editorTarget.planeOutline.xMin, 0f, editorTarget.planeOutline.yMax), // Top left new Vector3(editorTarget.planeOutline.xMin, 0f, editorTarget.planeOutline.yMin) }; // Bottom left for (int i = 0; i < outlinePoints.Length; i++) // Convert all points to world space { outlinePoints[i] = editorTarget.transform.TransformPoint(outlinePoints[i]); } Handles.color = Color.blue; Handles.DrawAAPolyLine(1f, outlinePoints); Handles.color = Color.white; Vector3 newPos; newPos = new Vector3(editorTarget.planeOutline.xMin, 0f, editorTarget.planeOutline.yMin); newPos = Handles.Slider2D(editorTarget.transform.TransformPoint(newPos), targetTransform.up, targetTransform.forward, targetTransform.right, 0.2f * HandleUtility.GetHandleSize(newPos), Handles.CubeCap, 0f); newPos = editorTarget.transform.InverseTransformPoint(newPos); editorTarget.planeOutline.xMin = newPos.x; editorTarget.planeOutline.yMin = newPos.z; newPos = new Vector3(editorTarget.planeOutline.xMax, 0f, editorTarget.planeOutline.yMin); newPos = Handles.Slider2D(editorTarget.transform.TransformPoint(newPos), targetTransform.up, targetTransform.forward, targetTransform.right, 0.2f * HandleUtility.GetHandleSize(newPos), Handles.CubeCap, 0f); newPos = editorTarget.transform.InverseTransformPoint(newPos); editorTarget.planeOutline.xMax = newPos.x; editorTarget.planeOutline.yMin = newPos.z; newPos = new Vector3(editorTarget.planeOutline.xMax, 0f, editorTarget.planeOutline.yMax); newPos = Handles.Slider2D(editorTarget.transform.TransformPoint(newPos), targetTransform.up, targetTransform.forward, targetTransform.right, 0.2f * HandleUtility.GetHandleSize(newPos), Handles.CubeCap, 0f); newPos = editorTarget.transform.InverseTransformPoint(newPos); editorTarget.planeOutline.xMax = newPos.x; editorTarget.planeOutline.yMax = newPos.z; newPos = new Vector3(editorTarget.planeOutline.xMin, 0f, editorTarget.planeOutline.yMax); newPos = Handles.Slider2D(editorTarget.transform.TransformPoint(newPos), targetTransform.up, targetTransform.forward, targetTransform.right, 0.2f * HandleUtility.GetHandleSize(newPos), Handles.CubeCap, 0f); newPos = editorTarget.transform.InverseTransformPoint(newPos); editorTarget.planeOutline.xMin = newPos.x; editorTarget.planeOutline.yMax = newPos.z; } // Render lines and edit spheres for the shape Line2D[] outline = shapeOutline.GetOutline(); for (int i = 0; i < outline.Length; i++) { Line2D line = outline[i]; Vector3 start = targetTransform.TransformPoint(VectorEx.Vec2ToVec3(line.start)); Vector3 end = targetTransform.TransformPoint(VectorEx.Vec2ToVec3(line.end)); Handles.color = Color.white; Handles.DrawLine(start, end); Handles.color = Color.green; Vector3 buttonPos = Vector3.Lerp(start, end, 0.5f); if (Handles.Button(buttonPos, targetTransform.rotation, 0.15f * HandleUtility.GetHandleSize(buttonPos), 0.2f * HandleUtility.GetHandleSize(buttonPos), Handles.SphereCap)) { shapeOutline.InsertPointAtIndex(VectorEx.Vec3ToVec2(targetTransform.InverseTransformPoint(buttonPos)), i + 1); } } Vector2[] points = shapeOutline.GetPoints(); for (int i = 0; i < points.Length; i++) { Vector3 worldPos = targetTransform.TransformPoint(VectorEx.Vec2ToVec3(points[i])); Handles.color = Color.blue; Vector3 newPos = Handles.Slider2D(worldPos, targetTransform.up, targetTransform.forward, targetTransform.right, 0.25f * HandleUtility.GetHandleSize(worldPos), Handles.SphereCap, 1f); Vector3 deleteButtonPos = worldPos + QuaternionEx.GetRightVector(SceneView.lastActiveSceneView.rotation) * 0.15f * HandleUtility.GetHandleSize(worldPos) + QuaternionEx.GetUpVector(SceneView.lastActiveSceneView.rotation) * 0.15f * HandleUtility.GetHandleSize(worldPos); newPos = targetTransform.InverseTransformPoint(newPos); Vector2 newPos2D = VectorEx.Vec3ToVec2(newPos); if (!Mathf.Approximately(points[i].x, newPos2D.x) || !Mathf.Approximately(points[i].y, newPos2D.y)) { shapeOutline.SetPointAtIndex(newPos2D, i); } Handles.color = Color.red; if (Handles.Button(deleteButtonPos, targetTransform.rotation, 0.05f * HandleUtility.GetHandleSize(deleteButtonPos), 0.05f * HandleUtility.GetHandleSize(deleteButtonPos), Handles.DotCap)) { shapeOutline.RemovePointAtIndex(i); } } }