Exemple #1
0
        public override void Update(ActionSelectorSM self)
        {
            var mesh = self.selectionCircleMesh;

            var enemiesInRange = GameTickManager.Instance.activeEnemies.Where(
                e => Astar.CalculateHeuristic(e.GridPosition, PlayerActor.Instance.GridPosition)
                < PlayerActor.Instance.stats.currentStats.awareness).ToList();

            var   ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            float enter;

            if (!plane.Raycast(ray, out enter))
            {
                return;
            }

            var field = new NVector2(GridUtil.WorldToGrid(ray.GetPoint(enter)));

            int?is_valid = null;

            for (var i = 0; i < enemiesInRange.Count; ++i)
            {
                if (enemiesInRange[i].GridPosition == field)
                {
                    is_valid = i;
                    Graphics.DrawMesh(mesh,
                                      Matrix4x4.Translate(enemiesInRange[i].transform.position), self.selectionCircleMaterial, 0, Camera.current, 0, activeCircle);
                }
                else
                {
                    Graphics.DrawMesh(mesh,
                                      Matrix4x4.Translate(enemiesInRange[i].transform.position), self.selectionCircleMaterial, 0, Camera.current, 0);
                }
            }

            if (Input.GetMouseButtonDown(0) && is_valid != null)
            {
                var enemy          = enemiesInRange[(int)is_valid];
                var selectedAction = new AttackAction(PlayerActor.Instance.gameObject, enemy.gameObject, enemy.attackPrefab, 1);
                onActionSelectedObservable.OnNext(selectedAction);
            }
        }
        public override void Update(ActionSelectorSM self)
        {
            if (mesh == null || meshMaterial == null)
            {
                return;
            }
            Graphics.DrawMesh(mesh, Matrix4x4.Translate(self.transform.position), meshMaterial, 0, Camera.current, 0, new MaterialPropertyBlock(), ShadowCastingMode.Off, receiveShadows: false);

            /* replace by input provider: */
            var   ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            float enter;

            if (plane.Raycast(ray, out enter))
            {
                var field = new NVector2(GridUtil.WorldToGrid(ray.GetPoint(enter)));

                fieldSelector.transform.position =
                    Vector3.MoveTowards(fieldSelector.transform.position,
                                        GridUtil.GridToWorld(field),
                                        32 * Time.deltaTime);

                var sel = new NVector2(GridUtil.WorldToGrid(fieldSelector.transform.position));

                if (Math.Abs(sel.x - field.x + sel.y - field.y) > 0)
                {
                    return;
                }

                var is_valid = walkableTiles.Contains(sel);
                fieldSelector.SetActive(is_valid);

                if (Input.GetMouseButtonDown(0) && is_valid)
                {
                    var path = Astar.Path(PlayerActor.Instance.GridPosition, sel, heurFactor: 2);
                    selectedAction = new MoveAction(PlayerActor.Instance.gameObject, path);
                    onActionSelectedObservable.OnNext(selectedAction);
                }
            }
        }
Exemple #3
0
 public abstract void Update(ActionSelectorSM self);