PlayerController.cs 47 KB

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