public virtual void Awake() { _jumpStopTimer = JumpStopTime; _patrolStopTimer = PatrolStopTime; _controller = GetComponent <CharacterController2D>(); _animator = GameAnimator.GetInstance(GetComponent <Animator>()); _controller.onControllerCollidedEvent += onControllerCollider; _controller.onTriggerExitEvent += onTriggerEnterEvent; _controller.onTriggerExitEvent += onTriggerExitEvent; CalculateGravityNVelocity(); }
/// <summary> /// 触发函数 /// </summary> /// <param name="self">挂载每个AbstractPerson身上的脚本,也可以识别的东西,这里以后可以换</param> /// <returns></returns> public override void Execute(AbstractPerson self) { //触发器执行具体代码 //这里也可以由延时调用,比如技能开始 0.15s后开始动画/音效/位移, if (self == null) { throw new Exception("SkillCore为空"); } var animator = GameAnimator.GetInstance(self.obj.GetComponent <Animator>()); if (animator == null) { throw new Exception(self.name + "没有Animator组件"); } animator.speed = this.speed * self.AttackSpeed; // Debug.Log("播放动画了"); animator.Play(Animator.StringToHash(this.animationName), AnimationWeight.High); }
public void RunTriggerUnit(IHighFivePerson self, params object[] args) { if (!enable) { return; } this.self = self; if (self == null || !self.IsAlive) { return; } var tempDegree = GetSuitableDegree(self); var dir = new Vector2(Mathf.Cos(Mathf.Deg2Rad * tempDegree), Mathf.Sin(Mathf.Deg2Rad * tempDegree)); MainLoop.Instance.ExecuteLater(() => { switch (type) { #region Effect case TriggerType.Effect: // Debug.Log("技能系统——TriggerType.Effect"); self.PlayAttackEffects(attackEffects); break; #endregion #region Animation case TriggerType.Animation: if (self == null) { throw new Exception("SkillCore为空"); } var animator = GameAnimator.GetInstance(self.gameObject.GetComponent <Animator>()); if (animator == null) { throw new Exception(self.CharacterName + "没有Animator组件"); } animator.speed = this.animationSpeed * self.AttackSpeed; animator.Play(Animator.StringToHash(this.animationName.StringValue), AnimationWeight.High); break; #endregion #region Audio case TriggerType.Audio: if (self.gameObject != null) { AudioMgr.Instance.PlayEffect(this.audioName.StringValue, self.gameObject.transform.position); } break; #endregion #region SingleBullet case TriggerType.SingleBullet: var bulletObj = ResourceMgr.InstantiateGameObject(bulletName.StringValue, GetSuitablePosition(self)); var bullet = bulletObj.GetComponent <SingleBullet>(); if (!bullet) { throw new Exception($"{bulletObj.name}没有DirectBullet组建"); } bullet.initialSpeed = speed * new Vector2(self.Dir * dir.x, dir.y).normalized; bullet.damageScale = damageScale; bullet.gravityScale = gravityScale; bullet.maxLife = maxLife; bullet.Init(self); break; #endregion #region CurvedBullet case TriggerType.CurvedBullet: var curveBulletObj = ResourceMgr.InstantiateGameObject(bulletName.StringValue, self.position + new Vector3(0, 0.3f, 0)); var curveBullet = curveBulletObj.GetComponent <CurvedBullet>(); if (!curveBullet) { throw new Exception($"{curveBulletObj.name}没有curveBulletObj组建"); } curveBullet.aniX = aniX; curveBullet.aniY = aniY; curveBullet.xDir = reverseX ? -self.Dir : self.Dir; curveBullet.yDir = reverseY ? -1 : 1; curveBullet.damageScale = damageScale; curveBullet.gravityScale = gravityScale; curveBullet.maxLife = maxLife; curveBullet.Init(self); break; #endregion #region RayDamage case TriggerType.RayDamage: //面对方向 var position = self.gameObject.transform.position; var p = new Vector2(position.x, position.y); var target = this.rayLength * new Vector2(dir.x * self.Dir, dir.y); //调整身高偏移 p += new Vector2(0, 0.1f * self.gameObject.transform.localScale.y); Debug.DrawLine(p, p + target, Color.red); var results = Physics2D.LinecastAll(p, p + target, this.rayTestLayer); if (results.Length == 0) { return; } foreach (var result in results) { //对打击到的目标进行操作,添加各种效果 var hitPerson = result.transform.gameObject.GetPersonInfo() as IHighFivePerson; if (hitPerson == null) { Debug.Log(result.transform.gameObject); continue; } self.TryAttack(hitPerson); } break; #endregion #region Trigger2D case TriggerType.Trigger2D: if (Mathf.Abs(preLastTime) < 0.01f) { preLastTime = lastTime; } lastTime /= self.AttackSpeed; if (self.gameObject == null) { break; } var sword = self.gameObject.transform.Find(triggerPath.Path); var trigger = sword.GetOrAddComponent <TriggerInputer>(); trigger.onTriggerEnterEvent2D += this.OnTriggerEnter; // Debug.Log("添加监听"); MainLoop.Instance.ExecuteLater(() => { // Debug.Log("移除监听"); trigger.onTriggerEnterEvent2D -= this.OnTriggerEnter; }, lastTime); break; #endregion #region LightSword case TriggerType.LightSword: var swordObj = ResourceMgr.InstantiateGameObject(swordPrefabName.StringValue); var lightSword = swordObj.GetComponent <LightSword>(); if (!lightSword) { throw new Exception($"{swordObj.name}没有LightSword组建"); } lightSword.anchorMode = anchorMode; lightSword.damageScale = damageScale; lightSword.delayTime = delayTime; lightSword.easeType = easeType; lightSword.startSize = startSize; lightSword.targetSize = targetSize; lightSword.widenTime = widenTime; lightSword.HandlePosition = GetSuitablePosition(self); lightSword.RotateDegree = GetSuitableDegree(self); lightSword.Init(self); break; #endregion } }, this.startTime); }
public void RunTriggerUnit(AbstractPerson self) { if (!enable) { return; } this.self = self; MainLoop.Instance.ExecuteLater(() => { // Debug.Log("运行Trigger单元:" + this.type); switch (type) { #region Effect case TriggerType.Effect: Debug.Log("技能系统——TriggerType.Effect"); self.PlayAttackEffects(attackEffects); break; #endregion #region Animation case TriggerType.Animation: if (self == null) { throw new Exception("SkillCore为空"); } var animator = GameAnimator.GetInstance(self.obj.GetComponent <Animator>()); if (animator == null) { throw new Exception(self.CharacterName + "没有Animator组件"); } animator.speed = this.animationSpeed * self.AttackSpeed; animator.Play(Animator.StringToHash(this.animationName.StringValue), AnimationWeight.High); break; #endregion #region Audio case TriggerType.Audio: if (self.obj != null) { AudioMgr.Instance.PlayEffect(this.audioName.Path, self.obj.transform.position); } break; #endregion #region Bullet case TriggerType.Bullet: this.dir = new Vector2(self.Dir * Mathf.Abs(this.dir.x), this.dir.y); new DirectLineBullet(GameMath.Damage(self.BaseAttack), this.dir, self.Pos + new Vector3(0, 0.3f * self.Scanler, 0) , self, this.bulletName.Path, speed: this.bulletSpeed, maxLife: this.maxLife); break; #endregion #region Parabloa case TriggerType.Parabloa: switch (targetType) { case TargetType.Vector3Offset: new ParabloaBullet(this.damage, this.bulletSpeed, this.timeToTarget, self.Pos + offset, self.Pos, self, this.bulletName.Path, this.maxLife); break; case TargetType.GetFromCache: // Debug.Log($"SkillAsset【{skillAsset.skillName.StringValue}】.Vector3Cache:"+skillAsset.Vector3Cache); new ParabloaBullet(this.damage, this.bulletSpeed, this.timeToTarget, skillAsset.Vector3Cache, self.Pos, self, this.bulletName.Path, this.maxLife); break; } break; #endregion #region RayDamage case TriggerType.RayDamage: //面对方向 var position = self.obj.transform.position; var p = new Vector2(position.x, position.y); var target = this.rayLength * self.Scanler * new Vector2(this.dir.x * self.Dir, this.dir.y); //调整身高偏移 p += new Vector2(0, 0.1f * self.obj.transform.localScale.y); Debug.DrawLine(p, p + target, Color.red); var results = Physics2D.LinecastAll(p, p + target, this.rayTestLayer); if (results.Length == 0) { return; } foreach (var result in results) { //对打击到的目标进行操作,添加各种效果 var hitPerson = AbstractPerson.GetInstance(result.transform.gameObject); if (hitPerson == null) { Debug.Log(result.transform.gameObject); continue; } self.OnCauseDamage(GameMath.Damage(self.BaseAttack)); hitPerson.PlayAcceptEffects(self); } break; #endregion #region Trigger2D case TriggerType.Trigger2D: if (Mathf.Abs(preLastTime) < 0.01f) { preLastTime = lastTime; } lastTime /= self.AttackSpeed; if (self.obj == null) { break; } var sword = self.obj.transform.Find(triggerPath); var trigger = (sword.GetComponent <TriggerInputer>() ?? sword.gameObject.AddComponent <TriggerInputer>()); trigger.onTriggerEnterEvent += this.OnTriggerEnter; // Debug.Log("添加监听"); MainLoop.Instance.ExecuteLater(() => { // Debug.Log("移除监听"); trigger.onTriggerEnterEvent -= this.OnTriggerEnter; }, lastTime); break; #endregion } }, this.startTime); }