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; } }
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)); }
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); } }
// 직선 등속 이동 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; }
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)); }
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)); }
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); }
// 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 해당 코드가 자동으로 최적화되는지 확인 }
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); }
// 목적과의 방향차이에 비례해서 선회 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; }
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); }
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)); }
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; }
private void FixedUpdate() { if (state == false) { return; } if (enableTargetUpdate) { TargetUpdate(); } if (target != null) { owner.targetDir = VEasyCalc.GetDirection(owner, target); } }
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)); }
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 }); }
protected override void ActionProcess(Trigger trigger) { from.targetDir = VEasyCalc.GetDirection(from, to); }
protected override void ActionProcess(Trigger trigger) { Vector2 mouseWorldPos = VEasyCalc.ScreenToWorldPos(Input.mousePosition); target.targetDir = VEasyCalc.GetDirection(target.transform.position, mouseWorldPos); }
protected override void ActionProcess(Trigger trigger) { Actor owner = trigger?.owner; owner.moveDir = VEasyCalc.GetReflectedDirection(owner.moveDir, owner.targetDir); }