예제 #1
0
        private void HandleFixedUpdate()
        {
            Collidable col         = owner.GetOperable <Collidable>();
            EDirection bounceByDir = VEasyCalc.CheckOutside2D(col.collider);

            switch (bounceByDir)
            {
            case EDirection.UP:
                targetPos = new Vector2(owner.transform.position.x, CameraManager.WorldHeightHalf);
                bounceTo  = 90f;
                ActivateTrigger();
                break;

            case EDirection.DOWN:
                targetPos = new Vector2(owner.transform.position.x, -CameraManager.WorldHeightHalf);
                bounceTo  = 270f;
                ActivateTrigger();
                break;

            case EDirection.LEFT:
                targetPos = new Vector2(-CameraManager.WorldWidthHalf, owner.transform.position.y);
                bounceTo  = 180f;
                ActivateTrigger();
                break;

            case EDirection.RIGHT:
                targetPos = new Vector2(CameraManager.WorldWidthHalf, owner.transform.position.y);
                bounceTo  = 0f;
                ActivateTrigger();
                break;
            }
        }
예제 #2
0
        public static Vector2 GetRotatedPosition(float degrees, Vector2 pos)
        {
            float prevDegrees = VEasyCalc.GetDirection(new Vector2(0f, 0f), pos);

            float distance = Vector2.Distance(new Vector2(0f, 0f), pos);

            return(GetRotatedPosition(prevDegrees + degrees, distance));
        }
예제 #3
0
 public static void UpdateText(GameObject key, string str, Vector2 worldPos)
 {
     if (textDisplayerDic.ContainsKey(key))
     {
         var text = textDisplayerDic[key].text;
         text.text = str;
         text.rectTransform.anchoredPosition = VEasyCalc.WorldToGuiPos(worldPos);
     }
 }
예제 #4
0
        // 직선 등속 이동
        protected override void MoveFrame()
        {
            float moveDistance = speed * Time.fixedDeltaTime;

            Vector2 moveVector = VEasyCalc.GetRotatedPosition(owner.moveDir, moveDistance);
            Vector2 v2Pos      = owner.transform.position;

            owner.transform.position = v2Pos + moveVector;
        }
예제 #5
0
        public override void PreFireProcess()
        {
            if (count == 1)
            {
                return;
            }

            float deltaDistance = length * (UnityEngine.Random.Range(0f, 1f) - 0.5f);

            deltaPos = VEasyCalc.GetRotatedPosition(direction, new Vector2(deltaDistance, 0f));
        }
예제 #6
0
        public override void PreFireProcess()
        {
            if (target != null)
            {
                targetPos = target.transform.position;
            }
            direction = VEasyCalc.GetDirection(position, targetPos);

            float deltaDistance = length * (UnityEngine.Random.Range(0f, 1f) - 0.5f);

            deltaPos = VEasyCalc.GetRotatedPosition(direction, new Vector2(deltaDistance, 0f));
        }
예제 #7
0
        public override void PreFireProcess()
        {
            if (target == null && owner != null)
            {
                target = owner.GetOperable <Targetable>().target;
            }

            if (target != null)
            {
                targetPos = target.transform.position;
            }
            direction = VEasyCalc.GetDirection(position, targetPos);
        }
예제 #8
0
        //

        protected virtual void TargetUpdate()
        {
            List <Unit> units = Unit.unitList;

            units = (from target in units
                     where target.force != owner.force
                     where isRangeless || VEasyCalc.GetSqrDistance(owner, target) < range * range
                     select target).ToList();

            target = units.FirstOrDefault(x => VEasyCalc.GetSqrDistance(owner, x) ==
                                          units.Min(y => VEasyCalc.GetSqrDistance(owner, y)));
            // TODO 해당 코드가 자동으로 최적화되는지 확인
        }
예제 #9
0
        private void Awake()
        {
            var rect = new Vector2(200f, 50f);
            var pos  = new Vector2(
                -CameraManager.WorldWidthHalf, CameraManager.WorldHeightHalf);

            var worldRect = VEasyCalc.GuiToWorldPos(rect);

            pos.x += worldRect.x * 0.5f;
            pos.y -= worldRect.y * 0.5f;

            TextDisplayer.AssignNewText(gameObject, "", new Color(1, 1, 1),
                                        pos, rect, TextAnchor.UpperLeft);
        }
예제 #10
0
        // 목적과의 방향차이에 비례해서 선회
        protected override void MoveFrame()
        {
            float moveDistance = speed * Time.fixedDeltaTime;

            float dirToPlayer = VEasyCalc.GetDirection(owner.transform.position, targetPos);

            owner.moveDir = VEasyCalc.GetLerpDirection(
                owner.moveDir, dirToPlayer, turnFactor * Time.fixedDeltaTime);

            Vector2 moveVector = VEasyCalc.GetRotatedPosition(owner.moveDir, moveDistance);

            Vector2 v2Pos = owner.transform.position;

            owner.transform.position = v2Pos + moveVector;
        }
예제 #11
0
        public override void PreFireProcess()
        {
            if (target == null && owner != null)
            {
                target = owner.GetOperable <Targetable>().target;
            }

            if (target != null)
            {
                targetPos = target.transform.position;
            }
            direction = VEasyCalc.GetDirection(position, targetPos);

            fireAngle = angle * (UnityEngine.Random.Range(0f, 1f) - 0.5f);
        }
예제 #12
0
        protected override void ActionProcess(Trigger trigger)
        {
            if (VEasyCalc.TryCast(trigger, out TrgCollision trgCol))
            {
                if (trgCol.target != null)
                {
                    target.moveDir = VEasyCalc.GetDirection(trgCol.target, target);
                }
            }
            else
            {
                target.moveDir += 180f;
            }

            GameManager.Instance.StartCoroutine(DecelerationProcess(trigger));
        }
예제 #13
0
        protected override void ActionProcess(Trigger trigger)
        {
            Vector2 targetPos;
            float   targetDir;
            float   distance = 0f;

            Collidable col = trigger.owner.GetOperable <Collidable>();

            if (VEasyCalc.TryCast(trigger, out TrgCollision trgCol))
            {
                Actor target = trgCol.target;
                targetPos = target.transform.position;
                targetDir = VEasyCalc.GetDirection(trigger.owner, target);

                // TODO 유닛간 block 처리 구현
                // Contact, Raycast 등 활용?
            }
            else if (VEasyCalc.TryCast(trigger, out TrgBoundaryTouch trgBndTch))
            {
                targetPos = trgBndTch.targetPos;
                targetDir = trgBndTch.bounceTo;

                if (VEasyCalc.TryCast(col?.collider, out CircleCollider2D circleCol))
                {
                    distance = circleCol.radius;
                }
                // TODO box collider 처리
            }
            else if (VEasyCalc.TryCast(trigger, out TrgBoundaryOut regBndOut))
            {
                targetPos = regBndOut.targetPos;
                targetDir = regBndOut.bounceTo;

                if (VEasyCalc.TryCast(col?.collider, out CircleCollider2D circleCol))
                {
                    distance = circleCol.radius;
                }
            }
            else
            {
                return;
            }

            Vector2 delta = VEasyCalc.GetRotatedPosition(targetDir + 180f, distance);

            trigger.owner.transform.position = targetPos + delta;
        }
예제 #14
0
        private void FixedUpdate()
        {
            if (state == false)
            {
                return;
            }

            if (enableTargetUpdate)
            {
                TargetUpdate();
            }

            if (target != null)
            {
                owner.targetDir = VEasyCalc.GetDirection(owner, target);
            }
        }
예제 #15
0
        public override void PreFireProcess()
        {
            if (count == 1)
            {
                return;
            }

            float fireIndex = (float)firedCount / (count - 1) - 0.5f;

            if (!isLeftToRight)
            {
                fireIndex = -fireIndex;
            }
            float deltaDistance = length * fireIndex;

            deltaPos = VEasyCalc.GetRotatedPosition(direction, new Vector2(deltaDistance, 0f));
        }
예제 #16
0
        public static void AssignNewText(GameObject root, string str, Color color,
                                         Vector2 worldPos, Vector2 guiRectSize, TextAnchor alignment)
        {
            var canvas = GUIManager.MainCanvas;
            var go     = new GameObject(root.name + " Text");
            var text   = go.AddComponent <Text>();

            text.rectTransform.SetParent(canvas.transform);

            text.rectTransform.sizeDelta        = new Vector2(guiRectSize.x, guiRectSize.y);
            text.rectTransform.localScale       = new Vector3(1, 1, 1);
            text.rectTransform.anchoredPosition = VEasyCalc.WorldToGuiPos(worldPos);

            text.font      = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
            text.color     = color;
            text.text      = str;
            text.alignment = alignment;

            textDisplayerDic.Add(root, new TextDisplayer {
                text = text
            });
        }
예제 #17
0
 protected override void ActionProcess(Trigger trigger)
 {
     from.targetDir = VEasyCalc.GetDirection(from, to);
 }
예제 #18
0
        protected override void ActionProcess(Trigger trigger)
        {
            Vector2 mouseWorldPos = VEasyCalc.ScreenToWorldPos(Input.mousePosition);

            target.targetDir = VEasyCalc.GetDirection(target.transform.position, mouseWorldPos);
        }
예제 #19
0
        protected override void ActionProcess(Trigger trigger)
        {
            Actor owner = trigger?.owner;

            owner.moveDir = VEasyCalc.GetReflectedDirection(owner.moveDir, owner.targetDir);
        }