Esempio n. 1
0
    public void CreateSkillRange(int range, Transform character)
    {
        this.character = character;
        startRotation  = character.rotation;
        var list = CreateRange(range, character.position);

        foreach (var position in list)
        {
            //检测到障碍物时地块不显示。后期实现水上行走,跳远,树上行走。
            if (DetectObstacle(position))
            {
                continue;
            }

            BattleFieldManager.GetInstance().GetFloor(position).SetActive(true);
            rangeDic.Add(position, BattleFieldManager.GetInstance().GetFloor(position));
        }

        var buffer = new List <Vector3>();

        foreach (var floor in rangeDic)
        {
            if (floor.Key != character.position && UseAstar(character.position, floor.Key, range).Count == 0)
            {
                floor.Value.SetActive(false);
                buffer.Add(floor.Key);
            }
        }
        foreach (var a in buffer)
        {
            rangeDic.Remove(a);
        }
    }
Esempio n. 2
0
    void Update()
    {
        //GetMousePosition();

        if (Input.GetMouseButtonDown(1))
        {
            if (SkillManager.GetInstance().skillQueue.Count > 0)
            {
                if (character)
                {
                    //Debug.Log("UIManager : " + SkillManager.GetInstance().skillQueue.Peek().Key.CName + " 队列剩余 " + SkillManager.GetInstance().skillQueue.Count);
                    if (!SkillManager.GetInstance().skillQueue.Peek().Key.done)
                    {
                        SkillManager.GetInstance().skillQueue.Peek().Key.Reset();
                    }
                }
            }
            else
            {
                Camera.main.GetComponent <RenderBlurOutline>().CancelRender();
                foreach (var f in BattleFieldManager.GetInstance().floors)
                {
                    f.Value.SetActive(false);
                }
                if (RoundManager.GetInstance().RoundState != null)
                {
                    ((RoundStateWaitingForInput)RoundManager.GetInstance().RoundState).DestroyPanel();
                }
            }
        }
    }
Esempio n. 3
0
 public override void OnUnitClicked(Unit unit)
 {
     if (!EventSystem.current.IsPointerOverGameObject())
     {
         if (roleInfoPanel)
         {
             GameObject.Destroy(roleInfoPanel);
         }
         foreach (var f in BattleFieldManager.GetInstance().floors)
         {
             f.Value.SetActive(false);
         }
         range = new MoveRange();
         if (unit.playerNumber.Equals(roundManager.CurrentPlayerNumber) && !unit.UnitEnd)
         {
             roundManager.RoundState = new RoundStateUnitSelected(roundManager, unit);
         }
         else
         {
             Camera.main.GetComponent <RenderBlurOutline>().RenderOutLine(unit.transform);
             range.CreateMoveRange(unit.transform);
             CreatePanel(unit);
         }
     }
 }
Esempio n. 4
0
    public override void OnUnitClicked(Unit unit)
    {
        foreach (var f in BattleFieldManager.GetInstance().floors)
        {
            f.Value.SetActive(false);
        }
        range = new MoveRange();
        if (unit.playerNumber.Equals(roundManager.CurrentPlayerNumber) && !unit.UnitEnd && SkillManager.GetInstance().skillQueue.Peek().Key.EName == "FirstAction")
        {
            SkillManager.GetInstance().skillQueue.Peek().Key.Reset();
            roundManager.RoundState = new RoundStateUnitSelected(roundManager, unit);
        }
        else if (SkillManager.GetInstance().skillQueue.Peek().Key.EName == "FirstAction")
        {
            var outline = Camera.main.GetComponent <RenderBlurOutline>();
            if (outline)
            {
                outline.RenderOutLine(unit.transform);
            }

            SkillManager.GetInstance().skillQueue.Peek().Key.Reset();

            RoundManager.GetInstance().RoundState = new RoundStateWaitingForInput(RoundManager.GetInstance());
            range.CreateMoveRange(unit.transform);
            ((RoundStateWaitingForInput)RoundManager.GetInstance().RoundState).CreatePanel(unit);
        }
        Camera.main.GetComponent <RTSCamera>().FollowTarget(unit.transform.position);
    }
Esempio n. 5
0
 public override void OnUnitClicked(Unit unit)
 {
     if (roleInfoPanel)
     {
         GameObject.Destroy(roleInfoPanel);
     }
     foreach (var f in BattleFieldManager.GetInstance().floors)
     {
         f.Value.SetActive(false);
     }
     range = new MoveRange();
     if (unit.playerNumber.Equals(roundManager.CurrentPlayerNumber) && !unit.UnitEnd)
     {
         roundManager.RoundState = new RoundStateUnitSelected(roundManager, unit);
     }
     else
     {
         var outline = Camera.main.GetComponent <RenderBlurOutline>();
         if (outline)
         {
             outline.RenderOutLine(unit.transform);
         }
         range.CreateMoveRange(unit.transform);
         CreatePanel(unit);
     }
     Camera.main.GetComponent <RTSCamera>().FollowTarget(unit.transform.position);
 }
