|
|
@ -1,24 +1,34 @@ |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections; |
|
|
using System.Collections; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using Unity.VisualScripting; |
|
|
|
|
|
using UnityEngine; |
|
|
using UnityEngine; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class CardActiveSort : Singleton <CardActiveSort> |
|
|
public class CardActiveSort : Singleton <CardActiveSort> |
|
|
{ |
|
|
{ |
|
|
public int cardCount; |
|
|
public int cardCount; |
|
|
public GameObject targrtPoint;//Ô²ÐÄ
|
|
|
public Vector3 targrtPoint;//圆心
|
|
|
public float radius;//半径
|
|
|
public float radius;//半径
|
|
|
public float angleIncrement;//起始角度增量
|
|
|
public float angleIncrement;//起始角度增量
|
|
|
|
|
|
|
|
|
public GameObject preparePoint; |
|
|
Camera mainCamera; |
|
|
|
|
|
|
|
|
[Header ("¿¨ÅÆÎ»ÖÃ")] |
|
|
[Header("抽卡")] |
|
|
public List<CardPointData> cardOringinPointDataList= new List<CardPointData>(); |
|
|
public int drawCardCount;//抽卡数量
|
|
|
|
|
|
public List<GameObject> prepareHandCard = new List<GameObject>();//正在飞还没到手里的卡牌
|
|
|
|
|
|
public List<Vector3> newPointList = new List<Vector3>();//预先计算好的新位置
|
|
|
|
|
|
public float drawMoveSpeed=4; |
|
|
|
|
|
public bool canDrawCard; |
|
|
|
|
|
|
|
|
|
|
|
private void Start() |
|
|
|
|
|
{ |
|
|
|
|
|
targrtPoint = transform.localPosition - new Vector3(0, radius, 0); |
|
|
|
|
|
Debug.Log(targrtPoint); |
|
|
|
|
|
mainCamera = FindObjectOfType<Camera>(); |
|
|
|
|
|
} |
|
|
void Update() |
|
|
void Update() |
|
|
{ |
|
|
{ |
|
|
if(transform .childCount > cardCount && transform .childCount >1) |
|
|
/* if(transform .childCount > cardCount && transform .childCount >1) |
|
|
{ |
|
|
{ |
|
|
ReflashCardPoint(); |
|
|
ReflashCardPoint(); |
|
|
cardCount = this.transform.childCount; |
|
|
cardCount = this.transform.childCount; |
|
|
@ -26,7 +36,7 @@ public class CardActiveSort : Singleton <CardActiveSort> |
|
|
if(transform.childCount < cardCount) |
|
|
if(transform.childCount < cardCount) |
|
|
{ |
|
|
{ |
|
|
cardCount = this.transform.childCount; |
|
|
cardCount = this.transform.childCount; |
|
|
} |
|
|
}*/ |
|
|
} |
|
|
} |
|
|
public void ReflashCardPoint() |
|
|
public void ReflashCardPoint() |
|
|
{ |
|
|
{ |
|
|
@ -59,46 +69,129 @@ public class CardActiveSort : Singleton <CardActiveSort> |
|
|
{ |
|
|
{ |
|
|
currentangle += angleIncrement ; |
|
|
currentangle += angleIncrement ; |
|
|
|
|
|
|
|
|
cardEntitieList[i].transform.position = new Vector3(targrtPoint.transform.position.x-radius * Mathf.Cos(currentangle * Mathf.Deg2Rad), targrtPoint.transform.position.y+ radius * Mathf.Sin(currentangle * Mathf.Deg2Rad), 0); |
|
|
cardEntitieList[i].transform.localPosition = new Vector3(targrtPoint.x - radius * Mathf.Cos(currentangle * Mathf.Deg2Rad), targrtPoint.y + radius * Mathf.Sin(currentangle * Mathf.Deg2Rad), 0); |
|
|
|
|
|
|
|
|
|
|
|
Vector3 direction = targrtPoint - cardEntitieList[i].transform.localPosition; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vector3 direction = targrtPoint.transform.position- cardEntitieList[i].transform.position; |
|
|
float angle = Vector3.SignedAngle(-transform.InverseTransformDirection(cardEntitieList[i].transform.up), direction, transform.InverseTransformDirection(cardEntitieList[i].transform.forward)); |
|
|
float angle = Vector3.SignedAngle(-cardEntitieList[i].transform.up, direction, cardEntitieList[i].transform.forward); |
|
|
cardEntitieList[i].GetComponent<RectTransform>().Rotate(0, 0, angle); |
|
|
cardEntitieList[i].transform.Rotate(0, 0, angle); |
|
|
Debug .Log (angle); |
|
|
} |
|
|
} |
|
|
//重置初始位置
|
|
|
//重置初始位置
|
|
|
foreach (var card in cardEntitieList) |
|
|
foreach (var card in cardEntitieList) |
|
|
{ |
|
|
{ |
|
|
CardOnMouseEnter cardOnMouseEnte = card.GetComponent<CardOnMouseEnter>(); |
|
|
CardOnMouseEnter cardOnMouseEnte = card.GetComponent<CardOnMouseEnter>(); |
|
|
cardOnMouseEnte.originPoint= cardOnMouseEnte.transform.position ; |
|
|
|
|
|
|
|
|
|
|
|
cardOnMouseEnte.originRotation = cardOnMouseEnte.GetComponent <RectTransform >().eulerAngles; |
|
|
cardOnMouseEnte.originPoint= cardOnMouseEnte.transform.localPosition; |
|
|
|
|
|
|
|
|
|
|
|
cardOnMouseEnte.originRotation = cardOnMouseEnte.GetComponent <RectTransform >().localEulerAngles; |
|
|
|
|
|
|
|
|
cardOnMouseEnte.oringinIndex = cardOnMouseEnte.transform.GetSiblingIndex(); |
|
|
cardOnMouseEnte.oringinIndex = cardOnMouseEnte.transform.GetSiblingIndex(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
public IEnumerator ReflashCardPointWithDrawCards() |
|
|
public void ReflashCardPointWithSave() |
|
|
|
|
|
{ |
|
|
{ |
|
|
|
|
|
prepareHandCard.Clear(); |
|
|
|
|
|
canDrawCard = false; |
|
|
List<RectTransform> cardEntitieList = new List<RectTransform>(); |
|
|
List<RectTransform> cardEntitieList = new List<RectTransform>(); |
|
|
|
|
|
//将已有的手牌加入列表
|
|
|
for (int i = 0; i < transform.childCount; i++) |
|
|
for (int i = 0; i < transform.childCount; i++) |
|
|
{ |
|
|
{ |
|
|
cardEntitieList.Add(transform.GetChild(i).GetComponent<RectTransform>()); |
|
|
cardEntitieList.Add(transform.GetChild(i).GetComponent<RectTransform>()); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int cardCount = cardEntitieList.Count + drawCardCount; |
|
|
|
|
|
|
|
|
//停止移动
|
|
|
//停止移动
|
|
|
foreach (var card in cardEntitieList) |
|
|
foreach (var card in cardEntitieList) |
|
|
{ |
|
|
{ |
|
|
CardOnMouseEnter cardOnMouseEnte = card.GetComponent<CardOnMouseEnter>(); |
|
|
CardOnMouseEnter cardOnMouseEnte = card.GetComponent<CardOnMouseEnter>(); |
|
|
cardOnMouseEnte.StopAllCoroutines(); |
|
|
cardOnMouseEnte.StopAllCoroutines(); |
|
|
} |
|
|
} |
|
|
Debug.Log("ÅÅÐò-Save"); |
|
|
|
|
|
|
|
|
Debug.Log("抽卡排序"); |
|
|
|
|
|
|
|
|
|
|
|
float currentangle = 0; |
|
|
|
|
|
if (cardCount % 2 == 0) |
|
|
|
|
|
{ |
|
|
|
|
|
currentangle = 90 - (angleIncrement * (cardCount / 2 + 0.5f)); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
currentangle = 90 - (angleIncrement * (cardCount / 2 + 1)); |
|
|
|
|
|
} |
|
|
|
|
|
newPointList.Clear(); |
|
|
|
|
|
//计算所有卡牌的新位置,包括将要抽取的
|
|
|
|
|
|
for (int i = 0; i < cardCount; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
currentangle += angleIncrement; |
|
|
|
|
|
newPointList .Add ( new Vector3(targrtPoint.x - radius * Mathf.Cos(currentangle * Mathf.Deg2Rad), targrtPoint.y + radius * Mathf.Sin(currentangle * Mathf.Deg2Rad), 0)); |
|
|
|
|
|
} |
|
|
|
|
|
//移动已有卡牌到新位置
|
|
|
for (int i = 0; i < cardEntitieList.Count; i++) |
|
|
for (int i = 0; i < cardEntitieList.Count; i++) |
|
|
{ |
|
|
{ |
|
|
cardEntitieList[i].transform.position = cardOringinPointDataList[i].originPoint; |
|
|
bool move = true; |
|
|
cardEntitieList[i].transform.eulerAngles = cardOringinPointDataList[i].originRotation; |
|
|
Vector3 startpos = cardEntitieList[i].transform.localPosition; |
|
|
|
|
|
float time = 0; |
|
|
|
|
|
while (move) |
|
|
|
|
|
{ |
|
|
|
|
|
Vector3 direction = targrtPoint - cardEntitieList[i].transform.localPosition; |
|
|
|
|
|
float angle = Vector3.SignedAngle(-transform.InverseTransformDirection(cardEntitieList[i].transform.up), direction, transform.InverseTransformDirection(cardEntitieList[i].transform.forward)); |
|
|
|
|
|
cardEntitieList[i].GetComponent<RectTransform>().Rotate(0, 0, angle); |
|
|
|
|
|
cardEntitieList[i].transform.localPosition = Vector3.Lerp(startpos, newPointList[i], time += Time.deltaTime * drawMoveSpeed); |
|
|
|
|
|
|
|
|
|
|
|
if (Vector3.Distance(cardEntitieList[i].transform.localPosition, newPointList[i]) < 0.01f) |
|
|
|
|
|
{ |
|
|
|
|
|
move = false; |
|
|
|
|
|
} |
|
|
|
|
|
yield return null; |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
canDrawCard = true;//标识已经移动完成,让抽卡方法生成新卡牌
|
|
|
|
|
|
yield return new WaitUntil(() => prepareHandCard.Count == drawCardCount);//等待新抽的卡牌移动到位
|
|
|
|
|
|
//将新加进来的卡牌加入列表
|
|
|
|
|
|
for (int i = 0; i < prepareHandCard.Count; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
cardEntitieList.Add(prepareHandCard[i].GetComponent<RectTransform>()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* for (int i = cardEntitieList.Count-drawCardCount; i < cardCount; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
bool move = true; |
|
|
|
|
|
Vector3 startpos = cardEntitieList[i].transform.localPosition; |
|
|
|
|
|
float time = 0; |
|
|
|
|
|
while (move) |
|
|
|
|
|
{ |
|
|
|
|
|
Vector3 direction = targrtPoint - cardEntitieList[i].transform.localPosition; |
|
|
|
|
|
float angle = Vector3.SignedAngle(-transform.InverseTransformDirection(cardEntitieList[i].transform.up), direction, transform.InverseTransformDirection(cardEntitieList[i].transform.forward)); |
|
|
|
|
|
cardEntitieList[i].GetComponent<RectTransform>().Rotate(0, 0, angle); |
|
|
|
|
|
cardEntitieList[i].transform.localPosition = Vector3.Lerp(startpos, newPointList[i], time += Time.deltaTime * drawMoveSpeed); |
|
|
|
|
|
|
|
|
|
|
|
if (Vector3.Distance(cardEntitieList[i].transform.localPosition, newPointList[i]) < 0.01f) |
|
|
|
|
|
{ |
|
|
|
|
|
move = false; |
|
|
|
|
|
} |
|
|
|
|
|
yield return null; |
|
|
|
|
|
} |
|
|
|
|
|
}*/ |
|
|
|
|
|
//重置初始位置
|
|
|
|
|
|
foreach (var card in cardEntitieList) |
|
|
|
|
|
{ |
|
|
|
|
|
CardOnMouseEnter cardOnMouseEnte = card.GetComponent<CardOnMouseEnter>(); |
|
|
|
|
|
|
|
|
|
|
|
cardOnMouseEnte.originPoint = cardOnMouseEnte.transform.localPosition; |
|
|
|
|
|
|
|
|
|
|
|
cardOnMouseEnte.originRotation = cardOnMouseEnte.GetComponent<RectTransform>().localEulerAngles; |
|
|
|
|
|
|
|
|
|
|
|
cardOnMouseEnte.oringinIndex = cardOnMouseEnte.transform.GetSiblingIndex(); |
|
|
} |
|
|
} |
|
|
|
|
|
GameManager.Instance.onDraw = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[System .Serializable ] |
|
|
[System .Serializable ] |
|
|
public class CardPointData |
|
|
public class CardPointData |
|
|
{ |
|
|
{ |
|
|
@ -113,4 +206,13 @@ public class CardActiveSort : Singleton <CardActiveSort> |
|
|
currentCardPointData.originRotation = originRotation; |
|
|
currentCardPointData.originRotation = originRotation; |
|
|
return currentCardPointData; |
|
|
return currentCardPointData; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Vector3 ScreenPointToWorldPoint(Vector2 screenPoint, float planeZ) |
|
|
|
|
|
{ |
|
|
|
|
|
// Camera.main 世界摄像机
|
|
|
|
|
|
Vector3 position = new Vector3(screenPoint.x, screenPoint.y, planeZ); |
|
|
|
|
|
Vector3 worldPoint = Camera.main.ScreenToWorldPoint(position); |
|
|
|
|
|
return worldPoint; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|