public PathGrid(Vector3 leftDownPos, Vector3 rightUpPos)
    {
        leftDownPosition = EveryFunction.FloorToInt(leftDownPos);
        rightUpPosition  = EveryFunction.FloorToInt(rightUpPos);
        width            = Mathf.Abs(leftDownPosition.x - this.rightUpPosition.x);
        height           = Mathf.Abs(leftDownPosition.y - this.rightUpPosition.y);
        grid             = new Grid <PathNode> (width, height, 1f,
                                                leftDownPosition, (Grid <PathNode> g, int x, int y) => new PathNode(g, x, y));

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                if (isAWall(x, y))
                {
//                     Debug.Log (grid.GetTGridObject (x, y).ToString ());
                    grid.GetTGridObject(x, y).SetIsThroughable(false);
                }
                else
                {
                    grid.GetTGridObject(x, y).SetIsThroughable(true);
                }
            }
        }
    }
Exemple #2
0
    public Grid(int width, int height, float cellsize, Vector3 oriPosition, Func <Grid <TGridObject>, int, int, TGridObject> createGridObject)
    {
        this.width       = width;
        this.height      = height;
        this.cellsize    = cellsize;
        this.oriPosition = oriPosition;
        gridArray        = new TGridObject[width, height];
        debugTextArray   = new TextMesh[width, height];

        for (int x = 0; x < gridArray.GetLength(0); x++)
        {
            for (int y = 0; y < gridArray.GetLength(1); y++)
            {
                gridArray[x, y] = createGridObject(this, x, y);
                if (isDrawLine)
                {
                    debugTextArray[x, y] = EveryFunction.CreateWorldText(gridArray[x, y].ToString(), null, GetWorldPosition(x, y) + new Vector3(cellsize, cellsize) * 0.5f, 45, Color.white, TextAnchor.MiddleCenter, TextAlignment.Center);
                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
                    Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
                }
            }
        }
        if (isDrawLine)
        {
            Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);
            Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
        }
    }
Exemple #3
0
        //生成技能需要知道的事情:技能数据,释放的目标位置
        public void GenerateSkill(SkillData data, Vector3 deployPosition)
        {
            //计算技能释放角度,默认为普通朝向(正向)
            Quaternion quaternion = transform.rotation;

            //如果跟随角色,就以角色为中心环绕
            if (data.isFollowCharacter)
            {
                quaternion = Quaternion.Euler(0, 0, EveryFunction.GetAngleOfTransform(data.owner.transform.position, deployPosition));
            }
            //创建技能预制件——通过对象池生成
            GameObject    skillObj      = GameObjectPool.Instance.CreateObject(data.prefabName, data.skillPrefab, deployPosition, quaternion);
            SkillDeployer skillDeployer = skillObj.GetComponentInChildren <SkillDeployer> ();

            //传递技能数据
            //内部创建算法对象
            skillDeployer.skillData = data;
            //播放动画
            skillObj.GetComponentInChildren <Animator> ().Play(skillDeployer.skillData.prefabName);
            //先播放动画再执行算法对象
            //内部执行算法对象
            //销毁技能
            GameObjectPool.Instance.CollectObject(skillObj, data.durationTime);
            //开启技能冷却
            StartCoroutine(CoolTimeDown(data));
        }
 private void Update()
 {
     if (Input.GetMouseButton(1))
     {
         //调用移动
         GetComponent <IMovePosition> ().SetPosition(EveryFunction.GetMouseWorldPositionWithZ(Input.mousePosition));
     }
 }
    public void Init()
    {
        //初始化路径网格
        PathGrid pathGrid = new PathGrid(leftDownTransform.position, rightUpTransform.position);

        EveryFunction.InitPathFinding(pathGrid);
        cameraController = GameObject.FindWithTag("MainCamera").GetComponent <CameraController> ();
    }
Exemple #6
0
 public void Execute(SkillDeployer deployer)
 {
     foreach (var targets in deployer.skillData.attackTargets)
     {
         if (targets != null)
         {
             Vector3 strikeDirection = EveryFunction.GetNormalDirection(deployer.skillData.owner.transform.position, targets.transform.position);
             var     characterBase   = targets.GetComponent <CharacterStatus> ();
             characterBase.data.rigidbody.MovePosition(targets.transform.position + strikeDirection * strikeLength);
         }
     }
 }