Esempio n. 6
0
    protected virtual void ResetSelf()
    {
        if (comboJudgeUI)
        {
            GameObject.Destroy(comboJudgeUI);
        }
        if (comboSelectUI)
        {
            GameObject.Destroy(comboSelectUI);
        }
        if (confirmUI)
        {
            UnityEngine.Object.Destroy(confirmUI);
        }
        UnitManager.GetInstance().units.ForEach(u => u.gameObject.layer = 0);
        if (range != null)
        {
            range.Reset();
        }

        foreach (var f in BattleFieldManager.GetInstance().floors)
        {
            f.Value.GetComponent <Floor>().FloorClicked -= Confirm;
            f.Value.GetComponent <Floor>().FloorExited  -= DeleteHoverRange;
            f.Value.GetComponent <Floor>().FloorHovered -= Focus;
        }


        skillState = SkillState.init;
    }
Esempio n. 7
0
    //返回一个列表,包含以p为中心大小为range的菱形范围的所有Vector3。
    public static List <Vector3> CreateRange(int range, Vector3 p)
    {
        List <Vector3> list = new List <Vector3>();

        //这个数组存放每一行(或者是每一列)应有的方块数,例如:如果range = 3,则数组应为{1,3,5,7,5,3,1}。
        int[] num = new int[2 * range + 1];
        //这个数组应该是奇数个元素个数,并且以中间元素为轴对称。
        for (int i = 0; i < range + 1; i++)
        {
            num[i]             = 2 * i + 1;
            num[2 * range - i] = num[i];
        }
        //根据这个数组,来创建范围。遍历的两个维度,一个是数组的长度,即行数,另一个是数组每一个值,即每一行应该有的方块数。
        for (int i = 0; i < num.Length; i++)
        {
            for (int j = 0; j < num[i]; j++)
            {
                //根据range、i、j、角色position算出每块地板的坐标。
                //中心点为transform.position,每一列应有一个偏移量,使最终显示结果为菱形而不是三角形。
                float rX = p.x + (range - i);
                float rZ = p.z + (range - j) - Mathf.Abs(range - i);

                if (rX < 1 || rZ < 1 || rX > BattleFieldManager.GetInstance().GridX - 1 || rZ > BattleFieldManager.GetInstance().GridY - 1)//超出边界的不创建  由于A*报数组下标越界(因为要检测一个单元周围的所有单元,而边界单元没有完整的周围单元),所以这里把边界缩小一圈。
                {
                    continue;
                }
                Vector3 position = new Vector3(rX, p.y, rZ);
                list.Add(position);
            }
        }
        return(list);
    }
Esempio n. 8
0
    public override bool Init(Transform character)
    {
        this.character = character;

        range.CreateMoveRange(character);

        focus = new Vector3(-1, -1, -1);
        final = false;
        if (!isAI)
        {
            foreach (var f in BattleFieldManager.GetInstance().floors)
            {
                if (f.Value.activeInHierarchy)
                {
                    f.Value.GetComponent <Floor>().FloorClicked += Confirm;
                    f.Value.GetComponent <Floor>().FloorHovered += Focus;
                    f.Value.GetComponent <Floor>().FloorExited  += RecoverColor;
                }
            }
        }
        //角色加入忽略层,方便选取
        UnitManager.GetInstance().units.FindAll(u => u.playerNumber == character.GetComponent <Unit>().playerNumber).ForEach(u => BattleFieldManager.GetInstance().GetFloor(u.transform.position).gameObject.layer = 2);
        UnitManager.GetInstance().units.ForEach(u => u.gameObject.layer = 2);

        return(true);
    }
Esempio n. 9
0
    IEnumerator MoveAI(Unit aiUnit, Vector3 targetFloor)
    {
        //target position is as same as aiUnit, don't need to move
        if (aiUnit.transform.position == targetFloor)
        {
            Debug.Log(aiUnit.name + " don't need to move");
            yield return(new WaitForSeconds(0.5f));
        }
        else
        {
            //auto move forward target
            aiUnit.GetComponent <CharacterAction>().SetSkill("Move");
            Move moveSkill = SkillManager.GetInstance().skillQueue.Peek().Key as Move;

            moveSkill.Init(aiUnit.transform);

            GameObject floor = BattleFieldManager.GetInstance().GetFloor(targetFloor);
            moveSkill.Focus(floor.GetComponent <Floor>());
            yield return(new WaitForSeconds(0.5f));

            aiTree.outline.CancelRender();
            moveSkill.Confirm();
            yield return(new WaitUntil(() => { return moveSkill.skillState == Skill.SkillState.reset; }));
        }
        aiTree.moveRange.Delete();
        yield return(new WaitForSeconds(0.1f));
    }
