PlayerController.cs 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239
  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. using TMPro;
  16. [Serializable]
  17. public struct AttackInfo
  18. {
  19. public int damage;
  20. public Vector3 attackDir;
  21. public float force;
  22. public bool changeHurt;
  23. public float repelValue;
  24. }
  25. public enum PlayerAttackState
  26. {
  27. Idle = 0,
  28. WalkForward = 1,
  29. WalkBack = 2,
  30. }
  31. public class PlayerController : MoveCharacter
  32. {
  33. [Header("玩家属性")]
  34. public int playerId;
  35. public bool canJump;
  36. public bool canfly;
  37. public bool endTranSummon; //是否在结束变身后召唤英灵
  38. [Header("变身英灵")]
  39. public bool isUltimate; //英灵释放大招
  40. public bool keyTransfigurateRelease; //松开英灵释放大招键
  41. public List<GameObject> changePrefabs;
  42. public int[] needCorpses;
  43. private GameObject spiritObj; //当前变身的对象
  44. public int endChange = 0; //结束变身后召唤的英灵
  45. public Vector2 rightDir;
  46. [Header("玩家组件")]
  47. public UIHP uiMp;
  48. public PlayerRope playerRope;
  49. public EventTrigger eventTrigger;
  50. public SprintLinkTrigger sprintLinkTrigger;
  51. private Spirits spirits;
  52. public Collider soulCollector;
  53. public SkeletonMecanim skeletonMecanim;
  54. public SkeletonDataAsset[] playerSpine;
  55. private SpiritSystem spiritSystem;
  56. [Header("血量")]
  57. private int curHp;
  58. private int curTotalHp;
  59. [Header("蓝耗")]
  60. public float mp;
  61. public float totalMp;
  62. public float totalMp_2Players; //双人模式下总蓝量
  63. public bool isMpRepel = true;
  64. public bool isRapedReply;
  65. public float mpReplySpeed;
  66. public float mpReplySpeed_2Players; //双人模式下蓝量回复速度
  67. public float rapidReplySpeed;
  68. public float lostMp;
  69. private float addMp = 10;
  70. public GameObject soul;
  71. public GameObject rapidReplyEffect;
  72. [Header("移动属性")]
  73. public Vector2 moveVec; //玩家不动时移动数据
  74. [HideInInspector]
  75. public Vector2 leftDir;
  76. [Header("冲刺属性")]
  77. public float rushSpeed = 100;
  78. public float rushCostMp = 5;
  79. public Vector3 rushDir;
  80. public float rushInvincibleTime = 0.2f;
  81. [HideInInspector]
  82. public float rushTime;
  83. public float totalRushTime = 0.5f;
  84. [HideInInspector]
  85. public float cacheRushTime; //无法Rush时按下Rush键不会Rush,手感不好,缓存几帧,在这几帧内落地会立即Rush;
  86. public float totalCacheRushTime = 0.1f;
  87. [Header("链条属性")]
  88. public float sprintCostMp = 5;
  89. [HideInInspector]
  90. public float cachePullRopeTime;
  91. public float totalCachePullRopeTime = 0.1f;
  92. [Header("跳跃属性")]
  93. public float jumpSpeed = 10;
  94. public float airJumpSpeed = 10;
  95. public int airJumped;
  96. public int airJumpNumber = 1; //最大跳跃次数
  97. public float canAirJumpSpeed = 5;//y轴速度大于这个值时不能进行空中跳跃
  98. [HideInInspector]
  99. public float canJumpTime; //离开平台后仍然可以跳跃的时间,用于提升手感
  100. public float leaveGroundCanJumpTime = 0.1f;
  101. [HideInInspector]
  102. public float cacheJumpTime; //即将落地时按下跳跃键不会跳跃,手感不好,缓存几帧,在这几帧内落地会立即跳跃;
  103. public float totalCacheJumpTime = 0.1f;
  104. [Header("飞行属性")]
  105. public float flySpeed = 5;
  106. public float maxFlyHeight;
  107. [Header("召唤属性")]
  108. public float cacheDir; //召唤的时候按左右召唤结束不会响应手感不好,缓存一下,召唤后摇期间有左右响应的话会转向
  109. [HideInInspector]
  110. public float summonTime;
  111. [HideInInspector]
  112. public float cacheSummonTime; //无法召唤时按下召唤键不会召唤,手感不好,缓存几帧,在这几帧内落地会立即召唤;
  113. [HideInInspector]
  114. public int cacheSummonId;
  115. [Header("召唤使魔")]
  116. public List<GameObject> demonicPrefabs;
  117. public List<Vector3> demonicSummonPos;
  118. public Dictionary<int, List<Demonic>> demonicDic;
  119. private List<Demonic> arrows = new List<Demonic>();
  120. private List<Demonic> giants = new List<Demonic>();
  121. private List<Demonic> swords = new List<Demonic>();
  122. public int arrowNum;
  123. public int giantNum;
  124. public int swordNum;
  125. [Header("攻击")]
  126. public PlayerAttackState attackState;
  127. public float attackMoveSpeed = 5f;
  128. [HideInInspector]
  129. public float cacheAttackTime; //无法攻击时按下攻击键不会攻击,手感不好,缓存几帧,在这几帧内落地会立即攻击;
  130. public float totalCacheAttackTime = 0.1f;
  131. [Header("复活")]
  132. public float reviveTime; //复活时间
  133. public float totalReviveTime;
  134. [Header("玩家是否在基地")]
  135. public bool isBaseBtnOut = false;
  136. [Header("八卦")]
  137. public ChooseYinYang chooseYinYang;
  138. [Header("锁魂塔")]
  139. public GameObject curSoulTower;
  140. //指挥功能
  141. private float conductTime; //指挥按键长按时间
  142. private int nowConductButton = -1; //现在按下的指挥键(0.J/1.K/2.L/-1.无)
  143. private int cacheConductId;
  144. [Header("召唤相应时间")] [Tooltip("在此时间内松手为召唤")] public float totalCacheSummonTime;
  145. [Header("指挥相应时间")] [Tooltip("在此时间以外松手为指挥")] public float[] canConductTime;
  146. [Header("指挥相应耗蓝")] [Tooltip("输入相应的技能耗蓝")] public float[] conductCostMp;
  147. [Header("指挥技能")] [Tooltip("选择相应的指挥技能")] public ConductSkills[] conductSkills;
  148. public bool[] conductCanRelease; //能否进入指挥技蓄力状态
  149. public ConductReadyTip conductReadyTip; //指挥技就绪
  150. private bool isReadyConduct;
  151. //大胖子
  152. public GameObject bigGiant;
  153. public float[] stageSize;
  154. public int[] giantDieNum;
  155. //光球
  156. public GameObject photosphereObj;
  157. //攻击力
  158. public float addAttack; //0-1的小数
  159. public GameObject attackEffect;
  160. //泰山压顶
  161. public GameObject mountain;
  162. public Vector3 offset;
  163. private GameObject curMountain;
  164. public float mountainTime;
  165. //气功波
  166. public GameObject wavePowerObj;
  167. //御剑术
  168. public GameObject flyingSwordsObj;
  169. public enum ConductSkills
  170. {
  171. Giant, //胖子:合成大胖子
  172. Photosphere, //胖子:光球
  173. AddAttack, //胖子:增加攻击力
  174. Mountain, //气功师:泰山压顶
  175. WavePower, //气功师:气功波
  176. SwordsControl, //气功师:御剑术
  177. }
  178. public bool btnJumpPress
  179. {
  180. get
  181. {
  182. //return Input.GetKeyDown(KeyCode.Space) || isClickBtnJump;
  183. return isClickBtnJump;
  184. }
  185. }
  186. [HideInInspector]
  187. public bool isClickBtnJump;
  188. public bool btnRushPress
  189. {
  190. get
  191. {
  192. //return Input.GetKeyDown(KeyCode.LeftShift) || isClickBtnRush;
  193. return isClickBtnRush;
  194. }
  195. }
  196. [HideInInspector]
  197. public bool isClickBtnRush;
  198. public bool btnRushKeep
  199. {
  200. get
  201. {
  202. //return Input.GetKey(KeyCode.LeftShift) || isKeepBtnRush;
  203. return LBisHold || isKeepBtnRush;
  204. }
  205. }
  206. [HideInInspector]
  207. public bool isKeepBtnRush;
  208. public bool btnTransfiguratePress
  209. {
  210. get
  211. {
  212. //return Input.GetKeyDown(KeyCode.L) || isClickBtnEast;
  213. return isClickBtnTransfigurate;
  214. }
  215. }
  216. [HideInInspector]
  217. public bool isClickBtnTransfigurate;
  218. public bool btnEastPress
  219. {
  220. get
  221. {
  222. return isClickBtnEast;
  223. }
  224. }
  225. [HideInInspector]
  226. public bool isClickBtnEast;
  227. public bool btnEastUp
  228. {
  229. get
  230. {
  231. return isBtnEastUp;
  232. }
  233. }
  234. [HideInInspector]
  235. public bool isBtnEastUp;
  236. public bool btnSouthPress
  237. {
  238. get
  239. {
  240. //return Input.GetKeyDown(KeyCode.K) || isClickBtnSouth;
  241. return isClickBtnSouth;
  242. }
  243. }
  244. [HideInInspector]
  245. public bool isClickBtnSouth;
  246. public bool btnSouthUp
  247. {
  248. get
  249. {
  250. //return Input.GetKeyDown(KeyCode.K) || isClickBtnSouth;
  251. return isBtnSouthUp;
  252. }
  253. }
  254. [HideInInspector]
  255. public bool isBtnSouthUp;
  256. public bool btnWestPress
  257. {
  258. get
  259. {
  260. return isClickBtnWest;
  261. }
  262. }
  263. [HideInInspector]
  264. public bool isClickBtnWest;
  265. public bool btnWestUp
  266. {
  267. get
  268. {
  269. return isBtnWestUp;
  270. }
  271. }
  272. [HideInInspector]
  273. public bool isBtnWestUp;
  274. public bool btnNorthPress
  275. {
  276. get
  277. {
  278. return isClickBtnNorth;
  279. }
  280. }
  281. [HideInInspector]
  282. public bool isClickBtnNorth;
  283. public bool btnNorthUp
  284. {
  285. get
  286. {
  287. return isBtnNorthUp;
  288. }
  289. }
  290. [HideInInspector]
  291. public bool isBtnNorthUp;
  292. public bool btnSpiritSummon
  293. {
  294. get
  295. {
  296. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  297. return isSpiritSummon;
  298. }
  299. }
  300. [HideInInspector]
  301. public bool isSpiritSummon;
  302. public bool btnSpiritSummon1
  303. {
  304. get
  305. {
  306. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  307. return isSpiritSummon1;
  308. }
  309. }
  310. [HideInInspector]
  311. public bool isSpiritSummon1;
  312. public bool btnSpiritSummon2
  313. {
  314. get
  315. {
  316. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  317. return isSpiritSummon2;
  318. }
  319. }
  320. [HideInInspector]
  321. public bool isSpiritSummon2;
  322. public bool btnSpiritSummon3
  323. {
  324. get
  325. {
  326. //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
  327. return isSpiritSummon3;
  328. }
  329. }
  330. [HideInInspector]
  331. public bool isSpiritSummon3;
  332. public bool btnNorthKeep
  333. {
  334. get
  335. {
  336. //return Input.GetKey(KeyCode.I) || isKeepBtnNorth;
  337. return isKeepBtnNorth;
  338. }
  339. }
  340. [HideInInspector]
  341. public bool isKeepBtnNorth;
  342. public override void Init()
  343. {
  344. base.Init();
  345. mp = totalMp;
  346. uiMp.Show(mp, totalMp);
  347. }
  348. private void Awake()
  349. {
  350. PlayerInput playerInput = transform.GetComponent<PlayerInput>();
  351. spirits = GetComponent<Spirits>();
  352. playerId = playerInput.playerIndex;
  353. transform.position = new Vector3(142 + 4 * playerId, 0, 0);
  354. playerRope.playerId = playerId;
  355. sprintLinkTrigger.playerID = playerId;
  356. switch (playerId)
  357. {
  358. case 0:
  359. PlayersInput.instance[0] = this;
  360. PlayersInput.instance[1] = this;
  361. SpiritSystem.isP1Out = true;
  362. SpiritSystem.isP1In = false;
  363. SpiritSystem.player1 = gameObject;
  364. SpiritSystem.p1Spirits = GetComponent<Spirits>();
  365. break;
  366. case 1:
  367. PlayersInput.instance[1] = this;
  368. SpiritSystem.isP2Out = true;
  369. SpiritSystem.isP2In = false;
  370. SpiritSystem.player2 = gameObject;
  371. SpiritSystem.p2Spirits = GetComponent<Spirits>();
  372. //切换为双人计算蓝量方式
  373. PlayerController p1 = PlayersInput.instance[0];
  374. mpReplySpeed = mpReplySpeed_2Players;
  375. p1.mpReplySpeed = mpReplySpeed_2Players;
  376. totalMp = totalMp_2Players;
  377. p1.totalMp = totalMp_2Players;
  378. if (mp > totalMp)
  379. {
  380. mp = totalMp;
  381. }
  382. if (p1.mp > totalMp)
  383. {
  384. p1.mp = totalMp;
  385. }
  386. uiMp.Show(mp, totalMp);
  387. p1.uiMp.Show(p1.mp, totalMp);
  388. break;
  389. default:
  390. break;
  391. }
  392. skeletonMecanim.skeletonDataAsset = playerSpine[playerId];
  393. demonicDic = new Dictionary<int, List<Demonic>>();
  394. for(int i = 0; i < 3; i++)
  395. {
  396. demonicDic.Add(i, new List<Demonic>());
  397. }
  398. Init();
  399. spiritSystem = GameObject.Find("SpiritSystem").GetComponent<SpiritSystem>();
  400. }
  401. private void Update()
  402. {
  403. if (LBisHold)
  404. {
  405. isKeepBtnRush = true;
  406. }
  407. if (floatState != 0)
  408. {
  409. CharacterFloat();
  410. }
  411. /* //到时间自动解除变身
  412. if (endChange != 0)
  413. {
  414. pastChangeTime += Time.deltaTime;
  415. if (pastChangeTime >= changeTime)
  416. {
  417. EndTransfiguration(endChange);
  418. endChange = 0;
  419. pastChangeTime = 0;
  420. }
  421. }
  422. */
  423. //if (isTransfiguration)
  424. //{
  425. // bodyTrans.position = spiritObj.transform.position;
  426. //}
  427. if (isInvisible)
  428. {
  429. invisibleTime -= Time.deltaTime;
  430. if (invisibleTime <= 0)
  431. {
  432. isInvisible = false;
  433. ChangeMat(1);
  434. }
  435. }
  436. if (haveTransmit)
  437. {
  438. transmitTime -= Time.deltaTime;
  439. if (transmitTime <= 0)
  440. {
  441. haveTransmit = false;
  442. portalsController.rbs.Remove(rb);
  443. }
  444. }
  445. if(rightDir.x<-0.5 || rightDir.x > 0.5)
  446. {
  447. ChangeSpirit();
  448. }
  449. }
  450. void OnSprintingPress()
  451. {
  452. LBisHold = true;
  453. isClickBtnRush = true;
  454. isKeepBtnRush = true;
  455. }
  456. void OnSprintingRelease()
  457. {
  458. LBisHold = false;
  459. }
  460. //手柄按下LB
  461. [HideInInspector]
  462. public bool LBisHold;
  463. //读取手柄参数
  464. private void OnMove(InputValue value)
  465. {
  466. if (canMove)
  467. {
  468. leftDir = value.Get<Vector2>();
  469. }
  470. else
  471. {
  472. leftDir = Vector3.zero;
  473. }
  474. moveVec = value.Get<Vector2>();
  475. }
  476. void OnJump()
  477. {
  478. if (canJump && canMove)
  479. {
  480. isClickBtnJump = true;
  481. }
  482. }
  483. void OnSummon0()
  484. {
  485. if (!isFloat && canMove && nowConductButton == -1)
  486. {
  487. isClickBtnWest = true;
  488. nowConductButton = 0;
  489. conductTime = 0;
  490. }
  491. }
  492. void OnSummon0Up()
  493. {
  494. if(nowConductButton == 0)
  495. {
  496. isBtnWestUp = true;
  497. cacheConductId = nowConductButton;
  498. nowConductButton = -1;
  499. }
  500. }
  501. void OnSummon1()
  502. {
  503. if (!isFloat && canMove && nowConductButton == -1)
  504. {
  505. isClickBtnSouth = true;
  506. nowConductButton = 1;
  507. conductTime = 0;
  508. }
  509. }
  510. void OnSummon1Up()
  511. {
  512. if (nowConductButton == 1)
  513. {
  514. isBtnSouthUp = true;
  515. cacheConductId = nowConductButton;
  516. nowConductButton = -1;
  517. }
  518. }
  519. void OnSummon2()
  520. {
  521. if (!isFloat && canMove && nowConductButton == -1)
  522. {
  523. isClickBtnEast = true;
  524. nowConductButton = 2;
  525. conductTime = 0;
  526. }
  527. }
  528. void OnSummon2Up()
  529. {
  530. if (nowConductButton == 2)
  531. {
  532. isBtnEastUp = true;
  533. cacheConductId = nowConductButton;
  534. nowConductButton = -1;
  535. }
  536. }
  537. //选英灵 (手柄右扳机,键盘TAB)
  538. void OnChooseSpirit()
  539. {
  540. switch (playerId)
  541. {
  542. case 0:
  543. SpiritSystem.isP1CardChangeR = true;
  544. break;
  545. case 1:
  546. SpiritSystem.isP2CardChangeR = true;
  547. break;
  548. default:
  549. break;
  550. }
  551. }
  552. //选英灵(手柄右摇杆,小键盘左右)
  553. void OnChooseSpirit_LR(InputValue value)
  554. {
  555. rightDir = value.Get<Vector2>();
  556. }
  557. //召唤英灵
  558. void OnTransfigurate()
  559. {
  560. if (!keyTransfigurateRelease && !isFloat && canMove && !isBaseBtnOut)
  561. {
  562. isClickBtnTransfigurate = true;
  563. }
  564. }
  565. //松开变身英灵键
  566. void OnTransfigurateUp()
  567. {
  568. if (!isBaseBtnOut)
  569. {
  570. keyTransfigurateRelease = true;
  571. }
  572. }
  573. public void Jump()
  574. {
  575. SetUpSpeed(jumpSpeed);
  576. ani.Play("jump", 0, 0);
  577. }
  578. public void AirJump()
  579. {
  580. SetUpSpeed(airJumpSpeed);
  581. ani.Play("jump", 0, 0);
  582. }
  583. public void SetUpSpeed(float speed)
  584. {
  585. ChangeState(CharacterState.Rise);
  586. Vector3 velocity = rb.velocity;
  587. CheckTurn();
  588. velocity.y = speed;
  589. rb.velocity = velocity;
  590. //animalAni.SetInteger("state", (int)PlayerState.Rise);
  591. }
  592. public bool CheckSummon()
  593. {
  594. if (btnTransfiguratePress)
  595. {
  596. if(spirits.ultimateTimes[spirits.nowSpirit] > 0)
  597. {
  598. Summon((int)spirits.ownSpirits[spirits.nowSpirit] + 3);
  599. return true;
  600. }
  601. }
  602. if (isBtnEastUp || isBtnWestUp || isBtnSouthUp)
  603. {
  604. if (cacheSummonTime >= 0 && conductTime <= totalCacheSummonTime)
  605. {
  606. CheckTurn();
  607. Summon(cacheSummonId);
  608. return true;
  609. }
  610. }
  611. if (state!=CharacterState.Conduct && nowConductButton != -1 && conductTime >= 0)
  612. {
  613. CheckTurn();
  614. if (conductCanRelease[nowConductButton])
  615. {
  616. ChangeState(CharacterState.Conduct);
  617. return true;
  618. }
  619. }
  620. return false;
  621. }
  622. public bool CheckConduct()
  623. {
  624. if (isBtnEastUp || isBtnWestUp || isBtnSouthUp)
  625. {
  626. if (isReadyConduct)
  627. {
  628. Conduct();
  629. }
  630. isReadyConduct = false;
  631. return true;
  632. }
  633. if (!isReadyConduct && conductTime >= canConductTime[nowConductButton])
  634. {
  635. conductReadyTip.Show();
  636. isReadyConduct = true;
  637. }
  638. return false;
  639. }
  640. private float TranSize(int dieNum)
  641. {
  642. for (int i = stageSize.Length - 1; i >= 0; i--)
  643. {
  644. if (dieNum >= giantDieNum[i])
  645. {
  646. if (i == stageSize.Length - 1)
  647. {
  648. return stageSize[i];
  649. }
  650. float size = stageSize[i] + (stageSize[i + 1] - stageSize[i]) / (giantDieNum[i + 1] - giantDieNum[i]) * (dieNum - giantDieNum[i]);
  651. return size;
  652. }
  653. }
  654. return 1;
  655. }
  656. public void Conduct()
  657. {
  658. if (mp >= conductCostMp[cacheConductId])
  659. {
  660. bool costMp = true; //如果指挥技能要消耗的使魔数量为0就改成false
  661. switch (conductSkills[cacheConductId])
  662. {
  663. //胖子
  664. case ConductSkills.Giant:
  665. if (demonicDic[1].Count > 0)
  666. {
  667. int dienum = demonicDic[1].Count;
  668. int tempthp = giantNum * 1000;
  669. foreach(Demonic d in giants)
  670. {
  671. d.ChangeState(CharacterState.Die);
  672. }
  673. ChangeState(CharacterState.Summon);
  674. GameObject prefab = bigGiant;
  675. summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
  676. GameObject demonicObj = PoolManager.Instantiate(prefab);
  677. Demonic demonic = demonicObj.GetComponent<Demonic>();
  678. demonic.playerID = playerId;
  679. demonicObj.transform.parent = null;
  680. demonicObj.transform.localEulerAngles = Vector3.zero;
  681. demonicObj.transform.localScale = new Vector3(1, 1, 1) * TranSize(dienum);
  682. Vector3 offset = demonicSummonPos[1] * 2;
  683. if (bodyTrans.localScale.x > 0)
  684. {
  685. demonicObj.transform.position = transform.position + offset;
  686. if (demonic.bodyTrans.localScale.x < 0)
  687. {
  688. demonic.Turn();
  689. }
  690. }
  691. else
  692. {
  693. demonicObj.transform.position = transform.position + new Vector3(-offset.x, offset.y, offset.z);
  694. if (demonic.bodyTrans.localScale.x > 0)
  695. {
  696. demonic.Turn();
  697. }
  698. }
  699. demonic.player = this;
  700. demonic.Init();
  701. int order = prefab.GetComponent<Demonic>().baseSortingOrder + demonicDic[demonic.id].Count;
  702. demonic.SetSortingOrder(order);
  703. if (isInSoulTower)
  704. {
  705. ls.AddDenomic(demonic);
  706. }
  707. demonic.GetTemptHP(tempthp, 5);
  708. }
  709. else
  710. {
  711. costMp = false;
  712. }
  713. break;
  714. case ConductSkills.Photosphere:
  715. if(demonicDic[1].Count > 0)
  716. {
  717. conductCanRelease[cacheConductId] = false;
  718. GameObject obj = GameObject.Instantiate(photosphereObj, transform);
  719. obj.transform.position = transform.position + Vector3.up;
  720. Photosphere photosphere = obj.GetComponent<Photosphere>();
  721. photosphere.owner = this;
  722. photosphere.conductId = cacheConductId;
  723. photosphere.hp = demonicDic[1].Count * 1000;
  724. }
  725. else
  726. {
  727. costMp = false;
  728. }
  729. break;
  730. case ConductSkills.AddAttack:
  731. if (demonicDic[1].Count > 0)
  732. {
  733. List<Demonic> newGiants = new List<Demonic>();
  734. foreach(Demonic d in giants)
  735. {
  736. if (!d.isDie)
  737. {
  738. newGiants.Add(d);
  739. if (d.addAttackEffect == null)
  740. {
  741. d.addAttackEffect = Instantiate(attackEffect, d.bodyTrans.position, new Quaternion(0, 0, 0, 0), d.bodyTrans);
  742. }
  743. d.addAttackEffect.transform.GetChild(0).gameObject.SetActive(true);
  744. }
  745. }
  746. giants = newGiants;
  747. foreach(Demonic d in giants)
  748. {
  749. int[] damages = d.curDamage;
  750. for(int i = 0; i < damages.Length; i++)
  751. {
  752. damages[i] += giantNum * swordNum;
  753. }
  754. }
  755. }
  756. else
  757. {
  758. costMp = false;
  759. }
  760. break;
  761. //气功师
  762. case ConductSkills.Mountain:
  763. if (demonicDic[2].Count > 0)
  764. {
  765. conductCanRelease[cacheConductId] = false;
  766. if (curMountain == null)
  767. {
  768. curMountain= GameObject.Instantiate(mountain, transform);
  769. curMountain.transform.position = transform.position + offset;
  770. curMountain.GetComponent<Mountain>().pc = this;
  771. curMountain.GetComponent<Mountain>().id = cacheConductId;
  772. }
  773. curMountain.SetActive(true);
  774. curMountain.GetComponent<Mountain>().continueTime = mountainTime;
  775. }
  776. else
  777. {
  778. costMp = false;
  779. }
  780. break;
  781. case ConductSkills.WavePower:
  782. if (demonicDic[2].Count > 0)
  783. {
  784. conductCanRelease[cacheConductId] = false;
  785. GameObject obj = Instantiate(wavePowerObj, transform);
  786. obj.transform.position = transform.position + Vector3.up;
  787. WavePowerSkill wps = obj.GetComponent<WavePowerSkill>();
  788. wps.damage = 100 * demonicDic[2].Count;
  789. wps.cacheID = cacheConductId;
  790. wps.pc = this;
  791. }
  792. else
  793. {
  794. costMp = false;
  795. }
  796. break;
  797. case ConductSkills.SwordsControl:
  798. if (demonicDic[2].Count > 0)
  799. {
  800. conductCanRelease[cacheConductId] = false;
  801. GameObject obj = Instantiate(flyingSwordsObj, transform);
  802. obj.transform.position = transform.position + Vector3.up;
  803. SwordsControl swordsControl = obj.GetComponentInChildren<SwordsControl>();
  804. swordsControl.owner = this;
  805. swordsControl.conductId = cacheConductId;
  806. swordsControl.damage = 100 * demonicDic[1].Count;
  807. }
  808. else
  809. {
  810. costMp = false;
  811. }
  812. break;
  813. }
  814. if (costMp)
  815. {
  816. mp -= conductCostMp[cacheConductId];
  817. uiMp.Show(mp, totalMp);
  818. }
  819. else
  820. {
  821. print("使魔不足");
  822. }
  823. }
  824. else
  825. {
  826. print("蓝量不足");
  827. }
  828. }
  829. //角色处于可自由活动状态时的通用切换状态逻辑,如Idle、Run状态,以及别的状态结束时准备回到Idle状态前
  830. public bool CheckPlayerChangeState(CharacterState excludeState = CharacterState.None)
  831. {
  832. if (!foot.TrigGround)
  833. {
  834. //if(excludeState != CharacterState.Summon)
  835. //{
  836. // if (CheckSummon())
  837. // {
  838. // return true;
  839. // }
  840. //}
  841. if(excludeState != CharacterState.Summon || excludeState != CharacterState.Conduct)
  842. {
  843. if (CheckSummon())
  844. {
  845. return true;
  846. }
  847. }
  848. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  849. {
  850. if (excludeState != CharacterState.Rush)
  851. {
  852. ChangeState(CharacterState.Rush);
  853. return true;
  854. }
  855. }
  856. if (rb.velocity.y > 0)
  857. {
  858. if (excludeState != CharacterState.Rise)
  859. {
  860. ChangeState(CharacterState.Rise);
  861. return true;
  862. }
  863. }
  864. else
  865. {
  866. if (excludeState != CharacterState.Fall)
  867. {
  868. ChangeState(CharacterState.Fall);
  869. return true;
  870. }
  871. }
  872. }
  873. else
  874. {
  875. airJumped = 0;
  876. //if (btnNorthPress || cacheAttackTime > 0)
  877. //{
  878. // if (excludeState != CharacterState.Attack)
  879. // {
  880. // Attack1();
  881. // return true;
  882. // }
  883. //}
  884. if (eventTrigger.triggedRivet && (btnNorthPress || cachePullRopeTime > 0))
  885. {
  886. if (sprintLinkTrigger.linkedEnemy.Count > 0)
  887. {
  888. eventTrigger.triggedRivet.BindingRopes(sprintLinkTrigger.linkedEnemy);
  889. }
  890. //ChangeState(CharacterState.PullRope);
  891. }
  892. if (excludeState != CharacterState.Summon || excludeState != CharacterState.Conduct)
  893. {
  894. if (CheckSummon())
  895. {
  896. return true;
  897. }
  898. }
  899. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  900. {
  901. if (excludeState != CharacterState.Rush)
  902. {
  903. ChangeState(CharacterState.Rush);
  904. return true;
  905. }
  906. }
  907. if (btnJumpPress || cacheJumpTime > 0)
  908. {
  909. if (excludeState != CharacterState.Rise)
  910. {
  911. Jump();
  912. ChangeState(CharacterState.Rise);
  913. return true;
  914. }
  915. }
  916. if(leftDir.y< -0.5)
  917. {
  918. Platform platform = foot.trigGroundList[0].GetComponent<Platform>();
  919. if (platform != null && platform.canDown)
  920. {
  921. foot.trigGroundList.Remove(platform.gameObject);
  922. }
  923. }
  924. if (canfly)
  925. {
  926. if (leftDir.x > 0.3f || leftDir.x < -0.3f || leftDir.y > 0.3f || leftDir.y < -0.3f)
  927. {
  928. if (excludeState != CharacterState.Run)
  929. {
  930. ChangeState(CharacterState.Run);
  931. return true;
  932. }
  933. }
  934. else
  935. {
  936. if (excludeState != CharacterState.Idle)
  937. {
  938. ChangeState(CharacterState.Idle);
  939. return true;
  940. }
  941. }
  942. }
  943. else
  944. {
  945. if (leftDir.x > 0.3f || leftDir.x < -0.3f)
  946. {
  947. if (excludeState != CharacterState.Run)
  948. {
  949. ChangeState(CharacterState.Run);
  950. return true;
  951. }
  952. }
  953. else
  954. {
  955. if (excludeState != CharacterState.Idle)
  956. {
  957. ChangeState(CharacterState.Idle);
  958. return true;
  959. }
  960. }
  961. }
  962. }
  963. return false;
  964. }
  965. public override Vector3 GetMoveDir()
  966. {
  967. return leftDir;
  968. }
  969. public void CachedPlayerInput()
  970. {
  971. if (btnRushPress)
  972. {
  973. cacheRushTime = totalCacheRushTime;
  974. }
  975. if (btnJumpPress)
  976. {
  977. cacheJumpTime = totalCacheJumpTime;
  978. }
  979. if (btnNorthPress)
  980. {
  981. cacheAttackTime = totalCacheAttackTime;
  982. }
  983. if (btnWestPress)
  984. {
  985. cacheSummonTime = totalCacheSummonTime;
  986. cacheSummonId = 0;
  987. }
  988. if (btnSouthPress)
  989. {
  990. cacheSummonTime = totalCacheSummonTime;
  991. cacheSummonId = 1;
  992. }
  993. if (btnEastPress)
  994. {
  995. cacheSummonTime = totalCacheSummonTime;
  996. cacheSummonId = 2;
  997. }
  998. //if (btnSpiritSummon)
  999. //{
  1000. // cacheSummonTime = totalCacheSummonTime;
  1001. // cacheSummonId = 3;
  1002. //}
  1003. //if (btnSpiritSummon1)
  1004. //{
  1005. // cacheSummonTime = totalCacheSummonTime;
  1006. // cacheSummonId = 4;
  1007. //}
  1008. //if (btnSpiritSummon2)
  1009. //{
  1010. // cacheSummonTime = totalCacheSummonTime;
  1011. // cacheSummonId = 5;
  1012. //}
  1013. //if (btnSpiritSummon3)
  1014. //{
  1015. // cacheSummonTime = totalCacheSummonTime;
  1016. // cacheSummonId = 6;
  1017. //}
  1018. }
  1019. public override void OnState()
  1020. {
  1021. base.OnState();
  1022. cacheJumpTime -= Time.deltaTime;
  1023. cacheAttackTime -= Time.deltaTime;
  1024. cacheSummonTime -= Time.deltaTime;
  1025. canJumpTime -= Time.deltaTime;
  1026. invincibleTime -= Time.deltaTime;
  1027. attackTime -= Time.deltaTime;
  1028. summonTime -= Time.deltaTime;
  1029. rushTime -= Time.deltaTime;
  1030. cacheRushTime -= Time.deltaTime;
  1031. dieKeepTime -= Time.deltaTime;
  1032. weakTime -= Time.deltaTime;
  1033. beRepelValue += Time.deltaTime;
  1034. if(nowConductButton != -1)
  1035. {
  1036. conductTime += Time.deltaTime;
  1037. }
  1038. CachedPlayerInput();
  1039. Vector3 velocity = rb.velocity;
  1040. switch (state)
  1041. {
  1042. case CharacterState.Idle:
  1043. if (CheckPlayerChangeState(CharacterState.Idle))
  1044. {
  1045. break;
  1046. }
  1047. rb.velocity = Vector3.right * velocityAddition;
  1048. break;
  1049. case CharacterState.Run:
  1050. if (CheckPlayerChangeState(CharacterState.Run))
  1051. {
  1052. break;
  1053. }
  1054. CheckTurn();
  1055. if (canfly)
  1056. {
  1057. rb.velocity = leftDir.normalized * moveSpeed;
  1058. }
  1059. else
  1060. {
  1061. if (leftDir.x > 0.3f)
  1062. {
  1063. rb.velocity = new Vector3(moveSpeed+velocityAddition,0,0);
  1064. }
  1065. else if (leftDir.x < -0.3f)
  1066. {
  1067. rb.velocity = new Vector3(-moveSpeed + velocityAddition,0,0);
  1068. }
  1069. }
  1070. break;
  1071. case CharacterState.Rise:
  1072. if (CheckSummon())
  1073. {
  1074. break;
  1075. }
  1076. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  1077. {
  1078. ChangeState(CharacterState.Rush);
  1079. break;
  1080. }
  1081. if (btnJumpPress || cacheJumpTime > 0)
  1082. {
  1083. if (airJumped < airJumpNumber && rb.velocity.y < canAirJumpSpeed)
  1084. {
  1085. airJumped++;
  1086. AirJump();
  1087. break;
  1088. }
  1089. }
  1090. rb.velocity = AirMove(rb.velocity);
  1091. if (rb.velocity.y <= 0)
  1092. {
  1093. ChangeState(CharacterState.Fall);
  1094. break;
  1095. }
  1096. break;
  1097. case CharacterState.Fall:
  1098. if (CheckSummon())
  1099. {
  1100. break;
  1101. }
  1102. if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
  1103. {
  1104. ChangeState(CharacterState.Rush);
  1105. break;
  1106. }
  1107. if (foot.TrigGround)
  1108. {
  1109. if (CheckPlayerChangeState())
  1110. {
  1111. break;
  1112. }
  1113. }
  1114. //if (foot.canStepPlayers.Count > 0)
  1115. //{
  1116. // Jump(jumpSpeed / 2);
  1117. // StepOther();
  1118. // break;
  1119. //}
  1120. //if (foot.canStepEnemyList.Count > 0)
  1121. //{
  1122. // Jump(jumpSpeed / 2);
  1123. // StepEnemy();
  1124. // break;
  1125. //}
  1126. if (btnJumpPress || cacheJumpTime > 0)
  1127. {
  1128. if (canJumpTime > 0)
  1129. {
  1130. Jump();
  1131. break;
  1132. }
  1133. else
  1134. {
  1135. if (airJumped < airJumpNumber)
  1136. {
  1137. airJumped++;
  1138. AirJump();
  1139. break;
  1140. }
  1141. }
  1142. }
  1143. rb.velocity = AirMove(rb.velocity);
  1144. break;
  1145. //case CharacterState.Hurt:
  1146. // if (hurtKeepTime <= 0 && rb.velocity.magnitude < hurtChangeVelocity)
  1147. // {
  1148. // if (CheckPlayerChangeState())
  1149. // {
  1150. // break;
  1151. // }
  1152. // }
  1153. // Vector3 vel = rb.velocity;
  1154. // if (!foot.TrigGround)
  1155. // {
  1156. // if (canfly)
  1157. // {
  1158. // vel.y = vel.y * (1 - decelerationRatio * Time.deltaTime);
  1159. // }
  1160. // else
  1161. // {
  1162. // vel += Vector3.up * extraFallGravity * Time.deltaTime;
  1163. // }
  1164. // }
  1165. // vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
  1166. // rb.velocity = vel;
  1167. // CachedPlayerInput();
  1168. // break;
  1169. case CharacterState.Coma:
  1170. break;
  1171. case CharacterState.Attack:
  1172. if (attackTime <= 0)
  1173. {
  1174. if (btnNorthKeep)
  1175. {
  1176. ChangeState(CharacterState.KeepAttack);
  1177. break;
  1178. }
  1179. if (CheckPlayerChangeState())
  1180. {
  1181. break;
  1182. }
  1183. }
  1184. break;
  1185. case CharacterState.KeepAttack:
  1186. if ((btnRushPress) && mp >= rushCostMp)
  1187. {
  1188. ChangeState(CharacterState.Rush);
  1189. break;
  1190. }
  1191. if (btnJumpPress && canJumpTime > 0)
  1192. {
  1193. Jump();
  1194. break;
  1195. }
  1196. if (!btnNorthKeep)
  1197. {
  1198. if (CheckPlayerChangeState(CharacterState.Attack))
  1199. {
  1200. break;
  1201. }
  1202. }
  1203. switch (attackState)
  1204. {
  1205. case PlayerAttackState.Idle:
  1206. if (bodyTrans.localScale.x > 0)
  1207. {
  1208. if (leftDir.x > 0.3f)
  1209. {
  1210. SetAttackState(PlayerAttackState.WalkBack);
  1211. velocity.x = attackMoveSpeed;
  1212. rb.velocity = velocity;
  1213. break;
  1214. }
  1215. else if (leftDir.x < -0.3f)
  1216. {
  1217. SetAttackState(PlayerAttackState.WalkForward);
  1218. velocity.x = -attackMoveSpeed;
  1219. rb.velocity = velocity;
  1220. break;
  1221. }
  1222. }
  1223. else
  1224. {
  1225. if (leftDir.x > 0.3f)
  1226. {
  1227. SetAttackState(PlayerAttackState.WalkForward);
  1228. velocity.x = attackMoveSpeed;
  1229. rb.velocity = velocity;
  1230. break;
  1231. }
  1232. else if (leftDir.x < -0.3f)
  1233. {
  1234. SetAttackState(PlayerAttackState.WalkBack);
  1235. velocity.x = -attackMoveSpeed;
  1236. rb.velocity = velocity;
  1237. break;
  1238. }
  1239. }
  1240. velocity.x = 0;
  1241. rb.velocity = velocity;
  1242. break;
  1243. case PlayerAttackState.WalkForward:
  1244. if (bodyTrans.localScale.x > 0)
  1245. {
  1246. if (leftDir.x > 0.3f)
  1247. {
  1248. SetAttackState(PlayerAttackState.WalkBack);
  1249. velocity.x = attackMoveSpeed;
  1250. rb.velocity = velocity;
  1251. break;
  1252. }
  1253. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1254. {
  1255. SetAttackState(PlayerAttackState.Idle);
  1256. velocity.x = 0;
  1257. rb.velocity = velocity;
  1258. break;
  1259. }
  1260. else
  1261. {
  1262. velocity.x = -attackMoveSpeed;
  1263. rb.velocity = velocity;
  1264. }
  1265. }
  1266. else
  1267. {
  1268. if (leftDir.x < -0.3f)
  1269. {
  1270. SetAttackState(PlayerAttackState.WalkBack);
  1271. velocity.x = -attackMoveSpeed;
  1272. rb.velocity = velocity;
  1273. break;
  1274. }
  1275. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1276. {
  1277. SetAttackState(PlayerAttackState.Idle);
  1278. velocity.x = 0;
  1279. rb.velocity = velocity;
  1280. break;
  1281. }
  1282. else
  1283. {
  1284. velocity.x = attackMoveSpeed;
  1285. rb.velocity = velocity;
  1286. }
  1287. }
  1288. break;
  1289. case PlayerAttackState.WalkBack:
  1290. if (bodyTrans.localScale.x > 0)
  1291. {
  1292. if (leftDir.x < -0.3f)
  1293. {
  1294. SetAttackState(PlayerAttackState.WalkForward);
  1295. velocity.x = -attackMoveSpeed;
  1296. rb.velocity = velocity;
  1297. break;
  1298. }
  1299. else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
  1300. {
  1301. SetAttackState(PlayerAttackState.Idle);
  1302. velocity.x = 0;
  1303. rb.velocity = velocity;
  1304. break;
  1305. }
  1306. else
  1307. {
  1308. velocity.x = attackMoveSpeed;
  1309. rb.velocity = velocity;
  1310. }
  1311. }
  1312. else
  1313. {
  1314. if (leftDir.x > 0.3f)
  1315. {
  1316. SetAttackState(PlayerAttackState.WalkForward);
  1317. velocity.x = attackMoveSpeed;
  1318. rb.velocity = velocity;
  1319. break;
  1320. }
  1321. else if (leftDir.x > -0.3f && leftDir.x > 0.3f)
  1322. {
  1323. SetAttackState(PlayerAttackState.Idle);
  1324. velocity.x = 0;
  1325. rb.velocity = velocity;
  1326. break;
  1327. }
  1328. else
  1329. {
  1330. velocity.x = -attackMoveSpeed;
  1331. rb.velocity = velocity;
  1332. }
  1333. }
  1334. break;
  1335. default:
  1336. break;
  1337. }
  1338. break;
  1339. case CharacterState.Summon:
  1340. if (summonTime <= 0 || btnTransfiguratePress)
  1341. {
  1342. if (CheckPlayerChangeState())
  1343. {
  1344. break;
  1345. }
  1346. }
  1347. rb.velocity = Vector3.right * velocityAddition;
  1348. if (leftDir.x > 0.3f || leftDir.x < -0.3f)
  1349. {
  1350. cacheDir = leftDir.x;
  1351. }
  1352. break;
  1353. case CharacterState.Rush:
  1354. if (rushTime <= 0)
  1355. {
  1356. if (btnRushKeep)
  1357. {
  1358. ChangeState(CharacterState.Sprint);
  1359. break;
  1360. }
  1361. if (CheckPlayerChangeState())
  1362. {
  1363. break;
  1364. }
  1365. }
  1366. //if (leftDir.magnitude < 0.3f)
  1367. //{
  1368. // if (bodyTrans.localScale.x > 0)
  1369. // {
  1370. // rushDir = Vector3.left;
  1371. // }
  1372. // else
  1373. // {
  1374. // rushDir = Vector3.right;
  1375. // }
  1376. //}
  1377. //else
  1378. //{
  1379. // rushDir = leftDir.normalized;
  1380. //}
  1381. rb.velocity = rushDir * rushSpeed;
  1382. break;
  1383. case CharacterState.Sprint:
  1384. if (!btnRushKeep)
  1385. {
  1386. if (CheckPlayerChangeState(CharacterState.Rush))
  1387. {
  1388. break;
  1389. }
  1390. }
  1391. if (mp < sprintCostMp * Time.deltaTime)
  1392. {
  1393. if (CheckPlayerChangeState(CharacterState.Rush))
  1394. {
  1395. break;
  1396. }
  1397. }
  1398. mp -= sprintCostMp * Time.deltaTime;
  1399. uiMp.Show(mp, totalMp);
  1400. //CheckTurn();
  1401. //if (leftDir.magnitude < 0.3f)
  1402. //{
  1403. // if (bodyTrans.localScale.x > 0)
  1404. // {
  1405. // rushDir = Vector3.left;
  1406. // }
  1407. // else
  1408. // {
  1409. // rushDir = Vector3.right;
  1410. // }
  1411. //}
  1412. //else
  1413. //{
  1414. // rushDir = leftDir.normalized;
  1415. //}
  1416. rb.velocity = rushDir * rushSpeed;
  1417. break;
  1418. case CharacterState.Die:
  1419. if (dieKeepTime <= 0)
  1420. {
  1421. if (isRevive)
  1422. {
  1423. reviveTime += Time.deltaTime;
  1424. if(reviveTime >= totalReviveTime)
  1425. {
  1426. PlayerRevive();
  1427. }
  1428. }
  1429. else
  1430. {
  1431. PlayerDie();
  1432. }
  1433. }
  1434. break;
  1435. case CharacterState.Weak:
  1436. if (rb.velocity.magnitude > 1)
  1437. {
  1438. if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "hitted")
  1439. {
  1440. ani.Play("hitted", 0, 0);
  1441. aniCollider.Play("Hurt", 0, 0);
  1442. }
  1443. Vector3 vel = rb.velocity;
  1444. if (!canfly)
  1445. {
  1446. if (foot.TrigGround && vel.y < 0)
  1447. {
  1448. vel.y = 0;
  1449. }
  1450. else
  1451. {
  1452. vel += Vector3.up * extraFallGravity * Time.deltaTime;
  1453. }
  1454. }
  1455. vel.y = vel.y * (1 - decelerationRatio * Time.deltaTime);
  1456. vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
  1457. rb.velocity = vel;
  1458. }
  1459. else
  1460. {
  1461. if (ani.GetCurrentAnimatorClipInfo(0)[0].clip.name != "weak")
  1462. {
  1463. ani.Play("weak", 0, 0);
  1464. aniCollider.Play("Weak", 0, 0);
  1465. rb.velocity = Vector3.zero;
  1466. weakTime = totalWeakTime;
  1467. }
  1468. rb.velocity = new Vector3(velocityAddition, rb.velocity.y, 0);
  1469. }
  1470. if (weakTime <= 0)
  1471. {
  1472. ChangeState(CharacterState.Idle);
  1473. break;
  1474. }
  1475. break;
  1476. case CharacterState.PullRope:
  1477. break;
  1478. case CharacterState.Conduct:
  1479. if (CheckSummon())
  1480. {
  1481. break;
  1482. }
  1483. if (CheckConduct())
  1484. {
  1485. ChangeState(CharacterState.Idle);
  1486. }
  1487. break;
  1488. default:
  1489. break;
  1490. }
  1491. if (!foot.TrigGround && !canfly)
  1492. {
  1493. if (rb.velocity.y > 0)
  1494. {
  1495. rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
  1496. }
  1497. else
  1498. {
  1499. rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
  1500. }
  1501. }
  1502. isClickBtnRush = false;
  1503. isKeepBtnRush = false;
  1504. isClickBtnJump = false;
  1505. isClickBtnSouth = false;
  1506. isClickBtnEast = false;
  1507. isClickBtnNorth = false;
  1508. isClickBtnWest = false;
  1509. isBtnSouthUp = false;
  1510. isBtnEastUp = false;
  1511. isBtnNorthUp = false;
  1512. isBtnWestUp = false;
  1513. isSpiritSummon = false;
  1514. isSpiritSummon1 = false;
  1515. isSpiritSummon2 = false;
  1516. isSpiritSummon3 = false;
  1517. isClickBtnTransfigurate = false;
  1518. keyTransfigurateRelease = false;
  1519. if (foot.TrigGround)
  1520. {
  1521. canJumpTime = leaveGroundCanJumpTime;
  1522. }
  1523. SearchTarget();
  1524. attackTarget = targetCharacter;
  1525. if (isMpRepel && floatState == 0)
  1526. {
  1527. if (mp < totalMp)
  1528. {
  1529. if (!isRapedReply)
  1530. {
  1531. mp += mpReplySpeed * Time.deltaTime;
  1532. }
  1533. else
  1534. {
  1535. mp += rapidReplySpeed * Time.deltaTime;
  1536. }
  1537. }
  1538. }
  1539. if (floatState != 0)
  1540. {
  1541. if (mp > 0)
  1542. {
  1543. lostMp += mpReplySpeed * Time.deltaTime;
  1544. mp -= mpReplySpeed * Time.deltaTime;
  1545. }
  1546. if (lostMp >= addMp)
  1547. {
  1548. Instantiate(soul, transform.position, new Quaternion(0, 0, 0, 0), null);
  1549. lostMp = 0;
  1550. }
  1551. }
  1552. if (mp > totalMp)
  1553. {
  1554. mp = totalMp;
  1555. }
  1556. if (mp < 0)
  1557. {
  1558. mp = 0;
  1559. }
  1560. uiMp.Show(mp, totalMp);
  1561. }
  1562. public void PlayerDie()
  1563. {
  1564. switch (playerId)
  1565. {
  1566. case 0:
  1567. SpiritSystem.isP1In = true;
  1568. SpiritSystem.isP1Out = false;
  1569. break;
  1570. case 1:
  1571. SpiritSystem.isP2In = true;
  1572. SpiritSystem.isP2Out = false;
  1573. break;
  1574. default:
  1575. break;
  1576. }
  1577. foot.trigGroundList.Clear();
  1578. bodyTrans.gameObject.SetActive(false);
  1579. uiHp.transform.parent.gameObject.SetActive(false);
  1580. rb.constraints = RigidbodyConstraints.FreezeAll;
  1581. isRevive = true;
  1582. reviveTime = 0;
  1583. }
  1584. public void PlayerRevive()
  1585. {
  1586. isRevive = false;
  1587. isBaseBtnOut = false;
  1588. bodyTrans.gameObject.SetActive(true);
  1589. uiHp.transform.parent.gameObject.SetActive(true);
  1590. rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
  1591. transform.position = new Vector3(142 + 4 * playerId, 0, 0);
  1592. switch (playerId)
  1593. {
  1594. case 0:
  1595. SpiritSystem.isP1In = false;
  1596. SpiritSystem.isP1Out = true;
  1597. SpiritSystem.player1 = gameObject;
  1598. SpiritSystem.p1Spirits = GetComponent<Spirits>();
  1599. break;
  1600. case 1:
  1601. SpiritSystem.isP2In = false;
  1602. SpiritSystem.isP2Out = true;
  1603. SpiritSystem.player2 = gameObject;
  1604. SpiritSystem.p2Spirits = GetComponent<Spirits>();
  1605. break;
  1606. default:
  1607. break;
  1608. }
  1609. Init();
  1610. }
  1611. public void RapidReplyMp()
  1612. {
  1613. isRapedReply = true;
  1614. rapidReplyEffect.SetActive(true);
  1615. }
  1616. public void NormalReplyMp()
  1617. {
  1618. isRapedReply = false;
  1619. rapidReplyEffect.SetActive(false);
  1620. }
  1621. public override void ChangeState(CharacterState newState)
  1622. {
  1623. if (state == newState)
  1624. {
  1625. return;
  1626. }
  1627. if(newState == CharacterState.Weak)
  1628. {
  1629. return;
  1630. }
  1631. Vector3 velocity = rb.velocity;
  1632. switch (state)
  1633. {
  1634. case CharacterState.Idle:
  1635. break;
  1636. case CharacterState.Run:
  1637. velocity.x = 0;
  1638. break;
  1639. case CharacterState.Rise:
  1640. bodyCollider.SetActive(true);
  1641. break;
  1642. case CharacterState.Fall:
  1643. break;
  1644. //case CharacterState.Hurt:
  1645. // break;
  1646. case CharacterState.Coma:
  1647. canMove = true;
  1648. break;
  1649. case CharacterState.Attack:
  1650. aniCollider.Play("NotAttack", 1, 0);
  1651. break;
  1652. case CharacterState.KeepAttack:
  1653. aniCollider.Play("NotAttack", 1, 0);
  1654. break;
  1655. case CharacterState.Summon:
  1656. rb.isKinematic = false;
  1657. if(cacheDir != 0)
  1658. {
  1659. if (cacheDir > 0.3f && bodyTrans.localScale.x > 0)
  1660. {
  1661. Turn();
  1662. }
  1663. else if (cacheDir < -0.3f && bodyTrans.localScale.x < 0)
  1664. {
  1665. Turn();
  1666. }
  1667. cacheDir = 0;
  1668. }
  1669. break;
  1670. case CharacterState.Transfiguration:
  1671. rb.isKinematic = false;
  1672. break;
  1673. case CharacterState.Rush:
  1674. velocity = Vector3.zero;
  1675. break;
  1676. case CharacterState.Sprint:
  1677. velocity = Vector3.zero;
  1678. break;
  1679. case CharacterState.Die:
  1680. if(isRevive)
  1681. {
  1682. return;
  1683. }
  1684. isDie = false;
  1685. break;
  1686. case CharacterState.Weak:
  1687. beRepelValue = totalBeRepelValue;
  1688. break;
  1689. case CharacterState.Conduct:
  1690. rb.isKinematic =false;
  1691. break;
  1692. default:
  1693. break;
  1694. }
  1695. CharacterState oldState = state;
  1696. state = newState;
  1697. switch (newState)
  1698. {
  1699. case CharacterState.Idle:
  1700. aniCollider.Play("Idle", 0, 0);
  1701. if (oldState == CharacterState.Fall)
  1702. {
  1703. ani.Play("fall_end", 0, 0);
  1704. }
  1705. else
  1706. {
  1707. ani.Play("idle", 0, 0);
  1708. }
  1709. velocity = Vector3.right * velocityAddition;
  1710. //animalAni.SetInteger("state", (int)PlayerState.Idle);
  1711. break;
  1712. case CharacterState.Run:
  1713. aniCollider.Play("Run", 0, 0);
  1714. ani.Play("run_start", 0, 0);
  1715. //animalAni.SetInteger("state", (int)PlayerState.Walk);
  1716. break;
  1717. case CharacterState.Rise:
  1718. aniCollider.Play("Rise", 0, 0);
  1719. canJumpTime = 0;
  1720. break;
  1721. case CharacterState.Fall:
  1722. aniCollider.Play("Fall", 0, 0);
  1723. ani.Play("fall", 0, 0);
  1724. //animalAni.SetInteger("state", (int)PlayerState.Fall);
  1725. break;
  1726. //case CharacterState.Hurt:
  1727. // aniCollider.Play("Hurt", 0, 0);
  1728. // ani.Play("hitted", 0, 0);
  1729. // invincibleTime = totalInvincibleTime;
  1730. // hurtKeepTime = minHurtKeepTime;
  1731. // //ani.Play("Invincible", 2, 0);
  1732. // break;
  1733. case CharacterState.Coma:
  1734. //ani.Play("Coma", 0, 0);
  1735. ani.Play("idle", 0, 0);
  1736. aniCollider.Play("Idle", 0, 0);
  1737. rb.velocity = Vector3.zero;
  1738. break;
  1739. case CharacterState.Attack:
  1740. attackTime = totalAttack1Time;
  1741. break;
  1742. case CharacterState.KeepAttack:
  1743. aniCollider.Play("Attack1Keep", 1, 0);
  1744. break;
  1745. case CharacterState.Summon:
  1746. aniCollider.Play("Summon", 0, 0);
  1747. ani.Play("summon", 0, 0);
  1748. velocity = Vector3.right * velocityAddition;
  1749. rb.isKinematic = true;
  1750. cacheDir = 0;
  1751. break;
  1752. case CharacterState.Transfiguration:
  1753. aniCollider.Play("Transfiguration", 0, 0);
  1754. ani.Play("transfiguration", 0, 0);
  1755. velocity = Vector3.zero;
  1756. rb.isKinematic = true;
  1757. break;
  1758. case CharacterState.Rush:
  1759. aniCollider.Play("Rush", 0, 0);
  1760. ani.Play("rush_loop", 0, 0);
  1761. rushTime = totalRushTime;
  1762. invincibleTime = rushInvincibleTime;
  1763. //if (leftDir.magnitude < 0.3f)
  1764. //{
  1765. // if (bodyTrans.localScale.x > 0)
  1766. // {
  1767. // rushDir = Vector3.left;
  1768. // }
  1769. // else
  1770. // {
  1771. // rushDir = Vector3.right;
  1772. // }
  1773. //}
  1774. //else
  1775. //{
  1776. // rushDir = leftDir.normalized;
  1777. //}
  1778. if (bodyTrans.localScale.x > 0)
  1779. {
  1780. rushDir = Vector3.left;
  1781. }
  1782. else
  1783. {
  1784. rushDir = Vector3.right;
  1785. }
  1786. velocity = rushDir * rushSpeed;
  1787. mp -= rushCostMp;
  1788. uiMp.Show(mp, totalMp);
  1789. break;
  1790. case CharacterState.Sprint:
  1791. aniCollider.Play("Sprint", 0, 0);
  1792. ani.Play("rush_loop", 0, 0);
  1793. velocity = rushDir * rushSpeed;
  1794. break;
  1795. case CharacterState.Die:
  1796. aniCollider.Play("Die", 0, 0);
  1797. ani.Play("die", 0, 0);
  1798. isDie = true;
  1799. dieKeepTime = totalDieKeepTime;
  1800. break;
  1801. case CharacterState.Weak:
  1802. weakTime = totalWeakTime;
  1803. //hurtKeepTime = minHurtKeepTime;
  1804. break;
  1805. case CharacterState.Conduct:
  1806. rb.velocity = Vector3.zero;
  1807. rb.isKinematic = true;
  1808. aniCollider.Play("Summon", 0, 0);
  1809. ani.Play("summon", 0, 0);
  1810. break;
  1811. default:
  1812. break;
  1813. }
  1814. rb.velocity = velocity;
  1815. }
  1816. public void CheckTurn()
  1817. {
  1818. if (leftDir.x > 0.3f && bodyTrans.localScale.x > 0)
  1819. {
  1820. Turn();
  1821. }
  1822. else if (leftDir.x < -0.3f && bodyTrans.localScale.x < 0)
  1823. {
  1824. Turn();
  1825. }
  1826. }
  1827. public Vector3 AirMove(Vector3 velocity)
  1828. {
  1829. CheckTurn();
  1830. if (canfly)
  1831. {
  1832. velocity = leftDir.normalized * flySpeed;
  1833. if (transform.position.y > maxFlyHeight && velocity.y > 0)
  1834. {
  1835. velocity.y = 0;
  1836. }
  1837. }
  1838. else
  1839. {
  1840. if (leftDir.x > 0.3f)
  1841. {
  1842. velocity = new Vector3(moveSpeed, velocity.y, velocity.z);
  1843. }
  1844. else if (leftDir.x < -0.3f)
  1845. {
  1846. velocity = new Vector3(-moveSpeed, velocity.y, velocity.z);
  1847. }
  1848. else
  1849. {
  1850. velocity = new Vector3(0, velocity.y, velocity.z);
  1851. }
  1852. }
  1853. return velocity;
  1854. }
  1855. public void Transfiguration(int id) //变身
  1856. {
  1857. id = id - 3;
  1858. if (id >= changePrefabs.Count)
  1859. {
  1860. Debug.LogError("未配置" + id + "号变身");
  1861. return;
  1862. }
  1863. GameObject prefab = changePrefabs[id];
  1864. ChangeState(CharacterState.Transfiguration);
  1865. summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
  1866. bodyTrans.gameObject.SetActive(false);
  1867. foot.trigGroundList.Clear();
  1868. spiritObj = PoolManager.Instantiate(prefab);
  1869. Demonic dem = spiritObj.GetComponent<Demonic>();
  1870. dem.id = id;
  1871. dem.playerID = playerId;
  1872. spiritObj.transform.parent = transform;
  1873. spiritObj.transform.localEulerAngles = Vector3.zero;
  1874. spiritObj.transform.localScale = new Vector3(1, 1, 1);
  1875. if (bodyTrans.localScale.x > 0)
  1876. {
  1877. spiritObj.transform.position = transform.position;
  1878. if (dem.bodyTrans.localScale.x < 0)
  1879. {
  1880. dem.Turn();
  1881. }
  1882. }
  1883. else
  1884. {
  1885. spiritObj.transform.position = transform.position;
  1886. if (dem.bodyTrans.localScale.x > 0)
  1887. {
  1888. dem.Turn();
  1889. }
  1890. }
  1891. mecanim = dem.mecanim;
  1892. ani = dem.ani;
  1893. aniCollider = dem.aniCollider;
  1894. bodyTrans = dem.bodyTrans;
  1895. beSearchTrigger = dem.beSearchTrigger;
  1896. bulletPrefab = dem.bulletPrefab;
  1897. searchTrigger = dem.searchTrigger;
  1898. foot = dem.foot;
  1899. spinee = dem.spinee;
  1900. mesh = dem.mesh;
  1901. mats = dem.mats;
  1902. soulCollector = dem.soulCollector;
  1903. outlineMats = dem.outlineMats;
  1904. if (dem.canFly)
  1905. {
  1906. canfly = true;
  1907. canJump = false;
  1908. rb.useGravity = false;
  1909. }
  1910. /* 法师出场释放浮空场
  1911. if (id == 3)
  1912. {
  1913. if ((int)spirits.currentSpirit == 0)
  1914. {
  1915. if (!spiritObj.GetComponent<Demonic>().hasEffect)
  1916. {
  1917. spiritObj.GetComponent<Demonic>().hasEffect = true;
  1918. Instantiate(spirits.floatEffect, spiritObj.transform.position, new Quaternion(0, 0, 0, 0), spiritObj.transform);
  1919. }
  1920. }
  1921. }
  1922. */
  1923. endChange = id + 3;
  1924. curHp = hp;
  1925. curTotalHp = totalHp;
  1926. uiHp.Show(hp, totalHp);
  1927. ChangeState(CharacterState.Idle);
  1928. }
  1929. public void Summon(int id)
  1930. {
  1931. if (id >= demonicPrefabs.Count)
  1932. {
  1933. Debug.LogError("未配置" + id + "号使魔");
  1934. return;
  1935. }
  1936. if (id >= demonicSummonPos.Count)
  1937. {
  1938. Debug.LogError("未配置" + id + "号使魔召唤位置");
  1939. return;
  1940. }
  1941. GameObject prefab;
  1942. if (id == 1)
  1943. {
  1944. prefab = chooseYinYang.SelectPrefab(playerId);
  1945. }
  1946. else
  1947. {
  1948. prefab = demonicPrefabs[id];
  1949. }
  1950. if (!CheckCanSummon(id))
  1951. {
  1952. return;
  1953. }
  1954. ChangeState(CharacterState.Summon);
  1955. summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
  1956. float costMp = prefab.GetComponent<Demonic>().costMp;
  1957. mp -= costMp;
  1958. uiMp.Show(mp, totalMp);
  1959. GameObject demonicObj = PoolManager.Instantiate(prefab);
  1960. Demonic demonic = demonicObj.GetComponent<Demonic>();
  1961. demonic.id = id;
  1962. demonic.playerID = playerId;
  1963. if (!demonicDic.ContainsKey(id))
  1964. {
  1965. demonicDic.Add(id, new List<Demonic>());
  1966. }
  1967. demonicDic[id].Add(demonic);
  1968. demonicObj.transform.parent = null;
  1969. demonicObj.transform.localEulerAngles = Vector3.zero;
  1970. demonicObj.transform.localScale = new Vector3(1, 1, 1);
  1971. Vector3 offset = demonicSummonPos[id];
  1972. if (bodyTrans.localScale.x > 0)
  1973. {
  1974. demonicObj.transform.position = transform.position + offset;
  1975. if (demonic.bodyTrans.localScale.x < 0)
  1976. {
  1977. demonic.Turn();
  1978. }
  1979. }
  1980. else
  1981. {
  1982. demonicObj.transform.position = transform.position + new Vector3(-offset.x, offset.y, offset.z);
  1983. if (demonic.bodyTrans.localScale.x > 0)
  1984. {
  1985. demonic.Turn();
  1986. }
  1987. }
  1988. if (demonic.canFly)
  1989. {
  1990. demonic.flyHeight = demonic.transform.position.y;
  1991. }
  1992. demonic.player = this;
  1993. demonic.Init();
  1994. int order = prefab.GetComponent<Demonic>().baseSortingOrder + demonicDic[demonic.id].Count;
  1995. demonic.SetSortingOrder(order);
  1996. if(id != 4)
  1997. {
  1998. demonic.Attack1();
  1999. }
  2000. //id 3~6 为四个英灵
  2001. if(id >= 3 && id <= 6)
  2002. {
  2003. spirits.ultimateTimes[spirits.nowSpirit] -= 1;
  2004. }
  2005. spiritSystem.RefreshPlayerUI();
  2006. if (isInSoulTower)
  2007. {
  2008. ls.AddDenomic(demonic);
  2009. }
  2010. switch (id)
  2011. {
  2012. case 0:
  2013. arrows.Add(demonic);
  2014. arrowNum++;
  2015. break;
  2016. case 1:
  2017. giants.Add(demonic);
  2018. giantNum++;
  2019. break;
  2020. case 2:
  2021. swords.Add(demonic);
  2022. swordNum++;
  2023. break;
  2024. default:
  2025. break;
  2026. }
  2027. }
  2028. public void OnDemonicRecycle(Demonic demonic)
  2029. {
  2030. if (!demonicDic.ContainsKey(demonic.id))
  2031. {
  2032. return;
  2033. }
  2034. demonicDic[demonic.id].Remove(demonic);
  2035. for (int i = 0; i < demonicDic[demonic.id].Count; i++)
  2036. {
  2037. int order = demonicDic[demonic.id][i].baseSortingOrder + i;
  2038. demonicDic[demonic.id][i].SetSortingOrder(order);
  2039. }
  2040. }
  2041. public bool CheckCanSummon(int id)
  2042. {
  2043. GameObject prefab;
  2044. if (id == 1)
  2045. {
  2046. prefab = chooseYinYang.SelectPrefab(playerId);
  2047. }
  2048. else
  2049. {
  2050. prefab = demonicPrefabs[id];
  2051. }
  2052. float costMp = prefab.GetComponent<Demonic>().costMp;
  2053. if (mp < costMp)
  2054. {
  2055. Debug.Log("mp不足召唤失败, 还得加个动画或者音效啥的");
  2056. return false;
  2057. }
  2058. return true;
  2059. }
  2060. public override void Attack1()
  2061. {
  2062. base.Attack1();
  2063. if (leftDir.x > 0.3f)
  2064. {
  2065. if (bodyTrans.localScale.x > 0)
  2066. {
  2067. Turn();
  2068. }
  2069. SetAttackState(PlayerAttackState.WalkForward);
  2070. }
  2071. else if (leftDir.x < -0.3f)
  2072. {
  2073. if (bodyTrans.localScale.x < 0)
  2074. {
  2075. Turn();
  2076. }
  2077. SetAttackState(PlayerAttackState.WalkForward);
  2078. }
  2079. else
  2080. {
  2081. SetAttackState(PlayerAttackState.Idle);
  2082. }
  2083. }
  2084. public void SetAttackState(PlayerAttackState value)
  2085. {
  2086. attackState = value;
  2087. ani.SetInteger("attackState", (int)value);
  2088. aniCollider.Play("Attack1Keep", 1, 0);
  2089. }
  2090. public void SearchTarget()
  2091. {
  2092. targetCharacter = searchTrigger.GetMinDisTarget(targetTypes, canHitFly);
  2093. }
  2094. public void ChangeSpirit()
  2095. {
  2096. if ((playerId == 0 && SpiritSystem.canP1CardChange) || (playerId == 1 && SpiritSystem.canP2CardChange))
  2097. {
  2098. if (rightDir.x >= 0.5)
  2099. {
  2100. switch (playerId)
  2101. {
  2102. case 0:
  2103. SpiritSystem.P1CardChangeTime = 0;
  2104. SpiritSystem.canP1CardChange = false;
  2105. SpiritSystem.isP1CardChangeR = true;
  2106. break;
  2107. case 1:
  2108. SpiritSystem.P2CardChangeTime = 0;
  2109. SpiritSystem.canP2CardChange = false;
  2110. SpiritSystem.isP2CardChangeR = true;
  2111. break;
  2112. default:
  2113. break;
  2114. }
  2115. }
  2116. else if (rightDir.x <= -0.5)
  2117. {
  2118. switch (playerId)
  2119. {
  2120. case 0:
  2121. SpiritSystem.P1CardChangeTime = 0;
  2122. SpiritSystem.canP1CardChange = false;
  2123. SpiritSystem.isP1CardChangeL = true;
  2124. break;
  2125. case 1:
  2126. SpiritSystem.P2CardChangeTime = 0;
  2127. SpiritSystem.canP2CardChange = false;
  2128. SpiritSystem.isP2CardChangeL = true;
  2129. break;
  2130. default:
  2131. break;
  2132. }
  2133. }
  2134. }
  2135. }
  2136. }