//creates a new HOTween tween which moves us to the next waypoint //(defined by passed arguments) internal void CreateTween() { //prepare HOTween's parameters, you can look them up here //http://www.holoville.com/hotween/documentation.html //////////////////////////////////////////////////////////// //create new HOTween plugin for curved paths //pass in array of Vector3 waypoint positions, relative = true plugPath = new PlugVector3Path(wpPos, true, pathtype); //orients the tween target along the path //constrains this game object on one axis if (orientToPath) { plugPath.OrientToPath(); } //create TweenParms for storing HOTween's parameters tParms = new TweenParms(); //sets the path plugin as tween position property tParms.Prop("position", plugPath); tParms.AutoKill(true); //use speed based tween with linear easing tParms.SpeedBased(); tParms.Ease(EaseType.Linear); tParms.OnComplete(OnPathComplete); //create a new tween, move this gameobject with given arguments tween = HOTween.To(transform, maxSpeed, tParms); }
public PlugVector3Path MakePlugVector3Path() { var p = new PlugVector3Path(Points, IsRelative, PathType); if (IsClosed) { p.ClosePath(); } return(p); }
/// <summary> /// Disables any running movement routines. /// <summary> public void Stop() { StopAllCoroutines(); if (tween != null) { tween.Kill(); } plugPath = null; tween = null; }
/// <summary> /// If this Tweener contains a <see cref="PlugVector3Path"/> tween, /// defines a portion of that path to use and re-adapt to, /// and rewinds/restarts the tween in its partial form (depending if it was paused or not). /// </summary> /// <param name="p_waypointId0"> /// Id of the new starting waypoint on the current path. /// If you want to be sure you're targeting the first point in the path, pass -1 /// (this is because the first waypoint of the path might be different from the first waypoint you passed, /// in case the target Transform was not already on the starting position, and thus needed to reach it). /// </param> /// <param name="p_waypointId1"> /// Id of the new ending waypoint on the current path /// (-1 in case you want to target the ending waypoint of a closed path) /// </param> /// <param name="p_newDuration"> /// Tween duration of the partial path (if -1 auto-calculates the correct partial based on the original duration) /// </param> /// <param name="p_newEaseType">New EaseType to apply</param> public Tweener UsePartialPath(int p_waypointId0, int p_waypointId1, float p_newDuration, EaseType p_newEaseType) { if (plugins.Count > 1) { TweenWarning.Log("Applying a partial path on a Tweener (" + _target + ") with more than one plugin/property being tweened is not allowed"); return(this); } if (pv3Path == null) { // Get eventual plugVector3Path plugin pv3Path = GetPlugVector3PathPlugin(); if (pv3Path == null) { TweenWarning.Log("Tweener for " + _target + " contains no PlugVector3Path plugin"); return(this); } } // Startup the tween (if not already started) to store the path data. Startup(); // Store original duration and easeType (if not already stored). if (!isPartialled) { isPartialled = true; _originalDuration = _duration; _originalEaseType = _easeType; } // Convert waypoints ids to path ids int pathWaypointId0 = ConvertWaypointIdToPathId(pv3Path, p_waypointId0, true); int pathWaypointId1 = ConvertWaypointIdToPathId(pv3Path, p_waypointId1, false); // Get waypoints length percentage (needed for auto-duration and calculation of lookAhed) float partialPerc = pv3Path.GetWaypointsLengthPercentage(pathWaypointId0, pathWaypointId1); float partialStartPerc = pathWaypointId0 == 0 ? 0 : pv3Path.GetWaypointsLengthPercentage(0, pathWaypointId0); // Assign new duration and ease _duration = p_newDuration >= 0 ? p_newDuration : _originalDuration * partialPerc; _easeType = p_newEaseType; // Convert path to partial pv3Path.SwitchToPartialPath(_duration, p_newEaseType, partialStartPerc, partialPerc); // Re-Startup and restart Startup(true); if (!_isPaused) { Restart(true); } else { Rewind(true, true); } return(this); // Returns this so it can be directly used with WaitForCompletion coroutines }
//disables any running movement methods public void Stop() { //exit waypoint coroutine StopAllCoroutines(); //destroy current HOTween movement component HOTween.Kill(transform); plugPath = null; tween = null; //play idle animation if set PlayIdle(); }
/// <summary> /// If this Tweener contains a <see cref="PlugVector3Path"/> tween returns the length of the path, /// otherwise returns -1</summary> public float GetPathLength() { PlugVector3Path plugVector3Path = GetPlugVector3PathPlugin(); if (plugVector3Path == null) { return(-1); } Startup(); // Ensure startup - if not already executed - to store the path data. return(plugVector3Path.path.pathLength); }
// =================================================================================== // PLUGINS SPECIFIC METHODS ---------------------------------------------------------- /// <summary> /// If this Tweener contains a <see cref="PlugVector3Path"/> tween, /// returns a point on the path at the given percentage (0 to 1). /// Returns a <c>zero Vector</c> if there's no path tween associated with this tween. /// Note that, if the tween wasn't started, the OnStart callback will be called /// the first time you call this method, because the tween needs to be initialized. /// </summary> /// <param name="t">The percentage (0 to 1) at which to get the point</param> public Vector3 GetPointOnPath(float t) { PlugVector3Path plugVector3Path = GetPlugVector3PathPlugin(); if (plugVector3Path == null) { return(Vector3.zero); } Startup(); // Ensure startup - if not already executed - to store the path data. return(plugVector3Path.GetConstPointOnPath(t)); }
/// <summary> /// Returns the correct id of the given waypoint, converted to path id. /// </summary> /// <param name="p_plugVector3Path">Vector3 path plugin to use</param> /// <param name="p_waypointId">Waypoint to convert</param> /// <param name="p_isStartingWp">If TRUE indicates that the given waypoint is the starting one, /// otherwise it's the ending one</param> /// <returns></returns> static int ConvertWaypointIdToPathId(PlugVector3Path p_plugVector3Path, int p_waypointId, bool p_isStartingWp) { if (p_waypointId == -1) { return(p_isStartingWp ? 1 : p_plugVector3Path.path.path.Length - 2); } if (p_plugVector3Path.hasAdditionalStartingP) { return(p_waypointId + 2); } return(p_waypointId + 1); }
/// <summary> /// Disables any running movement routines. /// <summary> public void Stop() { StopAllCoroutines(); //reset current waypoint index to zero currentPoint = 0; if (tween != null) { tween.Kill(); } plugPath = null; tween = null; }
/// <summary> /// If this Tweener contains a <see cref="PlugVector3Path"/>, returns it. /// Otherwise returns null. /// </summary> /// <returns></returns> private PlugVector3Path GetPlugVector3PathPlugin() { if (plugins == null) { return(null); } int pluginsCount = plugins.Count; for (int i = 0; i < pluginsCount; ++i) { ABSTweenPlugin plug = plugins[i]; PlugVector3Path plugVector3Path = plug as PlugVector3Path; if (plugVector3Path != null) { return(plugVector3Path); } } return(null); }
/// <summary> /// Completely resets this Tweener, except its target /// </summary> override protected void Reset() { base.Reset(); isFrom = false; plugins = null; isPartialled = false; pv3Path = null; _delay = _elapsedDelay = delayCount = 0; _pixelPerfect = false; _speedBased = false; _easeType = HOTween.defEaseType; _easeOvershootOrAmplitude = HOTween.defEaseOvershootOrAmplitude; _easePeriod = HOTween.defEasePeriod; _originalEaseType = HOTween.defEaseType; onPluginOverwritten = null; onStepCompleteWParms = null; onPluginOverwrittenParms = null; }
//creates a new HOTween tween which moves us to the next waypoint //(defined by passed arguments) internal void CreateTween() { //play walk animation if set PlayWalk(); //prepare HOTween's parameters, you can look them up here //http://www.holoville.com/hotween/documentation.html //////////////////////////////////////////////////////////// //create new HOTween plugin for curved paths //pass in array of Vector3 waypoint positions, relative = true plugPath = new PlugVector3Path(wpPos, true, pathtype); //orients the tween target along the path //constrains this game object on one axis if (orientToPath || lockAxis != Axis.None) { plugPath.OrientToPath(lookAhead, lockAxis); } //lock position axis if (lockPosition != Axis.None) { plugPath.LockPosition(lockPosition); } //create a smooth path if closePath was true if (closePath) { plugPath.ClosePath(true); } //create TweenParms for storing HOTween's parameters tParms = new TweenParms(); //sets the path plugin as tween position property if (local) { tParms.Prop("localPosition", plugPath); } else { tParms.Prop("position", plugPath); } //additional tween parameters for partial tweens tParms.AutoKill(false); tParms.Pause(true); tParms.Loops(1); //differ between TimeValue like mentioned above at enum TimeValue //use speed with linear easing if (timeValue == TimeValue.speed) { tParms.SpeedBased(); tParms.Ease(EaseType.Linear); } else { //use time in seconds and the chosen easetype tParms.Ease(easetype); } //create a new tween, move this gameobject with given arguments tween = HOTween.To(transform, originSpeed, tParms); //continue new tween with adjusted speed if it was changed before if (originSpeed != speed) { ChangeSpeed(speed); } }
//creates a new HOTween tween with give arguments that moves along the path private void CreateTween() { //prepare HOTween's parameters, you can look them up here //http://www.holoville.com/hotween/documentation.html //create new plugin for curved paths //pass in array of Vector3 waypoint positions, relative = true plugPath = new PlugVector3Path(waypoints, true, pathType); //orients the tween target along the path if (orientToPath) { plugPath.OrientToPath(lookAhead, lockAxis); } //lock position axis, if set if (lockPosition != Holoville.HOTween.Axis.None) { plugPath.LockPosition(lockPosition); } //create a closed loop, if set if (loopType == LoopType.loop && closeLoop) { plugPath.ClosePath(true); } //create TweenParms for storing HOTween's parameters tParms = new TweenParms(); //sets the path plugin as tween position property tParms.Prop("position", plugPath); //additional tween parameters tParms.AutoKill(false); tParms.Loops(1); if (!moveToPath) { tParms.OnComplete(ReachedEnd); } //differ between TimeValue, use speed with linear easing //or time based tweening with an animation easetype if (timeValue == TimeValue.speed) { tParms.SpeedBased(); tParms.Ease(EaseType.Linear); } else { //use time in seconds and the chosen easetype if (easeType == Holoville.HOTween.EaseType.AnimationCurve) { tParms.Ease(animEaseType); } else { tParms.Ease(easeType); } } //finally create the tween tween = HOTween.To(transform, originSpeed, tParms); //continue new tween with adjusted speed if it was changed before if (originSpeed != speed) { ChangeSpeed(speed); } }
void Start() { HOTween.showPathGizmos = true; Vector3[] path = new[] { Vector3.zero, new Vector3(0, 1, 0), new Vector3(1, 2, 0), new Vector3(2, 1, 0), new Vector3(2, 0, 0) }; Axis lockRotation = lockRotation0 | lockRotation1; PlugVector3Path plugPath = new PlugVector3Path(path, true).ClosePath().OrientToPath(0.1f, lockRotation).LockPosition(lockPosition); if (is2DPath) { plugPath.Is2D(is2DSideScroller); } HOTween.To(targets[0], 3, new TweenParms() .Prop("position", plugPath) .Ease(EaseType.Linear) .Loops(-1) ).Pause(); plugPath = new PlugVector3Path(path).ClosePath().LookAt(targets[2]).LockPosition(lockPosition); if (is2DPath) { plugPath.Is2D(is2DSideScroller); } HOTween.To(targets[1], 3, new TweenParms() .Prop("position", plugPath) .Ease(EaseType.Linear) .Loops(-1) ).Pause(); // Linear VS curved plugPath = new PlugVector3Path(path, true, PathType.Curved).ClosePath().LookAt(Vector3.zero).LockPosition(lockPosition); if (is2DPath) { plugPath.Is2D(is2DSideScroller); } HOTween.To(targets[2], 3, new TweenParms() .Prop("position", plugPath) .Ease(EaseType.Linear) .Loops(-1) ).Pause(); plugPath = new PlugVector3Path(path, true, PathType.Linear).ClosePath().OrientToPath(0.1f, lockRotation).LockPosition(lockPosition); if (is2DPath) { plugPath.Is2D(is2DSideScroller); } HOTween.To(targets[3], 3, new TweenParms() .Prop("position", plugPath) .Ease(EaseType.Linear) .Loops(-1) ).Pause(); // Linear VS curved top-down path = new[] { Vector3.zero, new Vector3(0, 0, 1), new Vector3(1, 0, 2), new Vector3(2, 0, 1), new Vector3(2, 0, 0) }; plugPath = new PlugVector3Path(path, true, PathType.Curved).ClosePath().OrientToPath(0.1f, lockRotation).LockPosition(lockPosition); if (is2DPath) { plugPath.Is2D(is2DSideScroller); } HOTween.To(targets[4], 3, new TweenParms() .Prop("position", plugPath) .Ease(EaseType.Linear) .Loops(-1) ).Pause(); plugPath = new PlugVector3Path(path, true, PathType.Linear).ClosePath().OrientToPath(0.1f, lockRotation).LockPosition(lockPosition); if (is2DPath) { plugPath.Is2D(is2DSideScroller); } HOTween.To(targets[5], 3, new TweenParms() .Prop("position", plugPath) .Ease(EaseType.Linear) .Loops(-1) ).Pause(); }