public void updateIndicatorMesh() { if (hideIndicator || pathArray == null) { this.GetComponent <MeshRenderer>().enabled = false; } else { this.GetComponent <MeshRenderer>().enabled = true; pathArray.CalculatePath(); selectionIndicatorPath.pathArray = pathArray; selectionIndicatorPath.generate(); this.GetComponent <MeshFilter>().mesh = selectionIndicatorPath.mesh; } }
public void calculatePath() { float currentPercentage = 0; if (arrowPathType == ArrowPathType.PathArray) { pathArray.CalculatePath(); fullPath = pathArray.path; pathLength = pathArray.maxPathLength; return; } fullPath = new List <Vector3>(); //Uses the path array to create the path, but removes duplicates and adds aditional points for levelofdetail>1 if (arrowPathType == ArrowPathType.PointArray) { pathLength = 0; Vector3 firstPathPoint = editedPath[0]; Vector3 secondPathPoint; fullPath.Add(firstPathPoint); currentPercentage += 1.0f / levelOfDetailAlongPath; for (int i = 1; i < editedPath.Count; i++) { if ((editedPath[i] - editedPath[i - 1]).magnitude < errorRate) { continue; } secondPathPoint = editedPath[i]; while (true) { if (currentPercentage + 1.0f / levelOfDetailAlongPath >= 1.0f) { if ((secondPathPoint - firstPathPoint).magnitude > errorRate) { fullPath.Add(secondPathPoint); } currentPercentage = 1.0f / levelOfDetailAlongPath; break; } if ((secondPathPoint - firstPathPoint).magnitude > errorRate) { fullPath.Add(firstPathPoint + currentPercentage * (secondPathPoint - firstPathPoint)); } currentPercentage += 1.0f / levelOfDetailAlongPath; } pathLength += (secondPathPoint - firstPathPoint).magnitude; firstPathPoint = secondPathPoint; } return; } //Sets default path function validateAnimationFunction(pathAlongXFunction, 0, 0); validateAnimationFunction(pathAlongYFunction, 0, 0); validateAnimationFunction(pathAlongZFunction, 0, 0); currentPercentage = 0; //Sets the first point Vector3 pointerDirection = endPoint - startPoint; fullPath.Add(startPoint + new Vector3(pathAlongXFunction.Evaluate(0), pathAlongYFunction.Evaluate(0), pathAlongZFunction.Evaluate(0))); pathLength = 0; int[] currentKey = new int[3] { 0, 0, 0 }; int currentKeyIndex = -1; float lastPathDifference = 0; //Calculates next point increasePathPercentage(ref currentKeyIndex, ref currentPercentage, ref currentKey); while (true) { Vector3 pathItem; if (currentPercentage >= 1.0f) { pathItem = endPoint + new Vector3(pathAlongXFunction.Evaluate(pathAlongXFunctionLength), pathAlongYFunction.Evaluate(pathAlongYFunctionLength), pathAlongZFunction.Evaluate(pathAlongZFunctionLength)); lastPathDifference = (fullPath[fullPath.Count - 1] - pathItem).magnitude; if (lastPathDifference > errorRate) { fullPath.Add(pathItem); } pathLength += lastPathDifference; break; } pathItem = startPoint + currentPercentage * pointerDirection + new Vector3(pathAlongXFunction.Evaluate(currentPercentage * pathAlongXFunctionLength), pathAlongYFunction.Evaluate(currentPercentage * pathAlongYFunctionLength), pathAlongZFunction.Evaluate(currentPercentage * pathAlongZFunctionLength)); lastPathDifference = (fullPath[fullPath.Count - 1] - pathItem).magnitude; if (lastPathDifference > errorRate) { fullPath.Add(pathItem); } pathLength += lastPathDifference; increasePathPercentage(ref currentKeyIndex, ref currentPercentage, ref currentKey); } }