public void Create() { Clear(); if (bezierPathDrawer == null) { return; } // draw BezierPath path = bezierPathDrawer.GetBezierPath(); pathLength = path.length; split = (pathLength / distance); float delta = 1.0f / split; for (int i = 0; i < split; i++) { float v = delta * i; BezierPointInfo pInfo = path.GetBezierPointInfo(v); // Hoop gObj = GameObject.Instantiate<Hoop>(hoopPrefab); GameObject gObj = ((GameObject)PrefabUtility.InstantiatePrefab(hoopPrefab)); gObj.transform.SetParent(hoopCourse.transform); gObj.transform.position = pInfo.point; gObj.transform.rotation = pInfo.rotation; gObj.gameObject.name = "Prot_" + i; } }
// Update is called once per frame void Update() { float ratio = dist / bezierPathDrawer.length; BezierPointInfo info = bezierPathDrawer.GetBezierPointInfo(ratio); //this.transform.position = info.point; //this.transform.rotation = info.rotation; info.point = bezierPathDrawer.transform.TransformPoint(info.point); info.rotation = bezierPathDrawer.transform.rotation * (info.rotation); this.transform.position = info.point; this.transform.rotation = info.rotation; }
// Update is called once per frame void Update() { if (target == null) { target = this.transform; } if (bezierPathDrawer != null && Application.isEditor && !Application.isPlaying) { path = bezierPathDrawer.path; } if (bezierPathDrawer == null || path == null || target == null) { return; } // update BezierPointInfo info = path.GetBezierPointInfo(ratio); target.transform.position = info.point; if (rotate) { target.transform.rotation = info.rotation; } }
// Update is called once per frame void OnDrawGizmos() { List <Quaternion> rotList = new List <Quaternion> (); for (int i = 0; i < bPoints.Count; i++) { BezierPt b = bPoints [i]; rotList.Add(b.transform.rotation); } List <Vector3> nodes = new List <Vector3> (); for (int i = 0; i < bPoints.Count - 1; i++) { BezierPt start = bPoints [i]; BezierPt end = bPoints [i + 1]; nodes.Add(start.transform.position); nodes.Add(end.inTrans.position); nodes.Add(start.outTrans.position); nodes.Add(end.transform.position); } path = new BezierPath(nodes.ToArray(), rotList.ToArray()); // draw float delta = 1.0f / split; Gizmos.color = drawColor; for (int i = 0; i < split - 1; i++) { float t0 = delta * i; float t1 = delta * (i + 1); Vector3 pos0 = this.GetPointAt(t0); Vector3 pos1 = this.GetPointAt(t1); Gizmos.DrawLine(pos0, pos1); } for (int i = 0; i < split; i++) { // float v = (float)i / split; float v = delta * i; BezierPointInfo pInfo = path.GetBezierPointInfo(v); Vector3 pt = pInfo.point; Gizmos.color = drawColor; Gizmos.DrawWireSphere(pt, 0.25f); // tangent Gizmos.color = Color.blue; Vector3 tangent = pInfo.tangent; Gizmos.DrawRay(pt, tangent); Quaternion quat = pInfo.rotation; Gizmos.color = Color.green; Gizmos.DrawRay(pt, quat * Vector3.up); Gizmos.color = Color.red; Gizmos.DrawRay(pt, quat * Vector3.right); } }
[SerializeField] public float _length = 0;// for Debug void OnDrawGizmos() { if (!isDrawGizmos) { return; } //if(Application.isPlaying){ return; } if (bPoints == null || bPoints.Count < 2) { return; } bool isChange = false; // -------- // delete point for (int i = bPoints.Count - 1; i >= 0; i--) { BezierPt b = bPoints [i]; if (b == null) { bPoints.RemoveAt(i); isChange = true; } } // transformの変更検知 for (int i = 0; i < bPoints.Count; i++) { BezierPt b = bPoints[i]; if (b.isTransformChange) { isChange = true; break; } } // -------- // updatePath if (isChange || path == null) { path = GetBezierPath(precision); } // -------- // draw float delta = 1.0f / split; Gizmos.color = drawColor; for (int i = 0; i < split - 1; i++) { if (i % 2 == 0) { float t0 = delta * i; float t1 = delta * (i + 1); Vector3 pos0 = GetPointAt(t0); Vector3 pos1 = GetPointAt(t1); Gizmos.DrawLine(pos0, pos1); } } if (isDrawPoints) { // point and tangent for (int i = 0; i < split; i++) { float v = delta * i; BezierPointInfo pInfo = GetBezierPointInfo(v); Vector3 pt = pInfo.point; Gizmos.color = drawColor; Gizmos.DrawWireSphere(pt, 0.25f); // tangent Gizmos.color = Color.blue; Vector3 tangent = pInfo.tangent; Gizmos.DrawRay(pt, tangent); Quaternion quat = pInfo.rotation; Gizmos.color = Color.green; Gizmos.DrawRay(pt, quat * Vector3.up); Gizmos.color = Color.red; Gizmos.DrawRay(pt, quat * Vector3.right); } } }