Esempio n. 10
0
    virtual public void Start()
    {
        bfm  = GameObject.Find("BattleFieldManager").GetComponent <BattleFieldManager>();
        uime = GameObject.Find("Canvas_UI").GetComponent <UIMessageExchanger>();

        operationPoint = maxOperationPoint;
    }
Esempio n. 11
0
 public void BackSpace()
 {
     if (SkillManager.GetInstance().skillQueue.Count > 0)
     {
         if (character)
         {
             //Debug.Log("UIManager : " + SkillManager.GetInstance().skillQueue.Peek().Key.CName + " 队列剩余 " + SkillManager.GetInstance().skillQueue.Count);
             if (!SkillManager.GetInstance().skillQueue.Peek().Key.done)
             {
                 SkillManager.GetInstance().skillQueue.Peek().Key.Reset();
             }
         }
     }
     else
     {
         var outline = Camera.main.GetComponent <RenderBlurOutline>();
         if (outline)
         {
             outline.CancelRender();
         }
         foreach (var f in BattleFieldManager.GetInstance().floors)
         {
             f.Value.SetActive(false);
         }
         if (RoundManager.GetInstance().RoundState != null)
         {
             ((RoundStateWaitingForInput)RoundManager.GetInstance().RoundState).DestroyPanel();
         }
     }
 }
Esempio n. 12
0
    protected List <Point> UseAstar(Vector3 origin, Vector3 destination, int range)
    {
        int[,] array = new int[BattleFieldManager.GetInstance().GridX, BattleFieldManager.GetInstance().GridY];     //可优化为更小的地图。
        path.Clear();
        for (int i = 0; i < BattleFieldManager.GetInstance().GridX; i++)
        {
            for (int j = 0; j < BattleFieldManager.GetInstance().GridY; j++)
            {
                array[i, j] = 1;
            }
        }

        var minX = origin.x - range;
        var minY = origin.z - range;
        var maxX = origin.x + range;
        var maxY = origin.z + range;

        minX = minX > 0 ? minX : 0.5f;
        minY = minY > 0 ? minY : 0.5f;
        maxX = maxX < BattleFieldManager.GetInstance().GridX ? maxX : BattleFieldManager.GetInstance().GridX - 0.5f;
        maxY = maxY < BattleFieldManager.GetInstance().GridY ? maxY : BattleFieldManager.GetInstance().GridY - 0.5f;

        //检测整张地图的地板块激活情况,判断障碍物,存入数组。

        for (int i = (int)minX; i <= (int)maxX; i++)
        {
            for (int j = (int)minY; j <= (int)maxY; j++)
            {
                floorPosition    = Vector3.zero;
                floorPosition.x += (i + anchorPoint);
                floorPosition.z += (j + anchorPoint);
                GameObject floor = BFM.GetFloor(floorPosition);
                //AI做预判时会有限制,不能用activeSelf,基于哈希表的Dictionary,ContainsKey比ContainsValue的效率高很多100ms <---> 400ms
                if (floor && rangeDic.ContainsKey(floor.transform.position) /* floor.activeSelf */ && (floor.transform.position == destination || !floorAroundEnemy.Contains(floor.transform.position)))   //地板是激活的且不在敌人周围,可用作寻路路径。如果是目的地且在激活的状态下,一定可以作为寻路路径。
                {
                    array[i, j] = 0;
                }
                else
                {
                    array[i, j] = 1;
                }
            }
        }
        //调用A*。
        Astar astar = new Astar(array);
        Point start = new Point((int)origin.x, (int)origin.z);
        Point end   = new Point((int)destination.x, (int)destination.z);

        var parent = astar.FindPath(start, end, false);

        while (parent != null)
        {
            path.Add(parent);
            parent = parent.ParentPoint;
        }
        path.Reverse();     //里面的元素顺序是反的,即从目的指向起点,这里变为由起点指向目的。
        return(path);
    }
