You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

348 lines
12 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace Animmal.Animmals1
  6. {
  7. public enum ANIMATORSTYLE { fourlegged, flying, bipedal, human}
  8. [System.Serializable]
  9. public class AssetDB
  10. {
  11. public string Name;
  12. public ANIMATORSTYLE AnimatorStyle;
  13. public SKINS AssetSkins;
  14. public Vector3 Offset;
  15. }
  16. public class PreviewManager : MonoBehaviour
  17. {
  18. #region VARIABLES
  19. [Header("Assets")]
  20. public bool LoopAssets = true;
  21. public List<AssetDB> AssetDB;
  22. public float AssetTransitionTime = 2f;
  23. [Header("Settings")]
  24. public int DefaultFov = 60;
  25. public int MaxZoomOutFov = 90;
  26. public int MinZoominFov = 40;
  27. public int DefaultRotation = -122;
  28. public int MinRotation = -270;
  29. public int MaxRotation = 90;
  30. [Header("SceneSetup")]
  31. public Camera DemoCamera;
  32. public Transform StageCenter;
  33. public Transform RightOffStage;
  34. public Transform LeftOffStage;
  35. [Header("UISetup")]
  36. public Text AssetName;
  37. [Space(5f)]
  38. public Slider RotationSlider;
  39. public Slider ZoomSlider;
  40. public Slider SkinSlider;
  41. public Image BlockerSliders;
  42. public Image BlockerButtons;
  43. [Space(5f)]
  44. public Button Idle;
  45. public Button Idle2;
  46. public Button Idle3;
  47. public Button Walk;
  48. public Button Run;
  49. public Button RunJumpL;
  50. public Button RunJumpR;
  51. public Button Jump;
  52. public Button Wave;
  53. public Button Falling;
  54. public Button Fly;
  55. public Button FlyStart;
  56. public Button FlyEnd;
  57. public Button Attack;
  58. public Button Hit;
  59. public Button Death;
  60. int CurrentItemID = 0;
  61. int CurrentSkinID = 0;
  62. AssetsObject AssetsItem1;
  63. AssetsObject AssetsItem2;
  64. int CurrentObjectOnStage = 0;
  65. bool buttonsLocked;
  66. bool ButtonsLocked
  67. {
  68. get
  69. {
  70. return buttonsLocked;
  71. }
  72. set
  73. {
  74. buttonsLocked = value;
  75. if (value)
  76. {
  77. BlockerSliders.gameObject.SetActive(true);
  78. BlockerButtons.gameObject.SetActive(true);
  79. }
  80. else
  81. {
  82. BlockerSliders.gameObject.SetActive(false);
  83. BlockerButtons.gameObject.SetActive(false);
  84. }
  85. }
  86. }
  87. #endregion
  88. #region SETUP
  89. private void Start()
  90. {
  91. ZoomSlider.minValue = MinZoominFov;
  92. ZoomSlider.maxValue = MaxZoomOutFov;
  93. ZoomSlider.value = DefaultFov;
  94. RotationSlider.minValue = MinRotation;
  95. RotationSlider.maxValue = MaxRotation;
  96. RotationSlider.value = DefaultRotation;
  97. SetupAssetItems();
  98. SetupSkinSlider();
  99. SetupAnimationButtons();
  100. SetupAssetName();
  101. }
  102. void SetupAssetItems()
  103. {
  104. AssetsItem1 = new GameObject().AddComponent<AssetsObject>();
  105. AssetsItem1.gameObject.name = "Assets1";
  106. AssetsItem1.Init(AssetDB);
  107. AssetsItem1.gameObject.transform.eulerAngles = new Vector3(0, DefaultRotation, 0);
  108. AssetsItem1.transform.position = StageCenter.position;
  109. AssetsItem2 = Instantiate(AssetsItem1) as AssetsObject;
  110. AssetsItem2.gameObject.name = "Assets2";
  111. AssetsItem2.transform.position = RightOffStage.position;
  112. AssetsItem2.gameObject.transform.eulerAngles = new Vector3(0, DefaultRotation, 0);
  113. }
  114. void SetupSkinSlider()
  115. {
  116. SkinSlider.maxValue = AssetDB[CurrentItemID].AssetSkins.Skins.Count - 1;
  117. SkinSlider.value = 0;
  118. }
  119. void SetupAssetName()
  120. {
  121. AssetName.text = AssetDB[CurrentItemID].Name.ToUpper() + " - Triangle Count: " + OnStageItem().GetObjectTriangleCount().ToString();
  122. }
  123. void SetupAnimationButtons()
  124. {
  125. switch (AssetDB[CurrentItemID].AnimatorStyle)
  126. {
  127. case ANIMATORSTYLE.fourlegged:
  128. Idle.gameObject.SetActive(true);
  129. Idle2.gameObject.SetActive(true);
  130. Walk.gameObject.SetActive(true);
  131. Run.gameObject.SetActive(true);
  132. Fly.gameObject.SetActive(false);
  133. FlyStart.gameObject.SetActive(false);
  134. FlyEnd.gameObject.SetActive(false);
  135. Attack.gameObject.SetActive(true);
  136. Hit.gameObject.SetActive(true);
  137. Jump.gameObject.SetActive(true);
  138. Idle3.gameObject.SetActive(false);
  139. RunJumpL.gameObject.SetActive(false);
  140. RunJumpR.gameObject.SetActive(false);
  141. Death.gameObject.SetActive(false);
  142. Wave.gameObject.SetActive(false);
  143. Falling.gameObject.SetActive(false);
  144. break;
  145. case ANIMATORSTYLE.flying:
  146. Idle.gameObject.SetActive(true);
  147. Idle2.gameObject.SetActive(false);
  148. Walk.gameObject.SetActive(false);
  149. Run.gameObject.SetActive(false);
  150. Fly.gameObject.SetActive(true);
  151. FlyStart.gameObject.SetActive(true);
  152. FlyEnd.gameObject.SetActive(true);
  153. Attack.gameObject.SetActive(true);
  154. Hit.gameObject.SetActive(true);
  155. Jump.gameObject.SetActive(true);
  156. Idle3.gameObject.SetActive(false);
  157. RunJumpL.gameObject.SetActive(false);
  158. RunJumpR.gameObject.SetActive(false);
  159. Death.gameObject.SetActive(false);
  160. Wave.gameObject.SetActive(false);
  161. Falling.gameObject.SetActive(false);
  162. break;
  163. case ANIMATORSTYLE.bipedal:
  164. Idle.gameObject.SetActive(true);
  165. Idle2.gameObject.SetActive(false);
  166. Walk.gameObject.SetActive(true);
  167. Run.gameObject.SetActive(false);
  168. Fly.gameObject.SetActive(false);
  169. FlyStart.gameObject.SetActive(false);
  170. FlyEnd.gameObject.SetActive(false);
  171. Attack.gameObject.SetActive(true);
  172. Hit.gameObject.SetActive(true);
  173. Jump.gameObject.SetActive(true);
  174. Idle3.gameObject.SetActive(false);
  175. RunJumpL.gameObject.SetActive(false);
  176. RunJumpR.gameObject.SetActive(false);
  177. Death.gameObject.SetActive(false);
  178. Wave.gameObject.SetActive(false);
  179. Falling.gameObject.SetActive(false);
  180. break;
  181. case ANIMATORSTYLE.human:
  182. Idle.gameObject.SetActive(true);
  183. Idle2.gameObject.SetActive(true);
  184. Idle3.gameObject.SetActive(true);
  185. Walk.gameObject.SetActive(true);
  186. Run.gameObject.SetActive(true);
  187. RunJumpL.gameObject.SetActive(true);
  188. RunJumpR.gameObject.SetActive(true);
  189. Death.gameObject.SetActive(true);
  190. Hit.gameObject.SetActive(true);
  191. Attack.gameObject.SetActive(true);
  192. Wave.gameObject.SetActive(true);
  193. Falling.gameObject.SetActive(true);
  194. Fly.gameObject.SetActive(false);
  195. FlyStart.gameObject.SetActive(false);
  196. FlyEnd.gameObject.SetActive(false);
  197. break;
  198. default:
  199. break;
  200. }
  201. }
  202. #endregion
  203. #region BUTTONS
  204. public void LeftClicked()
  205. {
  206. if (ButtonsLocked)
  207. return;
  208. if (CurrentItemID == 0)
  209. {
  210. if (LoopAssets)
  211. CurrentItemID = AssetDB.Count - 1;
  212. else
  213. return;
  214. }
  215. else
  216. CurrentItemID--;
  217. OffStageItem().SetObject(CurrentItemID);
  218. OffStageItem().transform.position = RightOffStage.position;
  219. StartCoroutine(MoveAssets(LeftOffStage.position, RightOffStage.position));
  220. }
  221. public void RightClicked()
  222. {
  223. if (ButtonsLocked)
  224. return;
  225. if (CurrentItemID == AssetDB.Count - 1)
  226. {
  227. if (LoopAssets)
  228. CurrentItemID = 0;
  229. else
  230. return;
  231. }
  232. else
  233. CurrentItemID++;
  234. OffStageItem().SetObject(CurrentItemID);
  235. OffStageItem().transform.position = LeftOffStage.position;
  236. StartCoroutine(MoveAssets(RightOffStage.position, LeftOffStage.position));
  237. }
  238. public void PlayAnimation(string _AnimTrigger)
  239. {
  240. OnStageItem().SetAnimation(_AnimTrigger);
  241. }
  242. public void RotationSliderValueChanged()
  243. {
  244. if (OnStageItem() != null)
  245. OnStageItem().transform.eulerAngles = new Vector3(0, RotationSlider.value, 0);
  246. }
  247. public void ZOOMSliderValueChanged()
  248. {
  249. DemoCamera.fieldOfView = ZoomSlider.value;
  250. }
  251. public void SKINSliderValueChanged()
  252. {
  253. OnStageItem().SetSkin((int)SkinSlider.value);
  254. }
  255. #endregion
  256. #region ASSETMOVEMENT
  257. IEnumerator MoveAssets(Vector3 _OffStageEndPoint, Vector3 _OnStageStartPoint)
  258. {
  259. ButtonsLocked = true;
  260. OffStageItem().transform.eulerAngles = new Vector3(0, DefaultRotation, 0);
  261. float elapsedTime = 0;
  262. Vector3 startingPos = transform.position;
  263. while (elapsedTime < AssetTransitionTime)
  264. {
  265. OnStageItem().transform.position = Mathfx.EasyInOut(StageCenter.position, _OffStageEndPoint, (elapsedTime / AssetTransitionTime));
  266. OffStageItem().transform.position = Mathfx.EasyInOut(_OnStageStartPoint, StageCenter.position, (elapsedTime / AssetTransitionTime));
  267. elapsedTime += Time.deltaTime;
  268. yield return new WaitForEndOfFrame();
  269. }
  270. OnStageItem().transform.position = _OffStageEndPoint;
  271. OnStageItem().transform.eulerAngles = new Vector3(0, DefaultRotation, 0);
  272. OffStageItem().transform.position = StageCenter.position;
  273. RotationSlider.value = -90;
  274. SwitchOnScreenItem();
  275. SetupSkinSlider();
  276. SetupAnimationButtons();
  277. SetupAssetName();
  278. ButtonsLocked = false;
  279. }
  280. AssetsObject OnStageItem()
  281. {
  282. if (CurrentObjectOnStage == 0)
  283. return AssetsItem1;
  284. else
  285. return AssetsItem2;
  286. }
  287. AssetsObject OffStageItem()
  288. {
  289. if (CurrentObjectOnStage == 0)
  290. return AssetsItem2;
  291. else
  292. return AssetsItem1;
  293. }
  294. void SwitchOnScreenItem()
  295. {
  296. if (CurrentObjectOnStage == 0)
  297. CurrentObjectOnStage = 1;
  298. else
  299. CurrentObjectOnStage = 0;
  300. }
  301. #endregion
  302. }
  303. }