Inheritance: YieldInstruction
Ejemplo n.º 1
1
        IEnumerator InsideTriggerRoutine()
        {
            var waitForFixedUpdate = new WaitForFixedUpdate();
            yield return (ProCamera2D.UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;

            _tempExclusivePoint = new Vector2(Vector3H(ProCamera2D.CameraTargetPosition), Vector3V(ProCamera2D.CameraTargetPosition));
            while (_insideTrigger)
            {
                _exclusiveInfluencePercentage = ExclusiveInfluencePercentage;

                var distancePercentage = GetDistanceToCenterPercentage(new Vector2(Vector3H(ProCamera2D.TargetsMidPoint), Vector3V(ProCamera2D.TargetsMidPoint)));
                var vectorFromPointToFocus = new Vector2(Vector3H(ProCamera2D.TargetsMidPoint), Vector3V(ProCamera2D.TargetsMidPoint)) - new Vector2(Vector3H(FocusPoint.position), Vector3V(FocusPoint.position));
                if (distancePercentage == 0)
                {
                    ProCamera2D.ExclusiveTargetPosition = Vector2.SmoothDamp(_tempExclusivePoint, new Vector2(Vector3H(FocusPoint.position), Vector3V(FocusPoint.position)), ref _velocity, InfluenceSmoothness);
                    _tempExclusivePoint = ProCamera2D.ExclusiveTargetPosition.Value;
                    _influence = -vectorFromPointToFocus * (1 - distancePercentage);
                    ProCamera2D.ApplyInfluence(_influence);
                }
                else
                {
                    _influence = Vector2.SmoothDamp(_influence, -vectorFromPointToFocus * (1 - distancePercentage), ref _velocity, InfluenceSmoothness);
                    ProCamera2D.ApplyInfluence(_influence);
                    _tempExclusivePoint = new Vector2(Vector3H(ProCamera2D.CameraTargetPosition), Vector3V(ProCamera2D.CameraTargetPosition));
                }

                yield return (ProCamera2D.UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;
            }
        }
Ejemplo n.º 2
0
	public RpcClient(Rpc.RpcClient client, GameManager Gm)
	{
		rpcStopSignal = new CancellationTokenSource ();
		this.client = client;
		this.Gm = Gm;
        fixedUpdate = new unity.WaitForFixedUpdate();
	}
 static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.WaitForFixedUpdate o;
         o = new UnityEngine.WaitForFixedUpdate();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Ejemplo n.º 4
0
 private IEnumerator Loop()
 {
     var wait = new WaitForFixedUpdate();
     var startPos = transform.position;
     while (true) {
     transform.position = GetLoopLerp(startPos, Direction, Distance, Speed);
     yield return wait;
     }
 }
Ejemplo n.º 5
0
 private IEnumerator Loop()
 {
     var wait = new WaitForFixedUpdate();
         var startPos = _lerper.transform.localPosition;
         print(_lerper.name);
         while (true)
         {
             _lerper.transform.localPosition = GetLoopLerp(startPos, Direction, Distance, Speed);
             yield return wait;
         }
 }
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.WaitForFixedUpdate o;
         o = new UnityEngine.WaitForFixedUpdate();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 7
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.WaitForFixedUpdate o;
         o = new UnityEngine.WaitForFixedUpdate();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.WaitForFixedUpdate o;
         o=new UnityEngine.WaitForFixedUpdate();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.WaitForFixedUpdate o;
         o=new UnityEngine.WaitForFixedUpdate();
         pushValue(l,true);
         pushValue(l,o);
         return 2;
     }
     catch(Exception e) {
         return error(l,e);
     }
 }