Esempio n. 13
0
File: Move.cs Progetto: gczxcyd/XDD
    public override bool OnUpdate(Transform character)
    {
        switch (skillState)
        {
        case SkillState.init:
            Init(character);
            skillState = SkillState.waitForInput;
            break;

        case SkillState.waitForInput:
            if (final)
            {
                if (Check())
                {
                    foreach (var f in BattleFieldManager.GetInstance().floors)
                    {
                        f.Value.GetComponent <Floor>().FloorClicked -= Confirm;
                        f.Value.GetComponent <Floor>().FloorHovered -= Focus;
                        f.Value.GetComponent <Floor>().FloorExited  -= RecoverColor;
                    }
                    path = range.CreatePath(focus);
                    //角色取出忽略层
                    UnitManager.GetInstance().units.FindAll(u => u.playerNumber == character.GetComponent <Unit>().playerNumber).ForEach(u => BattleFieldManager.GetInstance().GetFloor(u.transform.position).gameObject.layer = 0);
                    UnitManager.GetInstance().units.ForEach(u => u.gameObject.layer = 0);
                    skillState = SkillState.confirm;
                }
                else
                {
                    final = false;
                }
            }
            break;

        case SkillState.confirm:
            movement.SetMovement(path, character);
            skillState = SkillState.applyEffect;
            break;

        case SkillState.applyEffect:
            if (movement.ExcuteMove())
            {
                range.Delete();
                //SecondAction
                character.GetComponent <CharacterAction>().SetSkill("SecondAction");

                return(true);
            }
            break;

        case SkillState.reset:

            return(true);
        }
        return(false);
    }
Esempio n. 14
0
 //敌人周围四块变为黄色。
 void KeepYellowFloor()
 {
     if (floorAroundEnemy.Count != 0)
     {
         foreach (var a in floorAroundEnemy)
         {
             if (BattleFieldManager.GetInstance().GetFloor(a).GetComponent <Floor>().isActiveAndEnabled)
             {
                 BattleFieldManager.GetInstance().GetFloor(a).GetComponent <Floor>().ChangeRangeColorToYellow();
             }
         }
     }
 }
Esempio n. 15
0
    protected void RangeInit()
    {
        if (comboJudgeUI)
        {
            GameObject.Destroy(comboJudgeUI);
        }
        if (skillRange > 0)
        {
            range = new SkillRange();
            switch (rangeType)
            {
            case RangeType.common:
                range.CreateSkillRange(skillRange, character);
                break;

            case RangeType.straight:
                range.CreateStraightSkillRange(skillRange, character, aliesObstruct);
                break;

            case RangeType.other:
                range.CreateCustomizedRange(customizedRangeList, customizedHoverRangeList, enablePathFinding, character);
                break;
            }

            focus = new Vector3(-1, -1, -1);
            final = false;
            foreach (var f in BattleFieldManager.GetInstance().floors)
            {
                if (f.Value.activeInHierarchy)
                {
                    var player = RoundManager.GetInstance().Players.Find(p => p.playerNumber == SkillManager.GetInstance().skillQueue.Peek().Key.character.GetComponent <Unit>().playerNumber);

                    if (player is HumanPlayer || (player is AIPlayer && ((AIPlayer)player).AI == false))
                    {
                        f.Value.GetComponent <Floor>().FloorClicked += Confirm;
                        f.Value.GetComponent <Floor>().FloorExited  += DeleteHoverRange;
                        f.Value.GetComponent <Floor>().FloorHovered += Focus;
                    }
                }
            }
            //角色加入忽略层,方便选取
            UnitManager.GetInstance().units.ForEach(u => u.gameObject.layer = 2);

            range.RecoverColor();
        }
        else
        {
            Focus(character.gameObject, null);
            ShowConfirm();
        }
    }
Esempio n. 16
0
    protected List <Point> UseAstar(Vector3 origin, Vector3 destination, int range)
    {
        path.Clear();
        for (int i = 0; i < BattleFieldManager.GridX; i++)
        {
            for (int j = 0; j < BattleFieldManager.GridY; j++)
            {
                array[i, j] = 1;
            }
        }

        var minX = origin.x - range;
        var minY = origin.z - range;
        var maxX = origin.x + range;
        var maxY = origin.z + range;

        //检测整张地图的地板块激活情况,判断障碍物,存入数组。

        for (int i = (int)minX; i <= (int)maxX; i++)
        {
            for (int j = (int)minY; j <= (int)maxY; j++)
            {
                floorPosition    = Vector3.zero;
                floorPosition.x += (i + anchorPoint);
                floorPosition.z += (j + anchorPoint);
                GameObject floor = BattleFieldManager.GetInstance().GetFloor(floorPosition);
                if (floor && floor.activeSelf && (floor.transform.position == destination || !floorAroundEnemy.Contains(floor.transform.position)))   //地板是激活的且不在敌人周围,可用作寻路路径。如果是目的地且在激活的状态下,一定可以作为寻路路径。
                {
                    array[i, j] = 0;
                }
                else
                {
                    array[i, j] = 1;
                }
            }
        }
        //调用A*。
        Astar astar = new Astar(array);
        Point start = new Point((int)origin.x, (int)origin.z);
        Point end   = new Point((int)destination.x, (int)destination.z);

        var parent = astar.FindPath(start, end, false);

        while (parent != null)
        {
            path.Add(parent);
            parent = parent.ParentPoint;
        }
        path.Reverse();     //里面的元素顺序是反的,即从目的指向起点,这里变为由起点指向目的。
        return(path);
    }
