| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | using System.Collections; | 
					
						
							|  |  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  |  | using UnityEngine; | 
					
						
							| 
									
										
										
										
											2022-05-24 15:07:04 +00:00
										 |  |  |  | using DG.Tweening; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | public class Arrow : MonoBehaviour | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     [SerializeField] float mSpeed = 50; | 
					
						
							|  |  |  |  |     [SerializeField] GameObject mPfbExplode; | 
					
						
							|  |  |  |  |     [SerializeField] AudioClip mShootSound; | 
					
						
							|  |  |  |  |     [SerializeField] AudioClip mHitSound; | 
					
						
							| 
									
										
										
										
											2022-05-24 15:07:04 +00:00
										 |  |  |  |     [SerializeField] OrbitType mOrbit = OrbitType.Straight;  | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     private int mAtkVal; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private Transform mTrans; | 
					
						
							|  |  |  |  |     //for curve | 
					
						
							| 
									
										
										
										
											2022-05-24 15:07:04 +00:00
										 |  |  |  |     private float mMoveTime = 0f; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     private Vector3 mInitPos = Vector3.zero; | 
					
						
							|  |  |  |  |     private Vector3 mTargetPos = Vector3.zero; | 
					
						
							|  |  |  |  |     private Vector3 mDirection = Vector3.zero; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private WarUnit mTarget = null; | 
					
						
							|  |  |  |  |     private bool mIsActive = false; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void Awake() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         mTrans = transform; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void Update() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         if (!mIsActive) | 
					
						
							|  |  |  |  |             return; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-24 15:07:04 +00:00
										 |  |  |  |         if (mOrbit == OrbitType.Straight) | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-05-24 15:07:04 +00:00
										 |  |  |  |             mTrans.position += Time.deltaTime * mSpeed * mDirection; | 
					
						
							|  |  |  |  |             mMoveTime -= Time.deltaTime; | 
					
						
							|  |  |  |  |             if (mMoveTime <= 0) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 Hit(); | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-24 15:07:04 +00:00
										 |  |  |  |     public void Init(int pAtkVal, Vector3 pInitPos, Vector3 pTargetPos, WarUnit pTarget) | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |         mAtkVal = pAtkVal; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mInitPos = pInitPos; | 
					
						
							|  |  |  |  |         mTargetPos = pTargetPos; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mTrans.position = mInitPos; | 
					
						
							|  |  |  |  |          | 
					
						
							|  |  |  |  |         Vector3 v = mTargetPos - mInitPos; | 
					
						
							|  |  |  |  |         mDirection = v.normalized; | 
					
						
							| 
									
										
										
										
											2022-05-24 15:07:04 +00:00
										 |  |  |  |         mMoveTime = v.magnitude / mSpeed; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         mTarget = pTarget; | 
					
						
							|  |  |  |  |         AudioManager.Instance.PlaySound(mShootSound, 0.6f); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-24 15:07:04 +00:00
										 |  |  |  |         if (mOrbit == OrbitType.Straight) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mTrans.LookAt(mTargetPos); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             Vector3 tHandle = mInitPos + v * 0.5f + Vector3.up * v.magnitude * 0.5f; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-24 15:07:04 +00:00
										 |  |  |  |             Vector3[] tMovePath = BezierUtils.GetBezierListN2(mInitPos, tHandle, mTargetPos, Mathf.RoundToInt(Mathf.Max(5, v.magnitude))); | 
					
						
							|  |  |  |  |             mTrans.DOPath(tMovePath, mMoveTime).SetLookAt(0).SetEase(Ease.Linear).onComplete = Hit; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mIsActive = true; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void Hit() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         if (mPfbExplode != null) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             Instantiate(mPfbExplode, mTargetPos, Quaternion.identity); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         AudioManager.Instance.PlaySound(mHitSound, 0.6f); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mIsActive = false; | 
					
						
							|  |  |  |  |         mTarget.Hurt(mAtkVal); | 
					
						
							|  |  |  |  |         Destroy(gameObject); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-05-24 15:07:04 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | public enum OrbitType | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     Straight, | 
					
						
							|  |  |  |  |     Bezier | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | } |