HeroSceneTestScript.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using Funly.SkyStudio;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class HeroSceneTestScript : MonoBehaviour
  7. {
  8. private Vector3 touchOrigin;//按下原点(Input.mousePosition)
  9. private float scaleFactor;//Screen 2 Canvas 的转换因子
  10. private bool isDragged = false;//是否正在拖拽
  11. public class heroIndexInfo
  12. {
  13. public int index;
  14. }
  15. public TimeOfDayController m_TimeOfDayController;
  16. public SkyProfile[] m_SkyProfiles;
  17. public Transform[] m_Info;
  18. public Transform[] m_SelectedImager;
  19. public Button heroState1;
  20. public Button heroState2;
  21. public Button heroState3;
  22. public Button closeBtn;
  23. // Start is called before the first frame update
  24. void Start()
  25. {
  26. //EventTriggerListener.Get(heroState1.gameObject).onClick = setTimeOfDayControllerByObject;
  27. //EventTriggerListener.Get(heroState2.gameObject).onClick = setTimeOfDayControllerByObject;
  28. //EventTriggerListener.Get(heroState3.gameObject).onClick = setTimeOfDayControllerByObject;
  29. //EventTriggerListener.Get(closeBtn.gameObject).onClick = CloseScene;
  30. }
  31. // Update is called once per frame
  32. private void Update()
  33. {
  34. ////按下
  35. //if (Input.GetMouseButtonDown(0))
  36. //{
  37. // TouchDown();
  38. //}
  39. ////放开
  40. //if (Input.GetMouseButtonUp(0))
  41. //{
  42. // TouchUp();
  43. //}
  44. }
  45. private void LateUpdate()
  46. {
  47. ////拖动
  48. //if (Input.GetMouseButton(0))
  49. //{
  50. // TouchMove();
  51. //}
  52. }
  53. private void TouchDown()
  54. {
  55. Vector3 touchPosition = Input.mousePosition;
  56. Vector2 touchScreen = new Vector2(touchPosition.x / Screen.width, touchPosition.y / Screen.height);
  57. touchOrigin = touchPosition;
  58. }
  59. private void TouchMove()
  60. {
  61. Vector3 origin = touchOrigin / scaleFactor;
  62. Vector3 now = Input.mousePosition / scaleFactor;
  63. float distance = Vector3.Distance(now, origin);
  64. if (distance < 0.01f)
  65. return;
  66. isDragged = true;
  67. Debug.Log("1:"+ origin+" 2:" + now+distance.ToString());
  68. }
  69. private void TouchUp()
  70. {
  71. isDragged = false;
  72. }
  73. public void setTimeOfDayController(int index)
  74. {
  75. //设置背景色调
  76. m_TimeOfDayController.skyProfile = m_SkyProfiles[index];
  77. //设置属性图标
  78. for(int i=0;i< m_Info.Length; i++)
  79. {
  80. m_Info[i].gameObject.SetActive(false);
  81. }
  82. m_Info[index].gameObject.SetActive(true);
  83. //设置选中状态
  84. for (int i = 0; i < m_SelectedImager.Length; i++)
  85. {
  86. m_SelectedImager[i].gameObject.SetActive(false);
  87. }
  88. m_SelectedImager[index].gameObject.SetActive(true);
  89. }
  90. public void setTimeOfDayControllerByObject(GameObject obj)
  91. {
  92. int index = int.Parse(obj.name);
  93. --index;
  94. //设置背景色调
  95. m_TimeOfDayController.skyProfile = m_SkyProfiles[index];
  96. //设置属性图标
  97. for (int i = 0; i < m_Info.Length; i++)
  98. {
  99. m_Info[i].gameObject.SetActive(false);
  100. }
  101. m_Info[index].gameObject.SetActive(true);
  102. //设置选中状态
  103. for (int i = 0; i < m_SelectedImager.Length; i++)
  104. {
  105. m_SelectedImager[i].gameObject.SetActive(false);
  106. }
  107. m_SelectedImager[index].gameObject.SetActive(true);
  108. }
  109. public void CloseScene(GameObject obj)
  110. {
  111. LevelManager.Instance().LoadLevel(E_Level.Main, "UI_BaseMainWindow");
  112. }
  113. }