// Update is called once per frame void Update() { if (updateCurve) { updateCurve = false; newPoints = CurveCreator.CreateCurve(GetPositions(), numberOfPoint, alpha); } }
public void OnSceneGUI() // for scene { curveCreator = target as CurveCreator; PointTr = curveCreator.transform; PointRot = Tools.pivotRotation == PivotRotation.Local ? PointTr.rotation : Quaternion.identity; Vector3 D0 = SetPoints(0); for (int i = 1; i < curveCreator.EvoPointCount; i += 3) { Vector3 D1 = SetPoints(i); Vector3 D2 = SetPoints(i + 1); Vector3 D3 = SetPoints(i + 2); Handles.color = Color.gray; Handles.DrawLine(D0, D1); Handles.DrawLine(D2, D3); Handles.DrawBezier(D0, D3, D1, D2, Color.green, null, 2f); D0 = D3; } Handles.Label(SetPoints(0), "Start"); Handles.Label(SetPoints(curveCreator.EvoPointCount - 1), "End"); if (GUI.changed) { EditorUtility.SetDirty(target); } if (showpath) // if need to show a points { if (curveCreator.SetOfPoints.Count >= 1) { for (int i = 1; i < curveCreator.SetOfPoints.Count; i++) { Handles.color = Color.red; Vector3 currOfPoint = curveCreator.SetOfPoints [i]; float sizeCap = HandleUtility.GetHandleSize(currOfPoint); Handles.SphereCap(curveCreator.SetOfPoints.Count + i, currOfPoint, PointRot, sizeCap * 0.07f); } } } }
public void MoveToHex() { paths = new List <Vector3>(); List <Hex> path = new List <Hex>(); List <Vector3> points = new List <Vector3>(); path.Add(moveToHex); points.Add(moveToHex.position); /* * Vector3 normal = Vector3.Normalize() * points.Add(moveToHex.position);*/ while (path.Count != 3) { HexPath nextHex = movableHexes[path[path.Count - 1]]; path.Add(nextHex.from); points.Add(nextHex.from.position); if (nextHex.from == hex) { break; } } Vector3 normal = Vector3.Normalize(points[1] - points[0]) * 2f; points.Insert(0, points[0] - normal); normal = Vector3.Normalize(points[points.Count - 1] - points[points.Count - 2]) * 2f; points.Add(points[points.Count - 1] + normal); paths.AddRange(points); List <Vector3> movingPoints = CurveCreator.CreateCurve(points, 3, Alpha.Uniform); StartCoroutine(nameof(MoveAnimation), movingPoints); movableHexes.Clear(); hex = moveToHex; moveToHex = null; }
private void OnEnable() { curveCreator = target as CurveCreator; selectionInfo = new SelectionInfo(); Tools.hidden = true; }
private bool showpath; // if need to show a points public override void OnInspectorGUI() // for inspector { DrawDefaultInspector(); EditorGUI.BeginChangeCheck(); curveCreator = target as CurveCreator; GUI.skin.box = StyleEditor; GUI.skin.button = StyleEditor; EditorGUILayout.BeginVertical(); GUILayout.Box(EditCurve); EditorGUILayout.Space(); if (GUILayout.Button(ButtonAdd)) { Undo.RecordObject(curveCreator, "Add"); curveCreator.AddToCurve(); EditorUtility.SetDirty(curveCreator); } EditorGUILayout.Space(); if (curveCreator.EvoPointCount > 4) { if (GUILayout.Button(ButtonDel)) { Undo.RecordObject(curveCreator, "Delete"); curveCreator.Delete(); EditorUtility.SetDirty(curveCreator); } } else { GUILayout.Box(ButtonCntDel); } GUILayout.Box(LengthCurve); EditorGUILayout.Space(); GUILayout.Box(" Intarval: " + CalcInterval.ToString()); EditorGUILayout.Space(); if (GUILayout.Button(Calculate)) { Undo.RecordObject(curveCreator, "Calculate"); curveCreator.CalculateLength(CalcInterval, PointTr); curveCreator.interval = CalcInterval; } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); showpath = GUILayout.Toggle(showpath, "Show path"); float length = curveCreator.LengthOfBezier; GUILayout.FlexibleSpace(); EditorGUILayout.BeginVertical(); GUILayout.Label("Length ~ " + length.ToString().Substring(0, length.ToString().Length - 3)); GUILayout.Label("Points : " + curveCreator.SetOfPoints.Count.ToString()); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); if (iIndex >= 0 && iIndex < curveCreator.EvoPointCount) { EditorGUILayout.BeginHorizontal(); GUILayout.Box(Other); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); OpenPointInspector(); } EditorGUILayout.EndVertical(); }
// Use this for initialization void Start() { newPoints = CurveCreator.CreateCurve(GetPositions(), numberOfPoint, alpha); }