TimeLine代码代替

323 阅读6分钟

using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.UI;
using Pvr_UnitySDKAPI;

/// <summary>
/// start 10-12 瓦斯突出脚本
/// zq
/// </summary>
public class WaSiTuChuManager : GameManager
{
    public GameObject TheMe;//主题
    public GameObject UITip;//开场白提示界面
    public GameObject UI事故地点概况;//事故地点概况
    public GameObject UI瓦斯突出发生经过;//事故地点概况
    public GameObject UITitle;//事故地点标题
    public GameObject 虫洞;//虫洞
    public GameObject 穿越;//穿越
    public GameObject[] Env;//场景模型,穿越特效
    public GameObject Card;//事故卡片

    //TimeLine动画经过
    public PlayableDirector WaSiTuChuTimeLine;
    private Transform Player;//玩家

    //音频
    public AudioClip StartClip, ShiGuDiDianGaiKuoClip;//开场白  事故地点概况
    private AudioSource AudioTips, AudioBgs;//文字提示播放器

    public GameObject MarkRImage;//黑屏
    public GameObject UIYuanYin;//原因  
    private Button btnBlack;

    public AudioClip insert1Clip;
    public AudioClip insert2Clip;
    public AudioClip insert3Clip;
    private Clips AudioClips;

    private bool 跳过事故地点概况 = false;//是否跳过事故地点概括

    public GameObject UIWork;
    public Sprite[] WorkPrites;//事故地点概况图片
    public AudioClip[] WorkAudioClips;//事故地点概况音频
    public float[] clipcTime;//事故地点播放时间
    bool Insert1 = true, Insert2 = true, Insert3 = true, Insert4 = true;//插入剧情

    public GameObject 详情分析;


    private void Awake()
    {
        Init();
        StartCoroutine(InitGame());
    }

    // Update is called once per frame
    void Update()
    {
        if (跳过事故地点概况 && (Controller.UPvr_GetKeyUp(0, Pvr_KeyCode.TRIGGER) ||
            Controller.UPvr_GetKeyUp(1, Pvr_KeyCode.TRIGGER) ||
            Controller.UPvr_GetKeyUp(0, Pvr_KeyCode.TOUCHPAD) ||
            Controller.UPvr_GetKeyUp(1, Pvr_KeyCode.TOUCHPAD) || Input.GetKeyUp(KeyCode.Space)))
        {
            跳过事故地点概况 = false;
            StopAllCoroutines();
            StartCoroutine(跳过事故概况());
        }

    }

    /// <summary>
    /// 详情分析按钮事件
    /// </summary>
    void OnClick() {
        详情分析.GetChild(0).SetActive(false);
        详情分析.GetChild(1).SetActive(true);

    }
    //场景初始化
    private void Init()
    {
        详情分析.GetChild(0).GetChild(0).GetComponent<Button>().onClick.AddListener(OnClick);

        虫洞.SetActive(false);
        穿越.SetActive(false);
        // Env.Foreach(go_ => go_.SetActive(false));
        AudioBgs = transform.Find("Audio").Find("AudioBgs").GetComponent<AudioSource>();
        AudioTips = transform.Find("Audio").Find("TipsAudio").GetComponent<AudioSource>();
        AudioClips = AudioTips.transform.parent.GetComponent<Clips>();
        Player = GetComponent<RayManager>().HeadStart.parent;

    }

