public void PlayAttackAnimation(Vector3 targetPosition) { Vector2 deltaVector = (Vector2)(targetPosition - this.transform.position); CharacterDirection direction = DirectionHelper.GetDirectionFormVector(deltaVector); this.m_SpriteAnimator.Play(this.m_AnimationAttackDict[direction]); }
public virtual void Fire(GameObject target, Vector2 targetPosition) { AudioController.Play(this.m_AttackConfig.AttackSound); GameObject attackObject = GameObject.Instantiate(this.m_AttackConfig.AttackObjectPrefab) as GameObject; AttackObjectBehavior behavior = null; if (this.AttackType == AttackType.Single) { behavior = attackObject.AddComponent <AttackObjectBehavior>(); } else { behavior = attackObject.AddComponent <GroupAttackObjectBehavior>(); } BuildingBasePropertyBehavior property = this.GetComponent <BuildingBasePropertyBehavior>(); Vector2 deltaPosition = property == null ? targetPosition - (Vector2)transform.position : targetPosition - (Vector2)property.AnchorTransform.position; CharacterDirection direction = DirectionHelper.GetDirectionFormVector(deltaPosition); Vector2 offset = Vector2.zero; switch (direction) { case CharacterDirection.Up: { offset = this.m_AttackConfig.AttackUpOffset; } break; case CharacterDirection.Down: { offset = this.m_AttackConfig.AttackDownOffset; } break; case CharacterDirection.Left: { offset = this.m_AttackConfig.AttackLeftOffset; } break; case CharacterDirection.Right: { offset = this.m_AttackConfig.AttackRightOffset; } break; case CharacterDirection.LeftUp: { offset = this.m_AttackConfig.AttackLeftUpOffset; } break; case CharacterDirection.LeftDown: { offset = this.m_AttackConfig.AttackLeftDownOffset; } break; case CharacterDirection.RightUp: { offset = this.m_AttackConfig.AttackRightUpOffset; } break; case CharacterDirection.RightDown: { offset = this.m_AttackConfig.AttackRightDownOffset; } break; } Vector2 firePosition = property == null ? (Vector2)this.transform.position : (Vector2)property.AnchorTransform.position; attackObject.transform.position = new Vector3((firePosition + offset).x, (firePosition + offset).y, 0); behavior.SourceObject = gameObject; behavior.SetDestinationObject(target, targetPosition, firePosition); if (behavior is GroupAttackObjectBehavior) { ((GroupAttackObjectBehavior)behavior).DamageScope = this.m_DamageScope; } behavior.Velocity = this.m_BulletFlySpeed; behavior.Damage = this.AttackValue; behavior.AttackCategory = this.m_AttackCategory; behavior.PushTicks = this.m_PushTicks; behavior.PushVelocity = this.m_PushVelocity; if (this.BulletParent != null) { attackObject.transform.parent = this.BulletParent; } for (int i = 0; i < this.m_AttackConfig.FireEffectPrefabs.Count; i++) { GameObject prefab = this.m_AttackConfig.FireEffectPrefabs[i]; offset = this.m_AttackConfig.FireEffectOffsets[i].GetOffset(direction); GameObject fireEffect = GameObject.Instantiate(prefab) as GameObject; fireEffect.transform.position = property == null ? this.transform.position + new Vector3(offset.x, offset.y, 0) : property.AnchorTransform.position + new Vector3(offset.x, offset.y, 0); fireEffect.transform.parent = BattleObjectCache.Instance.EffectObjectParent.transform; } }
private void CalculateDirection(Vector2 dletaVector) { this.m_Direction = DirectionHelper.GetDirectionFormVector(dletaVector); }
public override void Initialize() { /* * this.m_Criterion = new AnimationCriterion(this.Behavior.MoveAnimation); * * this.Behavior.MoveAnimation.clip.ClearCurves(); * * Vector3 sourcePosition = this.Behavior.SourceObject.transform.position; * Vector3 destinationPosition = this.Behavior.DestinationObject.transform.position; * * float distance = Vector2.Distance(sourcePosition, destinationPosition); * * float moveTime = distance / this.Behavior.Velocity; * * AnimationCurve moveXCurve = AnimationCurve.Linear(0, sourcePosition.x, moveTime, destinationPosition.x); * AnimationCurve moveYCurve = AnimationCurve.Linear(0, sourcePosition.y, moveTime, destinationPosition.y); * AnimationCurve moveZCurve = AnimationCurve.Linear(0, sourcePosition.z, moveTime, destinationPosition.z); * * this.Behavior.MoveAnimation.clip.SetCurve("",typeof(Transform),"localPosition.x",moveXCurve); * this.Behavior.MoveAnimation.clip.SetCurve("",typeof(Transform),"localPosition.y",moveYCurve); * this.Behavior.MoveAnimation.clip.SetCurve("",typeof(Transform),"localPosition.z",moveZCurve); */ Vector3 sourcePosition = this.Behavior.transform.position; Vector3 destinationPosition = this.Behavior.DestinationObject.GetDestinationPosition(this.m_Behavior.transform.position); float distance = Vector2.Distance(new Vector2(destinationPosition.x, destinationPosition.y), new Vector2(sourcePosition.x, sourcePosition.y)); int middleFrames = Mathf.CeilToInt(distance / this.Behavior.Velocity); this.m_MoveVector = (destinationPosition - this.Behavior.transform.position) / middleFrames; this.m_Criterion = new FrameRelatedCriterion(middleFrames); if (this.m_Config.SpriteAnimator.GetClipByName(AnimationNameConstants.MIDDLE) != null) { this.m_Config.SpriteAnimator.Play(AnimationNameConstants.MIDDLE); } else { CharacterDirection direction = DirectionHelper.GetDirectionFormVector(destinationPosition - this.Behavior.transform.position); switch (direction) { case CharacterDirection.Up: { this.m_Config.SpriteAnimator.Play(AnimationNameConstants.MIDDLE_UP); } break; case CharacterDirection.Down: { this.m_Config.SpriteAnimator.Play(AnimationNameConstants.MIDDLE_DOWN); } break; case CharacterDirection.Left: { this.m_Config.SpriteAnimator.Play(AnimationNameConstants.MIDDLE_LEFT); } break; case CharacterDirection.Right: { this.m_Config.SpriteAnimator.Play(AnimationNameConstants.MIDDLE_RIGHT); } break; case CharacterDirection.LeftUp: { this.m_Config.SpriteAnimator.Play(AnimationNameConstants.MIDDLE_LEFT_UP); } break; case CharacterDirection.LeftDown: { this.m_Config.SpriteAnimator.Play(AnimationNameConstants.MIDDLE_LEFT_DOWN); } break; case CharacterDirection.RightUp: { this.m_Config.SpriteAnimator.Play(AnimationNameConstants.MIDDLE_RIGHT_UP); } break; case CharacterDirection.RightDown: { this.m_Config.SpriteAnimator.Play(AnimationNameConstants.MIDDLE_RIGHT_DOWN); } break; } } this.m_CurveCalculator = new CurveCalculator(this.m_Config.CurveG, middleFrames); this.m_CurrentPosition = this.Behavior.transform.position; base.Initialize(); }
private void CalculateTargetPosition(Vector2 sourcePosition, Vector2 targetPosition) { Vector2 offset = Vector2.zero; Vector2 newPosition = (Vector2)targetPosition; if (this.m_TargetConfig != null) { CharacterDirection direction = DirectionHelper.GetDirectionFormVector(newPosition - sourcePosition); switch (direction) { case CharacterDirection.Up: { offset = this.m_TargetConfig.BeAttackedUpOffset; } break; case CharacterDirection.Down: { offset = this.m_TargetConfig.BeAttackedDownOffset; } break; case CharacterDirection.Left: { offset = this.m_TargetConfig.BeAttackedLeftOffset; } break; case CharacterDirection.Right: { offset = this.m_TargetConfig.BeAttackedRightOffset; } break; case CharacterDirection.LeftUp: { offset = this.m_TargetConfig.BeAttackedLeftUpOffset; } break; case CharacterDirection.LeftDown: { offset = this.m_TargetConfig.BeAttackedLeftDownOffset; } break; case CharacterDirection.RightUp: { offset = this.m_TargetConfig.BeAttackedRightUpOffset; } break; case CharacterDirection.RightDown: { offset = this.m_TargetConfig.BeAttackedRightDownOffset; } break; } } this.m_CalculatedDestinationPosition = newPosition + offset; this.m_PreviousCalculatedObjectPosition = this.m_Target.transform.position; }