BuildManager.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using GameFramework.Event;
  5. using UnityGameFramework.Runtime;
  6. using UnityEngine.Video;
  7. using System;
  8. using DG;
  9. using DG.Tweening;
  10. public class BuildManager : MonoSingleton<BuildManager>
  11. {
  12. public static List<int> unlockbuildList = new List<int>();
  13. private bool _isPlay = false;
  14. private VideoPlayer vplayer;
  15. private float _duration = 0;
  16. private GameObject cmObj;
  17. private GameObject mainCm;
  18. private GameObject uiCm;
  19. private int unlockBuildId = 0;
  20. GameObject unlockEffect = null;
  21. /// <summary>
  22. /// 完成回调
  23. /// </summary>
  24. private Action finishAC = null;
  25. // private bool first = true;
  26. ///// <summary>
  27. /////
  28. ///// </summary>
  29. //public static void Init()
  30. //{
  31. // Debug.Log("注册建筑解锁消息成功");
  32. // EventComponent nowEvent = GameEntry.GetComponent<EventComponent>();
  33. // //nowEvent.Subscribe(BattleEventYLSkillFeatureS.EventId, OnYLSkillFeatureStart);
  34. // //EventComponent e = GameEntry.GetComponent<EventComponent>();
  35. // nowEvent.Subscribe(BuildUnlockEvent.EventId, FunUnlockBuild);
  36. // //unlockbuildList.Add(1002);
  37. // //unlockbuildList.Add(1000);
  38. // //unlockbuildList.Add(1001);
  39. // //unlockbuildList.Add(1003);
  40. //}
  41. //public static void FunUnlockBuild(object sender, GameEventArgs e)
  42. //{
  43. // BuildUnlockEvent buildunlock = e as BuildUnlockEvent;
  44. // Debug.Log("获得建筑解锁事件:" + buildunlock.buildId);
  45. // if (!unlockbuildList.Contains(buildunlock.buildId))
  46. // {
  47. // unlockbuildList.Add(buildunlock.buildId);
  48. // }
  49. //}
  50. public static void UnlockBuild(int BuildId)
  51. {
  52. if (!unlockbuildList.Contains(BuildId))
  53. {
  54. unlockbuildList.Add(BuildId);
  55. //if (UI_BaseMainWindow.Instance() != null)
  56. //{
  57. // UI_BaseMainWindow.Instance().UnlockBuild();
  58. //}
  59. }
  60. }
  61. public void Update()
  62. {
  63. if (_duration > 0)
  64. {
  65. _duration -= Time.deltaTime;
  66. if (_duration <= 0)
  67. {
  68. vplayer.gameObject.SetActive(false);
  69. _duration = 0;
  70. sm_gate gateMo = null;
  71. if (GameDateManager.Instance.GateID != 0)
  72. {
  73. gateMo = sm_gate.GetMoById(GameDateManager.Instance.GateID);
  74. }
  75. if (gateMo != null && ((BattleDefine.EBattleSceneType)int.Parse(gateMo.battleType) ==
  76. BattleDefine.EBattleSceneType.EBattleType_Safe))
  77. {
  78. // UnlockBuild(unlockBuildId);
  79. }
  80. if(mainCm)
  81. {
  82. mainCm.SetActive(true);
  83. }
  84. if (uiCm)
  85. {
  86. uiCm.SetActive(true);
  87. }
  88. if (cmObj)
  89. {
  90. cmObj.SetActive(false);
  91. }
  92. if (GameDateManager.Instance.lastBattleType == BattleDefine.EBattleSceneType.EBattleType_Safe)
  93. {
  94. PanelHelper.Instance.ShowPanel("UI_BaseMainWindow");
  95. }
  96. }
  97. }
  98. }
  99. /// <summary>
  100. /// 解锁建筑
  101. /// </summary>
  102. /// <param name="BuildId">建筑ID</param>
  103. /// <returns>播放时长</returns>
  104. public float NewUnlockBuild(int BuildId)
  105. {
  106. float playTime = 5;
  107. mainCm = Camera.main.gameObject;
  108. uiCm = GameObject.Find("UICamera");
  109. cmObj = GameObject.Find("ForeverUI").transform.Find("UnlockBuildEffect/Camera").gameObject;
  110. if (uiCm && mainCm)
  111. {
  112. float timer = 0;
  113. Tween t = DOTween.To(() => timer, x => timer = x, 1, 1.3f)
  114. .OnStepComplete(() =>
  115. {
  116. uiCm.SetActive(false);
  117. mainCm.SetActive(false);
  118. })
  119. .SetLoops(0);
  120. }
  121. cmObj.SetActive(true);
  122. sm_build build = sm_build.GetMoById(BuildId);
  123. unlockBuildId = BuildId;
  124. if (!unlockEffect)
  125. {
  126. unlockEffect = GameObject.Find("ForeverUI/UnlockBuildEffect");
  127. }
  128. vplayer = unlockEffect.transform.Find("VideoPlayer/unlockBuild_" + BuildId.ToString()).GetComponent<VideoPlayer>();
  129. vplayer.gameObject.SetActive(true);
  130. vplayer.targetCamera = cmObj.GetComponent<Camera>();
  131. if(vplayer.frameRate == 0)
  132. {
  133. return 0;
  134. }
  135. playTime = (float)vplayer.frameCount / vplayer.frameRate;
  136. _duration = playTime;
  137. vplayer.Play();
  138. UnlockBuild(unlockBuildId);
  139. //GameObject cameraObj = GameObject.Find("ForeverUI").transform.Find("Scenes/MainUIBuilder/CameraNode/Main Camera").gameObject;
  140. //GameObject bgObj = GameObject.Find("ForeverUI").transform.Find("Scenes/MainUIBuilder/BG/LensFlare").gameObject;
  141. //if (cameraObj)
  142. //{
  143. // UnityEngine.Rendering.PostProcessing.PostProcessLayer layer = cameraObj.GetComponent<UnityEngine.Rendering.PostProcessing.PostProcessLayer>();
  144. // layer.enabled = false;
  145. //}
  146. //if(bgObj)
  147. //{
  148. // bgObj.SetActive(false);
  149. //}
  150. return playTime;
  151. }
  152. }