Exemple #7
0
 public void SetPosition(Vector3 movePosition)
 {
     //索引值初始化
     pathIndex = -1;
     //限制区域:地图左下和右上,因为是地牢,所以不会占很多格子
     pathList = EveryFunction.GetPath(transform.position, movePosition);
     //路径点1:一定是自己位置上的格子,所以要算如果路径点>1,说明还没到目标位置
     if (pathList != null && pathList.Count > 1)
     {
         pathIndex = 1;
     }
 }
        public List <PathNode> FindRandomPos(out Vector3 movePosition)
        {
            List <PathNode> pathList;

            do
            {
                //随机位置
                movePosition = startPosition + EveryFunction.GetRandomDir() * UnityEngine.Random.Range(0, patrolRadius);
                //到达该位置的路径表
                pathList = GetPath(movePosition);
                //条件:路径表为空,而且路径点数==1(第一个路径点就是自身的位置)时就需要重新选择位置
            } while (pathList == null || pathList.Count == 1);
            return(pathList);
        }
Exemple #9
0
        //使用技能攻击,玩家直接用这个
        public void AttackUseSkill(int skillId)
        {
            //检测是否是受击状态,如果是受击状态则不产生技能
            if (GetComponent <CharacterStatus> ().data.textureTime > 0)
            {
                return;
            }
            //准备技能
            skill = skillManager.PrepareSkill(skillId);
            //如果技能无法使用(在cd或者不存在)
            if (skill == null)
            {
                return;
            }
            //播放动画:人物动画 非技能动画 技能动画生成自己播放
            anim.Play(skill.characterAnimationName);
            //            anim.SetBool (skill.animationName, true);

            //如果技能释放者是玩家,就不需要瞄准敌人:由鼠标瞄准
            if (this.tag == "Player")
            {
                deployPosition = EveryFunction.GetMouseWorldPosition();
                return;
            }
            //以下为npc的判断方式
            //如果是多攻,就不调用下面的方法了
            if (skill.attackType != AttackType.Single)
            {
                return;
            }
            //如果单攻
            //--朝向目标,生成技能的时候把朝向传输进去
            Transform targetTF = SelectTarget();

            if (targetTF != null)
            {
                deployPosition = targetTF.position;
            }
            //--选中目标:先取消上一次目标,再选中本次的目标
            //核心思想:存储上次选中的物体
            //先取消上次选中的物体
            SetSelectedActiveFX(false);
            //目标切换成当前的目标
            selectedTarget = targetTF;
            //激活当前的目标
            SetSelectedActiveFX(true);
            //因为现在没有动画/动画事件不会弄 默认为直接生成技能
            //            DeploySkill ();
        }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(1))
     {
         Vector3 mousePosition = EveryFunction.GetMouseWorldPosition();
         pathFinding.GetGrid().GetXY(mousePosition, out int x, out int y);
         pathFinding.GetGrid().GetXY(playerTransform.position, out int oriX, out int oriY);
         pathFinding.GetGrid().GetXY(GameController.Instance.leftDownTransform.position, out int minX, out int minY);
         pathFinding.GetGrid().GetXY(GameController.Instance.rightUpTransform.position, out int maxX, out int maxY);
         List <PathNode> path = pathFinding.FindPath(oriX, oriY, x, y, minX, minY, maxX, maxY);
         if (path != null)
         {
             for (int i = 0; i < path.Count - 1; i++)
             {
                 Vector3 currentPos = pathFinding.GetGrid().GetWorldCenterPosition(path[i].x, path[i].y);
                 Vector3 nextPos    = pathFinding.GetGrid().GetWorldCenterPosition(path[i + 1].x, path[i + 1].y);
                 Debug.DrawLine(currentPos, nextPos, Color.red, 100f);
             }
         }
     }
 }
 public override void Update()
 {
     base.Update();
     //人物翻转
     characterStatus.Flip(EveryFunction.GetMouseWorldPosition().x - transform.position.x);
 }
 //获取目标点(世界坐标)和路径列表(网格坐标)
 public List <PathNode> GetPath(Vector3 movePosition)
 {
     //返回路径表
     return(EveryFunction.GetPath(transform.position, movePosition));
 }