Example #1
0
        IEnumerator ActionCamRoutine(Unit srcUnit, Vector3 tgtPos)
        {
            TurnControl.ActionCommenced();

            actionCamInProgress = true;

            Vector3    rootPosOrigin = thisT.position;
            Quaternion rootRotOrigin = thisT.rotation;

            Vector3 posOrigin  = camT.localPosition;
            float   zoomOrigin = camT.localPosition.z;

            Vector3 centerPos = srcUnit.GetTargetT().position + (tgtPos - srcUnit.GetTargetT().position) * 0.35f;

            centerPos.y = thisT.position.y;

            Quaternion wantedRot = Quaternion.LookRotation(centerPos - srcUnit.GetTargetT().position);

            wantedRot *= Quaternion.Euler(10, 15, 0);
            wantedRot  = Quaternion.Euler(wantedRot.eulerAngles.x, wantedRot.eulerAngles.y, 0);

            float dist = Vector3.Distance(centerPos, srcUnit.GetTargetT().position);

            float duration = 0;

            while (duration < 1)
            {
                thisT.rotation = Quaternion.Euler(thisT.rotation.eulerAngles.x, thisT.rotation.eulerAngles.y, 0);

                camT.localPosition = Vector3.Lerp(new Vector3(0, 0, zoomOrigin), new Vector3(0, 0, -dist - GridManager.GetTileSize() * 2), duration);
                thisT.position     = Vector3.Lerp(rootPosOrigin, centerPos, duration);
                thisT.rotation     = Quaternion.Lerp(rootRotOrigin, wantedRot, duration);

                duration += Time.deltaTime * 1f;
                yield return(null);
            }
            thisT.rotation = wantedRot;

            TurnControl.ActionCompleted();

            yield return(null);

            while (!TurnControl.ClearToProceed())
            {
                yield return(null);
            }

            TurnControl.ActionCommenced();

            duration = 0;
            while (duration < 1)
            {
                thisT.rotation = Quaternion.Euler(thisT.rotation.eulerAngles.x, thisT.rotation.eulerAngles.y, 0);

                camT.localPosition = Vector3.Lerp(new Vector3(0, 0, -dist - GridManager.GetTileSize() * 2), new Vector3(0, 0, zoomOrigin), duration);
                thisT.position     = Vector3.Lerp(centerPos, rootPosOrigin, duration);
                thisT.rotation     = Quaternion.Lerp(wantedRot, rootRotOrigin, duration);

                duration += Time.deltaTime * 1f;
                yield return(null);
            }

            thisT.position     = rootPosOrigin;
            thisT.rotation     = rootRotOrigin;
            camT.localPosition = posOrigin;

            TurnControl.ActionCompleted();

            actionCamInProgress = false;
        }