PlayerController.cs 47 KB

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