Esempio n. 17
0
    //正方形去除四角的范围。
    List <Vector3> CreateHoverRangeList()
    {
        var p = character.position + character.forward * 5;

        p = new Vector3((int)p.x + 0.5f, 0, (int)p.z + 0.5f);
        List <Vector3> list = new List <Vector3>();

        //这个数组存放每一行(或者是每一列)应有的方块数。
        int[] num = new int[2 * hoverRange + 1];
        //这个数组应该是奇数个元素个数。
        for (int i = 0; i < 2 * hoverRange + 1; i++)
        {
            if (i == 0 || i == 2 * hoverRange)
            {
                num[i] = 2 * hoverRange - 1;
            }
            else
            {
                num[i] = 2 * hoverRange + 1;
            }
        }
        //根据这个数组,来创建范围。遍历的两个维度,一个是数组的长度,即行数,另一个是数组每一个值,即每一行应该有的方块数。
        for (int i = 0; i < num.Length; i++)
        {
            for (int j = 0; j < num[i]; j++)
            {
                //根据range、i、j、角色position算出每块地板的坐标。
                //中心点为transform.position,个别列有偏移量。
                float rX = p.x + (hoverRange - i);
                float rZ;
                if (i == 0 || i == num.Length - 1)
                {
                    rZ = p.z + (hoverRange - j) - 1;
                }
                else
                {
                    rZ = p.z + (hoverRange - j);
                }
                if (rX < 1 || rZ < 1 || rX > BattleFieldManager.GetInstance().GridX - 1 || rZ > BattleFieldManager.GetInstance().GridY - 1)//超出边界的不创建  由于A*报数组下标越界(因为要检测一个单元周围的所有单元,而边界单元没有完整的周围单元),所以这里把边界缩小一圈。
                {
                    continue;
                }
                Vector3 position = new Vector3(rX, p.y, rZ);
                list.Add(position);
            }
        }
        return(list);
    }
Esempio n. 18
0
 public void EnterTown()
 {
     gameState = DAY;
     title.gameObject.SetActive(false);
     startGameButton.gameObject.SetActive(false);
     runButton.gameObject.SetActive(true);
     BattleFieldManager.generateMap(daysWon);
     currentDeck = new List <FunctionBullet>(inventory);
     for (int i = 0; i < 6; i++)
     {
         int randomCard = (int)UnityEngine.Random.Range(0, currentDeck.Count);
         currentHand[i] = currentDeck[randomCard];
         currentDeck.RemoveAt(randomCard);
         functionUI[i] = Instantiate(drag, new Vector3(600, 380 - i * 50, 0f), new Quaternion());
         functionUI[i].GetComponent <DragableFunction>().init(i, currentHand[i]);
     }
 }
Esempio n. 19
0
    public override void Reset()
    {
        //按照顺序,逆序消除影响。因为每次会Init(),所以不必都Reset。
        movement.Reset();
        range.Reset();

        foreach (var f in BattleFieldManager.GetInstance().floors)
        {
            f.Value.GetComponent <Floor>().FloorClicked -= Confirm;
            f.Value.GetComponent <Floor>().FloorHovered -= Focus;
            f.Value.GetComponent <Floor>().FloorExited  -= RecoverColor;
        }
        //角色取出忽略层
        UnitManager.GetInstance().units.FindAll(u => u.playerNumber == character.GetComponent <Unit>().playerNumber).ForEach(u => BattleFieldManager.GetInstance().GetFloor(u.transform.position).gameObject.layer = 0);
        UnitManager.GetInstance().units.ForEach(u => u.gameObject.layer = 0);

        base.Reset();
    }
Esempio n. 20
0
    public void CreateSkillHoverRange(int range, Vector3 p)
    {
        hoverRangeList.Clear();
        var list = CreateRange(range, p);

        foreach (var position in list)
        {
            if (DetectObstacle(position))
            {
                continue;
            }
            if (!BattleFieldManager.GetInstance().GetFloor(position).activeSelf)
            {
                BattleFieldManager.GetInstance().GetFloor(position).SetActive(true);
                BattleFieldManager.GetInstance().GetFloor(position).GetComponent <Collider>().enabled = false;
            }
            hoverRangeList.Add(BattleFieldManager.GetInstance().GetFloor(position));
        }
    }
