/// <summary>
    /// Based on a set of mover details, lock the transform here.  This
    /// is good to garuntee a positoin instead of ending at a lerp of 0.001f etc
    /// </summary>    
    void LockTransformAtDetails(PlatformMoverLocationDetails detail, bool setSpin)
    {
        transform.position = detail.positon;
        transform.rotation = detail.rotation;

        if (setSpin)
            if (details.spin.isSpinToTarget)
                transform.Rotate(details.spin.spinAxis, details.spin.spinRevolutions * 360f);
    }
예제 #2
0
    /// <summary>
    /// Based on a set of mover details, lock the transform here.  This
    /// is good to garuntee a positoin instead of ending at a lerp of 0.001f etc
    /// </summary>
    void LockTransformAtDetails(PlatformMoverLocationDetails detail, bool setSpin)
    {
        transform.position = detail.positon;
        transform.rotation = detail.rotation;

        if (setSpin)
        {
            if (details.spin.isSpinToTarget)
            {
                transform.Rotate(details.spin.spinAxis, details.spin.spinRevolutions * 360f);
            }
        }
    }
예제 #3
0
    void OnEnable()
    {
        if (targetTransform == null)
        {
            Debug.LogError("No Target");
            return;
        }

        // Cahce the pos/rot of the mover and target
        details.start.positon   = transform.position;
        details.start.rotation  = transform.rotation;
        details.target.positon  = targetTransform.position;
        details.target.rotation = targetTransform.rotation;

        _previousDetails = details.start;
        _nextDetails     = details.target;

        StartCoroutine(MoveRoutine());
    }
	void OnEnable()
	{
        if (targetTransform == null)
        {
            Debug.LogError("No Target");
            return;
        }

        // Cahce the pos/rot of the mover and target
        details.start.positon = transform.position;
        details.start.rotation = transform.rotation;
        details.target.positon = targetTransform.position;
        details.target.rotation = targetTransform.rotation;

        _previousDetails = details.start;
        _nextDetails = details.target;

        isFirstRun = true;
		StartCoroutine(MoveRoutine());
	}
예제 #5
0
    void Arrived(PlatformMoverLocationDetails details, bool setSpin)
    {
        t = 0f;

        LockTransformAtDetails(details, setSpin);
    }
예제 #6
0
    float wT = 0;       // wait time at each end
    IEnumerator MoveRoutine()
    {
        bool isMovingTo = true;

        if (_previousDetails.toggleOnly)
        {
            while (!_toggledThisFrame)
            {
                yield return(null);
            }
            ResetToggle();
        }
        else
        if (details.isWaitFirstTime)
        {
            yield return(new WaitForSeconds(_previousDetails.waitTime));
        }


        while (true)
        {
            while (t < 1f)
            {
                t += Time.deltaTime * (1f / _previousDetails.timeToNextTargetTime);

                transform.position = Vector3.Lerp(_previousDetails.positon, _nextDetails.positon, GetEasingFloat(_previousDetails.easingToNextTarget, t));
                transform.rotation = Quaternion.Lerp(_previousDetails.rotation, _nextDetails.rotation, GetEasingFloat(_previousDetails.easingToNextTarget, t));

                // if spin, then add additional rotation each frame
                if (details.spin.isSpinToTarget)
                {
                    r = Mathf.Lerp(0, (details.spin.spinRevolutions * 360f), GetEasingFloat(_previousDetails.easingToNextTarget, t));
                    transform.Rotate(details.spin.spinAxis, r);
                }

                yield return(null);
            }


            // Arrived, so fire off any events
            Arrived(_nextDetails, isMovingTo);

            // If this target needs to wait for a toggle
            // then loop here otherwise wait for time
            if (_nextDetails.toggleOnly)
            {
                while (!_toggledThisFrame)
                {
                    yield return(null);
                }
                ResetToggle();
            }
            else
            {
                yield return(new WaitForSeconds(_nextDetails.waitTime));
            }

            // Switch the previous/next details
            if (isMovingTo)
            {
                _nextDetails     = details.start;
                _previousDetails = details.target;
            }
            else
            {
                _nextDetails     = details.target;
                _previousDetails = details.start;
            }
            isMovingTo = !isMovingTo;
        }
    }
    void Arrived(PlatformMoverLocationDetails details, bool setSpin)
    {
        t = 0f;

        LockTransformAtDetails(details, setSpin);
    }
    float wT = 0;       // wait time at each end
    IEnumerator MoveRoutine()
    {
        bool isMovingTo = true;

        if (_previousDetails.toggleOnly)
        {
            while (!_toggledThisFrame)
                yield return null;
            ResetToggle();
        }
        else
            if(details.isWaitFirstTime)
                yield return new WaitForSeconds(_previousDetails.waitTime);


        while (true)
        {
            while (t < 1f)
            {
                t += Time.deltaTime * (1f / _previousDetails.timeToNextTargetTime);

                transform.position = Vector3.Lerp(_previousDetails.positon, _nextDetails.positon, GetEasingFloat(_previousDetails.easingToNextTarget, t));
                transform.rotation = Quaternion.Lerp(_previousDetails.rotation, _nextDetails.rotation, GetEasingFloat(_previousDetails.easingToNextTarget, t));

                // if spin, then add additional rotation each frame
                if (details.spin.isSpinToTarget)
                {
                    r = Mathf.Lerp(0, (details.spin.spinRevolutions * 360f), GetEasingFloat(_previousDetails.easingToNextTarget, t));
                    transform.Rotate(details.spin.spinAxis, r);
                }

                yield return null;
            }


            // Arrived, so fire off any events
            Arrived(_nextDetails, isMovingTo);

            // If this target needs to wait for a toggle
            // then loop here otherwise wait for time
            if (_nextDetails.toggleOnly)
            {
                while(!_toggledThisFrame)
                    yield return null;
                ResetToggle();
            }
            else
                yield return new WaitForSeconds(_nextDetails.waitTime);

            // Switch the previous/next details
            if(isMovingTo)
            {                
                _nextDetails = details.start;
                _previousDetails = details.target;
            }
            else            
            {
                _nextDetails = details.target;
                _previousDetails = details.start;
            }
            isMovingTo = !isMovingTo;           
        }
    }