private void SetupSpriteShapeEditor() { m_ShapeEditor = new ShapeEditor() { //Data GetPosition = i => LocalToWorld(m_Spline.GetPosition(i)), SetPosition = (i, p) => m_Spline.SetPosition(i, WorldToLocal(p)), GetLeftTangent = i => LocalToWorld(m_Spline.GetLeftTangent(i) + m_Spline.GetPosition(i)) - LocalToWorld(m_Spline.GetPosition(i)), SetLeftTangent = (i, p) => m_Spline.SetLeftTangent(i, WorldToLocal(p + LocalToWorld(m_Spline.GetPosition(i))) - m_Spline.GetPosition(i)), GetRightTangent = i => LocalToWorld(m_Spline.GetRightTangent(i) + m_Spline.GetPosition(i)) - LocalToWorld(m_Spline.GetPosition(i)), SetRightTangent = (i, p) => m_Spline.SetRightTangent(i, WorldToLocal(p + LocalToWorld(m_Spline.GetPosition(i))) - m_Spline.GetPosition(i)), GetTangentMode = i => (ShapeEditor.TangentMode)m_Spline.GetTangentMode(i), SetTangentMode = (i, m) => m_Spline.SetTangentMode(i, (ShapeTangentMode)m), InsertPointAt = (i, p) => m_Spline.InsertPointAt(i, WorldToLocal(p)), RemovePointAt = i => m_Spline.RemovePointAt(i), GetPointCount = () => m_Spline.GetPointCount(), // Transforms ScreenToWorld = (p) => ScreenToWorld(p), LocalToWorldMatrix = () => Matrix4x4.identity, WorldToScreen = (p) => HandleUtility.WorldToGUIPoint(p), GetForwardVector = () => GetTransform().forward, GetUpVector = () => GetTransform().up, GetRightVector = () => GetTransform().right, // Other Snap = (p) => SnapPoint(p), RecordUndo = RecordUndo, OpenEnded = () => m_Spline.isOpenEnded, Repaint = m_CurrentEditor.Repaint }; }
private void HandleCreateNewOutline() { if (this.m_WasRectSelecting && !this.m_ShapeSelectionUI.isSelecting) { Rect?selectionRect = this.m_SelectionRect; if (selectionRect.HasValue && this.m_Selected != null) { bool flag = true; ShapeEditor[] shapeEditors = this.m_ShapeEditors; for (int i = 0; i < shapeEditors.Length; i++) { ShapeEditor shapeEditor = shapeEditors[i]; if (shapeEditor.selectedPoints.Count != 0) { flag = false; break; } } if (flag) { this.CreateNewOutline(this.m_SelectionRect.Value); } } } this.m_SelectionRect = null; }
public void InitShapeEditor() { m_ShapeEditor = new UnityEditor.U2D.ShapeEditor(); m_ShapeEditor.GetPosition = i => m_Points[i].m_Position; m_ShapeEditor.GetLeftTangent = i => m_Points[i].m_LeftTangent; m_ShapeEditor.GetRightTangent = i => m_Points[i].m_RightTangent; m_ShapeEditor.GetTangentMode = i => m_Points[i].m_Mode; m_ShapeEditor.GetPointCount = () => m_Points.Count; m_ShapeEditor.SetPosition = (i, vector3) => m_Points[i].m_Position = vector3; m_ShapeEditor.SetLeftTangent = (i, vector3) => m_Points[i].m_LeftTangent = vector3; m_ShapeEditor.SetRightTangent = (i, vector3) => m_Points[i].m_RightTangent = vector3; m_ShapeEditor.SetTangentMode = (i, mode) => m_Points[i].m_Mode = mode; m_ShapeEditor.ScreenToWorld = vector2 => new Vector3(vector2.x, vector2.y, 0); m_ShapeEditor.WorldToScreen = vector3 => new Vector2(vector3.x, vector3.y); m_ShapeEditor.RemovePointAt = i => m_Points.RemoveAt(i); m_ShapeEditor.InsertPointAt = (i, vector3) => m_Points.Insert(i, new ShapeEditorPoint(vector3, Vector3.zero, Vector3.zero, UnityEditor.U2D.ShapeEditor.TangentMode.Linear)); m_ShapeEditor.OpenEnded = () => openEnded; }
public void OnDisable() { m_ShapeEditor = null; }