Roman 14816a8f30 任务:推进游戏的流程化
场景:【序章-家中】
1.创建脚本【Door】,用来编写门相关
2.创建CG【暂用-战友】
3.优化脚本【CG管理员】,使其可以自动寻找CG,不用再手动拖入
4.优化脚本【ACG】,使其可以应付没有结束事件的CG
5.创建多态【准备出发】
6.创建事件【当播完开门演出】
7.优化一个很重要的基类【一般可交互物体】,使其可以对付排布密集的可交互的情况

下班。至此,完成了序章的流程框架,还有很多细节需要后面扣。明天一定会开始搭建第一关,因为游戏系统之前已经写了大概,应该不会很困难。加油吧。🙏
2021-08-15 01:32:33 +08:00

80 lines
2.6 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;
public class CGAdministrator : MonoBehaviour
{
// Start is called before the first frame update
//CG管理员相关代码
private RawImage rawImage;
[Tooltip("记录这个场景中的所有CG要加的话直接扩容数组并往新的CG里面加内容")][SerializeField][ReadOnly]
private ACG[] CGs;
private IndexRecoder indexRecoder;
private ACG playingCG;//正在播放的CG因为invoke无法传参而存在
void Start()
{
rawImage = GetComponent<RawImage>();
indexRecoder = FindObjectOfType<IndexRecoder>();
rawImage.CrossFadeAlpha(0,0,true);//为了淡入显示必须先把它的阿尔法值降到0对吧
//好像可以让它自己找到所有CG
CGs = new ACG[transform.childCount];
for(int i = 0; i < transform.childCount; i++)
{
CGs[i] = transform.GetChild(i).GetComponent<ACG>();
}
//
}
// 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
playingCG = CG;
Invoke("StopIt",CG.time);
}
}
}
//改变标记使管理员意识到CG该停了
private void StopIt(){rawImage.CrossFadeAlpha(0f,indexRecoder.CGFadeTime,true);//淡出CG
playingCG.OnEnded();}//告诉这个CG它结束了然后触发它的结束事件
//制造一个只读的变量,不要动这些
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);
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
GUI.enabled = false;
EditorGUI.PropertyField(position, property, label, true);
GUI.enabled = true;
}
}
//
}