PlayerController.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Spine;
  5. using Spine.Unity;
  6. using UnityEngine.LowLevel;
  7. using UnityEngine.Playables;
  8. using System.ComponentModel;
  9. using Unity.VisualScripting;
  10. using System;
  11. using Base.Common;
  12. using cfg;
  13. using static UnityEngine.EventSystems.EventTrigger;
  14. using UnityEngine.InputSystem;
  15. [Serializable]
  16. public struct AttackInfo
  17. {
  18. public int damage;
  19. public Vector3 attackDir;
  20. public float force;
  21. public bool changeHurt;
  22. public float repelValue;
  23. }
  24. public enum PlayerAttackState
  25. {
  26. Idle = 0,
  27. WalkForward = 1,
  28. WalkBack = 2,
  29. }
  30. public class PlayerController : MoveCharacter
  31. {
  32. //public static PlayerController instance;
  33. public List<GameObject> changePrefabs;
  34. private GameObject spiritObj; //当前变身的对象
  35. private int endChange = 0;
  36. //public float changeTime; //变身时长
  37. //private float pastChangeTime;
  38. public List<GameObject> demonicPrefabs;
  39. public List<Vector3> demonicSummonPos;
  40. public Dictionary<int, List<Demonic>> demonicDic;
  41. public List<int> demonicId;
  42. public UIHP uiMp;
  43. public PlayerRope playerRope;
  44. public EventTrigger eventTrigger;
  45. public SprintLinkTrigger sprintLinkTrigger;
  46. public float jumpSpeed = 10;
  47. public float airJumpSpeed = 10;
  48. //public float moveAcc = 5f;
  49. //public float airMoveAcc = 3f;
  50. public float rushSpeed = 100;
  51. public float mp;
  52. public float totalMp;
  53. public float mpReplySpeed = 1;
  54. public float rushCostMp = 5;
  55. public float sprintCostMp = 5;
  56. //尸体资源
  57. public int corpses = 0;
  58. public float rushInvincibleTime = 0.2f;
  59. [HideInInspector]
  60. public float canJumpTime; //离开平台后仍然可以跳跃的时间,用于提升手感
  61. public float leaveGroundCanJumpTime = 0.1f;
  62. [HideInInspector]
  63. public float cacheJumpTime; //即将落地时按下跳跃键不会跳跃,手感不好,缓存几帧,在这几帧内落地会立即跳跃;
  64. public float totalCacheJumpTime = 0.1f;
  65. [HideInInspector]
  66. public float tandemJumpTime; //即将落地时按下跳跃键不会跳跃,手感不好,缓存几帧,在这几帧内落地会立即跳跃;
  67. public float totalTandemJumpTime = 0.1f;
  68. [HideInInspector]
  69. public float summonTime;
  70. [HideInInspector]
  71. public float cacheAttackTime; //无法攻击时按下攻击键不会攻击,手感不好,缓存几帧,在这几帧内落地会立即攻击;
  72. public float totalCacheAttackTime = 0.1f;
  73. [HideInInspector]
  74. public float cachePullRopeTime;
  75. public float totalCachePullRopeTime = 0.1f;
  76. [HideInInspector]
  77. public float cacheSummonTime; //无法召唤时按下召唤键不会召唤,手感不好,缓存几帧,在这几帧内落地会立即召唤;
  78. public float totalCacheSummonTime = 0.1f;
  79. [HideInInspector]
  80. public int cacheSummonId;
  81. [HideInInspector]
  82. public float rushTime;
  83. public float totalRushTime = 0.5f;
  84. [HideInInspector]
  85. public float cacheRushTime; //无法Rush时按下Rush键不会Rush,手感不好,缓存几帧,在这几帧内落地会立即Rush;
  86. public float totalCacheRushTime = 0.1f;
  87. public int airJumped;
  88. public int jumpNumber = 2; //最大跳跃次数
  89. public PlayerAttackState attackState;
  90. public float attackMoveSpeed = 5f;
  91. public Vector3 rushDir;
  92. private int currentSpirit; //当前将要召唤的英灵种类
  93. private Spirits spirits;
  94. public float lostMp;
  95. public GameObject soul;
  96. private float addMp = 10;
  97. public Collider soulCollector;
  98. public bool isTransfiguration = false; //已变身
  99. public bool isinputJ;
  100. public bool isinputK;
  101. public bool isinputL;
  102. public Vector2 moveVec; //玩家不动时移动数据
  103. public float relieveTranTime; //解除变身所需长按时间
  104. private bool isTryingToRelieve = false;
  105. private float pressTime;
  106. public bool btnJumpPress
  107. {
  108. get
  109. {
  110. //return Input.GetKeyDown(KeyCode.Space) || isClickBtnJump;
  111. return isClickBtnJump;
  112. }
  113. }
  114. [HideInInspector]
  115. public bool isClickBtnJump;
  116. public bool btnRushPress
  117. {
  118. get
  119. {
  120. //return Input.GetKeyDown(KeyCode.LeftShift) || isClickBtnRush;
  121. return isClickBtnRush;
  122. }
  123. }
  124. [HideInInspector]
  125. public bool isClickBtnRush;
  126. public bool btnRushKeep
  127. {
  128. get
  129. {
  130. //return Input.GetKey(KeyCode.LeftShift) || isKeepBtnRush;
  131. return LBisHold || isKeepBtnRush;
  132. }
  133. }
  134. [HideInInspector]
  135. public bool isKeepBtnRush;
  136. public bool btnSouthPress
  137. {
  138. get
  139. {
  140. //return Input.GetKeyDown(KeyCode.K) || isClickBtnSouth;
  141. return isClickBtnSouth;
  142. }
  143. }
  144. [HideInInspector]
  145. public bool isClickBtnSouth;
  146. public bool btnEastPress
  147. {
  148. get
  149. {
  150. //return Input.GetKeyDown(KeyCode.L) || isClickBtnEast;
  151. return isClickBtnEast;
  152. }
  153. }
  154. [HideInInspector]
  155. public bool isClickBtnEast;
  156. public bool btnWestPress
  157. {
  158. get
  159. {
  160. //return Input.GetKeyDown(KeyCode.J) || isClickBtnWest;
  161. return isClickBtnWest;
  162. }
  163. }
  164. [HideInInspector]
  165. public bool isClickBtnWest;
  166. public bool btnNorthPress
  167. {
  168. get
  169. {
  170. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  171. return isClickBtnNorth;
  172. }
  173. }
  174. [HideInInspector]
  175. public bool isClickBtnNorth;
  176. public bool btnSpiritSummon
  177. {
  178. get
  179. {
  180. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  181. return isSpiritSummon;
  182. }
  183. }
  184. [HideInInspector]
  185. public bool isSpiritSummon;
  186. public bool btnSpiritSummon1
  187. {
  188. get
  189. {
  190. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  191. return isSpiritSummon1;
  192. }
  193. }
  194. [HideInInspector]
  195. public bool isSpiritSummon1;
  196. public bool btnSpiritSummon2
  197. {
  198. get
  199. {
  200. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  201. return isSpiritSummon2;
  202. }
  203. }
  204. [HideInInspector]
  205. public bool isSpiritSummon2;
  206. public bool btnSpiritSummon3
  207. {
  208. get
  209. {
  210. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  211. return isSpiritSummon3;
  212. }
  213. }
  214. [HideInInspector]
  215. public bool isSpiritSummon3;
  216. public bool btnNorthKeep
  217. {
  218. get
  219. {
  220. //return Input.GetKey(KeyCode.I) || isKeepBtnNorth;
  221. return isKeepBtnNorth;
  222. }
  223. }
  224. [HideInInspector]
  225. public bool isKeepBtnNorth;
  226. [HideInInspector]
  227. public Vector2 leftDir;
  228. public int playerId;
  229. public SkeletonMecanim skeletonMecanim;
  230. public SkeletonDataAsset[] playerSpine;
  231. public bool canJump;
  232. public bool canfly;
  233. //public Vector2 leftDir
  234. //{
  235. // get
  236. // {
  237. // int x = 0;
  238. // int y = 0;
  239. // if (Input.GetKey(KeyCode.A))
  240. // {
  241. // x--;
  242. // }
  243. // if (Input.GetKey(KeyCode.D))
  244. // {
  245. // x++;
  246. // }
  247. // if (Input.GetKey(KeyCode.S))
  248. // {
  249. // y--;
  250. // }
  251. // if (Input.GetKey(KeyCode.W))
  252. // {
  253. // y++;
  254. // }
  255. // return new Vector2(x, y);
  256. // }
  257. //}
  258. public override void Init()
  259. {
  260. base.Init();
  261. mp = totalMp;
  262. uiMp.Show(mp, totalMp);
  263. }
  264. private void Awake()
  265. {
  266. PlayerInput playerInput = transform.GetComponent<PlayerInput>();
  267. spirits = GetComponent<Spirits>();
  268. playerId = playerInput.playerIndex;
  269. transform.position = new Vector3(142 + 4 * playerId, 0, 0);
  270. playerRope.playerId = playerId;
  271. sprintLinkTrigger.playerID = playerId;
  272. if (PlayersInput.instance[1] == PlayersInput.instance[0])
  273. {
  274. PlayersInput.instance[1] = this;
  275. }
  276. PlayersInput.instance[playerId] = this;
  277. skeletonMecanim.skeletonDataAsset = playerSpine[playerId];
  278. //else
  279. //{
  280. // DestroyImmediate(gameObject);
  281. // return;
  282. //}
  283. demonicDic = new Dictionary<int, List<Demonic>>();
  284. demonicId = new List<int>() { 0, 0, 0, 0, 0, 0, 0 };
  285. Init();
  286. }
  287. private void Update()
  288. {
  289. //if (Input.GetKeyDown(KeyCode.LeftShift))
  290. //{
  291. // isClickBtnRush = true;
  292. //}
  293. //if (Input.GetKey(KeyCode.LeftShift))
  294. //{
  295. // isKeepBtnRush = true;
  296. //}
  297. //if (Input.GetKeyDown(KeyCode.Space))
  298. //{
  299. // isClickBtnJump = true;
  300. //}
  301. //if (Input.GetKeyDown(KeyCode.J))
  302. //{
  303. // isClickBtnWest = true;
  304. //}
  305. //if (Input.GetKeyDown(KeyCode.K))
  306. //{
  307. // isClickBtnSouth = true;
  308. //}
  309. //if (Input.GetKeyDown(KeyCode.L))
  310. //{
  311. // isClickBtnEast = true;
  312. //}
  313. //if (Input.GetKeyDown(KeyCode.I))
  314. //{
  315. // isClickBtnNorth = true;
  316. //}
  317. if (LBisHold)
  318. {
  319. isKeepBtnRush = true;
  320. }
  321. if (floatState != 0)
  322. {
  323. CharacterFloat();
  324. }
  325. /* //到时间自动解除变身
  326. if (endChange != 0)
  327. {
  328. pastChangeTime += Time.deltaTime;
  329. if (pastChangeTime >= changeTime)
  330. {
  331. EndTransfiguration(endChange);
  332. endChange = 0;
  333. pastChangeTime = 0;
  334. }
  335. }
  336. */
  337. if (isTransfiguration)
  338. {
  339. bodyTrans.position = spiritObj.transform.position;
  340. if (isTryingToRelieve)
  341. {
  342. pressTime += Time.deltaTime;
  343. if (pressTime >= relieveTranTime)
  344. {
  345. EndTransfiguration(endChange);
  346. isTryingToRelieve = false;
  347. pressTime = 0;
  348. }
  349. }
  350. }
  351. }
  352. void OnSprintingPress()
  353. {
  354. LBisHold = true;
  355. isClickBtnRush = true;
  356. isKeepBtnRush = true;
  357. }
  358. void OnSprintingRelease()
  359. {
  360. LBisHold = false;
  361. }
  362. //手柄按下LB
  363. [HideInInspector]
  364. public bool LBisHold;
  365. //读取手柄参数
  366. private void OnMove(InputValue value)
  367. {
  368. if (canMove)
  369. {
  370. leftDir = value.Get<Vector2>();
  371. }
  372. else
  373. {
  374. leftDir = Vector3.zero;
  375. moveVec = value.Get<Vector2>();
  376. }
  377. }
  378. void OnJump()
  379. {
  380. if (canJump && canMove)
  381. {
  382. isClickBtnJump = true;
  383. }
  384. }
  385. void OnSummon0()
  386. {
  387. if (!isFloat && canMove)
  388. {
  389. isClickBtnWest = true;
  390. if (isTransfiguration)
  391. {
  392. isinputJ = true;
  393. }
  394. }
  395. }
  396. void OnSummon0Up()
  397. {
  398. if (isTransfiguration)
  399. {
  400. isinputJ = false;
  401. }
  402. }
  403. void OnSummon1()
  404. {
  405. if (!isFloat && canMove)
  406. {
  407. isClickBtnSouth = true;
  408. if (isTransfiguration)
  409. {
  410. isinputK = true;
  411. }
  412. }
  413. }
  414. void OnSummon1Up()
  415. {
  416. if (isTransfiguration)
  417. {
  418. isinputK = false;
  419. }
  420. }
  421. void OnSummon2()
  422. {
  423. if (!isFloat && canMove)
  424. {
  425. isClickBtnEast = true;
  426. if (isTransfiguration)
  427. {
  428. isinputL = true;
  429. }
  430. }
  431. }
  432. void OnSummon2Up()
  433. {
  434. if (isTransfiguration)
  435. {
  436. isinputL = false;
  437. }
  438. }
  439. void OnSummonSpirit()
  440. {
  441. if (!isTransfiguration && !isFloat && canMove)
  442. isSpiritSummon = true;
  443. if (isTransfiguration && currentSpirit == 0)
  444. {
  445. isTryingToRelieve = true;
  446. }
  447. }
  448. void OnSummonSpiritUp()
  449. {
  450. if (isTryingToRelieve && currentSpirit == 0)
  451. {
  452. isTryingToRelieve = false;
  453. pressTime = 0;
  454. }
  455. }
  456. void OnSummonSpirit1()
  457. {
  458. if (!isTransfiguration && !isFloat && canMove)
  459. isSpiritSummon1 = true;
  460. if (isTransfiguration && currentSpirit == 1)
  461. {
  462. isTryingToRelieve = true;
  463. }
  464. }
  465. void OnSummonSpirit1Up()
  466. {
  467. if (isTryingToRelieve && currentSpirit == 1)
  468. {
  469. isTryingToRelieve = false;
  470. pressTime = 0;
  471. }
  472. }
  473. void OnSummonSpirit2()
  474. {
  475. if (!isTransfiguration && !isFloat && canMove)
  476. isSpiritSummon2 = true;
  477. if (isTransfiguration && currentSpirit == 2)
  478. {
  479. isTryingToRelieve = true;
  480. }
  481. }
  482. void OnSummonSpirit2Up()
  483. {
  484. if (isTryingToRelieve && currentSpirit == 2)
  485. {
  486. isTryingToRelieve = false;
  487. pressTime = 0;
  488. }
  489. }
  490. void OnSummonSpirit3()
  491. {
  492. if (!isTransfiguration && !isFloat && canMove)
  493. isSpiritSummon3 = true;
  494. if (isTransfiguration && currentSpirit == 3)
  495. {
  496. isTryingToRelieve = true;
  497. }
  498. }
  499. void OnSummonSpirit3Up()
  500. {
  501. if (isTryingToRelieve && currentSpirit == 3)
  502. {
  503. isTryingToRelieve = false;
  504. pressTime = 0;
  505. }
  506. }
  507. public void Jump()
  508. {
  509. SetUpSpeed(jumpSpeed);
  510. ani.Play("jump", 0, 0);
  511. }
  512. public void AirJump()
  513. {
  514. SetUpSpeed(airJumpSpeed);
  515. ani.Play("jump", 0, 0);
  516. }
  517. public void SetUpSpeed(float speed)
  518. {
  519. ChangeState(CharacterState.Rise);
  520. Vector3 velocity = rb.velocity;
  521. CheckTurn();
  522. velocity.y = speed;
  523. rb.velocity = velocity;
  524. //animalAni.SetInteger("state", (int)PlayerState.Rise);
  525. }
  526. public bool CheckSummon()
  527. {
  528. if (isTransfiguration)
  529. {
  530. return false;
  531. }
  532. if (cacheSummonTime > 0)
  533. {
  534. Summon(cacheSummonId);
  535. return true;
  536. }
  537. if (btnWestPress)
  538. {
  539. Summon(0);
  540. return true;
  541. }
  542. if (btnSouthPress)
  543. {
  544. Summon(1);
  545. return true;
  546. }
  547. if (btnEastPress)
  548. {
  549. Summon(2);
  550. return true;
  551. }
  552. if (isSpiritSummon)
  553. {
  554. Transfiguration(3);
  555. return true;
  556. }
  557. if (isSpiritSummon1)
  558. {
  559. Transfiguration(4);
  560. return true;
  561. }
  562. if (isSpiritSummon2)
  563. {
  564. Transfiguration(5);
  565. return true;
  566. }
  567. if (isSpiritSummon3)
  568. {
  569. Transfiguration(6);
  570. return true;
  571. }
  572. return false;
  573. }
  574. //角色处于可自由活动状态时的通用切换状态逻辑,如Idle、Run状态,以及别的状态结束时准备回到Idle状态前
  575. public bool CheckPlayerChangeState(CharacterState excludeState = CharacterState.None)
  576. {
  577. if (!foot.TrigGround)
  578. {
  579. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  580. {
  581. if (excludeState != CharacterState.Rush)
  582. {
  583. ChangeState(CharacterState.Rush);
  584. return true;
  585. }
  586. }
  587. if (rb.velocity.y > 0)
  588. {
  589. if (excludeState != CharacterState.Rise)
  590. {
  591. ChangeState(CharacterState.Rise);
  592. return true;
  593. }
  594. }
  595. else
  596. {
  597. if (excludeState != CharacterState.Fall)
  598. {
  599. ChangeState(CharacterState.Fall);
  600. return true;
  601. }
  602. }
  603. }
  604. else
  605. {
  606. airJumped = 0;
  607. //if (btnNorthPress || cacheAttackTime > 0)
  608. //{
  609. // if (excludeState != CharacterState.Attack)
  610. // {
  611. // Attack1();
  612. // return true;
  613. // }
  614. //}
  615. if (eventTrigger.triggedRivet && (btnNorthPress || cachePullRopeTime > 0))
  616. {
  617. if (sprintLinkTrigger.linkedEnemy.Count > 0)
  618. {
  619. eventTrigger.triggedRivet.BindingRopes(sprintLinkTrigger.linkedEnemy);
  620. }
  621. //ChangeState(CharacterState.PullRope);
  622. }
  623. if (excludeState != CharacterState.Summon)
  624. {
  625. if (CheckSummon())
  626. {
  627. return true;
  628. }
  629. }
  630. if (excludeState != CharacterState.Transfiguration)
  631. {
  632. if (CheckSummon())
  633. {
  634. return true;
  635. }
  636. }
  637. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  638. {
  639. if (excludeState != CharacterState.Rush)
  640. {
  641. ChangeState(CharacterState.Rush);
  642. return true;
  643. }
  644. }
  645. if (btnJumpPress || cacheJumpTime > 0)
  646. {
  647. if (excludeState != CharacterState.Rise)
  648. {
  649. Jump();
  650. ChangeState(CharacterState.Rise);
  651. return true;
  652. }
  653. }
  654. if (canfly)
  655. {
  656. if (leftDir.x > 0.3f || leftDir.x < -0.3f || leftDir.y > 0.3f || leftDir.y < -0.3f)
  657. {
  658. if (excludeState != CharacterState.Run)
  659. {
  660. ChangeState(CharacterState.Run);
  661. return true;
  662. }
  663. }
  664. else
  665. {
  666. if (excludeState != CharacterState.Idle)
  667. {
  668. ChangeState(CharacterState.Idle);
  669. return true;
  670. }
  671. }
  672. }
  673. else
  674. {
  675. if (leftDir.x > 0.3f || leftDir.x < -0.3f)
  676. {
  677. if (excludeState != CharacterState.Run)
  678. {
  679. ChangeState(CharacterState.Run);
  680. return true;
  681. }
  682. }
  683. else
  684. {
  685. if (excludeState != CharacterState.Idle)
  686. {
  687. ChangeState(CharacterState.Idle);
  688. return true;
  689. }
  690. }
  691. }
  692. }
  693. return false;
  694. }
  695. public override Vector3 GetMoveDir()
  696. {
  697. return leftDir;
  698. }
  699. public void CachedPlayerInput()
  700. {
  701. if (btnRushPress)
  702. {
  703. cacheRushTime = totalCacheRushTime;
  704. }
  705. if (btnJumpPress)
  706. {
  707. cacheJumpTime = totalCacheJumpTime;
  708. }
  709. if (btnNorthPress)
  710. {
  711. cacheAttackTime = totalCacheAttackTime;
  712. }
  713. if (btnWestPress)
  714. {
  715. cacheSummonTime = totalCacheSummonTime;
  716. cacheSummonId = 0;
  717. }
  718. if (btnSouthPress)
  719. {
  720. cacheSummonTime = totalCacheSummonTime;
  721. cacheSummonId = 1;
  722. }
  723. if (btnEastPress)
  724. {
  725. cacheSummonTime = totalCacheSummonTime;
  726. cacheSummonId = 2;
  727. }
  728. if (btnSpiritSummon)
  729. {
  730. cacheSummonTime = totalCacheSummonTime;
  731. cacheSummonId = 3;
  732. }
  733. if (btnSpiritSummon1)
  734. {
  735. cacheSummonTime = totalCacheSummonTime;
  736. cacheSummonId = 4;
  737. }
  738. if (btnSpiritSummon2)
  739. {
  740. cacheSummonTime = totalCacheSummonTime;
  741. cacheSummonId = 5;
  742. }
  743. if (btnSpiritSummon3)
  744. {
  745. cacheSummonTime = totalCacheSummonTime;
  746. cacheSummonId = 6;
  747. }
  748. }
  749. public override void OnState()
  750. {
  751. base.OnState();
  752. hurtKeepTime -= Time.deltaTime;
  753. cacheJumpTime -= Time.deltaTime;
  754. cacheAttackTime -= Time.deltaTime;
  755. cacheSummonTime -= Time.deltaTime;
  756. canJumpTime -= Time.deltaTime;
  757. invincibleTime -= Time.deltaTime;
  758. attackTime -= Time.deltaTime;
  759. summonTime -= Time.deltaTime;
  760. rushTime -= Time.deltaTime;
  761. cacheRushTime -= Time.deltaTime;
  762. dieKeepTime -= Time.deltaTime;
  763. weakTime -= Time.deltaTime;
  764. Vector3 velocity = rb.velocity;
  765. switch (state)
  766. {
  767. case CharacterState.Idle:
  768. if (CheckPlayerChangeState(CharacterState.Idle))
  769. {
  770. break;
  771. }
  772. break;
  773. case CharacterState.Run:
  774. if (CheckPlayerChangeState(CharacterState.Run))
  775. {
  776. break;
  777. }
  778. CheckTurn();
  779. if (canfly)
  780. {
  781. rb.velocity = leftDir.normalized * moveSpeed;
  782. }
  783. else
  784. {
  785. if (leftDir.x > 0.3f)
  786. {
  787. rb.velocity = Vector3.right * moveSpeed;
  788. }
  789. else if (leftDir.x < -0.3f)
  790. {
  791. rb.velocity = Vector3.left * moveSpeed;
  792. }
  793. }
  794. break;
  795. case CharacterState.Rise:
  796. if (CheckSummon())
  797. {
  798. break;
  799. }
  800. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  801. {
  802. ChangeState(CharacterState.Rush);
  803. break;
  804. }
  805. if (rb.velocity.y <= 0)
  806. {
  807. ChangeState(CharacterState.Fall);
  808. break;
  809. }
  810. if (btnJumpPress || cacheJumpTime > 0)
  811. {
  812. if (airJumped == 0 && jumpNumber >= 2 && rb.velocity.y < airJumpSpeed)
  813. {
  814. print(1);
  815. airJumped = 1;
  816. AirJump();
  817. break;
  818. }
  819. if (airJumped == 1 && jumpNumber >= 3 && rb.velocity.y < airJumpSpeed)
  820. {
  821. print(2);
  822. airJumped = 2;
  823. AirJump();
  824. break;
  825. }
  826. }
  827. CachedPlayerInput();
  828. rb.velocity = AirMove(rb.velocity);
  829. break;
  830. case CharacterState.Fall:
  831. if (CheckSummon())
  832. {
  833. break;
  834. }
  835. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  836. {
  837. ChangeState(CharacterState.Rush);
  838. break;
  839. }
  840. if (foot.TrigGround)
  841. {
  842. if (CheckPlayerChangeState())
  843. {
  844. break;
  845. }
  846. }
  847. //if (foot.canStepPlayers.Count > 0)
  848. //{
  849. // Jump(jumpSpeed / 2);
  850. // StepOther();
  851. // break;
  852. //}
  853. //if (foot.canStepEnemyList.Count > 0)
  854. //{
  855. // Jump(jumpSpeed / 2);
  856. // StepEnemy();
  857. // break;
  858. //}
  859. if (btnJumpPress || cacheJumpTime > 0)
  860. {
  861. if (canJumpTime > 0)
  862. {
  863. Jump();
  864. break;
  865. }
  866. else
  867. {
  868. switch (airJumped)
  869. {
  870. case 0:
  871. if(jumpNumber >= 2)
  872. {
  873. print(3);
  874. airJumped = 1;
  875. AirJump();
  876. }
  877. break;
  878. case 1:
  879. if(jumpNumber >= 3)
  880. {
  881. print(4);
  882. airJumped = 2;
  883. AirJump();
  884. }
  885. break;
  886. }
  887. }
  888. }
  889. CachedPlayerInput();
  890. rb.velocity = AirMove(rb.velocity);
  891. break;
  892. case CharacterState.Hurt:
  893. if (hurtKeepTime <= 0 && rb.velocity.magnitude < hurtChangeVelocity)
  894. {
  895. if (CheckPlayerChangeState())
  896. {
  897. break;
  898. }
  899. }
  900. Vector3 vel = rb.velocity;
  901. if (!foot.TrigGround)
  902. {
  903. if (canfly)
  904. {
  905. vel.y = vel.y * (1 - decelerationRatio * Time.deltaTime);
  906. }
  907. else
  908. {
  909. vel += Vector3.up * extraFallGravity * Time.deltaTime;
  910. }
  911. }
  912. vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
  913. rb.velocity = vel;
  914. CachedPlayerInput();
  915. break;
  916. case CharacterState.Coma:
  917. break;
  918. case CharacterState.Attack:
  919. if (attackTime <= 0)
  920. {
  921. if (btnNorthKeep)
  922. {
  923. ChangeState(CharacterState.KeepAttack);
  924. break;
  925. }
  926. if (CheckPlayerChangeState())
  927. {
  928. break;
  929. }
  930. }
  931. CachedPlayerInput();
  932. break;
  933. case CharacterState.KeepAttack:
  934. if ((btnRushPress) && mp >= rushCostMp)
  935. {
  936. ChangeState(CharacterState.Rush);
  937. break;
  938. }
  939. if (btnJumpPress && canJumpTime > 0)
  940. {
  941. Jump();
  942. break;
  943. }
  944. if (!btnNorthKeep)
  945. {
  946. if (CheckPlayerChangeState(CharacterState.Attack))
  947. {
  948. break;
  949. }
  950. }
  951. switch (attackState)
  952. {
  953. case PlayerAttackState.Idle:
  954. if (bodyTrans.localScale.x > 0)
  955. {
  956. if (leftDir.x > 0.3f)
  957. {
  958. SetAttackState(PlayerAttackState.WalkBack);
  959. velocity.x = attackMoveSpeed;
  960. rb.velocity = velocity;
  961. break;
  962. }
  963. else if (leftDir.x < -0.3f)
  964. {
  965. SetAttackState(PlayerAttackState.WalkForward);
  966. velocity.x = -attackMoveSpeed;
  967. rb.velocity = velocity;
  968. break;
  969. }
  970. }
  971. else
  972. {
  973. if (leftDir.x > 0.3f)
  974. {
  975. SetAttackState(PlayerAttackState.WalkForward);
  976. velocity.x = attackMoveSpeed;
  977. rb.velocity = velocity;
  978. break;
  979. }
  980. else if (leftDir.x < -0.3f)
  981. {
  982. SetAttackState(PlayerAttackState.WalkBack);
  983. velocity.x = -attackMoveSpeed;
  984. rb.velocity = velocity;
  985. break;
  986. }
  987. }
  988. velocity.x = 0;
  989. rb.velocity = velocity;
  990. break;
  991. case PlayerAttackState.WalkForward:
  992. if (bodyTrans.localScale.x > 0)
  993. {
  994. if (leftDir.x > 0.3f)
  995. {
  996. SetAttackState(PlayerAttackState.WalkBack);
  997. velocity.x = attackMoveSpeed;
  998. rb.velocity = velocity;
  999. break;
  1000. }
  1001. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1002. {
  1003. SetAttackState(PlayerAttackState.Idle);
  1004. velocity.x = 0;
  1005. rb.velocity = velocity;
  1006. break;
  1007. }
  1008. else
  1009. {
  1010. velocity.x = -attackMoveSpeed;
  1011. rb.velocity = velocity;
  1012. }
  1013. }
  1014. else
  1015. {
  1016. if (leftDir.x < -0.3f)
  1017. {
  1018. SetAttackState(PlayerAttackState.WalkBack);
  1019. velocity.x = -attackMoveSpeed;
  1020. rb.velocity = velocity;
  1021. break;
  1022. }
  1023. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1024. {
  1025. SetAttackState(PlayerAttackState.Idle);
  1026. velocity.x = 0;
  1027. rb.velocity = velocity;
  1028. break;
  1029. }
  1030. else
  1031. {
  1032. velocity.x = attackMoveSpeed;
  1033. rb.velocity = velocity;
  1034. }
  1035. }
  1036. break;
  1037. case PlayerAttackState.WalkBack:
  1038. if (bodyTrans.localScale.x > 0)
  1039. {
  1040. if (leftDir.x < -0.3f)
  1041. {
  1042. SetAttackState(PlayerAttackState.WalkForward);
  1043. velocity.x = -attackMoveSpeed;
  1044. rb.velocity = velocity;
  1045. break;
  1046. }
  1047. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1048. {
  1049. SetAttackState(PlayerAttackState.Idle);
  1050. velocity.x = 0;
  1051. rb.velocity = velocity;
  1052. break;
  1053. }
  1054. else
  1055. {
  1056. velocity.x = attackMoveSpeed;
  1057. rb.velocity = velocity;
  1058. }
  1059. }
  1060. else
  1061. {
  1062. if (leftDir.x > 0.3f)
  1063. {
  1064. SetAttackState(PlayerAttackState.WalkForward);
  1065. velocity.x = attackMoveSpeed;
  1066. rb.velocity = velocity;
  1067. break;
  1068. }
  1069. else if (leftDir.x > -0.3f && leftDir.x > 0.3f)
  1070. {
  1071. SetAttackState(PlayerAttackState.Idle);
  1072. velocity.x = 0;
  1073. rb.velocity = velocity;
  1074. break;
  1075. }
  1076. else
  1077. {
  1078. velocity.x = -attackMoveSpeed;
  1079. rb.velocity = velocity;
  1080. }
  1081. }
  1082. break;
  1083. default:
  1084. break;
  1085. }
  1086. break;
  1087. case CharacterState.Summon:
  1088. if (summonTime <= 0)
  1089. {
  1090. if (CheckPlayerChangeState())
  1091. {
  1092. break;
  1093. }
  1094. }
  1095. break;
  1096. case CharacterState.Rush:
  1097. if (rushTime <= 0)
  1098. {
  1099. if (btnRushKeep)
  1100. {
  1101. ChangeState(CharacterState.Sprint);
  1102. break;
  1103. }
  1104. if (CheckPlayerChangeState())
  1105. {
  1106. break;
  1107. }
  1108. }
  1109. CachedPlayerInput();
  1110. //if (leftDir.magnitude < 0.3f)
  1111. //{
  1112. // if (bodyTrans.localScale.x > 0)
  1113. // {
  1114. // rushDir = Vector3.left;
  1115. // }
  1116. // else
  1117. // {
  1118. // rushDir = Vector3.right;
  1119. // }
  1120. //}
  1121. //else
  1122. //{
  1123. // rushDir = leftDir.normalized;
  1124. //}
  1125. rb.velocity = rushDir * rushSpeed;
  1126. break;
  1127. case CharacterState.Sprint:
  1128. if (!btnRushKeep)
  1129. {
  1130. if (CheckPlayerChangeState(CharacterState.Rush))
  1131. {
  1132. break;
  1133. }
  1134. }
  1135. if (mp < sprintCostMp * Time.deltaTime)
  1136. {
  1137. if (CheckPlayerChangeState(CharacterState.Rush))
  1138. {
  1139. break;
  1140. }
  1141. }
  1142. mp -= sprintCostMp * Time.deltaTime;
  1143. uiMp.Show(mp, totalMp);
  1144. CachedPlayerInput();
  1145. //CheckTurn();
  1146. //if (leftDir.magnitude < 0.3f)
  1147. //{
  1148. // if (bodyTrans.localScale.x > 0)
  1149. // {
  1150. // rushDir = Vector3.left;
  1151. // }
  1152. // else
  1153. // {
  1154. // rushDir = Vector3.right;
  1155. // }
  1156. //}
  1157. //else
  1158. //{
  1159. // rushDir = leftDir.normalized;
  1160. //}
  1161. rb.velocity = rushDir * rushSpeed;
  1162. break;
  1163. case CharacterState.Die:
  1164. if (dieKeepTime <= 0)
  1165. {
  1166. gameObject.SetActive(false);
  1167. break;
  1168. }
  1169. break;
  1170. case CharacterState.Weak:
  1171. if (weakTime <= 0)
  1172. {
  1173. ChangeState(CharacterState.Idle);
  1174. break;
  1175. }
  1176. break;
  1177. case CharacterState.PullRope:
  1178. break;
  1179. default:
  1180. break;
  1181. }
  1182. if (!foot.TrigGround && !canfly)
  1183. {
  1184. if (rb.velocity.y > 0)
  1185. {
  1186. rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
  1187. }
  1188. else
  1189. {
  1190. rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
  1191. }
  1192. }
  1193. isClickBtnRush = false;
  1194. isKeepBtnRush = false;
  1195. isClickBtnJump = false;
  1196. isClickBtnSouth = false;
  1197. isClickBtnEast = false;
  1198. isClickBtnNorth = false;
  1199. isClickBtnWest = false;
  1200. isSpiritSummon = false;
  1201. isSpiritSummon1 = false;
  1202. isSpiritSummon2 = false;
  1203. isSpiritSummon3 = false;
  1204. if (foot.TrigGround)
  1205. {
  1206. canJumpTime = leaveGroundCanJumpTime;
  1207. }
  1208. SearchTarget();
  1209. attackTarget = targetCharacter;
  1210. if (floatState == 0)
  1211. {
  1212. if (mp < totalMp)
  1213. {
  1214. mp += mpReplySpeed * Time.deltaTime;
  1215. }
  1216. if (mp > totalMp)
  1217. {
  1218. mp = totalMp;
  1219. }
  1220. }
  1221. else
  1222. {
  1223. if (mp > 0)
  1224. {
  1225. lostMp += mpReplySpeed * Time.deltaTime;
  1226. mp -= mpReplySpeed * Time.deltaTime;
  1227. }
  1228. if (mp < 0)
  1229. {
  1230. mp = 0;
  1231. }
  1232. if (lostMp >= addMp)
  1233. {
  1234. Instantiate(soul, transform.position, new Quaternion(0, 0, 0, 0), null);
  1235. lostMp = 0;
  1236. }
  1237. }
  1238. uiMp.Show(mp, totalMp);
  1239. }
  1240. public override void ChangeState(CharacterState newState)
  1241. {
  1242. if (state == newState)
  1243. {
  1244. return;
  1245. }
  1246. Vector3 velocity = rb.velocity;
  1247. switch (state)
  1248. {
  1249. case CharacterState.Idle:
  1250. break;
  1251. case CharacterState.Run:
  1252. velocity.x = 0;
  1253. break;
  1254. case CharacterState.Rise:
  1255. break;
  1256. case CharacterState.Fall:
  1257. break;
  1258. case CharacterState.Hurt:
  1259. break;
  1260. case CharacterState.Coma:
  1261. canMove = true;
  1262. foreach (GameObject i in HitCols)
  1263. {
  1264. i.SetActive(true);
  1265. }
  1266. break;
  1267. case CharacterState.Attack:
  1268. aniCollider.Play("NotAttack", 1, 0);
  1269. break;
  1270. case CharacterState.KeepAttack:
  1271. aniCollider.Play("NotAttack", 1, 0);
  1272. break;
  1273. case CharacterState.Summon:
  1274. rb.isKinematic = false;
  1275. break;
  1276. case CharacterState.Transfiguration:
  1277. rb.isKinematic = false;
  1278. break;
  1279. case CharacterState.Rush:
  1280. velocity = Vector3.zero;
  1281. break;
  1282. case CharacterState.Sprint:
  1283. velocity = Vector3.zero;
  1284. break;
  1285. case CharacterState.Die:
  1286. isDie = false;
  1287. break;
  1288. case CharacterState.Weak:
  1289. break;
  1290. default:
  1291. break;
  1292. }
  1293. CharacterState oldState = state;
  1294. state = newState;
  1295. switch (newState)
  1296. {
  1297. case CharacterState.Idle:
  1298. aniCollider.Play("Idle", 0, 0);
  1299. if (oldState == CharacterState.Fall)
  1300. {
  1301. ani.Play("fall_end", 0, 0);
  1302. }
  1303. else
  1304. {
  1305. ani.Play("idle", 0, 0);
  1306. }
  1307. velocity = Vector3.zero;
  1308. //animalAni.SetInteger("state", (int)PlayerState.Idle);
  1309. break;
  1310. case CharacterState.Run:
  1311. aniCollider.Play("Run", 0, 0);
  1312. ani.Play("run_start", 0, 0);
  1313. //animalAni.SetInteger("state", (int)PlayerState.Walk);
  1314. break;
  1315. case CharacterState.Rise:
  1316. aniCollider.Play("Rise", 0, 0);
  1317. canJumpTime = 0;
  1318. break;
  1319. case CharacterState.Fall:
  1320. aniCollider.Play("Fall", 0, 0);
  1321. ani.Play("fall", 0, 0);
  1322. //animalAni.SetInteger("state", (int)PlayerState.Fall);
  1323. break;
  1324. case CharacterState.Hurt:
  1325. aniCollider.Play("Hurt", 0, 0);
  1326. ani.Play("hitted", 0, 0);
  1327. invincibleTime = totalInvincibleTime;
  1328. hurtKeepTime = minHurtKeepTime;
  1329. //ani.Play("Invincible", 2, 0);
  1330. break;
  1331. case CharacterState.Coma:
  1332. //ani.Play("Coma", 0, 0);
  1333. ani.Play("idle", 0, 0);
  1334. aniCollider.Play("Idle", 0, 0);
  1335. rb.velocity = Vector3.zero;
  1336. foreach (GameObject i in HitCols)
  1337. {
  1338. i.SetActive(false);
  1339. }
  1340. break;
  1341. case CharacterState.Attack:
  1342. attackTime = totalAttack1Time;
  1343. break;
  1344. case CharacterState.KeepAttack:
  1345. aniCollider.Play("Attack1Keep", 1, 0);
  1346. break;
  1347. case CharacterState.Summon:
  1348. aniCollider.Play("Summon", 0, 0);
  1349. ani.Play("summon", 0, 0);
  1350. velocity = Vector3.zero;
  1351. rb.isKinematic = true;
  1352. break;
  1353. case CharacterState.Transfiguration:
  1354. isTransfiguration = true;
  1355. aniCollider.Play("Transfiguration", 0, 0);
  1356. ani.Play("transfiguration", 0, 0);
  1357. velocity = Vector3.zero;
  1358. rb.isKinematic = true;
  1359. break;
  1360. case CharacterState.Rush:
  1361. aniCollider.Play("Rush", 0, 0);
  1362. ani.Play("rush_loop", 0, 0);
  1363. rushTime = totalRushTime;
  1364. invincibleTime = rushInvincibleTime;
  1365. //if (leftDir.magnitude < 0.3f)
  1366. //{
  1367. // if (bodyTrans.localScale.x > 0)
  1368. // {
  1369. // rushDir = Vector3.left;
  1370. // }
  1371. // else
  1372. // {
  1373. // rushDir = Vector3.right;
  1374. // }
  1375. //}
  1376. //else
  1377. //{
  1378. // rushDir = leftDir.normalized;
  1379. //}
  1380. if (bodyTrans.localScale.x > 0)
  1381. {
  1382. rushDir = Vector3.left;
  1383. }
  1384. else
  1385. {
  1386. rushDir = Vector3.right;
  1387. }
  1388. velocity = rushDir * rushSpeed;
  1389. mp -= rushCostMp;
  1390. uiMp.Show(mp, totalMp);
  1391. break;
  1392. case CharacterState.Sprint:
  1393. aniCollider.Play("Sprint", 0, 0);
  1394. ani.Play("rush_loop", 0, 0);
  1395. velocity = rushDir * rushSpeed;
  1396. break;
  1397. case CharacterState.Die:
  1398. aniCollider.Play("Die", 0, 0);
  1399. ani.Play("die", 0, 0);
  1400. isDie = true;
  1401. dieKeepTime = totalDieKeepTime;
  1402. break;
  1403. case CharacterState.Weak:
  1404. aniCollider.Play("Weak", 0, 0);
  1405. ani.Play("weak", 0, 0);
  1406. velocity.y = weakUpSpeed;
  1407. weakTime = totalWeakTime;
  1408. break;
  1409. default:
  1410. break;
  1411. }
  1412. rb.velocity = velocity;
  1413. }
  1414. public void CheckTurn()
  1415. {
  1416. if (leftDir.x > 0.3f && bodyTrans.localScale.x > 0)
  1417. {
  1418. Turn();
  1419. }
  1420. else if (leftDir.x < -0.3f && bodyTrans.localScale.x < 0)
  1421. {
  1422. Turn();
  1423. }
  1424. }
  1425. public Vector3 AirMove(Vector3 velocity)
  1426. {
  1427. CheckTurn();
  1428. if (canfly)
  1429. {
  1430. velocity = leftDir.normalized * moveSpeed;
  1431. }
  1432. else
  1433. {
  1434. if (leftDir.x > 0.3f)
  1435. {
  1436. velocity = new Vector3(moveSpeed, velocity.y, velocity.z);
  1437. }
  1438. else if (leftDir.x < -0.3f)
  1439. {
  1440. velocity = new Vector3(-moveSpeed, velocity.y, velocity.z);
  1441. }
  1442. else
  1443. {
  1444. velocity = new Vector3(0, velocity.y, velocity.z);
  1445. }
  1446. }
  1447. return velocity;
  1448. }
  1449. private Collider playerSoulCollector;
  1450. public void Transfiguration(int id) //变身
  1451. {
  1452. playerSoulCollector = soulCollector;
  1453. id = id - 3;
  1454. currentSpirit = id;
  1455. if (id >= changePrefabs.Count)
  1456. {
  1457. Debug.LogError("未配置" + id + "号变身");
  1458. return;
  1459. }
  1460. if (id == 3 && isInvisible)
  1461. {
  1462. isInvisible = false;
  1463. return;
  1464. }
  1465. GameObject prefab = changePrefabs[id];
  1466. if (!CheckCanSummon(id))
  1467. {
  1468. return;
  1469. }
  1470. ChangeState(CharacterState.Transfiguration);
  1471. summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
  1472. float costMp = prefab.GetComponent<Demonic>().costMp;
  1473. mp -= costMp;
  1474. uiMp.Show(mp, totalMp);
  1475. bodyTrans.gameObject.SetActive(false);
  1476. foot.trigGroundList.Clear();
  1477. spiritObj = PoolManager.Instantiate(prefab);
  1478. Demonic dem = spiritObj.GetComponent<Demonic>();
  1479. dem.id = id;
  1480. dem.playerID = playerId;
  1481. spiritObj.transform.parent = transform;
  1482. spiritObj.transform.localEulerAngles = Vector3.zero;
  1483. spiritObj.transform.localScale = new Vector3(1, 1, 1);
  1484. if (bodyTrans.localScale.x > 0)
  1485. {
  1486. spiritObj.transform.position = transform.position;
  1487. if (dem.bodyTrans.localScale.x < 0)
  1488. {
  1489. dem.Turn();
  1490. }
  1491. }
  1492. else
  1493. {
  1494. spiritObj.transform.position = transform.position;
  1495. if (dem.bodyTrans.localScale.x > 0)
  1496. {
  1497. dem.Turn();
  1498. }
  1499. }
  1500. mecanim = dem.mecanim;
  1501. ani = dem.ani;
  1502. aniCollider = dem.aniCollider;
  1503. bodyTrans = dem.bodyTrans;
  1504. beSearchTrigger = dem.beSearchTrigger;
  1505. bulletPrefab = dem.bulletPrefab;
  1506. searchTrigger = dem.searchTrigger;
  1507. foot = dem.foot;
  1508. spinee = dem.spinee;
  1509. mesh = dem.mesh;
  1510. mats = dem.mats;
  1511. soulCollector = dem.soulCollector;
  1512. outlineMats = dem.outlineMats;
  1513. if (dem.canFly)
  1514. {
  1515. canfly = true;
  1516. canJump = false;
  1517. rb.useGravity = false;
  1518. }
  1519. /* 法师出场释放浮空场
  1520. if (id == 3)
  1521. {
  1522. if ((int)spirits.currentSpirit == 0)
  1523. {
  1524. if (!spiritObj.GetComponent<Demonic>().hasEffect)
  1525. {
  1526. spiritObj.GetComponent<Demonic>().hasEffect = true;
  1527. Instantiate(spirits.floatEffect, spiritObj.transform.position, new Quaternion(0, 0, 0, 0), spiritObj.transform);
  1528. }
  1529. }
  1530. }
  1531. */
  1532. endChange = id + 3;
  1533. dem.hp = hp;
  1534. ChangeState(CharacterState.Idle);
  1535. }
  1536. public void EndTransfiguration(int id)
  1537. {
  1538. isTransfiguration = false;
  1539. isinputJ = false;
  1540. isinputK = false;
  1541. isinputL = false;
  1542. canfly = false;
  1543. canJump = true;
  1544. canMove = true;
  1545. rb.useGravity = true;
  1546. mecanim = playerMe;
  1547. ani = playerAni;
  1548. aniCollider = playerCol;
  1549. bodyTrans = playerTran;
  1550. beSearchTrigger = playerBst;
  1551. bulletPrefab = playerBullet;
  1552. searchTrigger = playerST;
  1553. foot = playerFoot;
  1554. spinee = playerSpinee;
  1555. mesh = playerMesh;
  1556. mats = playerMats;
  1557. soulCollector = playerSoulCollector;
  1558. outlineMats = playerOut;
  1559. bodyTrans.gameObject.SetActive(true);
  1560. uiHp.gameObject.SetActive(true);
  1561. spiritObj.transform.parent = null;
  1562. spiritObj.SetActive(false);
  1563. Summon(id);
  1564. CheckPlayerChangeState();
  1565. endChange = 0;
  1566. }
  1567. public void Summon(int id)
  1568. {
  1569. if (id >= demonicPrefabs.Count)
  1570. {
  1571. Debug.LogError("未配置" + id + "号使魔");
  1572. return;
  1573. }
  1574. if (id >= demonicSummonPos.Count)
  1575. {
  1576. Debug.LogError("未配置" + id + "号使魔召唤位置");
  1577. return;
  1578. }
  1579. if (id == 6 && isInvisible)
  1580. {
  1581. isInvisible = false;
  1582. return;
  1583. }
  1584. GameObject prefab = demonicPrefabs[id];
  1585. if (!CheckCanSummon(id))
  1586. {
  1587. return;
  1588. }
  1589. ChangeState(CharacterState.Summon);
  1590. summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
  1591. float costMp = prefab.GetComponent<Demonic>().costMp;
  1592. mp -= costMp;
  1593. uiMp.Show(mp, totalMp);
  1594. GameObject demonicObj = PoolManager.Instantiate(prefab);
  1595. Demonic demonic = demonicObj.GetComponent<Demonic>();
  1596. demonic.id = id;
  1597. demonic.playerID = playerId;
  1598. if (!demonicDic.ContainsKey(id))
  1599. {
  1600. demonicDic.Add(id, new List<Demonic>());
  1601. }
  1602. demonicDic[id].Add(demonic);
  1603. demonicObj.transform.parent = null;
  1604. demonicObj.transform.localEulerAngles = Vector3.zero;
  1605. demonicObj.transform.localScale = new Vector3(1, 1, 1);
  1606. Vector3 offset = demonicSummonPos[id];
  1607. if (bodyTrans.localScale.x > 0)
  1608. {
  1609. demonicObj.transform.position = transform.position + offset;
  1610. if (demonic.bodyTrans.localScale.x < 0)
  1611. {
  1612. demonic.Turn();
  1613. }
  1614. }
  1615. else
  1616. {
  1617. demonicObj.transform.position = transform.position + new Vector3(-offset.x, offset.y, offset.z);
  1618. if (demonic.bodyTrans.localScale.x > 0)
  1619. {
  1620. demonic.Turn();
  1621. }
  1622. }
  1623. if (demonic.canFly)
  1624. {
  1625. demonic.flyHeight = demonic.transform.position.y;
  1626. }
  1627. if (id == 3)
  1628. {
  1629. if ((int)spirits.currentSpirit == 0)
  1630. {
  1631. if (!demonicObj.GetComponent<Demonic>().hasEffect)
  1632. {
  1633. demonicObj.GetComponent<Demonic>().hasEffect = true;
  1634. Instantiate(spirits.floatEffect, demonicObj.transform.position, new Quaternion(0, 0, 0, 0), demonicObj.transform);
  1635. }
  1636. }
  1637. }
  1638. demonic.Init();
  1639. demonic.SetSortingOrder(demonic.sortingOrder + demonicId[id]);
  1640. demonicId[id]++;
  1641. demonic.Attack1();
  1642. }
  1643. public void OnDemonicRecycle(Demonic demonic)
  1644. {
  1645. if (!demonicDic.ContainsKey(demonic.id))
  1646. {
  1647. return;
  1648. }
  1649. demonicDic[demonic.id].Remove(demonic);
  1650. for (int i = 0; i < demonicDic[demonic.id].Count; i++)
  1651. {
  1652. demonicDic[demonic.id][i].SetSortingOrder(demonic.id * 1000 + i);
  1653. }
  1654. }
  1655. public bool CheckCanSummon(int id)
  1656. {
  1657. GameObject prefab = demonicPrefabs[id];
  1658. float costMp = prefab.GetComponent<Demonic>().costMp;
  1659. if (mp < costMp)
  1660. {
  1661. Debug.Log("mp不足召唤失败, 还得加个动画或者音效啥的");
  1662. return false;
  1663. }
  1664. return true;
  1665. }
  1666. public override void Attack1()
  1667. {
  1668. base.Attack1();
  1669. if (leftDir.x > 0.3f)
  1670. {
  1671. if (bodyTrans.localScale.x > 0)
  1672. {
  1673. Turn();
  1674. }
  1675. SetAttackState(PlayerAttackState.WalkForward);
  1676. }
  1677. else if (leftDir.x < -0.3f)
  1678. {
  1679. if (bodyTrans.localScale.x < 0)
  1680. {
  1681. Turn();
  1682. }
  1683. SetAttackState(PlayerAttackState.WalkForward);
  1684. }
  1685. else
  1686. {
  1687. SetAttackState(PlayerAttackState.Idle);
  1688. }
  1689. }
  1690. public void SetAttackState(PlayerAttackState value)
  1691. {
  1692. attackState = value;
  1693. ani.SetInteger("attackState", (int)value);
  1694. aniCollider.Play("Attack1Keep", 1, 0);
  1695. }
  1696. public void SearchTarget()
  1697. {
  1698. targetCharacter = searchTrigger.GetMinDisTarget(targetTypes, canHitFly);
  1699. }
  1700. }