PlayerController.cs 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609
  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. }
  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. uiHp.gameObject.SetActive(true);
  1418. spiritObj.transform.parent = null;
  1419. spiritObj.SetActive(false);
  1420. Summon(id);
  1421. }
  1422. public void Summon(int id)
  1423. {
  1424. if (id >= demonicPrefabs.Count)
  1425. {
  1426. Debug.LogError("未配置" + id + "号使魔");
  1427. return;
  1428. }
  1429. if (id >= demonicSummonPos.Count)
  1430. {
  1431. Debug.LogError("未配置" + id + "号使魔召唤位置");
  1432. return;
  1433. }
  1434. if (id == 6 && isInvisible)
  1435. {
  1436. isInvisible = false;
  1437. return;
  1438. }
  1439. GameObject prefab = demonicPrefabs[id];
  1440. if (!CheckCanSummon(id))
  1441. {
  1442. return;
  1443. }
  1444. ChangeState(CharacterState.Summon);
  1445. summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
  1446. float costMp = prefab.GetComponent<Demonic>().costMp;
  1447. mp -= costMp;
  1448. uiMp.Show(mp, totalMp);
  1449. GameObject demonicObj = PoolManager.Instantiate(prefab);
  1450. Demonic demonic = demonicObj.GetComponent<Demonic>();
  1451. demonic.id = id;
  1452. demonic.playerID = playerId;
  1453. if (!demonicDic.ContainsKey(id))
  1454. {
  1455. demonicDic.Add(id, new List<Demonic>());
  1456. }
  1457. demonicDic[id].Add(demonic);
  1458. demonicObj.transform.parent = null;
  1459. demonicObj.transform.localEulerAngles = Vector3.zero;
  1460. demonicObj.transform.localScale = new Vector3(1, 1, 1);
  1461. Vector3 offset = demonicSummonPos[id];
  1462. if (bodyTrans.localScale.x > 0)
  1463. {
  1464. demonicObj.transform.position = transform.position + offset;
  1465. if (demonic.bodyTrans.localScale.x < 0)
  1466. {
  1467. demonic.Turn();
  1468. }
  1469. }
  1470. else
  1471. {
  1472. demonicObj.transform.position = transform.position + new Vector3(-offset.x, offset.y, offset.z);
  1473. if (demonic.bodyTrans.localScale.x > 0)
  1474. {
  1475. demonic.Turn();
  1476. }
  1477. }
  1478. if (demonic.canFly)
  1479. {
  1480. demonic.flyHeight = demonic.transform.position.y;
  1481. }
  1482. if (id == 3)
  1483. {
  1484. if ((int)spirits.currentSpirit == 0)
  1485. {
  1486. if (!demonicObj.GetComponent<Demonic>().hasEffect)
  1487. {
  1488. demonicObj.GetComponent<Demonic>().hasEffect = true;
  1489. Instantiate(spirits.floatEffect, demonicObj.transform.position, new Quaternion(0, 0, 0, 0), demonicObj.transform);
  1490. }
  1491. }
  1492. }
  1493. demonic.Init();
  1494. demonic.SetSortingOrder(demonic.sortingOrder + demonicId[id]);
  1495. demonicId[id]++;
  1496. demonic.Attack1();
  1497. }
  1498. public void OnDemonicRecycle(Demonic demonic)
  1499. {
  1500. if (!demonicDic.ContainsKey(demonic.id))
  1501. {
  1502. return;
  1503. }
  1504. demonicDic[demonic.id].Remove(demonic);
  1505. for (int i = 0; i < demonicDic[demonic.id].Count; i++)
  1506. {
  1507. demonicDic[demonic.id][i].SetSortingOrder(demonic.id * 1000 + i);
  1508. }
  1509. }
  1510. public bool CheckCanSummon(int id)
  1511. {
  1512. GameObject prefab = demonicPrefabs[id];
  1513. float costMp = prefab.GetComponent<Demonic>().costMp;
  1514. if (mp < costMp)
  1515. {
  1516. Debug.Log("mp不足召唤失败, 还得加个动画或者音效啥的");
  1517. return false;
  1518. }
  1519. return true;
  1520. }
  1521. public override void Attack1()
  1522. {
  1523. base.Attack1();
  1524. if (leftDir.x > 0.3f)
  1525. {
  1526. if (bodyTrans.localScale.x > 0)
  1527. {
  1528. Turn();
  1529. }
  1530. SetAttackState(PlayerAttackState.WalkForward);
  1531. }
  1532. else if (leftDir.x < -0.3f)
  1533. {
  1534. if (bodyTrans.localScale.x < 0)
  1535. {
  1536. Turn();
  1537. }
  1538. SetAttackState(PlayerAttackState.WalkForward);
  1539. }
  1540. else
  1541. {
  1542. SetAttackState(PlayerAttackState.Idle);
  1543. }
  1544. }
  1545. public void SetAttackState(PlayerAttackState value)
  1546. {
  1547. attackState = value;
  1548. ani.SetInteger("attackState", (int)value);
  1549. aniCollider.Play("Attack1Keep", 1, 0);
  1550. }
  1551. public void SearchTarget()
  1552. {
  1553. targetCharacter = searchTrigger.GetMinDisTarget(targetTypes, canHitFly);
  1554. }
  1555. }