Ejemplo n.º 10
0
        IEnumerator OutsideTriggerRoutine()
        {
            var waitForFixedUpdate = new WaitForFixedUpdate();
            yield return (ProCamera2D.UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;

            while (!_insideTrigger && _influence != Vector2.zero)
            {
                _influence = Vector2.SmoothDamp(_influence, Vector2.zero, ref _velocity, InfluenceSmoothness);
                ProCamera2D.ApplyInfluence(_influence);

                yield return (ProCamera2D.UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;
            }
        }
Ejemplo n.º 11
0
    IEnumerator AvoidCar()
    {
        WaitForFixedUpdate wait = new WaitForFixedUpdate();

        while (Vector3.Distance(car.transform.position, transform.position) < runRadius * 1.25f)
        {
            rigidbody.velocity = Vector3.zero;
            Vector3 diff = (transform.position - car.transform.position);
            diff.Normalize();
            diff *= avoidSpeed * Time.deltaTime;

            rigidbody.MovePosition(transform.position + diff);
            yield return wait;
        }
    }
Ejemplo n.º 12
0
        IEnumerator InsideTriggerRoutine()
        {
            var waitForFixedUpdate = new WaitForFixedUpdate();
            while (_insideTrigger &&
                   _instanceID == ProCamera2D.CurrentZoomTriggerID)
            {
                _exclusiveInfluencePercentage = ExclusiveInfluencePercentage;

                var distancePercentage = GetDistanceToCenterPercentage(new Vector2(Vector3H(ProCamera2D.TargetsMidPoint), Vector3V(ProCamera2D.TargetsMidPoint)));

                float finalTargetSize;
                if (SetSizeAsMultiplier)
                    finalTargetSize = _startCamSize / TargetZoom;
                else if (ProCamera2D.GameCamera.orthographic)
                    finalTargetSize = TargetZoom;
                else
                    finalTargetSize = Mathf.Abs(Vector3D(ProCamera2D.CameraPosition)) * Mathf.Tan(TargetZoom * 0.5f * Mathf.Deg2Rad);

                var newTargetOrtographicSize = (_initialCamSize * distancePercentage) + (finalTargetSize * (1 - distancePercentage));

                if ((finalTargetSize > ProCamera2D.GameCameraSize
                    && newTargetOrtographicSize > _targetCamSize) ||
                    (finalTargetSize < ProCamera2D.GameCameraSize
                    && newTargetOrtographicSize < _targetCamSize))
                {
                    _targetCamSize = newTargetOrtographicSize;
                }

                _previousCamSize = ProCamera2D.ScreenSizeInWorldCoordinates.y;

                if (Mathf.Abs(ProCamera2D.GameCameraSize - _targetCamSize) > .0001f)
                    UpdateScreenSize(ZoomSmoothness);

                yield return (ProCamera2D.UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;

                if (_previousCamSize == ProCamera2D.ScreenSizeInWorldCoordinates.y)
                {
                    _targetCamSize = ProCamera2D.GameCameraSize;
                    _targetCamSizeSmoothed = _targetCamSize;
                    _zoomVelocity = 0f;
                }
            }
        }
Ejemplo n.º 13
0
    static int _CreateUnityEngine_WaitForFixedUpdate(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                var obj = new UnityEngine.WaitForFixedUpdate();
                ToLua.PushSealed(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: UnityEngine.WaitForFixedUpdate.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Ejemplo n.º 14
0
    IEnumerator DoType() {
        if(endGO) endGO.SetActive(true);

        mEnded = false;
        mActive = true;
        target.text = "";
        YieldInstruction wait; if(delay <= 0.0f) wait = new WaitForFixedUpdate(); else wait = new WaitForSeconds(delay);
        StringBuilder textBuffer = new StringBuilder(text.Length);

        yield return new WaitForSeconds(startDelay);

        for(int i = 0; i < text.Length; i++) {
            textBuffer.Append(text[i]);
            target.text = textBuffer.ToString();
            yield return wait;
        }

        mActive = false;
        mEnded = true;

        if(endGO) endGO.SetActive(false);
    }
Ejemplo n.º 15
0
    IEnumerator DoMoveFire() {
        WaitForFixedUpdate waitUpdate = new WaitForFixedUpdate();
        WaitForSeconds waitDelay = new WaitForSeconds(moveFireDelay);

        do {
            //wait till we face player
            while(Mathf.Sign(mPlayer.collider.bounds.center.x - collider.bounds.center.x) != Mathf.Sign(tank.bodyCtrl.localVelocity.x))
                yield return waitUpdate;

            //fire
            for(int i = 0; i < moveFirePts.Length; i++) {
                Vector3 dir = moveFirePts[i].up;
                Vector3 pos = moveFirePts[i].position; pos.z = 0.0f;
                Projectile.Create(projGroup, moveFireProjType, pos, dir, null);
            }

            yield return waitDelay;
        } while(mCurPhase == Phase.Move);
    }
Ejemplo n.º 16
0
    IEnumerator DoDrop() {
        mDropActive = true;

        WaitForFixedUpdate wait = new WaitForFixedUpdate();

        while(mDropActive) {
            yield return wait;

            float moveY = dropSpeed * Time.fixedDeltaTime;
            Vector3 pos = transform.position;

            RaycastHit hit;
            if(Physics.SphereCast(collider.bounds.center, mRadius, Vector3.down, out hit, moveY, dropLayerMask)) {
                pos = hit.point + hit.normal * mRadius;
                mDropActive = false;

                Invoke("Release", destroyDelay);
                Invoke("DoBlinkers", destroyStartBlinkDelay);
            }
            else {
                pos.y -= moveY;
            }

            transform.position = pos;
        }
    }
Ejemplo n.º 17
0
 static CoroutineEx()
 {
     CoroutineEx.waitForEndOfFrame    = new WaitForEndOfFrame();
     CoroutineEx.waitForFixedUpdate   = new WaitForFixedUpdate();
     CoroutineEx.waitForSecondsBuffer = new Dictionary <float, WaitForSeconds>();
 }
        IEnumerator ShakeRoutine(float smoothness)
        {
            var waitForFixedUpdate = new WaitForFixedUpdate();
            while (_shakePositions.Count > 0 || _shakeParent.position != Vector3.zero || _transform.localRotation != _originalRotation)
            {
                _shakePosition = Utils.GetVectorsSum(_shakePositions);
                _shakePositionSmoothed = Vector3.SmoothDamp(_shakePositionSmoothed, _shakePosition, ref _shakeVelocity, smoothness);
                _shakeParent.position = _shakePositionSmoothed;
                _shakePositions.Clear();

                _rotationTime = Mathf.SmoothDamp(_rotationTime, 1f, ref _rotationVelocity, smoothness);
                _rotationTargetSmoothed = Quaternion.Slerp(_rotationTargetSmoothed, _rotationTarget, _rotationTime);

                _transform.localRotation = _rotationTargetSmoothed;
                _rotationTarget = _originalRotation;

                yield return (ProCamera2D.UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;
            }

            _shakeCoroutine = null;
        }
Ejemplo n.º 19
0
    IEnumerator DoSuperStrike() {
        WaitForFixedUpdate waitUpdate = new WaitForFixedUpdate();

        Vector3 dest = superStrikeDest.position;

        //move towards target
        while(true) {
            yield return waitUpdate;

            float delta = dest.x - transform.position.x;
            if(Mathf.Abs(delta) > 0.1f) {
                bodyCtrl.moveSide = Mathf.Sign(delta);
            }
            else
                break;
        }

        bodyCtrl.moveSide = 0.0f;
        bodyCtrl.rigidbody.velocity = Vector3.zero;

        //jump
        Jump(bodyCtrl.jumpDelay);
        while(Mathf.Abs(dest.y - collider.bounds.center.y) > 0.1f) {
            yield return waitUpdate;
        }
        Jump(0);

        bodyCtrl.enabled = false;
        gravityCtrl.enabled = false;
        bodyCtrl.rigidbody.isKinematic = true;

        bodySpriteCtrl.PlayOverrideClip("chargeUp");

        superStrikeChargeGO.SetActive(true);

        superStrikeHolderGO.SetActive(true);
        Vector3 pos = collider.bounds.center; pos.z = 0;
        superStrikeHolderGO.transform.position = pos;
        superStrikeHolderGO.transform.eulerAngles = new Vector3(0,0,45);

        //prep
        superStrikeTargetGO.SetActive(true);
        yield return new WaitForSeconds(superStrikeReadyDelay);
        superStrikeTargetGO.SetActive(false);

        //attack
        superStrikeGO.SetActive(true);
        yield return new WaitForSeconds(superStrikeActiveDelay);

        mSuperStrikeSpinner.rotatePerSecond *= -1;

        if(mCurPhase == Phase.MidAirCharge) {
            mNextPhase = Phase.TargetStrike;
            ToPhase(Phase.Move);
        }
    }
Ejemplo n.º 20
0
        IEnumerator AdjustTargetInfluenceRoutine(CameraTarget cameraTarget, float influenceH, float influenceV, float duration, bool removeIfZeroInfluence = false)
        {
            var startInfluenceH = cameraTarget.TargetInfluenceH;
            var startInfluenceV = cameraTarget.TargetInfluenceV;

            var waitForFixedUpdate = new WaitForFixedUpdate();
            var t = 0f;
            while (t <= 1.0f)
            {
                t += (UpdateType == UpdateType.LateUpdate ? Time.deltaTime : Time.fixedDeltaTime) / duration;
                cameraTarget.TargetInfluenceH = Utils.EaseFromTo(startInfluenceH, influenceH, t, EaseType.Linear);
                cameraTarget.TargetInfluenceV = Utils.EaseFromTo(startInfluenceV, influenceV, t, EaseType.Linear);

                yield return (UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;
            }

            if (removeIfZeroInfluence && cameraTarget.TargetInfluenceH <= 0 && cameraTarget.TargetInfluenceV <= 0)
                CameraTargets.Remove(cameraTarget);
        }
Ejemplo n.º 21
0
    private IEnumerator Run(float initialProgress)
    {
        var fixedUpdateWait = new WaitForFixedUpdate();

        Vector3[] corner = new Vector3[path.corners.Length];
        path.GetCornersNonAlloc(corner);
        var length = getLength(path);
        float progress = initialProgress;
        float breakProgress = 0;
        bool searchingPath = false;
        bool waitingForSun = false;
        var tempLook = lookTarget;
        while (progress < length - 1)
        {
            yield return fixedUpdateWait;
            progress += myAgent.speed * Time.fixedDeltaTime;
            var movement = Vector3.ClampMagnitude(sample(corner, progress) - transform.position, myAgent.speed * Time.fixedDeltaTime * gameTime.PlayTime);
            myAgent.Move(Vector3.ClampMagnitude(movement, length - progress));

            Vector3 direction = (lookTarget - transform.position).normalized;
            Quaternion lookRotation = Quaternion.LookRotation(direction);
            transform.rotation = Quaternion.RotateTowards(transform.rotation, lookRotation, RotationSpeed);

            if (progress >= RecalcThreshold)
            {
                if (!myAgent.pathPending)
                {
                    if (!searchingPath)
                    {
                        searchingPath = true;
                        breakProgress = progress;
                        StartCoroutine(getPath(player.position));
                    }
                    else if (!waitingForSun)
                    {
                        waitingForSun = true;
                        StartCoroutine(calcSun());
                    }
                    else if (!calculatingSun)
                    {
                        run = StartCoroutine(Run(0));
                        yield break;
                    }
                }
            }
        }

        StartCoroutine(agentFollow());
    }
 IEnumerator OutsideTriggerRoutine()
 {
     var waitForFixedUpdate = new WaitForFixedUpdate();
     while (!_insideTrigger &&
            _instanceID == ProCamera2D.CurrentZoomTriggerID &&
            Mathf.Abs(ProCamera2D.GameCameraSize - _targetCamSize) > .0001f)
     {
         UpdateScreenSize(ResetSizeOnExit ? ResetSizeSmoothness : ZoomSmoothness);
         yield return (ProCamera2D.UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;
     }
     _zoomVelocity = 0f;
 }
Ejemplo n.º 23
0
        IEnumerator MoveCameraToTarget()
        {
            var initialCamPosH = Vector3H(ProCamera2D.CameraPosition);
            var initialCamPosV = Vector3V(ProCamera2D.CameraPosition);

            PositionAndSizeOverrider.OverridePosition = VectorHVD(initialCamPosH, initialCamPosV, Vector3D(ProCamera2D.CameraPosition));
            PositionAndSizeOverrider.OverrideSize = 0;
            PositionAndSizeOverrider.UseNumericBoundaries = true;
            PositionAndSizeOverrider.enabled = true;

            var waitForFixedUpdate = new WaitForFixedUpdate();
            var t = 0f;
            while (t <= 1.0f)
            {
                t += (ProCamera2D.UpdateType == UpdateType.LateUpdate ? Time.deltaTime : Time.fixedDeltaTime) / TransitionDuration;

                var currentCamPosH = Utils.EaseFromTo(initialCamPosH, ProCamera2D.CameraTargetPositionSmoothed.x, t, TransitionEaseType);
                var currentCamPosV = Utils.EaseFromTo(initialCamPosV, ProCamera2D.CameraTargetPositionSmoothed.y, t, TransitionEaseType);

                PositionAndSizeOverrider.UseTopBoundary = NumericBoundaries.UseTopBoundary;
                PositionAndSizeOverrider.TopBoundary = NumericBoundaries.TopBoundary;
                PositionAndSizeOverrider.UseBottomBoundary = NumericBoundaries.UseBottomBoundary;
                PositionAndSizeOverrider.BottomBoundary = NumericBoundaries.BottomBoundary;
                PositionAndSizeOverrider.UseLeftBoundary = NumericBoundaries.UseLeftBoundary;
                PositionAndSizeOverrider.LeftBoundary = NumericBoundaries.LeftBoundary;
                PositionAndSizeOverrider.UseRightBoundary = NumericBoundaries.UseRightBoundary;
                PositionAndSizeOverrider.RightBoundary = NumericBoundaries.RightBoundary;
                PositionAndSizeOverrider.OverridePosition = VectorHVD(currentCamPosH, currentCamPosV, Vector3D(ProCamera2D.CameraPosition));

                yield return (ProCamera2D.UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;
            }

            PositionAndSizeOverrider.enabled = false;
            NumericBoundaries.MoveCameraToTargetRoutine = null;
        }
Ejemplo n.º 24
0
        IEnumerator EndCinematicRoutine()
        {
            if (_letterbox != null && LetterboxAmount > 0)
                _letterbox.TweenTo(0f, LetterboxAnimDuration);

            var initialPosH = Vector3H(_overridePosition.OverridePosition);
            var initialPosV = Vector3V(_overridePosition.OverridePosition);

            var currentCameraSize = ProCamera2D.GameCameraSize;

            // Ease out
            var waitForFixedUpdate = new WaitForFixedUpdate();
            var t = 0f;
            while (t <= 1.0f)
            {
                t += (ProCamera2D.UpdateType == UpdateType.LateUpdate ? Time.deltaTime : Time.fixedDeltaTime) / EndDuration;

                _overridePosition.OverridePosition = VectorHVD(
                    Utils.EaseFromTo(initialPosH, Vector3H(_overridePosition.OverridenPosition), t, EndEaseType),
                    Utils.EaseFromTo(initialPosV, Vector3V(_overridePosition.OverridenPosition), t, EndEaseType),
                    Vector3D(ProCamera2D.CameraPosition));

                _overridePosition.OverrideSize = Utils.EaseFromTo(currentCameraSize, _initialCameraSize, t, EndEaseType);

                yield return (ProCamera2D.UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;
            }

            _overridePosition.enabled = false;

            if (CinematicEnded != null)
                CinematicEnded();
        }
Ejemplo n.º 25
0
        IEnumerator GoToCinematicTargetRoutine(CinematicTarget cinematicTarget, int targetIndex)
        {
            if (cinematicTarget.TargetTransform == null)
                yield break;

            var initialPosH = Vector3H(ProCamera2D.CameraPosition);
            var initialPosV = Vector3V(ProCamera2D.CameraPosition);

            var currentCameraSize = ProCamera2D.GameCameraSize;

            // Ease in
            var waitForFixedUpdate = new WaitForFixedUpdate();
            var t = 0f;
            while (t <= 1.0f)
            {
                t += (ProCamera2D.UpdateType == UpdateType.LateUpdate ? Time.deltaTime : Time.fixedDeltaTime) / cinematicTarget.EaseInDuration;

                _overridePosition.OverridePosition = VectorHVD(
                    Utils.EaseFromTo(initialPosH, Vector3H(cinematicTarget.TargetTransform.position), t, cinematicTarget.EaseType),
                    Utils.EaseFromTo(initialPosV, Vector3V(cinematicTarget.TargetTransform.position), t, cinematicTarget.EaseType),
                    Vector3D(ProCamera2D.CameraPosition));

                _overridePosition.OverrideSize = Utils.EaseFromTo(currentCameraSize, _initialCameraSize / cinematicTarget.Zoom, t, cinematicTarget.EaseType);

                yield return (ProCamera2D.UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;
            }

            // Dispatch target reached event
            if (CinematicReachedTarget != null)
                CinematicReachedTarget(targetIndex);

            // Send target reached message
            if (!string.IsNullOrEmpty(cinematicTarget.SendMessageName))
            {
                cinematicTarget.TargetTransform.SendMessage(cinematicTarget.SendMessageName, cinematicTarget.SendMessageParam, SendMessageOptions.DontRequireReceiver);
            }

            // Hold
            t = 0f;
            while (t <= cinematicTarget.HoldDuration)
            {
                t += ProCamera2D.UpdateType == UpdateType.LateUpdate ? Time.deltaTime : Time.fixedDeltaTime;

                _overridePosition.OverridePosition = VectorHVD(
                    Vector3H(cinematicTarget.TargetTransform.position),
                    Vector3V(cinematicTarget.TargetTransform.position),
                    Vector3D(ProCamera2D.CameraPosition));

                yield return (ProCamera2D.UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;
            }
        }
Ejemplo n.º 26
0
    private IEnumerator MoveInAndEat()
    {
        YieldInstruction wait = new WaitForFixedUpdate();
        float counter = 0f;
        float duration = 1f;
        List<Vector3> initialPositions = new List<Vector3>();
        for (int playerIndex = 0; playerIndex < gameStates.Length; playerIndex++) {
            GameState gameState = gameStates[playerIndex];
            initialPositions.Add(gameState.myMonster.position);
        }

        while (counter < duration) {
            yield return wait;
            counter += Time.fixedDeltaTime;
            for (int playerIndex = 0; playerIndex < gameStates.Length; playerIndex++) {
                GameState gameState = gameStates[playerIndex];
                Vector3 initialPosition = initialPositions[playerIndex];
                Vector3 screenCoords = globalCamera.ScreenToWorldPoint(new Vector3(Screen.width * playerIndex, 0, globalCamera.nearClipPlane)); // XXX: SUPER BAD HACK
                Vector3 difference = new Vector3(screenCoords.x, initialPosition.y, initialPosition.z) - initialPosition;
                gameState.myMonster.transform.position = eatingCurve.Evaluate(counter/duration) * difference + initialPosition;
            }
        }

        for (int playerIndex = 0; playerIndex < gameStates.Length; playerIndex++) {
            GameState gameState = gameStates[playerIndex];
            Vector3 initialPosition = initialPositions[playerIndex];
            Vector3 screenCoords = globalCamera.ScreenToWorldPoint(new Vector3(Screen.width * playerIndex, 0, globalCamera.nearClipPlane)); // XXX: SUPER BAD HACK
            gameState.myMonster.transform.position = new Vector3(screenCoords.x, initialPosition.y, initialPosition.z);
        }

        yield return StartCoroutine(EatTacos ());
    }
Ejemplo n.º 27
0
    private IEnumerator QuitOnComplete()
    {
        YieldInstruction wait = new WaitForFixedUpdate();
        float counter = 0f;
        float duration = 1f;

        while (counter < duration) {
            yield return wait;
            counter += Time.fixedDeltaTime;
        }

        Application.Quit();
    }
Ejemplo n.º 28
0
    private IEnumerator FixPath(Vector3 position)
    {
        var fixedUpdateWait = new WaitForFixedUpdate();

        while (Vector3.Distance(transform.position, position) > 1)
        {
            yield return fixedUpdateWait;
            myAgent.Move(Vector3.ClampMagnitude((position - transform.position).normalized * myAgent.speed * Time.fixedDeltaTime, Vector3.Magnitude(position - transform.position)));
        }
    }
Ejemplo n.º 29
0
    IEnumerator DoSeekerFire() {
        SpriteHFlipRigidbodyVelX tankSpriteFlip = tank.GetComponent<SpriteHFlipRigidbodyVelX>();

        WaitForFixedUpdate waitUpdate = new WaitForFixedUpdate();
        WaitForSeconds waitFireDelay = new WaitForSeconds(seekerFireDelay);

        //prep
        seekerAnimDat.Play("prep");
        do {
            yield return waitUpdate;
        } while(seekerAnimDat.isPlaying);

        //move to a far spot away from player
        Vector3 playerPos = mPlayer.collider.bounds.center;
        
        float farthestX = 0;
        float farthestDistSq = 0;
        for(int j = 0; j < movePts.Length; j++) {
            Vector3 p = movePts[j].position;
            float d = Mathf.Abs(playerPos.x - p.x);
            if(d > farthestDistSq) {
                farthestDistSq = d;
                farthestX = p.x;
            }
        }
        
        //move till we are close
        while(Mathf.Abs(farthestX - collider.bounds.center.x) > 0.1f) {
            if(tank.bodyCtrl.moveSide == 0.0f || Mathf.Abs(tank.bodyCtrl.rigidbody.velocity.x) > 2.0f)
                tank.bodyCtrl.moveSide = Mathf.Sign(farthestX - collider.bounds.center.x);
            yield return waitUpdate;
        }

        tank.bodyCtrl.moveSide = 0.0f;
        tank.bodyCtrl.rigidbody.velocity = Vector3.zero;

        //fire stuff
        for(int i = 0; i < seekerCount; i++) {
            //face player
            float sign = Mathf.Sign(mPlayer.collider.bounds.center.x - collider.bounds.center.x);
            tankSpriteFlip.SetFlip(sign < 0.0f);
            bodySpriteCtrl.isLeft = sign < 0.0f;

            seekerLauncherAnimDat.Play("fire");
            do {
                yield return waitUpdate;
            } while(seekerLauncherAnimDat.isPlaying);

            yield return waitFireDelay;
        }

        //holster
        seekerAnimDat.Play("holster");
        do {
            yield return waitUpdate;
        } while(seekerAnimDat.isPlaying);

        if(mCurPhase == Phase.FireSeeker)
            ToPhase(Phase.Move);
    }
Ejemplo n.º 30
0
        IEnumerator UpdateScreenSizeRoutine(float finalSize, float duration, EaseType easeType)
        {
            var startSize = 0f;
            if (GameCamera.orthographic)
            {
                startSize = GameCamera.orthographicSize;

                #if PC2D_TK2D_SUPPORT
                if (Tk2dCam != null)
                    startSize = Tk2dCam.CameraSettings.orthographicSize / Tk2dCam.ZoomFactor;
                #endif
            }
            else
                startSize = Mathf.Abs(Vector3D(CameraPosition)) * Mathf.Tan(GameCamera.fieldOfView * 0.5f * Mathf.Deg2Rad);

            var waitForFixedUpdate = new WaitForFixedUpdate();
            var t = 0f;
            var newSize = startSize;
            while (t <= 1.0f)
            {
                t += (UpdateType == UpdateType.LateUpdate ? Time.deltaTime : Time.fixedDeltaTime) / duration;
                newSize = Utils.EaseFromTo(startSize, finalSize, t, easeType);

                UpdateScreenSize(newSize);

                yield return (UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;
            }

            _updateScreenSizeCoroutine = null;
        }
 private IEnumerator DoChangeSprite(Sprite newSprite, float speed = 0.05f)
 {
     var currentColor = this.color;
     var waiter = new WaitForFixedUpdate();
     this.sprite = newSprite != null ? newSprite : this.sprite;
     //		this.color = new Color (this.color.r, this.color.g, this.color.b, 0.25f);
     //		while (this.color.a < 1f) {
     //			this.color = new Color (this.color.r, this.color.g, this.color.b,
     //			                        Mathf.Clamp (this.color.a + speed, 0f, 1f));
         yield return waiter;
     //		}
     this.color = currentColor;
 }
        IEnumerator TopTransitionRoutine(float duration, bool turnOffBoundaryAfterwards = false)
        {
            var initialTopBoundary = Vector3V(ProCamera2D.CameraPosition) + ProCamera2D.ScreenSizeInWorldCoordinates.y / 2;

            NumericBoundaries.TargetTopBoundary = TopBoundary;

            var waitForFixedUpdate = new WaitForFixedUpdate();
            var t = 0f;
            while (t <= 1.0f)
            {
                t += (ProCamera2D.UpdateType == UpdateType.LateUpdate ? Time.deltaTime : Time.fixedDeltaTime) / duration;

                // Move up
                if (UseTopBoundary && UseBottomBoundary && TopBoundary > initialTopBoundary)
                {
                    NumericBoundaries.TopBoundary = TopBoundary;
                }
                // Move down
                else if (UseTopBoundary)
                {
                    NumericBoundaries.TopBoundary = Utils.EaseFromTo(initialTopBoundary, TopBoundary, t, TransitionEaseType);

                    var currentCamTopEdge = Vector3V(ProCamera2D.CameraPosition) + ProCamera2D.ScreenSizeInWorldCoordinates.y / 2;
                    if (currentCamTopEdge > NumericBoundaries.TargetTopBoundary &&
                        NumericBoundaries.TopBoundary > currentCamTopEdge)
                        NumericBoundaries.TopBoundary = currentCamTopEdge;
                }

                yield return (ProCamera2D.UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;
            }

            if (turnOffBoundaryAfterwards)
            {
                NumericBoundaries.UseTopBoundary = false;
                UseTopBoundary = false;
            }

            if (!_hasFiredTransitionFinished && OnTransitionFinished != null)
                OnTransitionFinished();
        }
Ejemplo n.º 33
0
        IEnumerator ApplyInfluenceTimedRoutine(Vector2 influence, float duration)
        {
            var waitForFixedUpdate = new WaitForFixedUpdate();
            while (duration > 0)
            {
                duration -= UpdateType == UpdateType.LateUpdate ? Time.deltaTime : Time.fixedDeltaTime;

                ApplyInfluence(influence);

                yield return (UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;
            }
        }
Ejemplo n.º 34
0
    private IEnumerator EatTacos()
    {
        YieldInstruction wait = new WaitForFixedUpdate();

        int maxIndex = 0;
        int currMaxScore = 0;
        bool timeBonus = false;

        float counter = 0f;
        float duration = 2f;
        List<Vector3[]> initialPositions = new List<Vector3[]>();
        float[] priorMouthFractions = new float[gameStates.Length];
        for (int playerIndex = 0; playerIndex < gameStates.Length; playerIndex++) {

            GameState gameState = gameStates[playerIndex];
            if (gameState.scoreTacos.Count > currMaxScore) {
                currMaxScore = gameState.scoreTacos.Count;
                maxIndex = playerIndex;
            } else {
                if (gameState.scoreTacos.Count == currMaxScore) {
                    // TIE
                    if (gameState.scoreTacos.Count == 0) {
                        maxIndex = Random.Range(0,1);
                    } else {
                        maxIndex = firstBlood;
                        timeBonus = true;
                    }
                }
            }

            initialPositions.Add(new Vector3[gameState.scoreTacos.Count]);
            for (int tacoIndex = 0; tacoIndex < gameState.scoreTacos.Count; tacoIndex++) {
                initialPositions[playerIndex][tacoIndex] = gameState.scoreTacos[tacoIndex].transform.position;
            }
        }

        GameState winningGameState = gameStates[maxIndex];
        Instantiate(winTextPrefab, winningGameState.tacoSpawnTransform.position, Quaternion.identity);

        while (counter < duration) {
            yield return wait;
            counter += Time.fixedDeltaTime;
            float checkpointFraction = 0.5f;
            for (int playerIndex = 0; playerIndex < gameStates.Length; playerIndex++) {
                GameState gameState = gameStates[playerIndex];
                for (int tacoIndex = 0; tacoIndex < gameState.scoreTacos.Count; tacoIndex++) {
                    float fraction = counter/(duration - tacoIndex * duration/gameState.scoreTacos.Count);
                    Vector3 initialPosition;
                    Vector3 checkpoint = gameState.myMonsterMouthCheckpoint.position;
                    Vector3 mouth = gameState.myMonsterMouth.position;
                    Vector3 difference;
                    if (fraction >= checkpointFraction) {
                        float consumeFraction = (fraction-checkpointFraction)/(1f-checkpointFraction);
                        // float mouthFraction = Mathf.Repeat(consumeFraction,1f);
                        // float rotDifference = gameState.openRotation - gameState.closedRotation;
                        // Quaternion targetRotation = Quaternion.Euler(0, 0, eatingCurve.Evaluate(mouthFraction) * rotDifference + gameState.closedRotation);
                        // gameState.myMonsterMandible.rotation = targetRotation;
                        difference = (mouth - checkpoint);
                        gameState.scoreTacos[tacoIndex].transform.position = eatingCurve.Evaluate(consumeFraction) * difference + checkpoint;
                    } else {
                        initialPosition = initialPositions[playerIndex][tacoIndex];
                        difference = (checkpoint - initialPosition);
                        gameState.scoreTacos[tacoIndex].transform.position = eatingCurve.Evaluate(fraction/checkpointFraction) * difference + initialPosition;
                    }
                }

                // if (counter/duration >= checkpointFraction) {
                // 	float consumeFraction = (counter - (duration * checkpointFraction))/duration;
                // 	float mouthFraction = Mathf.Repeat(consumeFraction,(counter - (duration * checkpointFraction))/gameState.scoreTacos.Count);
                // 	float rotDifference = gameState.openRotation - gameState.closedRotation;
                // 	Quaternion targetRotation = Quaternion.Euler(0, 0, eatingCurve.Evaluate(mouthFraction) * rotDifference + gameState.closedRotation);
                // 	gameState.myMonsterMandible.rotation = targetRotation;
                // }

            }
        }

        yield return StartCoroutine(QuitOnComplete());
    }
        IEnumerator ApplyShakeTimedRoutine(Vector2 shake, Quaternion rotation, float duration)
        {
            _rotationTime = 0;
            _rotationVelocity = 0;
            var waitForFixedUpdate = new WaitForFixedUpdate();
            while (duration > 0)
            {
                duration -= ProCamera2D.UpdateType == UpdateType.LateUpdate ? Time.deltaTime : Time.fixedDeltaTime;

                _shakePositions.Add(VectorHV(shake.x, shake.y));

                _rotationTarget = rotation;

                yield return (ProCamera2D.UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;
            }
        }
        IEnumerator LeftTransitionRoutine(float duration, bool turnOffBoundaryAfterwards = false)
        {
            var initialLeftBoundary = Vector3H(ProCamera2D.CameraPosition) - ProCamera2D.ScreenSizeInWorldCoordinates.x / 2;

            NumericBoundaries.TargetLeftBoundary = LeftBoundary;

            var waitForFixedUpdate = new WaitForFixedUpdate();
            var t = 0f;
            while (t <= 1.0f)
            {
                t += (ProCamera2D.UpdateType == UpdateType.LateUpdate ? Time.deltaTime : Time.fixedDeltaTime) / duration;

                // Move left
                if (UseLeftBoundary && UseRightBoundary && LeftBoundary < initialLeftBoundary)
                {
                    NumericBoundaries.LeftBoundary = LeftBoundary;
                }
                // Move right
                else if (UseLeftBoundary)
                {
                    NumericBoundaries.LeftBoundary = Utils.EaseFromTo(initialLeftBoundary, LeftBoundary, t, TransitionEaseType);

                    var currentCamLeftEdge = Vector3H(ProCamera2D.CameraPosition) - ProCamera2D.ScreenSizeInWorldCoordinates.x / 2;
                    if (currentCamLeftEdge < NumericBoundaries.TargetLeftBoundary &&
                        NumericBoundaries.LeftBoundary < currentCamLeftEdge)
                        NumericBoundaries.LeftBoundary = currentCamLeftEdge;
                }

                yield return (ProCamera2D.UpdateType == UpdateType.FixedUpdate) ? waitForFixedUpdate : null;
            }

            if (turnOffBoundaryAfterwards)
            {
                NumericBoundaries.UseLeftBoundary = false;
                UseLeftBoundary = false;
            }

            if (!_hasFiredTransitionFinished && OnTransitionFinished != null)
                OnTransitionFinished();
        }