Esempio n. 21
0
    protected void RangeInit()
    {
        if (comboJudgeUI)
        {
            GameObject.Destroy(comboJudgeUI);
        }
        if (skillRange > 0)
        {
            range = new SkillRange();
            switch (rangeType)
            {
            case RangeType.common:
                range.CreateSkillRange(skillRange, character);
                break;

            case RangeType.straight:
                range.CreateStraightSkillRange(skillRange, character);
                break;
            }

            focus = new Vector3(-1, -1, -1);
            final = false;
            foreach (var f in BattleFieldManager.GetInstance().floors)
            {
                if (f.Value.activeInHierarchy)
                {
                    f.Value.GetComponent <Floor>().FloorClicked += Confirm;
                    f.Value.GetComponent <Floor>().FloorExited  += DeleteHoverRange;
                    f.Value.GetComponent <Floor>().FloorHovered += Focus;
                }
            }
            //角色加入忽略层,方便选取
            UnitManager.GetInstance().units.ForEach(u => u.gameObject.layer = 2);

            range.RecoverColor();
        }
        else
        {
            Focus(character.gameObject, null);
            ShowConfirm();
        }
    }
Esempio n. 22
0
    void Awake()
    {
        instance    = this;
        floorPrefab = (GameObject)Resources.Load("Prefabs/UI/Floor");
        //Debug.Log("X : " + GridX.ToString() + "; Y : " + GridY.ToString());
        //地板块铺满地板
        for (int i = 0; i < GridX; i++)
        {
            for (int j = 0; j < GridY; j++)
            {
                Vector3 position = new Vector3(i + anchorPoint, 0f, j + anchorPoint);

                GameObject floor = (GameObject)Instantiate(floorPrefab, position, Quaternion.identity);
                floor.transform.SetParent(GameObject.Find("Floors").transform);
                floor.tag = "Floor";
                floors.Add(position, floor);
                floor.SetActive(false);
            }
        }
    }
Esempio n. 23
0
    protected List <Vector3> CreateStraightRange(int range, Vector3 p)
    {
        List <Vector3> list = new List <Vector3>();

        int[] num = new int[2 * range + 1];

        for (int i = 0; i < range; i++)
        {
            num[i]             = 1;
            num[2 * range - i] = num[i];
        }
        num[range] = 2 * range + 1;
        //根据这个数组,来创建范围。遍历的两个维度,一个是数组的长度,即行数,另一个是数组每一个值,即每一行应该有的方块数。
        for (int i = 0; i < num.Length; i++)
        {
            for (int j = 0; j < num[i]; j++)
            {
                //根据range、i、j、角色position算出每块地板的坐标。
                //中心点为transform.position,每一列应有一个偏移量。
                float rX = p.x + (range - i);
                float rZ;
                if (i != range)
                {
                    rZ = p.z + (range - j) - range;
                }
                else
                {
                    rZ = p.z + (range - j);
                }
                if (rX < 1 || rZ < 1 || rX > BattleFieldManager.GetInstance().GridX - 1 || rZ > BattleFieldManager.GetInstance().GridY - 1)//超出边界的不创建  由于A*报数组下标越界(因为要检测一个单元周围的所有单元,而边界单元没有完整的周围单元),所以这里把边界缩小一圈。
                {
                    continue;
                }
                Vector3 position = new Vector3(rX, p.y, rZ);

                list.Add(position);
            }
        }
        return(list);
    }
Esempio n. 24
0
 // Use this for initialization
 void Start()
 {
     BattleFieldManager.calculateSize(GetComponent <Camera>());
     daysWon   = 0;
     gameState = TITLE;
     startGameButton.onClick.AddListener(EnterTown);
     runButton.onClick.AddListener(runCode);
     runButton.gameObject.SetActive(false);
     inventory = new FunctionBullet[24];
     for (int i = 0; i < 24; i++)
     {
         if (i < 6)
         {
             inventory[i] = new FunctionBullet(FunctionBullet.FIRE);
         }
         else if (i < 8)
         {
             inventory[i] = new FunctionBullet(FunctionBullet.ROLL_FORWARD);
         }
         else if (i < 10)
         {
             inventory[i] = new FunctionBullet(FunctionBullet.ROLL_BACKWARD);
         }
         else if (i < 14)
         {
             inventory[i] = new FunctionBullet(FunctionBullet.TURN_TO_NEAREST_ENEMY);
         }
         else if (i < 18)
         {
             inventory[i] = new FunctionBullet(FunctionBullet.TURN_TO_NEAREST_LOOT);
         }
         else
         {
             inventory[i] = new FunctionBullet(FunctionBullet.DO_NOTHING);
         }
     }
     currentHand = new FunctionBullet[6];
     functionUI  = new GameObject[6];
     alpha       = Instantiate(alpha, new Vector3(100, 100, 0f), new Quaternion());
 }
