123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- 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");
- }
- }
|