using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class GameDebug : MonoBehaviour { [SerializeField] Slider speedSlider; [SerializeField] Slider distanceSlider; [SerializeField] Text absoluteAngleText; [SerializeField] InputField offsetAngleInput; [SerializeField] Text logText; [SerializeField] GameObject outTip; bool loaded = false; public static GameDebug ins; void Awake() { ins = this; } void Start() { BowCamera.ins.enabled = false; onSlider(); onSlider1(); loaded = true; caluculateAbsoluteAngle(); //增加射程卡 PropInfo propInfo = new PropInfo(); propInfo.id = 22; propInfo.count = 1; propInfo.inuse = true; LoginMgr.myUserInfo.bagList.Add(propInfo); } public void onSlider() { float value = speedSlider.value; speedSlider.GetComponentInChildren().text = "发射速度 " + (value).ToString("#0.00") + "m/s"; Arrow.speed = GameMgr.RealSizeToGameSize(value); caluculateAbsoluteAngle(); } public void onSlider1() { float value = distanceSlider.value; distanceSlider.GetComponentInChildren().text = "靶心距离 " + (value).ToString("#0.00") + "m"; TargetBody target = GameObject.Find("GameArea/010").GetComponentInChildren(); target.SetDistance(value); caluculateAbsoluteAngle(); } public void caluculateAbsoluteAngle() { if (!loaded) return; float mySpeed = Arrow.speed; if (GameAssistUI.ins) { mySpeed *= (1 + GameAssistUI.ins.shootScaleValue); } Vector3 destination = GameObject.Find("GameArea/010").transform.position; Vector3 startPoint = BowCamera.ins.transform.position; float deltaX = Vector2.Distance( new Vector2(destination.x, destination.z), new Vector2(startPoint.x, startPoint.z) ); float deltaY = destination.y - startPoint.y; float a = 0.5f * Physics.gravity.y * Mathf.Pow(deltaX, 2) / Mathf.Pow(mySpeed, 2); float b = deltaX; float c = a - deltaY; bool hasParabolaAngle = Mathf.Pow(b, 2) - 4 * a * c >= 0; if (hasParabolaAngle) { float res1 = (-b + Mathf.Pow(Mathf.Pow(b, 2) - 4*a*c, 0.5f)) / (2 * a); float res2 = (-b - Mathf.Pow(Mathf.Pow(b, 2) - 4*a*c, 0.5f)) / (2 * a); float parabolaAngle = Mathf.Min(Mathf.Atan(res1), Mathf.Atan(res2)) / Mathf.PI * 180; absoluteAngleText.text = "绝对角度: " + parabolaAngle + "°"; outTip.SetActive(Mathf.Abs(parabolaAngle) > 5); } else { absoluteAngleText.text = "绝对角度: " + "无解"; } } private void Log(string text) { logText.text = text; } public float GetOffsetAngle() { float angle = 0; try { angle = float.Parse(offsetAngleInput.text); } catch (System.Exception) { Log("偏移角度解析错误"); } return angle; } public void ShowRes(Vector3 basePoint, Vector3 hitPoint, Vector3 offsetAngle) { basePoint /= 0.7f; hitPoint /= 0.7f; float dis = (hitPoint - basePoint).magnitude / 0.7f; string text = "准心瞄点 " + V3ToString(basePoint) + "\n" + "实际落点 " + V3ToString(hitPoint) + "\n" + "偏移角度 " + V3ToString(offsetAngle) + "\n" + "偏移距离 " + dis.ToString("#0.000") + "m"; Log(text); } public string V3ToString(Vector3 v) { return "(" + v.x.ToString("#0.00") + ", " + v.y.ToString("#0.00") + ", " + v.z.ToString("#0.00") + ")"; } public void deleteAllArrows() { Arrow[] arrows = GameObject.FindObjectsOfType(); foreach (var arrow in arrows) { if (!arrow.hasDoneNextShoot) continue; try { GameObject.Destroy(arrow.gameObject); } catch (UnityException e) { Debug.Log("Delete Arrow Error\n" + e.Message); } } } }