/// <summary> /// 移动 /// </summary> protected void Move() { float time = Time.fixedTime - mCreateTime; if (time > LifeTime) { EventOnOutOfLifeTime?.Invoke(this); Destroy(gameObject); return; } Vector3 originalPos = mOriginalPos; Vector3 projectilePos = transform.position; Vector3 targetPos = TargetObject.transform.position; Quaternion projectileRotation; bool hit = Const_Trajectory.Move(MoveType, VelocityOrTimeSpend, TrajectoryRotation, Radius, ProjectileRotation, time, ref originalPos, ref projectilePos, out projectileRotation, LaunchPos, targetPos, AlwaysFaceTarget, TimeOfLostControl); EventOnMove?.Invoke(this, mOriginalPos, transform.position, originalPos, projectilePos, projectileRotation); mOriginalPos = originalPos; transform.position = projectilePos; float angle; Vector3 direction; projectileRotation.ToAngleAxis(out angle, out direction); transform.rotation = Quaternion.FromToRotation(Vector3.forward, targetPos - LaunchPos) * Quaternion.Euler(0, 0, angle); Debug.Log(transform.rotation.eulerAngles); if (hit) { if (TargetObject != null) { GameObject lanuch = Instantiate(ImpactEffect, TargetObject.transform.position, transform.rotation); } EventOnHit?.Invoke(this); DestroyImmediate(gameObject); } }
/// <summary> /// 选择渲染 /// </summary> private void OnDrawGizmosSelected() { float time = 0f; Vector3 targetPos = TargetObject == null ? transform.forward.normalized * 10 + transform.position : TargetObject.transform.position; Vector3 newOriginalPos = transform.position; Vector3 newProjectilePos; Quaternion projectileRotation; Const_Trajectory.Move_UpdateProjectilePosAndRotation(TrajectoryRotation, Radius, ProjectileRotation, time, newOriginalPos, out newProjectilePos, out projectileRotation, newOriginalPos, targetPos, AlwaysFaceTarget); Vector3 preOriginalPos = newOriginalPos; Vector3 preProjectilePos = newProjectilePos; bool hit = false; while (!hit) { float debugInterval = time - DebugProjectileTime; if (debugInterval <= 0 && Mathf.Abs(time - DebugProjectileTime) < Time.fixedDeltaTime) { Gizmos.color = Color.green; Gizmos.DrawSphere(newProjectilePos, 0.5f); Vector3 polarAxis = -Vector3.Cross((targetPos - transform.position), Vector3.up).normalized; Vector3 showDirect = (projectileRotation * polarAxis).normalized * 1; Gizmos.DrawLine(newProjectilePos, newProjectilePos + showDirect); } hit = Const_Trajectory.Move(MoveType, VelocityOrTimeSpend, TrajectoryRotation, Radius, ProjectileRotation, time, ref newOriginalPos, ref newProjectilePos, out projectileRotation, transform.position, targetPos, AlwaysFaceTarget, TimeOfLostControl); Gizmos.color = Color.yellow; Gizmos.DrawLine(preOriginalPos, newOriginalPos); Gizmos.color = Color.red; Gizmos.DrawLine(preProjectilePos, newProjectilePos); time += Time.fixedDeltaTime; preOriginalPos = newOriginalPos; preProjectilePos = newProjectilePos; if (time > LifeTime) { break; } } }