Esempio n. 25
0
    void Awake()
    {
        instance    = this;
        floorPrefab = (GameObject)Resources.Load("Prefabs/UI/Floor");
        //获取地图长宽
        GridX = (int)FindObjectOfType <Terrain>().GetComponent <Terrain>().terrainData.size.x;
        GridY = (int)FindObjectOfType <Terrain>().GetComponent <Terrain>().terrainData.size.z;
        //地板块铺满地板
        for (int i = 0; i < GridX; i++)
        {
            for (int j = 0; j < GridY; j++)
            {
                Vector3 position = new Vector3(i + anchorPoint, 0f, j + anchorPoint);

                GameObject floor = (GameObject)Instantiate(floorPrefab, position, Quaternion.identity);
                floor.transform.SetParent(GameObject.Find("Floors").transform);
                floor.tag = "Floor";
                floors.Add(position, floor);
                floor.SetActive(false);
            }
        }
    }
Esempio n. 26
0
    /// <summary>
    /// 与ResetSelf的区别:Reset在Skill层对技能进行出列入列,而ResetSelf仅用于类似替身术时候的自身重置。
    /// </summary>
    public override void Reset()
    {
        //按照顺序,逆序消除影响。因为每次会Init(),所以不必都Reset。

        if (range != null)
        {
            range.Reset();
        }

        foreach (var f in BattleFieldManager.GetInstance().floors)
        {
            f.Value.GetComponent <Floor>().FloorClicked -= Confirm;
            f.Value.GetComponent <Floor>().FloorExited  -= DeleteHoverRange;
            f.Value.GetComponent <Floor>().FloorHovered -= Focus;
        }

        //角色取出忽略层
        UnitManager.GetInstance().units.ForEach(u => u.gameObject.layer = 0);
        if (comboJudgeUI)
        {
            GameObject.Destroy(comboJudgeUI);
        }
        if (comboSelectUI)
        {
            GameObject.Destroy(comboSelectUI);
        }
        if (confirmUI)
        {
            UnityEngine.Object.Destroy(confirmUI);
        }
        if (originSkill != null)
        {
            originSkill.ResetSelf();
            character.GetComponent <Unit>().action.Pop();
        }

        base.Reset();
    }
Esempio n. 27
0
 public void ExcuteChangeRoadColorAndRotate(Vector3 position)
 {
     //显示路径需要每一个路径点。
     RecoverColor();
     if (rangeDic.ContainsKey(position))
     {
         List <Vector3> pathList = ChangePathType(UseAstar(character.position, position, range));
         if (pathList.Count > 1)
         {
             Quaternion wantedRot = Quaternion.LookRotation(pathList[1] - character.position);
             character.rotation = wantedRot;
         }
         //这里可能会有问题,先调用变蓝,再调用变红,不知为何是管用的,可能是覆盖。
         foreach (var f in pathList)
         {
             GameObject p = BattleFieldManager.GetInstance().GetFloor(f);
             if (p != null)
             {
                 p.GetComponent <Floor>().ChangeRangeColorToRed();
             }
         }
         BattleFieldManager.GetInstance().GetFloor(character.position).GetComponent <Floor>().ChangeRangeColorToRed();
     }
 }
Esempio n. 28
0
 public override void ExecuteFunctionBullet()
 {
     if (currentAction != null)
     {
         if (currentAction.GetFunction().GetCode() == FunctionBullet.ROLL_FORWARD)
         {
             anim.SetBool("dashF", true);
             float rollLength = 200f;
             transform.position += new Vector3(rollLength / timePerAction * Time.deltaTime * Mathf.Cos(direction), rollLength / timePerAction * Time.deltaTime * Mathf.Sin(direction), 0f);
         }
         else if (currentAction.GetFunction().GetCode() == FunctionBullet.ROLL_BACKWARD)
         {
             anim.SetBool("dashB", true);
             float rollLength = 200f;
             transform.position -= new Vector3(rollLength / timePerAction * Time.deltaTime * Mathf.Cos(direction), rollLength / timePerAction * Time.deltaTime * Mathf.Sin(direction), 0f);
         }
         else if (currentAction.GetFunction().GetCode() == FunctionBullet.TURN_TO_NEAREST_ENEMY)
         {
             anim.SetBool("Walking", true);
             GameObject nearest = BattleFieldManager.GetNearestEnemy(transform.position);
             if (nearest != null)
             {
                 direction = Mathf.Atan((nearest.transform.position.y - transform.position.y) / (nearest.transform.position.x - transform.position.x));
                 if (nearest.transform.position.x < transform.position.x)
                 {
                     direction += Mathf.PI;
                 }
             }
         }
         else if (currentAction.GetFunction().GetCode() == FunctionBullet.TURN_TO_NEAREST_LOOT)
         {
             anim.SetBool("Walking", true);
             GameObject nearest = BattleFieldManager.GetNearestLoot(transform.position);
             if (nearest != null)
             {
                 direction = Mathf.Atan((nearest.transform.position.y - transform.position.y) / (nearest.transform.position.x - transform.position.x));
                 if (nearest.transform.position.x < transform.position.x)
                 {
                     direction += Mathf.PI;
                 }
             }
         }
         else if (currentAction.GetFunction().GetCode() == FunctionBullet.FIRE)
         {
             if (!fired)
             {
                 GameObject bullet = new GameObject("bullet");
                 bullet.AddComponent <BulletManager>();
                 bullet.GetComponent <BulletManager>().init(direction, 10, gameObject);
                 Instantiate(bullet, transform.position, new Quaternion());
                 fired = true;
             }
         }
         else
         {
             fired = false;
             anim.SetBool("dashF", false);
             anim.SetBool("dashB", false);
             anim.SetBool("Walking", false);
         }
         timeTaken += Time.deltaTime;
         if (timeTaken > timePerAction)
         {
             currentAction = null;
         }
     }
     else
     {
         Debug.Log("w");
         anim.SetBool("dashF", false);
         anim.SetBool("dashB", false);
         anim.SetBool("Walking", false);
     }
 }
