Commit 7be44462 authored by hex's avatar hex

fix and optimized

parent dde96b6a
Pipeline #39607 failed
...@@ -42,21 +42,20 @@ public class MonoCardInDeckManager : MonoBehaviour ...@@ -42,21 +42,20 @@ public class MonoCardInDeckManager : MonoBehaviour
if (isDraging) if (isDraging)
{ {
gameObject.transform.position += gameObject.transform.position +=
(getGoodPosition(4) - gameObject.transform.position) * 0.3f; (GetMouseWorldPosition(4) - gameObject.transform.position) * 0.3f;
} }
if (Vector3.Distance(Vector3.zero, gameObject.transform.position) > 50 && bool_physicalON) if (Vector3.Distance(Vector3.zero, gameObject.transform.position) > 50 && bool_physicalON)
{ {
killIt(); KillCard();
} }
} }
public void KillCard()
public void killIt()
{ {
if (Program.I().deckManager.condition == DeckManager.Condition.changeSide) if (Program.I().deckManager.condition == DeckManager.Condition.changeSide)
{ {
gameObject.transform.position = new Vector3(0, 5, 0); gameObject.transform.position = new Vector3(0, 5, 0);
endDrag(); EndDrag();
if (Program.I().deckManager.cardInDragging == this) if (Program.I().deckManager.cardInDragging == this)
{ {
Program.I().deckManager.cardInDragging = null; Program.I().deckManager.cardInDragging = null;
...@@ -74,7 +73,7 @@ public class MonoCardInDeckManager : MonoBehaviour ...@@ -74,7 +73,7 @@ public class MonoCardInDeckManager : MonoBehaviour
} }
} }
public Vector3 getGoodPosition(float height) public Vector3 GetMouseWorldPosition(float height)
{ {
float x = Input.mousePosition.x; float x = Input.mousePosition.x;
float y = Input.mousePosition.y; float y = Input.mousePosition.y;
...@@ -97,7 +96,7 @@ public class MonoCardInDeckManager : MonoBehaviour ...@@ -97,7 +96,7 @@ public class MonoCardInDeckManager : MonoBehaviour
return to_ltemp; return to_ltemp;
} }
public void beginDrag() public void BeginDrag()
{ {
physicalOFF(); physicalOFF();
physicalHalfON(); physicalHalfON();
...@@ -105,7 +104,7 @@ public class MonoCardInDeckManager : MonoBehaviour ...@@ -105,7 +104,7 @@ public class MonoCardInDeckManager : MonoBehaviour
transform.DORotate(new Vector3(90, 0, 0), 0.6f).SetDelay(0); transform.DORotate(new Vector3(90, 0, 0), 0.6f).SetDelay(0);
} }
public void endDrag() public void EndDrag()
{ {
physicalON(); physicalON();
stopDragThisFrame = true; stopDragThisFrame = true;
...@@ -113,18 +112,18 @@ public class MonoCardInDeckManager : MonoBehaviour ...@@ -113,18 +112,18 @@ public class MonoCardInDeckManager : MonoBehaviour
if ( if (
Input.GetKey(KeyCode.LeftControl) Input.GetKey(KeyCode.LeftControl)
|| Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.RightControl)
|| getIfAlive() == false || !IsAlive()
) )
{ {
Vector3 from_position = getGoodPosition(4); Vector3 from_position = GetMouseWorldPosition(4);
Vector3 to_position = getGoodPosition(0); Vector3 to_position = GetMouseWorldPosition(0);
Vector3 delta_position = to_position - from_position; Vector3 delta_position = to_position - from_position;
GetComponent<Rigidbody>().AddForce(delta_position * 1000); GetComponent<Rigidbody>().AddForce(delta_position * 1000);
dying = true; dying = true;
} }
} }
public void tweenToVectorAndFall(Vector3 position, Vector3 rotation, float delay = 0) public void TweenToPositionAndFall(Vector3 position, Vector3 rotation, float delay = 0)
{ {
var rigidbody = GetComponent<Rigidbody>(); var rigidbody = GetComponent<Rigidbody>();
if (rigidbody != null) rigidbody.Sleep(); if (rigidbody != null) rigidbody.Sleep();
...@@ -173,7 +172,7 @@ public class MonoCardInDeckManager : MonoBehaviour ...@@ -173,7 +172,7 @@ public class MonoCardInDeckManager : MonoBehaviour
public bool IsInDeckArea() public bool IsInDeckArea()
{ {
// 此逻辑专门用于检查卡片是否在物理上位于有效的卡组区域内。 // 此逻辑专门用于检查卡片是否在物理上位于有效的卡组区域内。
Vector3 to_ltemp = refLectPosition(gameObject.transform.position); Vector3 to_ltemp = ReflectPositionToGround(gameObject.transform.position);
if (to_ltemp.x < -15.2f || to_ltemp.x > 15.2f) if (to_ltemp.x < -15.2f || to_ltemp.x > 15.2f)
{ {
return false; return false;
...@@ -181,7 +180,7 @@ public class MonoCardInDeckManager : MonoBehaviour ...@@ -181,7 +180,7 @@ public class MonoCardInDeckManager : MonoBehaviour
return true; return true;
} }
public bool getIfAlive() public bool IsAlive()
{ {
// 步骤 1: 检查不可逆的“死亡”状态,这在任何模式下都适用。 // 步骤 1: 检查不可逆的“死亡”状态,这在任何模式下都适用。
if (died || gameObject.transform.position.y < -0.5f) if (died || gameObject.transform.position.y < -0.5f)
...@@ -200,7 +199,7 @@ public class MonoCardInDeckManager : MonoBehaviour ...@@ -200,7 +199,7 @@ public class MonoCardInDeckManager : MonoBehaviour
} }
} }
public static Vector3 refLectPosition(Vector3 pos) public static Vector3 ReflectPositionToGround(Vector3 pos)
{ {
Vector3 to_ltemp = pos; Vector3 to_ltemp = pos;
Vector3 dv = to_ltemp - Program.I().main_camera.transform.position; Vector3 dv = to_ltemp - Program.I().main_camera.transform.position;
......
This diff is collapsed.
...@@ -273,6 +273,9 @@ public class Program : MonoBehaviour ...@@ -273,6 +273,9 @@ public class Program : MonoBehaviour
public static Vector3 cameraPosition = new Vector3(0, 23, -23); public static Vector3 cameraPosition = new Vector3(0, 23, -23);
public static Vector3 cameraRotation = new Vector3(60, 0, 0); public static Vector3 cameraRotation = new Vector3(60, 0, 0);
// public static Vector3 cameraPosition = new Vector3(0, 23, -40);
// public static Vector3 cameraRotation = new Vector3(35, 0, 0);
public static bool cameraFacing = false; public static bool cameraFacing = false;
public static float verticleScale = 5f; public static float verticleScale = 5f;
...@@ -747,8 +750,8 @@ public class Program : MonoBehaviour ...@@ -747,8 +750,8 @@ public class Program : MonoBehaviour
{ {
camera_game_main = this.main_camera; camera_game_main = this.main_camera;
} }
camera_game_main.transform.position = new Vector3(0, 23, -23); camera_game_main.transform.position = cameraPosition;
camera_game_main.transform.eulerAngles = new Vector3(60, 0, 0); camera_game_main.transform.eulerAngles = cameraRotation;
camera_game_main.transform.localScale = new Vector3(1, 1, 1); camera_game_main.transform.localScale = new Vector3(1, 1, 1);
camera_game_main.rect = new Rect(0, 0, 1, 1); camera_game_main.rect = new Rect(0, 0, 1, 1);
camera_game_main.depth = 0; camera_game_main.depth = 0;
...@@ -779,8 +782,8 @@ public class Program : MonoBehaviour ...@@ -779,8 +782,8 @@ public class Program : MonoBehaviour
camera_container_3d.cullingMask = (int)Mathf.Pow(2, 9); camera_container_3d.cullingMask = (int)Mathf.Pow(2, 9);
camera_container_3d.fieldOfView = 75; camera_container_3d.fieldOfView = 75;
camera_container_3d.rect = camera_game_main.rect; camera_container_3d.rect = camera_game_main.rect;
camera_container_3d.transform.position = new Vector3(0, 23, -23); camera_container_3d.transform.position = cameraPosition;
camera_container_3d.transform.eulerAngles = new Vector3(60, 0, 0); camera_container_3d.transform.eulerAngles = cameraRotation;
camera_container_3d.transform.localScale = new Vector3(1, 1, 1); camera_container_3d.transform.localScale = new Vector3(1, 1, 1);
camera_container_3d.rect = new Rect(0, 0, 1, 1); camera_container_3d.rect = new Rect(0, 0, 1, 1);
camera_container_3d.clearFlags = CameraClearFlags.Depth; camera_container_3d.clearFlags = CameraClearFlags.Depth;
...@@ -818,8 +821,8 @@ public class Program : MonoBehaviour ...@@ -818,8 +821,8 @@ public class Program : MonoBehaviour
camera_main_3d.cullingMask = (int)Mathf.Pow(2, 10); camera_main_3d.cullingMask = (int)Mathf.Pow(2, 10);
camera_main_3d.fieldOfView = 75; camera_main_3d.fieldOfView = 75;
camera_main_3d.rect = new Rect(0, 0, 1, 1); camera_main_3d.rect = new Rect(0, 0, 1, 1);
camera_main_3d.transform.position = new Vector3(0, 23, -23); camera_main_3d.transform.position = cameraPosition;
camera_main_3d.transform.eulerAngles = new Vector3(60, 0, 0); camera_main_3d.transform.eulerAngles = cameraRotation;
camera_main_3d.transform.localScale = new Vector3(1, 1, 1); camera_main_3d.transform.localScale = new Vector3(1, 1, 1);
camera_main_3d.clearFlags = CameraClearFlags.Depth; camera_main_3d.clearFlags = CameraClearFlags.Depth;
......
...@@ -148,21 +148,6 @@ public class DeckManager : ServantWithCardDescription ...@@ -148,21 +148,6 @@ public class DeckManager : ServantWithCardDescription
itemOnListProducer, itemOnListProducer,
86 86
); );
// Program.go(
// 500,
// () =>
// {
// List<MonoCardInDeckManager> cs = new List<MonoCardInDeckManager>();
// for (int i = 0; i < 300; i++)
// {
// cs.Add(createCard());
// }
// for (int i = 0; i < 300; i++)
// {
// destroyCard(cs[i]);
// }
// }
// );
} }
GameObject itemOnListProducer(string[] Args) GameObject itemOnListProducer(string[] Args)
...@@ -1461,7 +1446,7 @@ public class DeckManager : ServantWithCardDescription ...@@ -1461,7 +1446,7 @@ public class DeckManager : ServantWithCardDescription
{ {
// 判定为拖拽,开始拖拽卡牌 // 判定为拖拽,开始拖拽卡牌
cardInDragging = cardForLongPress; cardInDragging = cardForLongPress;
cardInDragging.beginDrag(); cardInDragging.BeginDrag();
cardForLongPress = null; // 清除长按检测状态 cardForLongPress = null; // 清除长按检测状态
isContinuouslyAdding = false; // 确保连续添加状态也被重置 isContinuouslyAdding = false; // 确保连续添加状态也被重置
} }
...@@ -1633,12 +1618,12 @@ public class DeckManager : ServantWithCardDescription ...@@ -1633,12 +1618,12 @@ public class DeckManager : ServantWithCardDescription
if ((cardInSearchResult.data.Type & (UInt32)CardType.Token) == 0) if ((cardInSearchResult.data.Type & (UInt32)CardType.Token) == 0)
{ {
MonoCardInDeckManager card = createCard(); MonoCardInDeckManager card = createCard();
card.transform.position = card.getGoodPosition(4); card.transform.position = card.GetMouseWorldPosition(4f);
card.cardData = cardInSearchResult.data; card.cardData = cardInSearchResult.data;
card.gameObject.layer = 16; card.gameObject.layer = 16;
deck.IMain.Add(card); deck.IMain.Add(card);
cardInDragging = card; cardInDragging = card;
card.beginDrag(); card.BeginDrag();
} }
} }
} }
...@@ -1650,11 +1635,11 @@ public class DeckManager : ServantWithCardDescription ...@@ -1650,11 +1635,11 @@ public class DeckManager : ServantWithCardDescription
if (cardInDragging != null) if (cardInDragging != null)
{ {
// 第一步:终止拖拽,设置物理状态 // 第一步:终止拖拽,设置物理状态
cardInDragging.endDrag(); cardInDragging.EndDrag();
// 第二步:逻辑判断是否仍应纳入卡组 // 第二步:逻辑判断是否仍应纳入卡组
if (condition == Condition.changeSide && !cardInDragging.IsInDeckArea()) { } if (condition == Condition.changeSide && !cardInDragging.IsInDeckArea()) { }
else if (cardInDragging.getIfAlive()) else if (cardInDragging.IsAlive())
{ {
deckDirty = true; deckDirty = true;
} }
...@@ -1684,7 +1669,7 @@ public class DeckManager : ServantWithCardDescription ...@@ -1684,7 +1669,7 @@ public class DeckManager : ServantWithCardDescription
Program.pointedGameObject.GetComponent<MonoCardInDeckManager>(); Program.pointedGameObject.GetComponent<MonoCardInDeckManager>();
if (cardInDeck != null) if (cardInDeck != null)
{ {
cardInDeck.killIt(); // 标记为待删除 cardInDeck.KillCard(); // 标记为待删除
// 从数据结构中移除 // 从数据结构中移除
deck.IMain.Remove(cardInDeck); deck.IMain.Remove(cardInDeck);
deck.IExtra.Remove(cardInDeck); deck.IExtra.Remove(cardInDeck);
...@@ -1734,7 +1719,7 @@ public class DeckManager : ServantWithCardDescription ...@@ -1734,7 +1719,7 @@ public class DeckManager : ServantWithCardDescription
if (checkBanlistAvail(data.Id)) if (checkBanlistAvail(data.Id))
{ {
MonoCardInDeckManager card = createCard(); MonoCardInDeckManager card = createCard();
card.transform.position = card.getGoodPosition(4); card.transform.position = card.GetMouseWorldPosition(4f);
card.cardData = data; card.cardData = data;
card.gameObject.layer = 16; card.gameObject.layer = 16;
if (data.IsExtraCard()) if (data.IsExtraCard())
...@@ -1974,11 +1959,11 @@ public class DeckManager : ServantWithCardDescription ...@@ -1974,11 +1959,11 @@ public class DeckManager : ServantWithCardDescription
Vector3 rightPosition = right.gameObject.transform.position; Vector3 rightPosition = right.gameObject.transform.position;
if (leftPosition.y > 3f) if (leftPosition.y > 3f)
{ {
leftPosition = MonoCardInDeckManager.refLectPosition(leftPosition); leftPosition = MonoCardInDeckManager.ReflectPositionToGround(leftPosition);
} }
if (rightPosition.y > 3f) if (rightPosition.y > 3f)
{ {
rightPosition = MonoCardInDeckManager.refLectPosition(rightPosition); rightPosition = MonoCardInDeckManager.ReflectPositionToGround(rightPosition);
} }
if (leftPosition.z > -3 && rightPosition.z > -3) if (leftPosition.z > -3 && rightPosition.z > -3)
{ {
...@@ -2020,7 +2005,7 @@ public class DeckManager : ServantWithCardDescription ...@@ -2020,7 +2005,7 @@ public class DeckManager : ServantWithCardDescription
for (int i = 0; i < deckTemp.Count; i++) for (int i = 0; i < deckTemp.Count; i++)
{ {
Vector3 p = deckTemp[i].gameObject.transform.position; Vector3 p = deckTemp[i].gameObject.transform.position;
if (deckTemp[i].getIfAlive() == true) if (deckTemp[i].IsAlive())
{ {
if (p.z > -8) if (p.z > -8)
{ {
...@@ -2179,7 +2164,7 @@ public class DeckManager : ServantWithCardDescription ...@@ -2179,7 +2164,7 @@ public class DeckManager : ServantWithCardDescription
// tweenToVectorAndFall 本身就是DoTween动画, 它会独立运行, // tweenToVectorAndFall 本身就是DoTween动画, 它会独立运行,
// 而我们的Sequence只负责在正确的时间点触发它。 // 而我们的Sequence只负责在正确的时间点触发它。
card.tweenToVectorAndFall(toVector, new Vector3(90, 0, 0)); card.TweenToPositionAndFall(toVector, new Vector3(90, 0, 0));
}); });
} }
...@@ -2247,7 +2232,7 @@ public class DeckManager : ServantWithCardDescription ...@@ -2247,7 +2232,7 @@ public class DeckManager : ServantWithCardDescription
0.6f + Mathf.Sin((90 - toAngle.x) / 180f * Mathf.PI) * k, 0.6f + Mathf.Sin((90 - toAngle.x) / 180f * Mathf.PI) * k,
11.8f - v.x * 4f 11.8f - v.x * 4f
); );
deck.IMain[i].tweenToVectorAndFall(toVector, toAngle); deck.IMain[i].TweenToPositionAndFall(toVector, toAngle);
} }
for (int i = 0; i < deck.IExtra.Count; i++) for (int i = 0; i < deck.IExtra.Count; i++)
{ {
...@@ -2265,7 +2250,7 @@ public class DeckManager : ServantWithCardDescription ...@@ -2265,7 +2250,7 @@ public class DeckManager : ServantWithCardDescription
0.6f + Mathf.Sin((90 - toAngle.x) / 180f * Mathf.PI) * k, 0.6f + Mathf.Sin((90 - toAngle.x) / 180f * Mathf.PI) * k,
-6.2f -6.2f
); );
deck.IExtra[i].tweenToVectorAndFall(toVector, toAngle); deck.IExtra[i].TweenToPositionAndFall(toVector, toAngle);
} }
for (int i = 0; i < deck.ISide.Count; i++) for (int i = 0; i < deck.ISide.Count; i++)
...@@ -2284,7 +2269,7 @@ public class DeckManager : ServantWithCardDescription ...@@ -2284,7 +2269,7 @@ public class DeckManager : ServantWithCardDescription
0.6f + Mathf.Sin((90 - toAngle.x) / 180f * Mathf.PI) * k, 0.6f + Mathf.Sin((90 - toAngle.x) / 180f * Mathf.PI) * k,
-12f -12f
); );
deck.ISide[i].tweenToVectorAndFall(toVector, toAngle); deck.ISide[i].TweenToPositionAndFall(toVector, toAngle);
} }
} }
......
...@@ -166,22 +166,22 @@ namespace YGOSharp ...@@ -166,22 +166,22 @@ namespace YGOSharp
{ {
foreach (var item in stack) foreach (var item in stack)
{ {
if (item.cardData.Id == code && item.getIfAlive()) if (item.cardData.Id == code && item.IsAlive())
{ {
returnValue++; returnValue++;
continue; continue;
} }
if (item.cardData.Alias == code && item.getIfAlive()) if (item.cardData.Alias == code && item.IsAlive())
{ {
returnValue++; returnValue++;
continue; continue;
} }
if (item.cardData.Id == al && item.getIfAlive()) if (item.cardData.Id == al && item.IsAlive())
{ {
returnValue++; returnValue++;
continue; continue;
} }
if (item.cardData.Alias == al && item.getIfAlive() && al > 0) if (item.cardData.Alias == al && item.IsAlive() && al > 0)
{ {
returnValue++; returnValue++;
continue; continue;
...@@ -244,7 +244,7 @@ namespace YGOSharp ...@@ -244,7 +244,7 @@ namespace YGOSharp
public List<MonoCardInDeckManager> getAllObjectCardAndDeload() public List<MonoCardInDeckManager> getAllObjectCardAndDeload()
{ {
List<MonoCardInDeckManager> r = new List<MonoCardInDeckManager>(); List<MonoCardInDeckManager> r = new List<MonoCardInDeckManager>();
IList<MonoCardInDeckManager>[] stacks = { IMain, IExtra, ISide,IRemoved }; IList<MonoCardInDeckManager>[] stacks = { IMain, IExtra, ISide, IRemoved };
foreach (var stack in stacks) foreach (var stack in stacks)
{ {
foreach (var item in stack) foreach (var item in stack)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment