CangJie/Assets/Scripts//播片系统/CGAdministrator.cs
Roman ab6cfd79a0 任务:搭建场景
1.添加场景1查看绳结仓颉动画
(*:为玩家基类添加功能,public void StopInputUntil(float time);表示接下来多长时间内,无视输入事件。

2.适配了播片系统

3.编写演出:凤凰

好像不能摸鱼了,明天不知道写什么,下班了喵😿
2022-04-02 21:46:10 +08:00

78 lines
2.5 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using UnityEngine.Video;
using UnityEngine.InputSystem;
public class CGAdministrator : UnitySingleton<CGAdministrator>
{
// Start is called before the first frame update
//CG管理员相关代码
private RawImage rawImage;
[Tooltip("记录这个场景中的所有CG要加的话直接扩容数组并往新的CG里面加内容")][SerializeField]
private ACG[] CGs;
private ACG playingCG;//正在播放的CG因为invoke无法传参而存在
void Start()
{
rawImage = GetComponent<RawImage>();
rawImage.CrossFadeAlpha(0,0,true);//为了淡入显示必须先把它的阿尔法值降到0对吧
//把rawImage的颜色的透明度变为0
//rawImage.color = new Color(rawImage.color.r, rawImage.color.g, rawImage.color.b, 1);
//好像可以让它自己找到所有CG
CGs = new ACG[transform.childCount];
for(int i = 0; i < transform.childCount; i++)
{
CGs[i] = transform.GetChild(i).GetComponent<ACG>();
}
//
//
//CallACG("鸟");
//
}
//外部呼叫CG用传入你要调用的CG名
public void CallACG(string CGName)
{
//当外面叫了一个CG传入CG名
foreach(ACG CG in CGs)
{
//找到这个CG
if(CG.CGName.Equals(CGName))
{
Debug.Log("正在显示CG"+CG.name);
rawImage.texture = CG.texture;//把CG的内容装载上
rawImage.CrossFadeAlpha(1,1f,true);//淡入显示CG
playingCG = CG;
try
{
CG.GetComponent<VideoPlayer>().Play();//开始播放这个CG
//FindObjectOfType<PlayerInput>().SwitchCurrentActionMap("NullMap");//使玩家无法操作
}
catch(System.NullReferenceException)
{
Debug.Log("播放CG失败看看赋值对不对");
}
Invoke("StopIt",CG.time);
}
}
}
//改变标记使管理员意识到CG该停了
private void StopIt(){rawImage.CrossFadeAlpha(0f,1f,true);//淡出CG
playingCG.OnEnded();}//告诉这个CG它结束了然后触发它的结束事件
public float GetPlayingCGTime()
{
return playingCG.time;
}
}