| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Spine;
- using Spine.Unity;
- using UnityEngine.LowLevel;
- using UnityEngine.Playables;
- using System.ComponentModel;
- using Unity.VisualScripting;
- using System;
- using Base.Common;
- using cfg;
- using static UnityEngine.EventSystems.EventTrigger;
- using UnityEngine.InputSystem;
- using TMPro;
- [Serializable]
- public struct AttackInfo
- {
- public int damage;
- public Vector3 attackDir;
- public float force;
- public bool changeHurt;
- public float repelValue;
- }
- public enum PlayerAttackState
- {
- Idle = 0,
- WalkForward = 1,
- WalkBack = 2,
- }
- public class PlayerController : MoveCharacter
- {
- //public static PlayerController instance;
- public List<GameObject> changePrefabs;
- private GameObject spiritObj; //当前变身的对象
- public int endChange = 0;
- //public float changeTime; //变身时长
- //private float pastChangeTime;
- public List<GameObject> demonicPrefabs;
- public List<Vector3> demonicSummonPos;
- public Dictionary<int, List<Demonic>> demonicDic;
- public List<int> demonicId;
- public UIHP uiMp;
- public PlayerRope playerRope;
- public EventTrigger eventTrigger;
- public SprintLinkTrigger sprintLinkTrigger;
- public float jumpSpeed = 10;
- public float airJumpSpeed = 10;
- //public float moveAcc = 5f;
- //public float airMoveAcc = 3f;
- public float rushSpeed = 100;
- public float flySpeed = 5;
- public float mp;
- public float totalMp;
- public float mpReplySpeed = 1;
- public float rushCostMp = 5;
- public float sprintCostMp = 5;
- public float rushInvincibleTime = 0.2f;
- [HideInInspector]
- public float canJumpTime; //离开平台后仍然可以跳跃的时间,用于提升手感
- public float leaveGroundCanJumpTime = 0.1f;
- [HideInInspector]
- public float cacheJumpTime; //即将落地时按下跳跃键不会跳跃,手感不好,缓存几帧,在这几帧内落地会立即跳跃;
- public float totalCacheJumpTime = 0.1f;
- [HideInInspector]
- public float tandemJumpTime; //即将落地时按下跳跃键不会跳跃,手感不好,缓存几帧,在这几帧内落地会立即跳跃;
- public float totalTandemJumpTime = 0.1f;
- [HideInInspector]
- public float summonTime;
- [HideInInspector]
- public float cacheAttackTime; //无法攻击时按下攻击键不会攻击,手感不好,缓存几帧,在这几帧内落地会立即攻击;
- public float totalCacheAttackTime = 0.1f;
- [HideInInspector]
- public float cachePullRopeTime;
- public float totalCachePullRopeTime = 0.1f;
- [HideInInspector]
- public float cacheSummonTime; //无法召唤时按下召唤键不会召唤,手感不好,缓存几帧,在这几帧内落地会立即召唤;
- public float totalCacheSummonTime = 0.1f;
- [HideInInspector]
- public int cacheSummonId;
- [HideInInspector]
- public float rushTime;
- public float totalRushTime = 0.5f;
- [HideInInspector]
- public float cacheRushTime; //无法Rush时按下Rush键不会Rush,手感不好,缓存几帧,在这几帧内落地会立即Rush;
- public float totalCacheRushTime = 0.1f;
- public int airJumped;
- public int jumpNumber = 2; //最大跳跃次数
- public PlayerAttackState attackState;
- public float attackMoveSpeed = 5f;
- public Vector3 rushDir;
- private int currentSpirit; //当前将要召唤的英灵种类
- private Spirits spirits;
- public float lostMp;
- public GameObject soul;
- private float addMp = 10;
- public Collider soulCollector;
- public bool isTransfiguration = false; //已变身
- public Vector2 moveVec; //玩家不动时移动数据
- public float reviveTime; //复活时间
- public float totalReviveTime;
- public bool isBaseBtnOut = false;
- public bool btnJumpPress
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.Space) || isClickBtnJump;
- return isClickBtnJump;
- }
- }
- [HideInInspector]
- public bool isClickBtnJump;
- public bool btnRushPress
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.LeftShift) || isClickBtnRush;
- return isClickBtnRush;
- }
- }
- [HideInInspector]
- public bool isClickBtnRush;
- public bool btnRushKeep
- {
- get
- {
- //return Input.GetKey(KeyCode.LeftShift) || isKeepBtnRush;
- return LBisHold || isKeepBtnRush;
- }
- }
- [HideInInspector]
- public bool isKeepBtnRush;
- public bool btnSouthPress
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.K) || isClickBtnSouth;
- return isClickBtnSouth;
- }
- }
- [HideInInspector]
- public bool isClickBtnSouth;
- public bool btnEastPress
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.L) || isClickBtnEast;
- return isClickBtnEast;
- }
- }
- [HideInInspector]
- public bool isClickBtnEast;
- public bool btnTransfiguratePress
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.L) || isClickBtnEast;
- return isClickBtnTransfigurate;
- }
- }
- [HideInInspector]
- public bool isClickBtnTransfigurate;
- public bool btnWestPress
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.J) || isClickBtnWest;
- return isClickBtnWest;
- }
- }
- [HideInInspector]
- public bool isClickBtnWest;
- public bool btnNorthPress
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
- return isClickBtnNorth;
- }
- }
- [HideInInspector]
- public bool isClickBtnNorth;
- public bool btnSpiritSummon
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
- return isSpiritSummon;
- }
- }
- [HideInInspector]
- public bool isSpiritSummon;
- public bool btnSpiritSummon1
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
- return isSpiritSummon1;
- }
- }
- [HideInInspector]
- public bool isSpiritSummon1;
- public bool btnSpiritSummon2
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
- return isSpiritSummon2;
- }
- }
- [HideInInspector]
- public bool isSpiritSummon2;
- public bool btnSpiritSummon3
- {
- get
- {
- //return Input.GetKeyDown(KeyCode.I) || isClickBtnNorth;
- return isSpiritSummon3;
- }
- }
- [HideInInspector]
- public bool isSpiritSummon3;
- public bool btnNorthKeep
- {
- get
- {
- //return Input.GetKey(KeyCode.I) || isKeepBtnNorth;
- return isKeepBtnNorth;
- }
- }
- [HideInInspector]
- public bool isKeepBtnNorth;
- [HideInInspector]
- public Vector2 leftDir;
- public int playerId;
- public SkeletonMecanim skeletonMecanim;
- public SkeletonDataAsset[] playerSpine;
- public bool canJump;
- public bool canfly;
- //public Vector2 leftDir
- //{
- // get
- // {
- // int x = 0;
- // int y = 0;
- // if (Input.GetKey(KeyCode.A))
- // {
- // x--;
- // }
- // if (Input.GetKey(KeyCode.D))
- // {
- // x++;
- // }
- // if (Input.GetKey(KeyCode.S))
- // {
- // y--;
- // }
- // if (Input.GetKey(KeyCode.W))
- // {
- // y++;
- // }
- // return new Vector2(x, y);
- // }
- //}
- public override void Init()
- {
- base.Init();
- mp = totalMp;
- uiMp.Show(mp, totalMp);
- }
- private void Awake()
- {
- PlayerInput playerInput = transform.GetComponent<PlayerInput>();
- spirits = GetComponent<Spirits>();
- playerId = playerInput.playerIndex;
- transform.position = new Vector3(142 + 4 * playerId, 0, 0);
- playerRope.playerId = playerId;
- sprintLinkTrigger.playerID = playerId;
- if (PlayersInput.instance[1] == PlayersInput.instance[0])
- {
- PlayersInput.instance[1] = this;
- }
- PlayersInput.instance[playerId] = this;
- skeletonMecanim.skeletonDataAsset = playerSpine[playerId];
- switch (playerId)
- {
- case 0:
- SpiritSystem.isP1Out = true;
- SpiritSystem.isP1In = false;
- SpiritSystem.player1 = gameObject;
- SpiritSystem.p1Spirits = GetComponent<Spirits>();
- break;
- case 1:
- SpiritSystem.isP2Out = true;
- SpiritSystem.isP2In = false;
- SpiritSystem.player2 = gameObject;
- SpiritSystem.p2Spirits = GetComponent<Spirits>();
- break;
- default:
- break;
- }
- //else
- //{
- // DestroyImmediate(gameObject);
- // return;
- //}
- demonicDic = new Dictionary<int, List<Demonic>>();
- demonicId = new List<int>() { 0, 0, 0, 0, 0, 0, 0 };
- Init();
- }
- private void Update()
- {
- //if (Input.GetKeyDown(KeyCode.LeftShift))
- //{
- // isClickBtnRush = true;
- //}
- //if (Input.GetKey(KeyCode.LeftShift))
- //{
- // isKeepBtnRush = true;
- //}
- //if (Input.GetKeyDown(KeyCode.Space))
- //{
- // isClickBtnJump = true;
- //}
- //if (Input.GetKeyDown(KeyCode.J))
- //{
- // isClickBtnWest = true;
- //}
- //if (Input.GetKeyDown(KeyCode.K))
- //{
- // isClickBtnSouth = true;
- //}
- //if (Input.GetKeyDown(KeyCode.L))
- //{
- // isClickBtnEast = true;
- //}
- //if (Input.GetKeyDown(KeyCode.I))
- //{
- // isClickBtnNorth = true;
- //}
- if (LBisHold)
- {
- isKeepBtnRush = true;
- }
- if (floatState != 0)
- {
- CharacterFloat();
- }
- /* //到时间自动解除变身
- if (endChange != 0)
- {
- pastChangeTime += Time.deltaTime;
- if (pastChangeTime >= changeTime)
- {
- EndTransfiguration(endChange);
- endChange = 0;
- pastChangeTime = 0;
- }
- }
- */
- if (isTransfiguration)
- {
- bodyTrans.position = spiritObj.transform.position;
- }
- if (isInvisible)
- {
- invisibleTime -= Time.deltaTime;
- if (invisibleTime <= 0)
- {
- isInvisible = false;
- ChangeMat(1);
- }
- }
- }
- void OnSprintingPress()
- {
- LBisHold = true;
- isClickBtnRush = true;
- isKeepBtnRush = true;
- }
- void OnSprintingRelease()
- {
- LBisHold = false;
- }
- //手柄按下LB
- [HideInInspector]
- public bool LBisHold;
- //读取手柄参数
- private void OnMove(InputValue value)
- {
- if (canMove)
- {
- leftDir = value.Get<Vector2>();
- }
- else
- {
- leftDir = Vector3.zero;
- moveVec = value.Get<Vector2>();
- }
- }
- void OnJump()
- {
- if (canJump && canMove)
- {
- isClickBtnJump = true;
- }
- }
- void OnSummon0()
- {
- if (!isFloat && canMove)
- {
- isClickBtnWest = true;
- }
- }
- void OnSummon1()
- {
- if (!isFloat && canMove)
- {
- isClickBtnSouth = true;
- }
- }
- void OnSummon2()
- {
- if (!isFloat && canMove)
- {
- isClickBtnEast = true;
- }
- }
- public int[] needCorpses;
- void OnChooseSpirit() //选英灵
- {
- switch (playerId)
- {
- case 0:
- SpiritSystem.isP1CardChange = true;
- break;
- case 1:
- SpiritSystem.isP2CardChange = true;
- break;
- default:
- break;
- }
- }
- public bool isUltimate; //英灵释放大招
- public bool keyTransfigurateRelease; //松开英灵释放大招键
- void OnTransfigurate() //变身
- {
- if (!isFloat && canMove)
- {
- isClickBtnTransfigurate = true;
- }
- }
- void OnTransfigurateUp() //松开变身键
- {
- if (isTransfiguration)
- {
- keyTransfigurateRelease = true;
- }
- }
- public void Jump()
- {
- SetUpSpeed(jumpSpeed);
- ani.Play("jump", 0, 0);
- }
- public void AirJump()
- {
- SetUpSpeed(airJumpSpeed);
- ani.Play("jump", 0, 0);
- }
- public void SetUpSpeed(float speed)
- {
- ChangeState(CharacterState.Rise);
- Vector3 velocity = rb.velocity;
- CheckTurn();
- velocity.y = speed;
- rb.velocity = velocity;
- //animalAni.SetInteger("state", (int)PlayerState.Rise);
- }
- public bool canTranSummon = true;
- public bool CheckSummon()
- {
- if (cacheSummonTime > 0)
- {
- Summon(cacheSummonId);
- return true;
- }
- if (btnWestPress)
- {
- if (!isBaseBtnOut)
- {
- if (isTransfiguration && !canTranSummon)
- {
- return true;
- }
- Summon(0);
- }
- else
- {
- }
- return true;
- }
- if (btnSouthPress)
- {
- if (isTransfiguration && !canTranSummon)
- {
- return true;
- }
- Summon(1);
- return true;
- }
- if (btnEastPress)
- {
- if (!isBaseBtnOut)
- {
- if (isTransfiguration && !canTranSummon)
- {
- return true;
- }
- Summon(2);
- }
- else
- {
- }
- return true;
- }
- if (btnTransfiguratePress)
- {
- if (!isTransfiguration)
- {
- Transfiguration((int)spirits.currentSpirit + 3);
- }
- else
- {
- isUltimate = true;
- keyTransfigurateRelease = false;
- }
- return true;
- }
- if (isSpiritSummon)
- {
- Transfiguration(3);
- return true;
- }
- if (isSpiritSummon1)
- {
- Transfiguration(4);
- return true;
- }
- if (isSpiritSummon2)
- {
- Transfiguration(5);
- return true;
- }
- if (isSpiritSummon3)
- {
- Transfiguration(6);
- return true;
- }
- return false;
- }
- //角色处于可自由活动状态时的通用切换状态逻辑,如Idle、Run状态,以及别的状态结束时准备回到Idle状态前
- public bool CheckPlayerChangeState(CharacterState excludeState = CharacterState.None)
- {
- if (!foot.TrigGround)
- {
- if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
- {
- if (excludeState != CharacterState.Rush)
- {
- ChangeState(CharacterState.Rush);
- return true;
- }
- }
- if (rb.velocity.y > 0)
- {
- if (excludeState != CharacterState.Rise)
- {
- ChangeState(CharacterState.Rise);
- return true;
- }
- }
- else
- {
- if (excludeState != CharacterState.Fall)
- {
- ChangeState(CharacterState.Fall);
- return true;
- }
- }
- }
- else
- {
- airJumped = 0;
- //if (btnNorthPress || cacheAttackTime > 0)
- //{
- // if (excludeState != CharacterState.Attack)
- // {
- // Attack1();
- // return true;
- // }
- //}
- if (eventTrigger.triggedRivet && (btnNorthPress || cachePullRopeTime > 0))
- {
- if (sprintLinkTrigger.linkedEnemy.Count > 0)
- {
- eventTrigger.triggedRivet.BindingRopes(sprintLinkTrigger.linkedEnemy);
- }
- //ChangeState(CharacterState.PullRope);
- }
- if (excludeState != CharacterState.Summon)
- {
- if (CheckSummon())
- {
- return true;
- }
- }
- if (excludeState != CharacterState.Transfiguration)
- {
- if (CheckSummon())
- {
- return true;
- }
- }
- if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
- {
- if (excludeState != CharacterState.Rush)
- {
- ChangeState(CharacterState.Rush);
- return true;
- }
- }
- if (btnJumpPress || cacheJumpTime > 0)
- {
- if (excludeState != CharacterState.Rise)
- {
- Jump();
- ChangeState(CharacterState.Rise);
- return true;
- }
- }
- if (canfly)
- {
- if (leftDir.x > 0.3f || leftDir.x < -0.3f || leftDir.y > 0.3f || leftDir.y < -0.3f)
- {
- if (excludeState != CharacterState.Run)
- {
- ChangeState(CharacterState.Run);
- return true;
- }
- }
- else
- {
- if (excludeState != CharacterState.Idle)
- {
- ChangeState(CharacterState.Idle);
- return true;
- }
- }
- }
- else
- {
- if (leftDir.x > 0.3f || leftDir.x < -0.3f)
- {
- if (excludeState != CharacterState.Run)
- {
- ChangeState(CharacterState.Run);
- return true;
- }
- }
- else
- {
- if (excludeState != CharacterState.Idle)
- {
- ChangeState(CharacterState.Idle);
- return true;
- }
- }
- }
- }
- return false;
- }
- public override Vector3 GetMoveDir()
- {
- return leftDir;
- }
- public void CachedPlayerInput()
- {
- if (btnRushPress)
- {
- cacheRushTime = totalCacheRushTime;
- }
- if (btnJumpPress)
- {
- cacheJumpTime = totalCacheJumpTime;
- }
- if (btnNorthPress)
- {
- cacheAttackTime = totalCacheAttackTime;
- }
- if (btnWestPress)
- {
- cacheSummonTime = totalCacheSummonTime;
- cacheSummonId = 0;
- }
- if (btnSouthPress)
- {
- cacheSummonTime = totalCacheSummonTime;
- cacheSummonId = 1;
- }
- if (btnEastPress)
- {
- cacheSummonTime = totalCacheSummonTime;
- cacheSummonId = 2;
- }
- if (btnSpiritSummon)
- {
- cacheSummonTime = totalCacheSummonTime;
- cacheSummonId = 3;
- }
- if (btnSpiritSummon1)
- {
- cacheSummonTime = totalCacheSummonTime;
- cacheSummonId = 4;
- }
- if (btnSpiritSummon2)
- {
- cacheSummonTime = totalCacheSummonTime;
- cacheSummonId = 5;
- }
- if (btnSpiritSummon3)
- {
- cacheSummonTime = totalCacheSummonTime;
- cacheSummonId = 6;
- }
- }
- public override void OnState()
- {
- base.OnState();
- hurtKeepTime -= Time.deltaTime;
- cacheJumpTime -= Time.deltaTime;
- cacheAttackTime -= Time.deltaTime;
- cacheSummonTime -= Time.deltaTime;
- canJumpTime -= Time.deltaTime;
- invincibleTime -= Time.deltaTime;
- attackTime -= Time.deltaTime;
- summonTime -= Time.deltaTime;
- rushTime -= Time.deltaTime;
- cacheRushTime -= Time.deltaTime;
- dieKeepTime -= Time.deltaTime;
- weakTime -= Time.deltaTime;
- Vector3 velocity = rb.velocity;
- switch (state)
- {
- case CharacterState.Idle:
- if (CheckPlayerChangeState(CharacterState.Idle))
- {
- break;
- }
- break;
- case CharacterState.Run:
- if (CheckPlayerChangeState(CharacterState.Run))
- {
- break;
- }
- CheckTurn();
- if (canfly)
- {
- rb.velocity = leftDir.normalized * moveSpeed;
- }
- else
- {
- if (leftDir.x > 0.3f)
- {
- rb.velocity = Vector3.right * moveSpeed;
- }
- else if (leftDir.x < -0.3f)
- {
- rb.velocity = Vector3.left * moveSpeed;
- }
- }
- break;
- case CharacterState.Rise:
- if (CheckSummon())
- {
- break;
- }
- if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
- {
- ChangeState(CharacterState.Rush);
- break;
- }
- if (rb.velocity.y <= 0)
- {
- ChangeState(CharacterState.Fall);
- break;
- }
- if (btnJumpPress || cacheJumpTime > 0)
- {
- if (airJumped == 0 && jumpNumber >= 2 && rb.velocity.y < airJumpSpeed)
- {
- airJumped = 1;
- AirJump();
- break;
- }
- if (airJumped == 1 && jumpNumber >= 3 && rb.velocity.y < airJumpSpeed)
- {
- airJumped = 2;
- AirJump();
- break;
- }
- isClickBtnJump = false;
- }
- CachedPlayerInput();
- rb.velocity = AirMove(rb.velocity);
- break;
- case CharacterState.Fall:
- if (CheckSummon())
- {
- break;
- }
- if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
- {
- ChangeState(CharacterState.Rush);
- break;
- }
- if (foot.TrigGround)
- {
- if (CheckPlayerChangeState())
- {
- break;
- }
- }
- //if (foot.canStepPlayers.Count > 0)
- //{
- // Jump(jumpSpeed / 2);
- // StepOther();
- // break;
- //}
- //if (foot.canStepEnemyList.Count > 0)
- //{
- // Jump(jumpSpeed / 2);
- // StepEnemy();
- // break;
- //}
- if (btnJumpPress || cacheJumpTime > 0)
- {
- if (canJumpTime > 0)
- {
- Jump();
- break;
- }
- else
- {
- switch (airJumped)
- {
- case 0:
- if(jumpNumber >= 2)
- {
- airJumped = 1;
- AirJump();
-
- }
- break;
- case 1:
- if(jumpNumber >= 3)
- {
- airJumped = 2;
- AirJump();
- }
- break;
- }
- }
- isClickBtnJump = false;
- }
- CachedPlayerInput();
- rb.velocity = AirMove(rb.velocity);
- break;
- case CharacterState.Hurt:
- if (hurtKeepTime <= 0 && rb.velocity.magnitude < hurtChangeVelocity)
- {
- if (CheckPlayerChangeState())
- {
- break;
- }
- }
- Vector3 vel = rb.velocity;
- if (!foot.TrigGround)
- {
- if (canfly)
- {
- vel.y = vel.y * (1 - decelerationRatio * Time.deltaTime);
- }
- else
- {
- vel += Vector3.up * extraFallGravity * Time.deltaTime;
- }
-
- }
- vel.x = vel.x * (1 - decelerationRatio * Time.deltaTime);
- rb.velocity = vel;
- CachedPlayerInput();
- break;
- case CharacterState.Coma:
- break;
- case CharacterState.Attack:
- if (attackTime <= 0)
- {
- if (btnNorthKeep)
- {
- ChangeState(CharacterState.KeepAttack);
- break;
- }
- if (CheckPlayerChangeState())
- {
- break;
- }
- }
- CachedPlayerInput();
- break;
- case CharacterState.KeepAttack:
- if ((btnRushPress) && mp >= rushCostMp)
- {
- ChangeState(CharacterState.Rush);
- break;
- }
- if (btnJumpPress && canJumpTime > 0)
- {
- Jump();
- break;
- }
- if (!btnNorthKeep)
- {
- if (CheckPlayerChangeState(CharacterState.Attack))
- {
- break;
- }
- }
- switch (attackState)
- {
- case PlayerAttackState.Idle:
- if (bodyTrans.localScale.x > 0)
- {
- if (leftDir.x > 0.3f)
- {
- SetAttackState(PlayerAttackState.WalkBack);
- velocity.x = attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- else if (leftDir.x < -0.3f)
- {
- SetAttackState(PlayerAttackState.WalkForward);
- velocity.x = -attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- }
- else
- {
- if (leftDir.x > 0.3f)
- {
- SetAttackState(PlayerAttackState.WalkForward);
- velocity.x = attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- else if (leftDir.x < -0.3f)
- {
- SetAttackState(PlayerAttackState.WalkBack);
- velocity.x = -attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- }
- velocity.x = 0;
- rb.velocity = velocity;
- break;
- case PlayerAttackState.WalkForward:
- if (bodyTrans.localScale.x > 0)
- {
- if (leftDir.x > 0.3f)
- {
- SetAttackState(PlayerAttackState.WalkBack);
- velocity.x = attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
- {
- SetAttackState(PlayerAttackState.Idle);
- velocity.x = 0;
- rb.velocity = velocity;
- break;
- }
- else
- {
- velocity.x = -attackMoveSpeed;
- rb.velocity = velocity;
- }
- }
- else
- {
- if (leftDir.x < -0.3f)
- {
- SetAttackState(PlayerAttackState.WalkBack);
- velocity.x = -attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
- {
- SetAttackState(PlayerAttackState.Idle);
- velocity.x = 0;
- rb.velocity = velocity;
- break;
- }
- else
- {
- velocity.x = attackMoveSpeed;
- rb.velocity = velocity;
- }
- }
- break;
- case PlayerAttackState.WalkBack:
- if (bodyTrans.localScale.x > 0)
- {
- if (leftDir.x < -0.3f)
- {
- SetAttackState(PlayerAttackState.WalkForward);
- velocity.x = -attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
- {
- SetAttackState(PlayerAttackState.Idle);
- velocity.x = 0;
- rb.velocity = velocity;
- break;
- }
- else
- {
- velocity.x = attackMoveSpeed;
- rb.velocity = velocity;
- }
- }
- else
- {
- if (leftDir.x > 0.3f)
- {
- SetAttackState(PlayerAttackState.WalkForward);
- velocity.x = attackMoveSpeed;
- rb.velocity = velocity;
- break;
- }
- else if (leftDir.x > -0.3f && leftDir.x > 0.3f)
- {
- SetAttackState(PlayerAttackState.Idle);
- velocity.x = 0;
- rb.velocity = velocity;
- break;
- }
- else
- {
- velocity.x = -attackMoveSpeed;
- rb.velocity = velocity;
- }
- }
- break;
- default:
- break;
- }
- break;
- case CharacterState.Summon:
- if (summonTime <= 0)
- {
- if (CheckPlayerChangeState())
- {
- break;
- }
- }
- break;
- case CharacterState.Rush:
- if (rushTime <= 0)
- {
- if (btnRushKeep)
- {
- ChangeState(CharacterState.Sprint);
- break;
- }
- if (CheckPlayerChangeState())
- {
- break;
- }
- }
- CachedPlayerInput();
- //if (leftDir.magnitude < 0.3f)
- //{
- // if (bodyTrans.localScale.x > 0)
- // {
- // rushDir = Vector3.left;
- // }
- // else
- // {
- // rushDir = Vector3.right;
- // }
- //}
- //else
- //{
- // rushDir = leftDir.normalized;
- //}
- rb.velocity = rushDir * rushSpeed;
- break;
- case CharacterState.Sprint:
- if (!btnRushKeep)
- {
- if (CheckPlayerChangeState(CharacterState.Rush))
- {
- break;
- }
- }
- if (mp < sprintCostMp * Time.deltaTime)
- {
- if (CheckPlayerChangeState(CharacterState.Rush))
- {
- break;
- }
- }
- mp -= sprintCostMp * Time.deltaTime;
- uiMp.Show(mp, totalMp);
- CachedPlayerInput();
- //CheckTurn();
- //if (leftDir.magnitude < 0.3f)
- //{
- // if (bodyTrans.localScale.x > 0)
- // {
- // rushDir = Vector3.left;
- // }
- // else
- // {
- // rushDir = Vector3.right;
- // }
- //}
- //else
- //{
- // rushDir = leftDir.normalized;
- //}
- rb.velocity = rushDir * rushSpeed;
- break;
- case CharacterState.Die:
- if (dieKeepTime <= 0)
- {
- if (isRevive)
- {
- reviveTime += Time.deltaTime;
- if(reviveTime >= totalReviveTime)
- {
- PlayerRevive();
- }
- }
- else
- {
- PlayerDie();
- }
- }
- break;
- case CharacterState.Weak:
- if (weakTime <= 0)
- {
- ChangeState(CharacterState.Idle);
- break;
- }
- break;
- case CharacterState.PullRope:
- break;
- default:
- break;
- }
- if (!foot.TrigGround && !canfly)
- {
- if (rb.velocity.y > 0)
- {
- rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
- }
- else
- {
- rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
- }
- }
- isClickBtnRush = false;
- isKeepBtnRush = false;
- isClickBtnJump = false;
- isClickBtnSouth = false;
- isClickBtnEast = false;
- isClickBtnNorth = false;
- isClickBtnWest = false;
- isSpiritSummon = false;
- isSpiritSummon1 = false;
- isSpiritSummon2 = false;
- isSpiritSummon3 = false;
- isClickBtnTransfigurate = false;
- if (foot.TrigGround)
- {
- canJumpTime = leaveGroundCanJumpTime;
- }
- SearchTarget();
- attackTarget = targetCharacter;
- if (isMpRepel && floatState == 0)
- {
- if (mp < totalMp)
- {
- if (!isRapedReply)
- {
- mp += mpReplySpeed * Time.deltaTime;
- }
- else
- {
- mp += rapidReplySpeed * Time.deltaTime;
- }
- }
- }
- if (floatState != 0)
- {
- if (mp > 0)
- {
- lostMp += mpReplySpeed * Time.deltaTime;
- mp -= mpReplySpeed * Time.deltaTime;
- }
- if (lostMp >= addMp)
- {
- Instantiate(soul, transform.position, new Quaternion(0, 0, 0, 0), null);
- lostMp = 0;
- }
- }
- if (mp > totalMp)
- {
- mp = totalMp;
- }
- if (mp < 0)
- {
- mp = 0;
- }
- uiMp.Show(mp, totalMp);
- }
- public void PlayerDie()
- {
- switch (playerId)
- {
- case 0:
- SpiritSystem.isP1In = true;
- SpiritSystem.isP1Out = false;
- break;
- case 1:
- SpiritSystem.isP2In = true;
- SpiritSystem.isP2Out = false;
- break;
- default:
- break;
- }
- bodyTrans.gameObject.SetActive(false);
- uiHp.transform.parent.gameObject.SetActive(false);
- rb.constraints = RigidbodyConstraints.FreezeAll;
- isRevive = true;
- reviveTime = 0;
- }
- public void PlayerRevive()
- {
- bodyTrans.gameObject.SetActive(true);
- uiHp.transform.parent.gameObject.SetActive(true);
- rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
- transform.position = new Vector3(142 + 4 * playerId, 0, 0);
- switch (playerId)
- {
- case 0:
- SpiritSystem.isP1In = false;
- SpiritSystem.isP1Out = true;
- SpiritSystem.player1 = gameObject;
- SpiritSystem.p1Spirits = GetComponent<Spirits>();
- break;
- case 1:
- SpiritSystem.isP2In = false;
- SpiritSystem.isP2Out = true;
- SpiritSystem.player2 = gameObject;
- SpiritSystem.p2Spirits = GetComponent<Spirits>();
- break;
- default:
- break;
- }
- Init();
- }
- public bool isMpRepel = true;
- public float rapidReplySpeed;
- public bool isRapedReply;
- public void RapidReplyMp(float speed)
- {
- rapidReplySpeed = speed;
- isRapedReply = true;
- }
- public void NormalReplyMp()
- {
- isRapedReply = false;
- }
- public override void ChangeState(CharacterState newState)
- {
- if (state == newState)
- {
- return;
- }
- Vector3 velocity = rb.velocity;
- switch (state)
- {
- case CharacterState.Idle:
- break;
- case CharacterState.Run:
- velocity.x = 0;
- break;
- case CharacterState.Rise:
- if (!canFly)
- {
- bodyCollider.SetActive(true);
- }
- break;
- case CharacterState.Fall:
- break;
- case CharacterState.Hurt:
- break;
- case CharacterState.Coma:
- canMove = true;
- foreach (GameObject i in HitCols)
- {
- i.SetActive(true);
- }
- break;
- case CharacterState.Attack:
- aniCollider.Play("NotAttack", 1, 0);
- break;
- case CharacterState.KeepAttack:
- aniCollider.Play("NotAttack", 1, 0);
- break;
- case CharacterState.Summon:
- rb.isKinematic = false;
- break;
- case CharacterState.Transfiguration:
- rb.isKinematic = false;
- break;
- case CharacterState.Rush:
- velocity = Vector3.zero;
- break;
- case CharacterState.Sprint:
- velocity = Vector3.zero;
- break;
- case CharacterState.Die:
- isDie = false;
- break;
- case CharacterState.Weak:
- break;
- default:
- break;
- }
- CharacterState oldState = state;
- state = newState;
- switch (newState)
- {
- case CharacterState.Idle:
- aniCollider.Play("Idle", 0, 0);
- if (oldState == CharacterState.Fall)
- {
- ani.Play("fall_end", 0, 0);
- }
- else
- {
- ani.Play("idle", 0, 0);
- }
- velocity = Vector3.zero;
- //animalAni.SetInteger("state", (int)PlayerState.Idle);
- break;
- case CharacterState.Run:
- aniCollider.Play("Run", 0, 0);
- ani.Play("run_start", 0, 0);
- //animalAni.SetInteger("state", (int)PlayerState.Walk);
- break;
- case CharacterState.Rise:
- aniCollider.Play("Rise", 0, 0);
- canJumpTime = 0;
- break;
- case CharacterState.Fall:
- aniCollider.Play("Fall", 0, 0);
- ani.Play("fall", 0, 0);
- //animalAni.SetInteger("state", (int)PlayerState.Fall);
- break;
- case CharacterState.Hurt:
- aniCollider.Play("Hurt", 0, 0);
- ani.Play("hitted", 0, 0);
- invincibleTime = totalInvincibleTime;
- hurtKeepTime = minHurtKeepTime;
- //ani.Play("Invincible", 2, 0);
- break;
- case CharacterState.Coma:
- //ani.Play("Coma", 0, 0);
- ani.Play("idle", 0, 0);
- aniCollider.Play("Idle", 0, 0);
- rb.velocity = Vector3.zero;
- foreach (GameObject i in HitCols)
- {
- i.SetActive(false);
- }
- break;
- case CharacterState.Attack:
- attackTime = totalAttack1Time;
- break;
- case CharacterState.KeepAttack:
- aniCollider.Play("Attack1Keep", 1, 0);
- break;
- case CharacterState.Summon:
- aniCollider.Play("Summon", 0, 0);
- ani.Play("summon", 0, 0);
- velocity = Vector3.zero;
- rb.isKinematic = true;
- break;
- case CharacterState.Transfiguration:
- isTransfiguration = true;
- aniCollider.Play("Transfiguration", 0, 0);
- ani.Play("transfiguration", 0, 0);
- velocity = Vector3.zero;
- rb.isKinematic = true;
- break;
- case CharacterState.Rush:
- aniCollider.Play("Rush", 0, 0);
- ani.Play("rush_loop", 0, 0);
- rushTime = totalRushTime;
- invincibleTime = rushInvincibleTime;
- //if (leftDir.magnitude < 0.3f)
- //{
- // if (bodyTrans.localScale.x > 0)
- // {
- // rushDir = Vector3.left;
- // }
- // else
- // {
- // rushDir = Vector3.right;
- // }
- //}
- //else
- //{
- // rushDir = leftDir.normalized;
- //}
- if (bodyTrans.localScale.x > 0)
- {
- rushDir = Vector3.left;
- }
- else
- {
- rushDir = Vector3.right;
- }
- velocity = rushDir * rushSpeed;
- mp -= rushCostMp;
- uiMp.Show(mp, totalMp);
- break;
- case CharacterState.Sprint:
- aniCollider.Play("Sprint", 0, 0);
- ani.Play("rush_loop", 0, 0);
- velocity = rushDir * rushSpeed;
- break;
- case CharacterState.Die:
- aniCollider.Play("Die", 0, 0);
- ani.Play("die", 0, 0);
- isDie = true;
- dieKeepTime = totalDieKeepTime;
- break;
- case CharacterState.Weak:
- aniCollider.Play("Weak", 0, 0);
- ani.Play("weak", 0, 0);
- velocity.y = weakUpSpeed;
- weakTime = totalWeakTime;
- break;
- default:
- break;
- }
- rb.velocity = velocity;
- }
- public void CheckTurn()
- {
- if (leftDir.x > 0.3f && bodyTrans.localScale.x > 0)
- {
- Turn();
- }
- else if (leftDir.x < -0.3f && bodyTrans.localScale.x < 0)
- {
- Turn();
- }
- }
- public float maxFlyHeight;
- public Vector3 AirMove(Vector3 velocity)
- {
- CheckTurn();
- if (canfly)
- {
- velocity = leftDir.normalized * flySpeed;
- if (transform.position.y > maxFlyHeight && velocity.y > 0)
- {
- velocity.y = 0;
- }
- }
- else
- {
- if (leftDir.x > 0.3f)
- {
- velocity = new Vector3(moveSpeed, velocity.y, velocity.z);
- }
- else if (leftDir.x < -0.3f)
- {
- velocity = new Vector3(-moveSpeed, velocity.y, velocity.z);
- }
- else
- {
- velocity = new Vector3(0, velocity.y, velocity.z);
- }
- }
- return velocity;
- }
- private Collider playerSoulCollector;
- public void Transfiguration(int id) //变身
- {
- playerSoulCollector = soulCollector;
- id = id - 3;
- currentSpirit = id;
- if (id >= changePrefabs.Count)
- {
- Debug.LogError("未配置" + id + "号变身");
- return;
- }
- GameObject prefab = changePrefabs[id];
- ChangeState(CharacterState.Transfiguration);
- summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
- bodyTrans.gameObject.SetActive(false);
- foot.trigGroundList.Clear();
- spiritObj = PoolManager.Instantiate(prefab);
- Demonic dem = spiritObj.GetComponent<Demonic>();
- dem.id = id;
- dem.playerID = playerId;
- spiritObj.transform.parent = transform;
- spiritObj.transform.localEulerAngles = Vector3.zero;
- spiritObj.transform.localScale = new Vector3(1, 1, 1);
- if (bodyTrans.localScale.x > 0)
- {
- spiritObj.transform.position = transform.position;
- if (dem.bodyTrans.localScale.x < 0)
- {
- dem.Turn();
- }
- }
- else
- {
- spiritObj.transform.position = transform.position;
- if (dem.bodyTrans.localScale.x > 0)
- {
- dem.Turn();
- }
- }
- mecanim = dem.mecanim;
- ani = dem.ani;
- aniCollider = dem.aniCollider;
- bodyTrans = dem.bodyTrans;
- beSearchTrigger = dem.beSearchTrigger;
- bulletPrefab = dem.bulletPrefab;
- searchTrigger = dem.searchTrigger;
- foot = dem.foot;
- spinee = dem.spinee;
- mesh = dem.mesh;
- mats = dem.mats;
- soulCollector = dem.soulCollector;
- outlineMats = dem.outlineMats;
- if (dem.canFly)
- {
- canfly = true;
- canJump = false;
- rb.useGravity = false;
- }
- /* 法师出场释放浮空场
- if (id == 3)
- {
- if ((int)spirits.currentSpirit == 0)
- {
- if (!spiritObj.GetComponent<Demonic>().hasEffect)
- {
- spiritObj.GetComponent<Demonic>().hasEffect = true;
- Instantiate(spirits.floatEffect, spiritObj.transform.position, new Quaternion(0, 0, 0, 0), spiritObj.transform);
- }
- }
- }
- */
- endChange = id + 3;
- dem.hp = hp;
- ChangeState(CharacterState.Idle);
- }
- public bool endTranSummon; //是否在结束变身后召唤英灵
- public void EndTransfiguration(int id)
- {
- isTransfiguration = false;
- canfly = false;
- canJump = true;
- canMove = true;
- rb.useGravity = true;
- mecanim = playerMe;
- ani = playerAni;
- aniCollider = playerCol;
- bodyTrans = playerTran;
- beSearchTrigger = playerBst;
- bulletPrefab = playerBullet;
- searchTrigger = playerST;
- foot = playerFoot;
- spinee = playerSpinee;
- mesh = playerMesh;
- mats = playerMats;
- soulCollector = playerSoulCollector;
- outlineMats = playerOut;
- bodyTrans.gameObject.SetActive(true);
- uiHp.gameObject.SetActive(true);
- spiritObj.transform.parent = null;
- spiritObj.SetActive(false);
- if (endTranSummon)
- {
- Summon(endChange);
- }
- CheckPlayerChangeState();
- endChange = 0;
- }
- public bool canArrowHitFloat; //可以让弓箭手攻击概率漂浮
- public float probability; //攻击的漂浮概率
- public float gainAbilityProbability; //弓箭手获得漂浮能力的概率
- public int abilityTimes; //弓箭手释放漂浮能力的次数
- private bool isFirst = true;
- public void Summon(int id)
- {
- if (id >= demonicPrefabs.Count)
- {
- Debug.LogError("未配置" + id + "号使魔");
- return;
- }
- if (id >= demonicSummonPos.Count)
- {
- Debug.LogError("未配置" + id + "号使魔召唤位置");
- return;
- }
- GameObject prefab = demonicPrefabs[id];
- if (!CheckCanSummon(id))
- {
- return;
- }
- ChangeState(CharacterState.Summon);
- summonTime = prefab.GetComponent<Demonic>().totalSummonTime;
- float costMp = prefab.GetComponent<Demonic>().costMp;
- mp -= costMp;
- uiMp.Show(mp, totalMp);
- GameObject demonicObj = PoolManager.Instantiate(prefab);
- Demonic demonic = demonicObj.GetComponent<Demonic>();
- if (canArrowHitFloat && id == 0)
- {
- float k = UnityEngine.Random.Range(0, 100);
- if (isFirst || k <= gainAbilityProbability)
- {
- isFirst = false;
- demonic.attackToFloat = true;
- demonic.floatProbability = probability;
- demonic.floatTimes = abilityTimes;
- }
- }
- if (id == 2)
- {
- demonic.criticalChance = criticalChance;
- demonic.criticalMultiplier = criticalMultiplier;
- }
- demonic.id = id;
- demonic.playerID = playerId;
- if (!demonicDic.ContainsKey(id))
- {
- demonicDic.Add(id, new List<Demonic>());
- }
- demonicDic[id].Add(demonic);
- demonicObj.transform.parent = null;
- demonicObj.transform.localEulerAngles = Vector3.zero;
- demonicObj.transform.localScale = new Vector3(1, 1, 1);
- Vector3 offset = demonicSummonPos[id];
- if (bodyTrans.localScale.x > 0)
- {
- demonicObj.transform.position = transform.position + offset;
- if (demonic.bodyTrans.localScale.x < 0)
- {
- demonic.Turn();
- }
- }
- else
- {
- demonicObj.transform.position = transform.position + new Vector3(-offset.x, offset.y, offset.z);
- if (demonic.bodyTrans.localScale.x > 0)
- {
- demonic.Turn();
- }
- }
- if (demonic.canFly)
- {
- demonic.flyHeight = demonic.transform.position.y;
- }
- if (id == 3)
- {
- if ((int)spirits.currentSpirit == 0)
- {
- if (!demonicObj.GetComponent<Demonic>().hasEffect)
- {
- demonicObj.GetComponent<Demonic>().hasEffect = true;
- Instantiate(spirits.floatEffect, demonicObj.transform.position, new Quaternion(0, 0, 0, 0), demonicObj.transform);
- }
- }
- }
- demonic.player = this;
- demonic.Init();
- demonic.SetSortingOrder(demonic.sortingOrder + demonicId[id]);
- demonicId[id]++;
- demonic.Attack1();
- }
- public void OnDemonicRecycle(Demonic demonic)
- {
- if (!demonicDic.ContainsKey(demonic.id))
- {
- return;
- }
- demonicDic[demonic.id].Remove(demonic);
- for (int i = 0; i < demonicDic[demonic.id].Count; i++)
- {
- demonicDic[demonic.id][i].SetSortingOrder(demonic.id * 1000 + i);
- }
- }
- public bool CheckCanSummon(int id)
- {
- GameObject prefab = demonicPrefabs[id];
- float costMp = prefab.GetComponent<Demonic>().costMp;
- if (mp < costMp)
- {
- Debug.Log("mp不足召唤失败, 还得加个动画或者音效啥的");
- return false;
- }
- return true;
- }
- public override void Attack1()
- {
- base.Attack1();
- if (leftDir.x > 0.3f)
- {
- if (bodyTrans.localScale.x > 0)
- {
- Turn();
- }
- SetAttackState(PlayerAttackState.WalkForward);
- }
- else if (leftDir.x < -0.3f)
- {
- if (bodyTrans.localScale.x < 0)
- {
- Turn();
- }
- SetAttackState(PlayerAttackState.WalkForward);
- }
- else
- {
- SetAttackState(PlayerAttackState.Idle);
- }
- }
- public void SetAttackState(PlayerAttackState value)
- {
- attackState = value;
- ani.SetInteger("attackState", (int)value);
- aniCollider.Play("Attack1Keep", 1, 0);
- }
- public void SearchTarget()
- {
- targetCharacter = searchTrigger.GetMinDisTarget(targetTypes, canHitFly);
- }
- }
|