123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using GameFramework.Event;
- using UnityGameFramework.Runtime;
- using UnityEngine.Video;
- using System;
- using DG;
- using DG.Tweening;
- public class BuildManager : MonoSingleton<BuildManager>
- {
- public static List<int> unlockbuildList = new List<int>();
- private bool _isPlay = false;
- private VideoPlayer vplayer;
- private float _duration = 0;
- private GameObject cmObj;
- private GameObject mainCm;
- private GameObject uiCm;
- private int unlockBuildId = 0;
- GameObject unlockEffect = null;
- /// <summary>
- /// 完成回调
- /// </summary>
- private Action finishAC = null;
- // private bool first = true;
- ///// <summary>
- /////
- ///// </summary>
- //public static void Init()
- //{
- // Debug.Log("注册建筑解锁消息成功");
- // EventComponent nowEvent = GameEntry.GetComponent<EventComponent>();
- // //nowEvent.Subscribe(BattleEventYLSkillFeatureS.EventId, OnYLSkillFeatureStart);
- // //EventComponent e = GameEntry.GetComponent<EventComponent>();
- // nowEvent.Subscribe(BuildUnlockEvent.EventId, FunUnlockBuild);
- // //unlockbuildList.Add(1002);
- // //unlockbuildList.Add(1000);
- // //unlockbuildList.Add(1001);
- // //unlockbuildList.Add(1003);
- //}
- //public static void FunUnlockBuild(object sender, GameEventArgs e)
- //{
- // BuildUnlockEvent buildunlock = e as BuildUnlockEvent;
- // Debug.Log("获得建筑解锁事件:" + buildunlock.buildId);
- // if (!unlockbuildList.Contains(buildunlock.buildId))
- // {
- // unlockbuildList.Add(buildunlock.buildId);
- // }
- //}
- public static void UnlockBuild(int BuildId)
- {
- if (!unlockbuildList.Contains(BuildId))
- {
- unlockbuildList.Add(BuildId);
- //if (UI_BaseMainWindow.Instance() != null)
- //{
- // UI_BaseMainWindow.Instance().UnlockBuild();
- //}
- }
- }
- public void Update()
- {
- if (_duration > 0)
- {
- _duration -= Time.deltaTime;
- if (_duration <= 0)
- {
- vplayer.gameObject.SetActive(false);
- _duration = 0;
- sm_gate gateMo = null;
- if (GameDateManager.Instance.GateID != 0)
- {
- gateMo = sm_gate.GetMoById(GameDateManager.Instance.GateID);
- }
- if (gateMo != null && ((BattleDefine.EBattleSceneType)int.Parse(gateMo.battleType) ==
- BattleDefine.EBattleSceneType.EBattleType_Safe))
- {
- // UnlockBuild(unlockBuildId);
- }
- if(mainCm)
- {
- mainCm.SetActive(true);
- }
- if (uiCm)
- {
- uiCm.SetActive(true);
- }
- if (cmObj)
- {
- cmObj.SetActive(false);
- }
- if (GameDateManager.Instance.lastBattleType == BattleDefine.EBattleSceneType.EBattleType_Safe)
- {
- PanelHelper.Instance.ShowPanel("UI_BaseMainWindow");
- }
- }
- }
- }
- /// <summary>
- /// 解锁建筑
- /// </summary>
- /// <param name="BuildId">建筑ID</param>
- /// <returns>播放时长</returns>
- public float NewUnlockBuild(int BuildId)
- {
- float playTime = 5;
- mainCm = Camera.main.gameObject;
- uiCm = GameObject.Find("UICamera");
- cmObj = GameObject.Find("ForeverUI").transform.Find("UnlockBuildEffect/Camera").gameObject;
- if (uiCm && mainCm)
- {
- float timer = 0;
- Tween t = DOTween.To(() => timer, x => timer = x, 1, 1.3f)
- .OnStepComplete(() =>
- {
- uiCm.SetActive(false);
- mainCm.SetActive(false);
- })
- .SetLoops(0);
- }
- cmObj.SetActive(true);
- sm_build build = sm_build.GetMoById(BuildId);
- unlockBuildId = BuildId;
- if (!unlockEffect)
- {
- unlockEffect = GameObject.Find("ForeverUI/UnlockBuildEffect");
- }
- vplayer = unlockEffect.transform.Find("VideoPlayer/unlockBuild_" + BuildId.ToString()).GetComponent<VideoPlayer>();
- vplayer.gameObject.SetActive(true);
- vplayer.targetCamera = cmObj.GetComponent<Camera>();
- if(vplayer.frameRate == 0)
- {
- return 0;
- }
- playTime = (float)vplayer.frameCount / vplayer.frameRate;
- _duration = playTime;
- vplayer.Play();
- UnlockBuild(unlockBuildId);
-
- //GameObject cameraObj = GameObject.Find("ForeverUI").transform.Find("Scenes/MainUIBuilder/CameraNode/Main Camera").gameObject;
- //GameObject bgObj = GameObject.Find("ForeverUI").transform.Find("Scenes/MainUIBuilder/BG/LensFlare").gameObject;
- //if (cameraObj)
- //{
- // UnityEngine.Rendering.PostProcessing.PostProcessLayer layer = cameraObj.GetComponent<UnityEngine.Rendering.PostProcessing.PostProcessLayer>();
- // layer.enabled = false;
- //}
- //if(bgObj)
- //{
- // bgObj.SetActive(false);
- //}
- return playTime;
- }
- }
|