private void RunPrimitive(MovementPrimitive current) { UpdateDeltaDuration(current); if (current.path == Type.Line) { MoveAlongLineSegment(current.startPoint, current.endPoint, current.startTime, current.duration + current.timeDeltaSum); } else if (current.path == Type.Curve) { MoveAlongCurve(current.startPoint, current.endPoint, current.curveDepth, current.startTime, current.duration + current.timeDeltaSum); } else if (current.path == Type.Circle) { MoveAlongCircle(current.startPoint, current.endPoint, current.startTime, current.duration + current.timeDeltaSum, current.circleCenter, current.rotationAngle, current.radius, current.ccw); } else if (current.path == Type.Sine) { MoveAlongSineWave(current.startPoint, current.endPoint, current.startTime, current.duration + current.timeDeltaSum, current.amplitude, current.frequency, current.phase); } else if (current.path == Type.Wait) { entity.transform.position = current.startPoint; } }
private string StringifyMovement() { string buffer = ""; buffer += (MovementPrimitive.FirstLine()) + '\n'; foreach (var item in movementPrimitivesList) { buffer += (item.GetFullState() + '\n'); } buffer += ("PERIODIC|" + periodic + '\n'); buffer += ("REPETITIONS|" + repetitions + '\n'); return(buffer); }
/// <summary> /// Update this instance movement. Must be called from Monobehaviour::Update() /// </summary> public void Update() { if (!running) { return; } MovementPrimitive current = movementPrimitivesList [currentMovementidx]; if (Time.time >= (current.startTime + current.duration)) // time to go to next movement primitive { if (currentMovementidx == movementPrimitivesList.Count - 1) { if (periodic) { this.resetState(); } else { if (this.repetitions > 1) { repetitions--; this.resetState(); } else { running = false; } } } else { currentMovementidx++; } current = movementPrimitivesList[currentMovementidx]; } if (trail) { //instantiate a marker from prefab and put it here GameObject x = GameObject.Instantiate(markerPrefab) as GameObject; x.transform.position = entity.transform.position; } RunPrimitive(current); }
private void UpdateDeltaDuration(MovementPrimitive m) { m.timeDeltaSum += m.timeDelta; }