21 changed files with 448 additions and 739 deletions
@ -1,525 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections; |
|
||||
using System.Collections.Generic; |
|
||||
using Unity.VisualScripting; |
|
||||
using UnityEngine; |
|
||||
using UnityEngine.UI; |
|
||||
using UnityEngine.EventSystems; |
|
||||
using UnityEngine.InputSystem; |
|
||||
|
|
||||
public class CardEntity_OldSave : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler |
|
||||
{ |
|
||||
public CardOriginalData cardOriginalData; |
|
||||
//public CardOriginalData cardData;
|
|
||||
|
|
||||
public int cardId; |
|
||||
public int CardId |
|
||||
{ |
|
||||
get { return cardId; } |
|
||||
set { cardId = value; } |
|
||||
} |
|
||||
|
|
||||
// public Vector3 OriginTransform;
|
|
||||
//private Vector3 EndTransform;
|
|
||||
[Header("拖拽参数")] |
|
||||
public Transform originalParent; |
|
||||
public Vector3 originalpoint; |
|
||||
|
|
||||
bool canUse = true;//决定卡牌是否可以释放
|
|
||||
bool choosed;//标识卡牌是否被选中
|
|
||||
|
|
||||
[Header("贝塞尔曲线瞄准")] |
|
||||
public GameObject ainPanle; |
|
||||
|
|
||||
[Header("影响格参数")] |
|
||||
public MapUnity currentNode;//瞄准的格子
|
|
||||
public List<MapUnity> influencePreviewPool;//卡牌的影响范围
|
|
||||
|
|
||||
[Header("卡牌拖拽状态")] |
|
||||
public CardDragState dragState; |
|
||||
public enum CardDragState |
|
||||
{ |
|
||||
onBeginDrag, |
|
||||
onDrag, |
|
||||
onEndDrag, |
|
||||
noDrag |
|
||||
} |
|
||||
public EventSystem eventSystem; |
|
||||
PointerEventData eventData; |
|
||||
List<RaycastResult> result = new List<RaycastResult>(); |
|
||||
|
|
||||
public void Start() |
|
||||
{ |
|
||||
//cardData = GetComponent<CardOriginalData>();
|
|
||||
eventSystem = GameObject.FindObjectOfType<EventSystem>(); |
|
||||
eventData = new PointerEventData(eventSystem); |
|
||||
} |
|
||||
private void Update() |
|
||||
{ |
|
||||
//右键取消释放
|
|
||||
if (choosed && Mouse.current.rightButton.wasPressedThisFrame) |
|
||||
{ |
|
||||
Debug.Log("1"); |
|
||||
dragState = CardDragState.noDrag; |
|
||||
canUse = false;//取消释放
|
|
||||
ainPanle.SetActive(false); |
|
||||
//遍历范围预览池消除影响色
|
|
||||
for (int i = 0; i < GameManager.Instance.player.influencePreviewPool.Count; i++) |
|
||||
{ |
|
||||
GameManager.Instance.player.influencePreviewPool[i].influenced = false; |
|
||||
} |
|
||||
GameManager.Instance.player.influencePreviewPool.Clear(); |
|
||||
//遍历影响池变色
|
|
||||
for (int i = 0; i < influencePreviewPool.Count; i++) |
|
||||
{ |
|
||||
influencePreviewPool[i].influenced = false; |
|
||||
} |
|
||||
influencePreviewPool.Clear(); |
|
||||
|
|
||||
|
|
||||
//其他位置都归位
|
|
||||
transform.SetParent(originalParent); |
|
||||
transform.localPosition = originalpoint; |
|
||||
GetComponent<CanvasGroup>().blocksRaycasts = true; |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
if (dragState != CardDragState.noDrag && dragState != CardDragState.onDrag) |
|
||||
{ |
|
||||
//UI射线检测
|
|
||||
|
|
||||
eventData.position = Mouse.current.position.value; |
|
||||
|
|
||||
eventSystem.RaycastAll(eventData, result); |
|
||||
if (result.Count > 0) |
|
||||
{ |
|
||||
Debug.Log(result[0].gameObject.name); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
switch (dragState) |
|
||||
{ |
|
||||
case CardDragState.onBeginDrag: |
|
||||
TurnMaster.Instance.playerAction = TurnMaster.PlayerAction.useCard; |
|
||||
CardChoose(eventData); |
|
||||
dragState = CardDragState.onDrag; |
|
||||
break; |
|
||||
case CardDragState.onDrag: |
|
||||
CardFollow(); |
|
||||
if (Mouse.current.leftButton.wasReleasedThisFrame) |
|
||||
{ |
|
||||
dragState = CardDragState.onEndDrag; |
|
||||
} |
|
||||
break; |
|
||||
case CardDragState.onEndDrag: |
|
||||
TurnMaster.Instance.playerAction = TurnMaster.PlayerAction.none; |
|
||||
CardUse(); |
|
||||
break; |
|
||||
case CardDragState.noDrag: |
|
||||
if (Mouse.current.leftButton.wasReleasedThisFrame) |
|
||||
{ |
|
||||
eventData.position = Mouse.current.position.value; |
|
||||
|
|
||||
eventSystem.RaycastAll(eventData, result); |
|
||||
if (result.Count > 0) |
|
||||
{ |
|
||||
Debug.Log(result[0].gameObject.name); |
|
||||
if (result[0].gameObject == this.gameObject) |
|
||||
{ |
|
||||
dragState = CardDragState.onBeginDrag; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
} |
|
||||
break; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
public void createCard(int cardId) |
|
||||
{ |
|
||||
this.cardId = cardId; |
|
||||
Debug.Log(cardId + "-" + CardOriginalDataList.Instance.cardOriginalDataList[cardId]); |
|
||||
cardOriginalData = CardOriginalDataList.Instance.cardOriginalDataList[cardId]; |
|
||||
settleForStart(SettlementManager.settleTurn); |
|
||||
} |
|
||||
|
|
||||
//不应该为void,返回值为作用的地块
|
|
||||
public void use() |
|
||||
{ |
|
||||
settle(0); |
|
||||
|
|
||||
|
|
||||
} |
|
||||
//卡牌效果的结算
|
|
||||
public void settle(int settleTurn) |
|
||||
{ |
|
||||
for (int i = 0; i < cardOriginalData.Function.Length; i++) |
|
||||
{ |
|
||||
switch (cardOriginalData.Function[i]) |
|
||||
{ |
|
||||
case CardFunction.cardDamage: |
|
||||
damageWork(int.Parse(cardOriginalData.FunctionVal[i])); |
|
||||
break; |
|
||||
case CardFunction.cardShield: |
|
||||
Usermanager.Instance.Shield = Usermanager.Instance.Shield + int.Parse(cardOriginalData.FunctionVal[i]); |
|
||||
break; |
|
||||
case CardFunction.posion: |
|
||||
case CardFunction.weak: |
|
||||
case CardFunction.coma: |
|
||||
case CardFunction.disarm: |
|
||||
case CardFunction.sleep: |
|
||||
case CardFunction.bleed: |
|
||||
case CardFunction.thorn: |
|
||||
abnormalConditionWork(cardOriginalData.Function[i], int.Parse(cardOriginalData.FunctionVal[i])); |
|
||||
break; |
|
||||
case CardFunction.costRestore: |
|
||||
break; |
|
||||
case CardFunction.dyeing: |
|
||||
Debug.Log("功能是:" + cardOriginalData.Function[1]); |
|
||||
dyeingWork(); |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
|
|
||||
public void abnormalConditionWork(string condition, int stackVak) |
|
||||
{ |
|
||||
for (int i = 0; i < influencePreviewPool.Count; i++) |
|
||||
{ |
|
||||
//施加负面
|
|
||||
if (influencePreviewPool[i].enemyNode != null) |
|
||||
{ |
|
||||
influencePreviewPool[i].enemyNode.sufferAbnormalCondition(condition, stackVak); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private void damageWork(int damageVal) |
|
||||
{ |
|
||||
for (int i = 0; i < influencePreviewPool.Count; i++) |
|
||||
{ |
|
||||
//造成伤害
|
|
||||
if (influencePreviewPool[i].enemyNode != null) |
|
||||
{ |
|
||||
influencePreviewPool[i].enemyNode.sufferDamage(damageVal); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private void dyeingWork() |
|
||||
{ |
|
||||
Debug.Log(influencePreviewPool.Count); |
|
||||
for (int i = 0; i < influencePreviewPool.Count; i++) |
|
||||
{ |
|
||||
influencePreviewPool[i].whoColour = MapUnity.WhoColour.playerColour; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
private void dyeing() |
|
||||
{ |
|
||||
//遍历影响池变色
|
|
||||
for (int i = 0; i < influencePreviewPool.Count; i++) |
|
||||
{ |
|
||||
influencePreviewPool[i].influenced = true; |
|
||||
influencePreviewPool[i].choossedMark.GetComponent<Renderer>().material = influencePreviewPool[i].yellow; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
//生成卡牌时候遗物的结算
|
|
||||
public void settleForStart(int settleTurn) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
//卡牌效果结束之后结算
|
|
||||
public void settleForEnd(int settleTurn) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
public void OnBeginDrag(PointerEventData eventData) |
|
||||
{ |
|
||||
dragState = CardDragState.onBeginDrag; |
|
||||
} |
|
||||
|
|
||||
public void OnDrag(PointerEventData eventData) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
private void ainPanleWork() |
|
||||
{ |
|
||||
//射线检测瞄准的地图节点,判断是否可放置和改变放置影响区
|
|
||||
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.value); |
|
||||
|
|
||||
if (Physics.Raycast(ray, out RaycastHit raycastHit)) |
|
||||
{ |
|
||||
Debug.Log(raycastHit.collider.gameObject.name); |
|
||||
//检测到跟上次瞄准地方不同,更新
|
|
||||
if (currentNode == null || raycastHit.collider.transform.gameObject != currentNode.gameObject) |
|
||||
{ |
|
||||
for (int i = 0; i < influencePreviewPool.Count; i++) |
|
||||
{ |
|
||||
influencePreviewPool[i].influenced = false; |
|
||||
} |
|
||||
influencePreviewPool.Clear(); |
|
||||
currentNode = raycastHit.collider.transform.GetComponent<MapUnity>(); |
|
||||
|
|
||||
//重新调用范围预览
|
|
||||
GameManager.Instance.player.StepPreviewInfluencedNode(cardOriginalData.CastingRange); |
|
||||
Debug.Log(cardOriginalData.CastingRange); |
|
||||
//预览影响范围
|
|
||||
if (currentNode.influenced) |
|
||||
{ |
|
||||
//根据卡牌属性改变影响池
|
|
||||
influencePreviewPool.Add(currentNode); |
|
||||
Vector3 face = currentNode.transform.position - GameManager.Instance.playerOn.transform.position; |
|
||||
float euler = Vector3.SignedAngle(-GameManager.Instance.playerOn.transform.forward, face, GameManager.Instance.playerOn.transform.up) + 180; |
|
||||
Debug.Log(euler); |
|
||||
if (euler > 0 && euler < 45) |
|
||||
{ |
|
||||
if (currentNode.unitPool[0] != null) |
|
||||
influencePreviewPool.Add(currentNode.unitPool[0]); |
|
||||
if (currentNode.unitPool[4] != null) |
|
||||
influencePreviewPool.Add(currentNode.unitPool[4]); |
|
||||
} |
|
||||
else if (euler > 45 && euler < 135) |
|
||||
{ |
|
||||
if (currentNode.unitPool[1] != null) |
|
||||
influencePreviewPool.Add(currentNode.unitPool[1]); |
|
||||
if (currentNode.unitPool[5] != null) |
|
||||
influencePreviewPool.Add(currentNode.unitPool[5]); |
|
||||
} |
|
||||
else if (euler > 135 && euler < 180) |
|
||||
{ |
|
||||
if (currentNode.unitPool[2] != null) |
|
||||
influencePreviewPool.Add(currentNode.unitPool[2]); |
|
||||
if (currentNode.unitPool[0] != null) |
|
||||
influencePreviewPool.Add(currentNode.unitPool[0]); |
|
||||
} |
|
||||
else if (euler > 180 && euler < 225) |
|
||||
{ |
|
||||
if (currentNode.unitPool[1] != null) |
|
||||
influencePreviewPool.Add(currentNode.unitPool[1]); |
|
||||
if (currentNode.unitPool[3] != null) |
|
||||
influencePreviewPool.Add(currentNode.unitPool[3]); |
|
||||
} |
|
||||
else if (euler > 225 && euler < 315) |
|
||||
{ |
|
||||
if (currentNode.unitPool[2] != null) |
|
||||
influencePreviewPool.Add(currentNode.unitPool[2]); |
|
||||
if (currentNode.unitPool[4] != null) |
|
||||
influencePreviewPool.Add(currentNode.unitPool[4]); |
|
||||
} |
|
||||
else if (euler > 315 && euler < 360) |
|
||||
{ |
|
||||
if (currentNode.unitPool[3] != null) |
|
||||
influencePreviewPool.Add(currentNode.unitPool[3]); |
|
||||
if (currentNode.unitPool[5] != null) |
|
||||
influencePreviewPool.Add(currentNode.unitPool[5]); |
|
||||
} |
|
||||
//influencePreviewPool.Add(currentNode);
|
|
||||
|
|
||||
|
|
||||
} |
|
||||
|
|
||||
|
|
||||
} |
|
||||
} |
|
||||
|
|
||||
Debug.Log("结束影响数值" + influencePreviewPool.Count); |
|
||||
} |
|
||||
|
|
||||
private void noAinPanleWork(PointerEventData eventData) |
|
||||
{ |
|
||||
|
|
||||
Ray ray = Camera.main.ScreenPointToRay(Mouse.current.position.value); |
|
||||
if (eventData.pointerCurrentRaycast.gameObject != null) |
|
||||
{ |
|
||||
if (Physics.Raycast(ray, out RaycastHit raycastHit)) |
|
||||
{ |
|
||||
currentNode = raycastHit.collider.transform.GetComponent<MapUnity>(); |
|
||||
influencePreviewPool.Add(currentNode); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
public void OnEndDrag(PointerEventData eventData) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
//卡片动作
|
|
||||
//开始选中
|
|
||||
public void CardChoose(PointerEventData eventData) |
|
||||
{ |
|
||||
// if (GameObject.Find("CardPanel") != null)
|
|
||||
// graphicRaycaster = GameObject.Find("CardPanel").GetComponent<GraphicRaycaster>();
|
|
||||
choosed = true; |
|
||||
|
|
||||
GetComponent<CanvasGroup>().blocksRaycasts = false; |
|
||||
|
|
||||
originalParent = this.gameObject.transform.parent; |
|
||||
originalpoint = this.transform.localPosition; |
|
||||
|
|
||||
transform.SetParent(transform.parent.parent); |
|
||||
transform.position = eventData.position; |
|
||||
|
|
||||
//根据卡牌数据决定是否调用曲线
|
|
||||
if (cardOriginalData.CastingRange != 0) |
|
||||
{ |
|
||||
//释放范围为0则不需要调用曲线
|
|
||||
ainPanle.SetActive(true); |
|
||||
} |
|
||||
else |
|
||||
{ |
|
||||
ainPanle.SetActive(false); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
//todo-统一确定锚点位置
|
|
||||
|
|
||||
//重新调用范围预览--以后要写到卡牌效果里,现在默认影响1格
|
|
||||
//GameManager.Instance.player.StepPreviewInfluencedNode(1);
|
|
||||
} |
|
||||
|
|
||||
//拖拽中
|
|
||||
public void CardFollow() |
|
||||
{ |
|
||||
if (cardOriginalData.CastingRange != 0) |
|
||||
{ |
|
||||
ainPanleWork(); |
|
||||
} |
|
||||
else |
|
||||
{ |
|
||||
//没有范围不需要射线吧,因为不需要指定目标点?
|
|
||||
// noAinPanleWork(eventData);
|
|
||||
} |
|
||||
dyeing(); |
|
||||
} |
|
||||
|
|
||||
//卡牌释放
|
|
||||
public void CardUse() |
|
||||
{ |
|
||||
choosed = false; |
|
||||
if (canUse) |
|
||||
{ |
|
||||
Debug.Log("进入影响数值" + influencePreviewPool.Count); |
|
||||
if (result.Count > 0) |
|
||||
{ |
|
||||
if (result[0].gameObject.tag == "Card") |
|
||||
{ |
|
||||
choosed = true; |
|
||||
dragState = CardDragState.onDrag; |
|
||||
TurnMaster.Instance.playerAction = TurnMaster.PlayerAction.useCard; |
|
||||
/* |
|
||||
GetComponent<CanvasGroup>().blocksRaycasts = true; |
|
||||
|
|
||||
ainPanle.SetActive(false);//关闭贝塞尔曲线
|
|
||||
//遍历范围预览池消除影响色
|
|
||||
for (int i = 0; i < GameManager.Instance.player.influencePreviewPool.Count; i++) |
|
||||
{ |
|
||||
GameManager.Instance.player.influencePreviewPool[i].influenced = false; |
|
||||
} |
|
||||
//GameManager.Instance.player.influencePreviewPool.Clear();
|
|
||||
*/ |
|
||||
return; |
|
||||
} |
|
||||
else if (result[0].gameObject.name == "cardSlot") |
|
||||
{ |
|
||||
choosed = true; |
|
||||
dragState = CardDragState.onDrag; |
|
||||
TurnMaster.Instance.playerAction = TurnMaster.PlayerAction.useCard; |
|
||||
/* |
|
||||
transform.SetParent(result[0].gameObject.transform); |
|
||||
transform.position = result [0].gameObject.transform.position; |
|
||||
GetComponent<CanvasGroup>().blocksRaycasts = true; |
|
||||
|
|
||||
ainPanle.SetActive(false);//关闭贝塞尔曲线
|
|
||||
//遍历范围预览池消除影响色
|
|
||||
for (int i = 0; i < GameManager.Instance.player.influencePreviewPool.Count; i++) |
|
||||
{ |
|
||||
GameManager.Instance.player.influencePreviewPool[i].influenced = false; |
|
||||
} |
|
||||
//GameManager.Instance.player.influencePreviewPool.Clear();
|
|
||||
*/ |
|
||||
return; |
|
||||
} |
|
||||
} |
|
||||
if (ainPanle.activeSelf) |
|
||||
{ |
|
||||
ainPanle.SetActive(false);//关闭贝塞尔曲线
|
|
||||
} |
|
||||
|
|
||||
//先判断该卡牌的类型是否是需要范围
|
|
||||
if (cardOriginalData.CastingRange != 0) |
|
||||
{ |
|
||||
//检测碰撞的地图节点是否被影响(可释放)
|
|
||||
if (currentNode == null || currentNode.influenced == false) |
|
||||
{ |
|
||||
//遍历范围预览池消除影响色(红色,卡牌的释放范围)
|
|
||||
for (int i = 0; i < GameManager.Instance.player.influencePreviewPool.Count; i++) |
|
||||
{ |
|
||||
GameManager.Instance.player.influencePreviewPool[i].influenced = false; |
|
||||
} |
|
||||
//GameManager.Instance.player.influencePreviewPool.Clear();
|
|
||||
} |
|
||||
else if (currentNode.influenced) |
|
||||
{ |
|
||||
|
|
||||
//卡牌释放效果
|
|
||||
use(); |
|
||||
Debug.Log("玩家盾量:" + Usermanager.Instance.Shield); |
|
||||
|
|
||||
//临时效果--将其加入墓地并销毁实体
|
|
||||
TurnMaster.Instance.usedCard.usedCardList.Add(this.gameObject.GetComponent<CardEntity>().CardId); |
|
||||
Destroy(this.gameObject); |
|
||||
} |
|
||||
//遍历范围预览池消除影响色
|
|
||||
for (int i = 0; i < GameManager.Instance.player.influencePreviewPool.Count; i++) |
|
||||
{ |
|
||||
GameManager.Instance.player.influencePreviewPool[i].influenced = false; |
|
||||
} |
|
||||
GameManager.Instance.player.influencePreviewPool.Clear(); |
|
||||
//遍历影响池变色
|
|
||||
for (int i = 0; i < influencePreviewPool.Count; i++) |
|
||||
{ |
|
||||
influencePreviewPool[i].influenced = false; |
|
||||
} |
|
||||
influencePreviewPool.Clear(); |
|
||||
GetComponent<CanvasGroup>().blocksRaycasts = true; |
|
||||
|
|
||||
//其他位置都归位
|
|
||||
transform.SetParent(originalParent); |
|
||||
transform.localPosition = originalpoint; |
|
||||
return; |
|
||||
}//范围类,需要指定被影响的节点才能释放
|
|
||||
else |
|
||||
{ |
|
||||
//卡牌释放效果
|
|
||||
use(); |
|
||||
Debug.Log("玩家盾量:" + Usermanager.Instance.Shield); |
|
||||
|
|
||||
//临时效果--将其加入墓地并销毁实体
|
|
||||
TurnMaster.Instance.usedCard.usedCardList.Add(this.gameObject.GetComponent<CardEntity>().CardId); |
|
||||
Destroy(this.gameObject); |
|
||||
|
|
||||
return; |
|
||||
|
|
||||
}//无范围类,直接释放
|
|
||||
|
|
||||
} |
|
||||
else |
|
||||
{ |
|
||||
canUse = true; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -0,0 +1,51 @@ |
|||||
|
using System; |
||||
|
using System.Collections; |
||||
|
using System.Collections.Generic; |
||||
|
using UnityEngine; |
||||
|
|
||||
|
public class EffectRangeHandler1 : EffectRangeHandlerBase |
||||
|
{ |
||||
|
public EffectRangeHandler1(MapUnity currentNode, float euler) |
||||
|
{ |
||||
|
influencePreviewPool.Clear(); |
||||
|
influencePreviewPool.Add(currentNode); |
||||
|
angleActions = new Dictionary<float, Func<List<MapUnity>>> |
||||
|
{ |
||||
|
{ 30.0f, () => |
||||
|
{ |
||||
|
return influencePreviewPool; |
||||
|
} |
||||
|
}, |
||||
|
{ 90.0f, () => |
||||
|
{ |
||||
|
return influencePreviewPool; |
||||
|
} |
||||
|
}, |
||||
|
{ 150.0f, () => |
||||
|
{ |
||||
|
return influencePreviewPool; |
||||
|
} |
||||
|
}, |
||||
|
{ 210.0f, () => |
||||
|
{ |
||||
|
return influencePreviewPool; |
||||
|
} |
||||
|
}, |
||||
|
{ 270.0f, () => |
||||
|
{ |
||||
|
return influencePreviewPool; |
||||
|
} |
||||
|
}, |
||||
|
{ 330.0f, () => |
||||
|
{ |
||||
|
return influencePreviewPool; |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -1,5 +1,5 @@ |
|||||
fileFormatVersion: 2 |
fileFormatVersion: 2 |
||||
guid: 7831439f6bbbdf14b8546fd1ac26d312 |
guid: 00c6f2acf33d3594aa85dff634c0b326 |
||||
MonoImporter: |
MonoImporter: |
||||
externalObjects: {} |
externalObjects: {} |
||||
serializedVersion: 2 |
serializedVersion: 2 |
||||
@ -0,0 +1,41 @@ |
|||||
|
using System.Collections; |
||||
|
using System.Collections.Generic; |
||||
|
using UnityEngine; |
||||
|
|
||||
|
public class MapUnityManager : MonoBehaviour |
||||
|
{ |
||||
|
public List<MapUnity> findReachableTiles(MapUnity startNode, int movePoints) |
||||
|
{ |
||||
|
List<MapUnity> reachableNodes = new List<MapUnity>(); |
||||
|
Queue<MapUnity> queue = new Queue<MapUnity>(); |
||||
|
Dictionary<MapUnity, int> remainingMovePoints = new Dictionary<MapUnity, int>(); |
||||
|
|
||||
|
queue.Enqueue(startNode); |
||||
|
remainingMovePoints[startNode] = movePoints; |
||||
|
|
||||
|
while (queue.Count > 0) |
||||
|
{ |
||||
|
MapUnity currentNode = queue.Dequeue(); |
||||
|
int currentMovePoints = remainingMovePoints[currentNode]; |
||||
|
|
||||
|
foreach (MapUnity neighbor in currentNode.unitPool) |
||||
|
{ |
||||
|
if (neighbor == null || neighbor.blocked || remainingMovePoints.ContainsKey(neighbor)) |
||||
|
continue; |
||||
|
|
||||
|
int newMovePoints = currentMovePoints - 1; // 每移动一格,减少一点移动点数
|
||||
|
|
||||
|
if (newMovePoints >= 0) |
||||
|
{ |
||||
|
queue.Enqueue(neighbor); |
||||
|
remainingMovePoints[neighbor] = newMovePoints; |
||||
|
reachableNodes.Add(neighbor); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//遍历影响池变色
|
||||
|
|
||||
|
return reachableNodes; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: d344126aa8082fa48b7e5f19eff09202 |
||||
|
MonoImporter: |
||||
|
externalObjects: {} |
||||
|
serializedVersion: 2 |
||||
|
defaultReferences: [] |
||||
|
executionOrder: 0 |
||||
|
icon: {instanceID: 0} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
|
Loading…
Reference in new issue