Esempio n. 29
0
    void Awake()
    {
        if (Instance == null)
            Instance = this;
        else if (Instance != this)
            Destroy(gameObject);

        columnsPer = Mathf.RoundToInt((columns - 1) * .5f);

        Grid = transform.FindChild("Grid Canvas").FindChild("Grid").gameObject;
        Player = Grid.transform.FindChild("Player").gameObject;
        PlayerTarget = Player.transform.FindChild("Target");

        Middle = Grid.transform.FindChild("Middle").gameObject;
        MiddleTarget = Middle.transform.FindChild("Target");

        Enemy = Grid.transform.FindChild("Enemy").gameObject;
        EnemyTarget = Enemy.transform.FindChild("Target");
    }
Esempio n. 30
0
File: Range.cs Progetto: gczxcyd/XDD
 public Range()
 {
     BFM = BattleFieldManager.GetInstance();
 }
Esempio n. 31
0
    //传入范围和创建范围角色的transform.position即可创建。p即transform.position
    public void CreateMoveRange(Transform character)
    {
        this.character = character;
        startRotation  = character.rotation;
        range          = character.GetComponent <CharacterStatus>().attributes.Find(d => d.eName == "mrg").value;
        if (range < 1)
        {
            return;
        }
        var list = CreateRange(range, character.position);
        //比list大一圈以保证enemy在范围外一圈时范围内颜色的正常显示。
        var detect = CreateRange(range + 1, character.position);    //此处创建范围比应有范围大1,正确的显示效果 是在下面 A*检测到路径但距离大于角色mrg的地块不显示 处得到保证。


        //检测到敌人时地块不显示,且加入名单。
        foreach (var position in detect)
        {
            if (CheckEnemy(Detect.DetectObject(position)) == 2)
            {
                enemyFloor.Add(position);
                continue;
            }
            //检测到障碍物时地块不显示。后期实现水上行走,跳远,树上行走。
            if (DetectObstacle(position))
            {
                continue;
            }

            BattleFieldManager.GetInstance().GetFloor(position).SetActive(true);
            rangeDic.Add(position, BattleFieldManager.GetInstance().GetFloor(position));
        }
        //添加enemyFloor周围的坐标进入容器。
        foreach (var floor in enemyFloor)
        {
            Vector3 V1 = new Vector3(floor.x - 1, 0, floor.z);
            Vector3 V2 = new Vector3(floor.x + 1, 0, floor.z);
            Vector3 V3 = new Vector3(floor.x, 0, floor.z - 1);
            Vector3 V4 = new Vector3(floor.x, 0, floor.z + 1);
            TryAddValue(floorAroundEnemy, V1);
            TryAddValue(floorAroundEnemy, V2);
            TryAddValue(floorAroundEnemy, V3);
            TryAddValue(floorAroundEnemy, V4);
        }

        var buffer0 = new List <Vector3>();

        foreach (var floor in rangeDic)
        {
            if (!list.Contains(floor.Key))
            {
                floor.Value.SetActive(false);
                buffer0.Add(floor.Key);
            }
        }
        foreach (var a in buffer0)
        {
            rangeDic.Remove(a);
        }

        //A*检测到路径但距离大于角色mrg的地块不显示。A*无法检测到路径的地块不显示。必须第二次遍历,即创建完成,A*寻路才有意义。
        //不能迭代时改变或删除Dictionary中的元素。
        var buffer = new List <Vector3>();

        foreach (var floor in rangeDic)
        {
            if ((UseAstar(character.position, floor.Key, range).Count > range + 1) || (floor.Key != character.position && UseAstar(character.position, floor.Key, range).Count == 0))
            {
                floor.Value.SetActive(false);
                buffer.Add(floor.Key);
            }
        }
        foreach (var a in buffer)
        {
            rangeDic.Remove(a);
        }

        RecoverColor();
    }