    //开始广播
    IEnumerator InitGame()
    {
       
         //显示火星图片   字带有特效,需设计一下
         TheMe.SetActive(true);
         yield return new WaitForSeconds(3);
         TheMe.SetActive(false);
         //开场白  文字显示用时13s,语调平滑
         UITip.SetActive(true);
         UITip.GetChild(0).GetComponent<Text>().DOText("20141081545分,贵州省某煤矿发生一起煤与瓦斯突出事故,造成13人死亡,5人受伤,直接经济损失2890.8万元。", 16).SetEase(Ease.Linear);
         AudioTips.clip = StartClip;
         AudioTips.Play();
         yield return new WaitForSeconds(16);
         UITip.GetChild(0).GetComponent<Text>().text = "";
         UITip.SetActive(false);
         UITitle.SetActive(true);
         UITitle.GetChild(0).GetComponent<Text>().text = "一、矿井及事故地点概况";
         yield return new WaitForSeconds(1);
         UITitle.GetChild(0).GetComponent<Text>().text = "";
         UITitle.SetActive(false);
         //事故地点
         跳过事故地点概况 = true;
         //显示煤层图片
         UI事故地点概况.SetActive(true);
         UI事故地点概况.GetChild(0).SetActive(true);
         UI事故地点概况.GetChild(0).GetChild(0).SetActive(true);
         UI事故地点概况.GetChild(0).GetChild(1).GetChild(1).GetComponent<Text>().text = "地点概括";
         yield return new WaitForSeconds(0.5f);
         UI事故地点概况.GetChild(0).GetChild(1).SetActive(true);
         UI事故地点概况.GetChild(0).GetChild(1).GetChild(1).SetActive(true);

         yield return new WaitForSeconds(0.5f);
         AudioTips.clip = ShiGuDiDianGaiKuoClip;
         AudioTips.Play();
         UI事故地点概况.GetChild(0).GetChild(1).GetChild(0).SetActive(true);
         UI事故地点概况.GetChild(0).GetChild(1).GetChild(0).GetComponent<Text>()
             .DOText("该煤矿为设计生产能力15万吨 / 年的乡镇生产矿井,201421日,矿井将井下生产承包给某施工队。该矿17号煤层在 + 1350米标高以上,有突出危险性,属煤与瓦斯突出矿井;", 10)
             .SetEase(Ease.Linear);
         yield return new WaitForSeconds(10);
         UI事故地点概况.GetChild(0).GetChild(1).GetChild(0).GetComponent<Text>().text = "";
         UI事故地点概况.GetChild(0).GetChild(1).GetChild(0).SetActive(false);
         //Tip6
         UI事故地点概况.GetChild(0).GetChild(2).SetActive(true);
         yield return new WaitForSeconds(1.5f);
         UI事故地点概况.GetChild(0).GetChild(2).GetChild(2).SetActive(true);
         yield return new WaitForSeconds(1.5f);
         UI事故地点概况.GetChild(0).GetChild(2).GetChild(3).SetActive(true);
         yield return new WaitForSeconds(1.5f);
         UI事故地点概况.GetChild(0).GetChild(2).GetChild(4).SetActive(true);
         yield return new WaitForSeconds(1.5f);
         UI事故地点概况.GetChild(0).GetChild(2).GetChild(5).SetActive(true);
         yield return new WaitForSeconds(1.5f);
         UI事故地点概况.GetChild(0).GetChild(2).GetChild(6).SetActive(true);
         yield return new WaitForSeconds(1.5f);
         UI事故地点概况.GetChild(0).GetChild(1).GetChild(1).GetComponent<Text>().text = "";
         UI事故地点概况.GetChild(0).GetChild(2).GetChild(2).SetActive(false);
         UI事故地点概况.GetChild(0).GetChild(2).GetChild(3).SetActive(false);
         UI事故地点概况.GetChild(0).GetChild(2).GetChild(4).SetActive(false);
         UI事故地点概况.GetChild(0).GetChild(2).GetChild(5).SetActive(false);
         UI事故地点概况.GetChild(0).GetChild(2).GetChild(6).SetActive(false);
         UI事故地点概况.GetChild(0).GetChild(1).GetChild(1).SetActive(false);
         UI事故地点概况.GetChild(0).GetChild(1).SetActive(false);
         UI事故地点概况.GetChild(0).GetChild(2).SetActive(false);

         //UIShiGuDiDianGaiKuang.GetChild(0).GetChild(0).GetChild(0).SetActive(false);
         UI事故地点概况.GetChild(0).GetChild(0).SetActive(false);


         // Env.Foreach(go_ => go_.SetActive(true));

         //工作场景
         UIWork.SetActive(true);
         //前两个  中间夹着提示  之后使用循环
         UIWork.GetChild(0).SetActive(true);//里面放声音
         yield return new WaitForSeconds(2f);
         UIWork.GetChild(1).SetActive(true);//里面放声音
         yield return new WaitForSeconds(2f);

         UIWork.GetChild(3).SetActive(true);//里面放声音
         UIWork.GetChild(3).GetChild(0).GetComponent<Text>().DOText("从20144月起,矿井在未采取任何区域防突措施的情况下在西翼布置2172运输巷和回风巷掘进工作面;并于81日在2172运输巷开掘2172下山。", 2).SetEase(Ease.Linear);
         UIWork.GetChild(2).SetActive(true);//里面放声音
         yield return new WaitForSeconds(2f);

         for (int i = 0; i < 4; i++)
         {
             UIWork.GetChild(i).SetActive(false);
         }
         UIWork.GetChild(4).SetActive(true);//里面放声音
         for (int i = 0; i < WorkPrites.Length; i++)
         {
             yield return StartCoroutine(setImage(WorkPrites[i], WorkAudioClips[i], clipcTime[i]));
         }
         UIWork.SetActive(false);





         UI事故地点概况.GetChild(0).SetActive(false);
         UI事故地点概况.SetActive(false);
         //跳过事故地点
         跳过事故地点概况 = false;

         //事故发生经过
         UITitle.SetActive(true);
         UITitle.GetChild(0).GetComponent<Text>().text = "事故经过";
         yield return new WaitForSeconds(1);
         UI瓦斯突出发生经过.SetActive(true);
         UI瓦斯突出发生经过.GetChild(0).GetChild(0).SetActive(true);

         //TODO位置/色块突显  再来一张图替换放大显示

         UI瓦斯突出发生经过.GetChild(0).GetChild(0).SetActive(false);
         UI瓦斯突出发生经过.SetActive(false);
         UITitle.SetActive(false);
         //提示
         UITip.SetActive(true);
         UITip.GetChild(0).GetComponent<Text>().DOText("108日,十时左右,2172下山当班第一次放炮,循环进尺1米左右;", 5).SetEase(Ease.Linear);
         AudioTips.clip = insert1Clip;
         AudioTips.Play();
         UITip.GetChild(0).GetComponent<Text>().text = "";
         UITip.SetActive(false);
        //事故地点示意图 timeLine
        WaSiTuChuTimeLine.Play();
       
        yield return new WaitForSeconds(1.5f);


        详情分析.SetActive(true);

        详情分析.GetChild(1).SetActive(false);

    }
    IEnumerator setImage(Sprite s, AudioClip a, float time) {
        UIWork.GetChild(4).GetComponent<Image>().sprite = s;
        AudioTips.clip = a;
        AudioTips.Play();
        yield return new WaitForSeconds(time);
    }
    /// <summary>
    /// 剧情引入
    /// </summary>
    /// <param name="s"></param>
    /// <param name="a"></param>
    /// <param name="time"></param>
    /// <returns></returns>
    IEnumerator JuQing(String s, AudioClip a, float time)
    {
        UITip.SetActive(true);
        UITip.GetChild(0).GetComponent<Text>().DOText(s, time).SetEase(Ease.Linear);
        AudioTips.clip = a;
        AudioTips.Play();
        yield return new WaitForSeconds(time);
        UITip.GetChild(0).GetComponent<Text>().text = "";
        UITip.SetActive(false);
    }


