2021-08-13 00:31:42 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityEditor;
|
2021-08-20 01:24:11 +08:00
|
|
|
|
using UnityEngine.Video;
|
2021-09-10 22:17:49 +08:00
|
|
|
|
using UnityEngine.InputSystem;
|
2021-08-13 00:31:42 +08:00
|
|
|
|
|
|
|
|
|
public class CGAdministrator : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
//CG管理员相关代码
|
|
|
|
|
|
|
|
|
|
private RawImage rawImage;
|
2021-09-07 16:43:58 +08:00
|
|
|
|
[Tooltip("记录这个场景中的所有CG,要加的话直接扩容数组,并往新的CG里面加内容")][SerializeField]
|
2021-08-15 01:32:33 +08:00
|
|
|
|
private ACG[] CGs;
|
2021-08-13 00:31:42 +08:00
|
|
|
|
private IndexRecoder indexRecoder;
|
2021-08-14 01:43:04 +08:00
|
|
|
|
private ACG playingCG;//正在播放的CG,因为invoke无法传参而存在
|
2021-08-13 00:31:42 +08:00
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
rawImage = GetComponent<RawImage>();
|
|
|
|
|
indexRecoder = FindObjectOfType<IndexRecoder>();
|
2021-08-14 01:43:04 +08:00
|
|
|
|
rawImage.CrossFadeAlpha(0,0,true);//为了淡入显示,必须先把它的阿尔法值降到0,对吧?
|
2021-08-15 01:32:33 +08:00
|
|
|
|
|
|
|
|
|
//好像可以让它自己找到所有CG
|
|
|
|
|
CGs = new ACG[transform.childCount];
|
|
|
|
|
for(int i = 0; i < transform.childCount; i++)
|
|
|
|
|
{
|
|
|
|
|
CGs[i] = transform.GetChild(i).GetComponent<ACG>();
|
|
|
|
|
}
|
|
|
|
|
//
|
2021-08-20 01:24:11 +08:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
//CallACG("暂用");
|
|
|
|
|
//
|
2021-08-13 00:31:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//外部呼叫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,indexRecoder.CGFadeTime,true);//淡入显示CG
|
2021-08-14 01:43:04 +08:00
|
|
|
|
playingCG = CG;
|
2021-08-20 01:24:11 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
CG.GetComponent<VideoPlayer>().Play();//开始播放这个CG
|
2021-09-10 22:17:49 +08:00
|
|
|
|
FindObjectOfType<PlayerInput>().SwitchCurrentActionMap("NullMap");//使玩家无法操作
|
2021-08-20 01:24:11 +08:00
|
|
|
|
}
|
|
|
|
|
catch(System.NullReferenceException)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("播放CG失败,看看赋值对不对");
|
|
|
|
|
}
|
2021-08-13 00:31:42 +08:00
|
|
|
|
Invoke("StopIt",CG.time);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//改变标记,使管理员意识到CG该停了
|
2021-08-14 01:43:04 +08:00
|
|
|
|
private void StopIt(){rawImage.CrossFadeAlpha(0f,indexRecoder.CGFadeTime,true);//淡出CG
|
|
|
|
|
playingCG.OnEnded();}//告诉这个CG它结束了,然后触发它的结束事件
|
2021-08-13 00:31:42 +08:00
|
|
|
|
|
2021-09-07 16:43:58 +08:00
|
|
|
|
// //制造一个只读的变量,不要动这些
|
|
|
|
|
// public class ReadOnlyAttribute : PropertyAttribute{}
|
|
|
|
|
// [CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
|
|
|
|
|
// public class ReadOnlyDrawer : PropertyDrawer
|
|
|
|
|
// {
|
|
|
|
|
// public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
|
|
|
|
// {
|
|
|
|
|
// return EditorGUI.GetPropertyHeight(property, label, true);
|
|
|
|
|
// }
|
2021-08-13 00:31:42 +08:00
|
|
|
|
|
2021-09-07 16:43:58 +08:00
|
|
|
|
// public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
|
|
|
// {
|
|
|
|
|
// GUI.enabled = false;
|
|
|
|
|
// EditorGUI.PropertyField(position, property, label, true);
|
|
|
|
|
// GUI.enabled = true;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// //
|
2021-08-13 00:31:42 +08:00
|
|
|
|
|
|
|
|
|
}
|