From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/DragonExpedition/XDragonExpedition.cs | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Client/Assets/Scripts/DragonExpedition/XDragonExpedition.cs (limited to 'Client/Assets/Scripts/DragonExpedition/XDragonExpedition.cs') diff --git a/Client/Assets/Scripts/DragonExpedition/XDragonExpedition.cs b/Client/Assets/Scripts/DragonExpedition/XDragonExpedition.cs new file mode 100644 index 00000000..6461871c --- /dev/null +++ b/Client/Assets/Scripts/DragonExpedition/XDragonExpedition.cs @@ -0,0 +1,90 @@ +using UnityEngine; +using System.Collections; +using XUtliPoolLib; +using System; + +public class XDragonExpedition : MonoBehaviour, IXDragonExpedition +{ + #region 接口 + public void Drag(float delta) + { + MoveCamera(delta); + } + + public void Assign(float delta) + { + AssignCamera(delta); + } + + public Transform GetGO(string name) + { + return transform.Find(name); + } + + public void SetLimitPos(float MinPos) + { + MIN_POS = MinPos; + } + + RaycastHit[] hits = null; + + public GameObject Click() + { + //Vector3 pos = mCamera.ScreenToViewportPoint(Input.mousePosition); + + Ray ray = mCamera.ScreenPointToRay(Input.mousePosition); + + float dist = mCamera.farClipPlane - mCamera.nearClipPlane; + + hits = Physics.RaycastAll(ray, dist); + for (int i = 0; i < hits.Length; ++i) + { + if (hits[i].collider.gameObject.name.StartsWith("building")) + return hits[i].collider.gameObject; + } + + return null; + } + + public Camera GetDragonCamera() + { + return mCamera; + } + + #endregion + + void Start() + { + curPos = mCamera.transform.localPosition; + } + + public Camera mCamera = null; + + public float MoveSpeed = 5; + + public float MIN_POS = 0; + + public float MAX_POS = 100; + + Vector3 curPos = Vector3.zero; + + void MoveCamera(float delta) + { + curPos.x += delta * MoveSpeed; + + if (curPos.x < MIN_POS) curPos.x = MIN_POS; + if (curPos.x > MAX_POS) curPos.x = MAX_POS; + + mCamera.transform.localPosition = curPos; + } + + void AssignCamera(float delta) + { + Vector3 pos = mCamera.transform.localPosition; + pos.x = delta; + if (pos.x < MIN_POS) pos.x = MIN_POS; + if (pos.x > MAX_POS) pos.x = MAX_POS; + curPos.x = pos.x; + mCamera.transform.localPosition = pos; + } +} -- cgit v1.1-26-g67d0