using Funly.SkyStudio; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class HeroSceneTestScript : MonoBehaviour { private Vector3 touchOrigin;//按下原点(Input.mousePosition) private float scaleFactor;//Screen 2 Canvas 的转换因子 private bool isDragged = false;//是否正在拖拽 public class heroIndexInfo { public int index; } public TimeOfDayController m_TimeOfDayController; public SkyProfile[] m_SkyProfiles; public Transform[] m_Info; public Transform[] m_SelectedImager; public Button heroState1; public Button heroState2; public Button heroState3; public Button closeBtn; // Start is called before the first frame update void Start() { //EventTriggerListener.Get(heroState1.gameObject).onClick = setTimeOfDayControllerByObject; //EventTriggerListener.Get(heroState2.gameObject).onClick = setTimeOfDayControllerByObject; //EventTriggerListener.Get(heroState3.gameObject).onClick = setTimeOfDayControllerByObject; //EventTriggerListener.Get(closeBtn.gameObject).onClick = CloseScene; } // Update is called once per frame private void Update() { ////按下 //if (Input.GetMouseButtonDown(0)) //{ // TouchDown(); //} ////放开 //if (Input.GetMouseButtonUp(0)) //{ // TouchUp(); //} } private void LateUpdate() { ////拖动 //if (Input.GetMouseButton(0)) //{ // TouchMove(); //} } private void TouchDown() { Vector3 touchPosition = Input.mousePosition; Vector2 touchScreen = new Vector2(touchPosition.x / Screen.width, touchPosition.y / Screen.height); touchOrigin = touchPosition; } private void TouchMove() { Vector3 origin = touchOrigin / scaleFactor; Vector3 now = Input.mousePosition / scaleFactor; float distance = Vector3.Distance(now, origin); if (distance < 0.01f) return; isDragged = true; Debug.Log("1:"+ origin+" 2:" + now+distance.ToString()); } private void TouchUp() { isDragged = false; } public void setTimeOfDayController(int index) { //设置背景色调 m_TimeOfDayController.skyProfile = m_SkyProfiles[index]; //设置属性图标 for(int i=0;i< m_Info.Length; i++) { m_Info[i].gameObject.SetActive(false); } m_Info[index].gameObject.SetActive(true); //设置选中状态 for (int i = 0; i < m_SelectedImager.Length; i++) { m_SelectedImager[i].gameObject.SetActive(false); } m_SelectedImager[index].gameObject.SetActive(true); } public void setTimeOfDayControllerByObject(GameObject obj) { int index = int.Parse(obj.name); --index; //设置背景色调 m_TimeOfDayController.skyProfile = m_SkyProfiles[index]; //设置属性图标 for (int i = 0; i < m_Info.Length; i++) { m_Info[i].gameObject.SetActive(false); } m_Info[index].gameObject.SetActive(true); //设置选中状态 for (int i = 0; i < m_SelectedImager.Length; i++) { m_SelectedImager[i].gameObject.SetActive(false); } m_SelectedImager[index].gameObject.SetActive(true); } public void CloseScene(GameObject obj) { LevelManager.Instance().LoadLevel(E_Level.Main, "UI_BaseMainWindow"); } }