| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class SpiritSystem : MonoBehaviour
- {
- [Header("玩家UI位置")]
- public Transform p1;
- public Transform p2;
- public Transform p1Orig;
- public Transform p2Orig;
- public Transform p1To;
- public Transform p2To;
- public Transform p1WordOrig;
- public Transform p1WordTo;
- public Transform p2WordOrig;
- public Transform p2WordTo;
- public float uiSpeed;
- [Header("玩家1图标")]
- static public GameObject player1;
- static public Spirits p1Spirits;
- public Image[] player1cards;
- public GameObject choose1;
- private int curCard1;
- static public bool isP1CardChange;
- public GameObject P1icon;
- [Header("玩家2图标")]
- static public GameObject player2;
- static public Spirits p2Spirits;
- public Image[] player2cards;
- public GameObject choose2;
- private int curCard2;
- static public bool isP2CardChange;
- public GameObject P2icon;
- [Header("英灵图标")]
- public Sprite floatHead;
- public Sprite CookHead;
- public Sprite AssassinHead;
- public Sprite InvisibleHead;
- public Sprite isChoosing;
- public Sprite isSelected;
- //ref速度
- private Vector3 re1 = Vector3.right;
- private Vector3 re2 = Vector3.left;
- //ui是否进入离开bool
- static public bool isP1Out = false;
- static public bool isP2Out = false;
- static public bool isP1In = false;
- static public bool isP2In = false;
- //是否选中
- static public bool isSelect1 = false;
- static public bool isSelect2 = false;
- //是否结束变身
- static public bool isEndtran1 = false;
- static public bool isEndtran2 = false;
- private void Start()
- {
- p1.position = p1Orig.position;
- p2.position = p2Orig.position;
- }
- private void ChangeSpirit(int id)
- {
- switch (id)
- {
- case 0:
- int man = p1Spirits.hasSpirits;
- if (man != 0)
- {
- curCard1 += 1;
- if (curCard1 == man)
- {
- curCard1 = 0;
- }
- choose1.transform.position = player1cards[curCard1].transform.position;
- p1Spirits.currentSpirit = p1Spirits.ownSpirits[curCard1];
- }
- break;
- case 1:
- int mann = p2Spirits.hasSpirits;
- if (mann != 0)
- {
- curCard2 += 1;
- if (curCard2 == mann)
- {
- curCard2 = 0;
- }
- choose2.transform.position = player2cards[curCard2].transform.position;
- p2Spirits.currentSpirit = p2Spirits.ownSpirits[curCard2];
- }
- break;
- default:
- break;
- }
- }
- private void SelectSpirit(int id)
- {
- switch (id)
- {
- case 0:
- P1icon.transform.localPosition = p1WordTo.localPosition;
- choose1.GetComponent<Image>().sprite = isSelected;
- break;
- case 1:
- P2icon.transform.localPosition = p2WordTo.localPosition;
- choose2.GetComponent<Image>().sprite = isSelected;
- break;
- default:
- break;
- }
- }
- private void EndTransfigurate(int id)
- {
- switch (id)
- {
- case 0:
- P1icon.transform.localPosition = p1WordOrig.localPosition;
- choose1.GetComponent<Image>().sprite = isChoosing;
- break;
- case 1:
- P2icon.transform.localPosition = p2WordOrig.localPosition;
- choose2.GetComponent<Image>().sprite = isChoosing;
- break;
- default:
- break;
- }
- }
- private void playerUIout(int id)
- {
- switch (id)
- {
- case 0:
- p1.position = Vector3.SmoothDamp(p1.position, p1To.position, ref re1, uiSpeed);
- if (p1To.position.x - p1.position.x <= 0.5f)
- {
- p1.position = p1To.position;
- isP1Out = false;
- }
- break;
- case 1:
- p2.position = Vector3.SmoothDamp(p2.position, p2To.position, ref re2, uiSpeed);
- if (p2.position.x - p2To.position.x <= 0.5f)
- {
- p2.position = p2To.position;
- isP2Out = false;
- }
- break;
- default:
- break;
- }
- }
- private void playerUIin(int id)
- {
- switch (id)
- {
- case 0:
- p1.position = Vector3.SmoothDamp(p1.position, p1Orig.position, ref re2, uiSpeed);
- if (p1.position.x - p1Orig.position.x <= 0.5f)
- {
- p1.position = p1Orig.position;
- isP1In = false;
- }
- break;
- case 1:
- p2.position = Vector3.SmoothDamp(p2.position, p2Orig.position, ref re1, uiSpeed);
- if (p2Orig.position.x - p2.position.x <= 0.5f)
- {
- p2.position = p2Orig.position;
- isP2In = false;
- }
- break;
- default:
- break;
- }
- }
- private void Update()
- {
- if (isP1Out)
- {
- playerUIout(0);
- }
- if (isP2Out)
- {
- playerUIout(1);
- }
- if (isP1In)
- {
- playerUIin(0);
- }
- if (isP2In)
- {
- playerUIin(1);
- }
- if (isP1CardChange)
- {
- isP1CardChange = false;
- ChangeSpirit(0);
- }
- if (isP2CardChange)
- {
- isP2CardChange = false;
- ChangeSpirit(1);
- }
- if (isSelect1)
- {
- isSelect1 = false;
- SelectSpirit(0);
- }
- if (isSelect2)
- {
- isSelect2 = false;
- SelectSpirit(1);
- }
- if (isEndtran1)
- {
- isEndtran1 = false;
- EndTransfigurate(0);
- }
- if (isEndtran2)
- {
- isEndtran2 = false;
- EndTransfigurate(1);
- }
- }
- }
|