    /// <summary>
    /// 收藏卡片
    /// </summary>
    async void CardAction()
    {
        //Card.SetActive(true);
        CardManager.Instance.CardStatue(true);
        await CardManager.Instance.AddEndAction(8);
        Debug.LogError("卡片收集完成");
        CardManager.Instance.CardStatue(false);
        //虫洞
        虫洞.SetActive(true);
        AudioTips.clip = AudioClips.出现虫洞;
        AudioTips.Play();
        AudioBgs.clip = AudioClips.虫洞开启;
        AudioBgs.Play();
    }

    IEnumerator 跳过事故概况()
    {
        AudioTips.Stop();
        UI事故地点概况.GetChild(0).GetChild(1).GetChild(1).GetComponent<Text>().text = "";
        UI事故地点概况.SetActive(false);

        标题提示("事故经过");

        String str = "108日,十时左右,2172下山当班第一次放炮,循环进尺1米左右;";
        yield return StartCoroutine(JuQing(str, insert3Clip, 5));

        WaSiTuChuTimeLine.Play();


    }
    IEnumerator 标题提示(String str)
    {
        UITitle.SetActive(true);
        UITitle.GetChild(0).GetComponent<Text>().text = str;
        yield return new WaitForSeconds(2);
        UITitle.GetChild(0).GetComponent<Image>().DOColor(new Color(0, 0, 0, 0), 2);
        UITitle.GetChild(0).GetComponent<Text>().DOColor(new Color(0, 0, 0, 0), 2);
        yield return new WaitForSeconds(2);
        UITitle.GetChild(0).GetComponent<Image>().DOColor(new Color(0, 0, 0, 1), 0);
        UITitle.GetChild(0).GetComponent<Text>().DOColor(new Color(1, 1, 1, 1), 0);
        UITitle.SetActive(false);
    }

    public override void RayImage(Transform t)
    {
        if (t.GetComponent<Image>())
            t.GetComponent<Image>().color = Color.yellow;
        if (Controller.UPvr_GetKeyUp(0, Pvr_KeyCode.TRIGGER) || Controller.UPvr_GetKeyUp(1, Pvr_KeyCode.TRIGGER) || Controller.UPvr_GetKeyUp(0, Pvr_KeyCode.TOUCHPAD) || Controller.UPvr_GetKeyUp(1, Pvr_KeyCode.TOUCHPAD) || Input.GetKeyUp(KeyCode.Space))
        {
            if (t.name == "jieshao")
            {
                详情分析.GetChild(0).SetActive(false);
            }
            if (t.name == "zhijieyuanyin")
            {
                StartCoroutine(收集());
                详情分析.GetChild(2).SetActive(true);
            }
            if (t.parent.GetComponent<CardManager>())
            {
                t.GetComponent<CardBase>().OnClick();
            }
            if (t.name == "虫洞")
            {
                t.GetComponent<Collider>().enabled = false;
                点击虫洞();
            }
        }
    }
    IEnumerator 收集() 
    {
        //标记成已收集
        UIYuanYin.GetChild(1).SetActive(true);
        yield return new WaitForSeconds(1);
        UIYuanYin.SetActive(false);
        CardAction();
    }
    async void 点击虫洞()
    {
        AudioTips.Stop();
        AudioBgs.clip = AudioClips.穿越虫洞;
        AudioBgs.Play();
        Player.transform.LookAt(虫洞.transform);//玩家面向虫洞
        while (Vector3.Distance(Player.transform.position, 虫洞.transform.position) > 0.1f)//如果玩家的位置与虫洞的距离大于0.1米
        {
            Player.transform.Translate(Vector3.forward * Time.deltaTime * 1);//玩家向前方移动,因为玩家已经面向虫洞了
            await new WaitForUpdate();
        }
        Debug.LogError("移动结束");
        虫洞.SetActive(false);
        Env.Foreach(_ => _.SetActive(false));//隐藏Env数组的所有物体
        穿越.SetActive(true);
        await Task.Delay(6000);
        Debug.LogError("穿越虫洞结束");
        Env.Foreach(_ => _.SetActive(true));//隐藏Env数组的所有物体
        穿越.SetActive(false);
        AudioBgs.Stop();
        WaSiTuChuTimeLine.Play();
    }
    public override void RayImageUp(Transform t)
    {
        if (t.GetComponent<Image>())
            t.GetComponent<Image>().color = Color.white;
    }
}