private void OnEnable() { MapPolygon path = (MapPolygon)target; if (path.GetVertsRaw().Count == 0) { path.AddPointAt(0, Vector3.zero); path.AddPointAt(0, new Vector3(1f, 0f, 1f)); path.AddPointAt(0, Vector3.right); path.Init(); } selectedPoints.Clear(); LoadTextures(); }
private void DoNormalModeHandles(MapPolygon path, int i, Matrix4x4 mat, Matrix4x4 invMat, Transform camTransform) { List <Vector3> pathVerts = path.GetVertsRaw(); int nextId = i == path.GetVertsRaw().Count - 1?0:i + 1; Vector3 pos = mat.MultiplyPoint3x4(pathVerts[i]); Vector3 posNext = mat.MultiplyPoint3x4(pathVerts[nextId]); bool isSelected = false; if (selectedPoints != null) { isSelected = selectedPoints.Contains(i); } // check for moving the point Handles.DrawCapFunction cap = CapDot; cap = isSelected ? (Handles.DrawCapFunction)CapDotSelected : (Handles.DrawCapFunction)CapDot; Vector3 result = Handles.FreeMoveHandle(pos, Quaternion.Euler(Vector3.zero), HandleScale(pos), snap, cap); Handles.Label(pos, i.ToString(), EditorStyles.boldLabel); if (result != pos) { EnsureVertSelected(i, ref isSelected); for (int s = 0; s < selectedPoints.Count; s++) { path.UpdateVerts(selectedPoints [s], invMat.MultiplyPoint3x4(result)); //pathVerts [selectedPoints [s]] = invMat.MultiplyPoint3x4 (result); } } // make sure we can add new point at the midpoints!s Vector3 mid = (pos + posNext) / 2f; float handleScale = HandleScale(mid); if (Handles.Button(mid, camTransform.rotation, handleScale, handleScale, CapDotPlus)) { Vector3 pt = invMat.MultiplyPoint3x4(mid); path.AddPointAt(nextId, pt); } }