fxvDemo.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using TMPro;
  5. using UnityEngine.UI;
  6. using FXV.Internal;
  7. namespace FXV.FogDemo
  8. {
  9. public class fxvDemo : MonoBehaviour
  10. {
  11. [SerializeField]
  12. Image fadeInImage;
  13. [SerializeField]
  14. Text toggleText;
  15. [SerializeField]
  16. GameObject groupTypesRoot;
  17. [SerializeField]
  18. GameObject animationRoot;
  19. [SerializeField]
  20. Light mainLight;
  21. [SerializeField]
  22. Color fogColorLit = Color.white;
  23. [SerializeField]
  24. Color fogColorUnlit = Color.white;
  25. [SerializeField]
  26. GameObject[] cameraObjects;
  27. int currentType = 0;
  28. float fadeT = 1.0f;
  29. bool affectedByLights = true;
  30. void Start()
  31. {
  32. if (toggleText)
  33. {
  34. toggleText.gameObject.SetActive(false);
  35. }
  36. if (fadeInImage)
  37. {
  38. fadeInImage.gameObject.SetActive(true);
  39. fadeInImage.color = Color.black;
  40. fadeT = 1.5f;
  41. }
  42. else
  43. {
  44. fadeT = 0.0f;
  45. }
  46. if (animationRoot && groupTypesRoot)
  47. {
  48. for (int i = 0; i < groupTypesRoot.transform.childCount; i++)
  49. {
  50. fxvFogPresentation fogPres = groupTypesRoot.transform.GetChild(i).GetComponent<fxvFogPresentation>();
  51. fogPres.SetLightsFade(0.0f, false);
  52. }
  53. }
  54. }
  55. public void SetActionTex(string text)
  56. {
  57. if (toggleText)
  58. {
  59. if (text != null)
  60. {
  61. toggleText.gameObject.SetActive(true);
  62. toggleText.text = text;
  63. }
  64. else
  65. {
  66. toggleText.gameObject.SetActive(false);
  67. }
  68. }
  69. }
  70. void Update()
  71. {
  72. if (fadeT > 0.0f)
  73. {
  74. fadeT -= Time.deltaTime;
  75. if (fadeT <= 0.0f)
  76. {
  77. fadeT = 0.0f;
  78. fadeInImage.gameObject.SetActive(false);
  79. }
  80. Color c = Color.black;
  81. c.a = fadeT;
  82. fadeInImage.color = c;
  83. }
  84. if (animationRoot)
  85. {
  86. if (fadeT == 0.0f)
  87. {
  88. Animator anim = animationRoot.GetComponentInChildren<Animator>();
  89. if (!anim.enabled)
  90. {
  91. anim.enabled = true;
  92. groupTypesRoot.transform.GetChild(0).GetComponent<fxvFogPresentation>().SetLightsFade(1.0f, 1.5f);
  93. }
  94. if (Input.GetKeyDown(KeyCode.RightArrow) || anim.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1.0f)
  95. {
  96. NextType();
  97. }
  98. if (Input.GetKeyDown(KeyCode.Space))
  99. {
  100. SwitchLights();
  101. }
  102. }
  103. }
  104. if (cameraObjects != null && cameraObjects.Length > 1)
  105. {
  106. if (Input.GetKeyDown(KeyCode.C))
  107. {
  108. for (int i = 0;i < cameraObjects.Length; ++i)
  109. {
  110. cameraObjects[i].SetActive(!cameraObjects[i].activeSelf);
  111. }
  112. }
  113. }
  114. }
  115. public void SwitchLights()
  116. {
  117. if (groupTypesRoot)
  118. {
  119. affectedByLights = !affectedByLights;
  120. if (mainLight)
  121. {
  122. mainLight.intensity = affectedByLights ? 0.1f : 0.6f;
  123. }
  124. for (int i = 0; i < groupTypesRoot.transform.childCount; i++)
  125. {
  126. fxvFogPresentation fogPres = groupTypesRoot.transform.GetChild(i).GetComponent<fxvFogPresentation>();
  127. fogPres.SetAffectedByLights(affectedByLights);
  128. fogPres.SetFogColor(affectedByLights ? fogColorLit : fogColorUnlit);
  129. }
  130. }
  131. }
  132. public void NextType()
  133. {
  134. if (groupTypesRoot)
  135. {
  136. currentType++;
  137. if (currentType >= groupTypesRoot.transform.childCount)
  138. {
  139. currentType = 0;
  140. }
  141. animationRoot.transform.position = groupTypesRoot.transform.GetChild(currentType).position;
  142. animationRoot.GetComponentInChildren<Animator>().Play("CameraShowcase", -1, 0.0f);
  143. for (int i = 0; i < groupTypesRoot.transform.childCount; i++)
  144. {
  145. fxvFogPresentation fogPres = groupTypesRoot.transform.GetChild(i).GetComponent<fxvFogPresentation>();
  146. if (i == currentType)
  147. {
  148. fogPres.SetLightsFade(1.0f, 1.5f);
  149. }
  150. else
  151. {
  152. fogPres.SetLightsFade(0.0f);
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }