void ReCalcBezier() { BezierCreater bc = target as BezierCreater; bc.points.Clear(); bc.length = 0; List <Vector3> plist = new List <Vector3>(); Vector3 prevPos; for (int i = 0; i < bc.bcList.Count - 1; i++) { BezierCreater.PointPart pp = new BezierCreater.PointPart(); plist.Clear(); //plist.Add(bc.bcList[i].point + bc.bcList[i].lp); plist.Add(bc.bcList[i].point); if (bc.bcList[i].rp != Vector3.zero) { plist.Add(bc.bcList[i].point + bc.bcList[i].rp); } if (bc.bcList[i + 1].lp != Vector3.zero) { plist.Add(bc.bcList[i + 1].point + bc.bcList[i + 1].lp); } plist.Add(bc.bcList[i + 1].point); //plist.Add(bc.bcList[i + 1].point + bc.bcList[i + 1].rp); CalcBeizer(plist, pp); bc.points.Add(pp); bc.length += pp.length; } }
void FixedUpdate() { if (path == null) { return; } _dt += Time.deltaTime; _dt = Mathf.Min(_dt, duration); float rt = _dt / duration; if (curve != null) { rt = curve.Evaluate(rt); } Vector3 pos = path.GetPointAtRate(rt); transform.localPosition = pos; if (lookAt != null) { transform.LookAt(lookAt); } if (rt == 1) { path = null; } }
public GoTweenConfig positionOnPath(BezierCreater path, bool isRelative = false) { var prop = new PositionBezierPathTweenProperty(path, isRelative); _tweenProperties.Add(prop); return(this); }
bool MouseLogic() { bool repaint = false; BezierCreater bc = target as BezierCreater; if (Event.current.isMouse) { if (Event.current.type == EventType.MouseDown) { foreach (BezierCreater.BCPoint p in bc.bcList) { Vector3 pos = bc.SrcPosition + p.point; Vector3 poslp = pos + p.lp; Vector3 posrp = pos + p.rp; Vector3 posOnGUI = HandleUtility.WorldToGUIPoint(pos); if (Vector3.Distance(Event.current.mousePosition, posOnGUI) < _capSize * 100) { if (!Event.current.shift) { foreach (BezierCreater.BCPoint p2 in bc.bcList) { p2.selected = false; p2.selectedlp = false; p2.selectedrp = false; } } p.selected = true; //Tools.current = Tool.View; } else if (isInBox(Event.current.mousePosition, HandleUtility.WorldToGUIPoint(poslp), Vector3.one * _subCapSize * 1000)) { foreach (BezierCreater.BCPoint p2 in bc.bcList) { p2.selected = false; p2.selectedlp = false; p2.selectedrp = false; } p.selectedlp = true; //Tools.current = Tool.View; } else if (isInBox(Event.current.mousePosition, HandleUtility.WorldToGUIPoint(posrp), Vector3.one * _subCapSize * 1000)) { foreach (BezierCreater.BCPoint p2 in bc.bcList) { p2.selected = false; p2.selectedlp = false; p2.selectedrp = false; } p.selectedrp = true; //Tools.current = Tool.View; } } } } return(repaint); }
void BCSelectNone() { BezierCreater bc = target as BezierCreater; foreach (BezierCreater.BCPoint bp in bc.bcList) { bp.selected = false; bp.selectedlp = false; bp.selectedrp = false; } }
public PositionBezierPathTweenProperty(BezierCreater path, bool isRelative = false) { _path = path; }
public static GoTween positionOnPath(this Transform self, float duration, BezierCreater path, bool isRelative = false) { return(Go.to(self, duration, new GoTweenConfig().positionOnPath(path, isRelative))); }
void ShowDefault() { BezierCreater bc = target as BezierCreater; bool repaint = false; GUILayout.Label("总长度: " + bc.length); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("标记大小"); float ival = EditorGUILayout.Slider(_capSize, 0.02f, 1f); if (ival != _capSize) { _capSize = ival; repaint = true; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("平滑度"); ival = EditorGUILayout.Slider(_srate, 0.1f, 1f); if (ival != _srate) { _srate = ival; repaint = true; } EditorGUILayout.EndHorizontal(); bool bval = EditorGUILayout.ToggleLeft("位置测试", _showToggleTest, GUILayout.Width(60)); if (bval != _showToggleTest) { _showToggleTest = bval; repaint = true; _cameraRot = Camera.main.transform.rotation.eulerAngles; } if (_showToggleTest) { _cameraRot = EditorGUILayout.Vector3Field("摄像机角度", _cameraRot); _cameraLookAt = EditorGUILayout.ObjectField("观察目标", _cameraLookAt, typeof(Transform), true) as Transform; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("自动速度"); _showTestAuto = EditorGUILayout.Slider(_showTestAuto, 0, 2); EditorGUILayout.EndHorizontal(); if (_showTestAuto > 0) { SceneView.RepaintAll(); repaint = true; } ival = EditorGUILayout.Slider(_posTest, 0.0f, 1f); if (ival != _posTest) { _posTest = ival; repaint = true; } } bval = EditorGUILayout.ToggleLeft("锁定位置", _isLockPosition); if (bval != _isLockPosition) { _isLockPosition = bval; _lockPosition = bc.transform.position; } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("新路点")) { BezierCreater.BCPoint nbp = new BezierCreater.BCPoint(); bc.bcList.Add(nbp); BCSelectNone(); nbp.selected = true; repaint = true; } if (GUILayout.Button("全选")) { BCSelectNone(); foreach (BezierCreater.BCPoint p in bc.bcList) { p.selected = true; } repaint = true; } if (GUILayout.Button("全不选")) { BCSelectNone(); repaint = true; } EditorGUILayout.EndHorizontal(); int delIdx = -1; int moveUpIdx = -1; int moveDownIdx = -1; for (int i = 0; i < bc.bcList.Count; i++) { Rect rect = EditorGUILayout.BeginHorizontal(); if (bc.bcList[i].selected || bc.bcList[i].selectedlp || bc.bcList[i].selectedrp) { rect.size = new Vector2(rect.size.x, rect.size.y * 2 + 5); EditorGUI.DrawRect(rect, Color.blue); } else { EditorGUI.DrawRect(rect, Color.black); } bool val = EditorGUILayout.ToggleLeft("", bc.bcList[i].selected, GUILayout.Width(15)); if (val != bc.bcList[i].selected) { if (!Event.current.shift) { BCSelectNone(); } bc.bcList[i].selected = val; repaint = true; } Vector3 newpos = EditorGUILayout.Vector3Field("", bc.bcList[i].point); if (newpos != bc.bcList[i].point) { bc.bcList[i].point = newpos; repaint = true; } val = GUILayout.Toggle(bc.bcList[i].locklr, "对称锁定"); if (val != bc.bcList[i].locklr) { bc.bcList[i].locklr = val; bc.bcList[i].rp = -bc.bcList[i].lp; repaint = true; } if (bc.bcList[i].selected || bc.bcList[i].selectedlp || bc.bcList[i].selectedrp) { EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("↑", GUILayout.Width(20))) { moveUpIdx = i; repaint = true; } if (GUILayout.Button("↓", GUILayout.Width(20))) { moveDownIdx = i; repaint = true; } if (GUILayout.Button("无弧度", GUILayout.Width(50))) { bc.bcList[i].lp = Vector3.zero; bc.bcList[i].rp = Vector3.zero; repaint = true; } if (GUILayout.Button("左右", GUILayout.Width(40))) { SetSwapLR(bc.bcList[i], Vector3.left); repaint = true; } if (GUILayout.Button("上下", GUILayout.Width(40))) { SetSwapLR(bc.bcList[i], Vector3.up); repaint = true; } if (GUILayout.Button("前后", GUILayout.Width(40))) { SetSwapLR(bc.bcList[i], Vector3.forward); repaint = true; } if (GUILayout.Button("删除", GUILayout.Width(40))) { if (EditorUtility.DisplayDialog("删除节点", "要删除这个节点吗?", "是", "否")) { BCSelectNone(); delIdx = i; repaint = true; } } if (GUILayout.Button("复制", GUILayout.Width(40))) { BezierCreater.BCPoint nbp = new BezierCreater.BCPoint(); nbp.point = bc.bcList[i].point; bc.bcList.Add(nbp); BCSelectNone(); nbp.selected = true; repaint = true; } } if (i == 0) { bc.bcList[i].lp = Vector3.zero; } if (i == bc.bcList.Count - 1) { bc.bcList[i].rp = Vector3.zero; } EditorGUILayout.EndHorizontal(); } if (moveUpIdx > 0) { BezierCreater.BCPoint bp = bc.bcList[moveUpIdx]; bc.bcList.RemoveAt(moveUpIdx); bc.bcList.Insert(moveUpIdx - 1, bp); } if (moveDownIdx >= 0 && moveDownIdx < bc.bcList.Count - 1) { BezierCreater.BCPoint bp = bc.bcList[moveDownIdx]; bc.bcList.RemoveAt(moveDownIdx); bc.bcList.Insert(moveDownIdx + 1, bp); } if (delIdx >= 0) { bc.bcList.RemoveAt(delIdx); } if (GUILayout.Button("Save")) { repaint = true; } showDefault = EditorGUILayout.Foldout(showDefault, "原始信息"); if (showDefault) { base.DrawDefaultInspector(); } if (repaint) { EditorUtility.SetDirty(target); SceneView.RepaintAll(); ReCalcBezier(); } }
public void OnSceneGUI() { bool repaint = false; //repaint = MouseLogic(); BezierCreater bc = target as BezierCreater; Vector3 pmove = Vector3.zero; foreach (BezierCreater.BCPoint p in bc.bcList) { Vector3 pos = bc.SrcPosition + p.point; Vector3 poslp = pos + p.lp; Vector3 posrp = pos + p.rp; // 绘制修正点 if (p.selected || p.selectedlp || p.selectedrp) { Handles.color = p.selectedlp ? Color.red : Color.blue; if (Handles.Button(poslp, Quaternion.identity, _subCapSize, _subCapSize, Handles.DotCap)) { if (!Event.current.shift) { p.selected = false; p.selectedrp = false; } p.selectedlp = true; } Handles.DrawLine(poslp, pos); Handles.color = p.selectedrp ? Color.red : Color.green; if (Handles.Button(posrp, Quaternion.identity, _subCapSize, _subCapSize, Handles.DotCap)) { if (!Event.current.shift) { p.selected = false; p.selectedlp = false; } p.selectedrp = true; } Handles.DrawLine(posrp, pos); } // 绘制标准点 Handles.color = p.selected ? Color.red : Color.white; if (Handles.Button(pos, Quaternion.identity, _capSize, _capSize, Handles.SphereCap)) { if (!Event.current.shift) { BCSelectNone(); } p.selected = true; } if (p.selectedlp || p.selectedrp) { Handles.color = Color.red * 0.5f; } if (p.selected) { Vector3 npos = Handles.DoPositionHandle(pos, Quaternion.identity); if (npos != pos) { pmove = npos - pos; repaint = true; } } else if (p.selectedlp) { Vector3 npos = Handles.DoPositionHandle(poslp, Quaternion.identity); if (npos != poslp) { pmove = npos - poslp; p.lp += pmove; if (p.locklr) { p.rp = -p.lp; } repaint = true; } } else if (p.selectedrp) { Vector3 npos = Handles.DoPositionHandle(posrp, Quaternion.identity); if (npos != posrp) { pmove = npos - posrp; p.rp += pmove; if (p.locklr) { p.lp = -p.rp; } repaint = true; } } } if (pmove != Vector3.zero) { foreach (BezierCreater.BCPoint p in bc.bcList) { if (p.selected) { p.point += pmove; } } } if (_isLockPosition) { bc.transform.position = _lockPosition; } if (_showToggleTest) { if (_showTestAuto > 0) { _posTest += Time.deltaTime * _showTestAuto; _posTest = _posTest % 1; SceneView.RepaintAll(); } Handles.color = Color.blue; Vector3 pos = bc.GetPointAtRate(_posTest); Handles.SphereCap(0, pos, Quaternion.identity, _capSize); if (Camera.main != null) { Camera.main.transform.position = pos; if (_cameraLookAt != null) { Camera.main.transform.LookAt(_cameraLookAt); } } } if (repaint) { SceneView.RepaintAll(); ReCalcBezier(); } }
public void Play(int i = 0) { path = paths[i]; curve = curves[i]; _dt = 0; }