2021-12-22 11:17:21 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using DG.Tweening;
|
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 控制转场黑块
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Blcak : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public enum State{停, 入, 全, 出}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 黑块的目前运行状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Header("状态")][ReadOnly]
|
|
|
|
|
public State state;
|
|
|
|
|
public enum Type{水平, 竖直}
|
|
|
|
|
[Header("类型")]
|
|
|
|
|
public Type tyepe;
|
|
|
|
|
private RectTransform rectTransform;
|
|
|
|
|
|
|
|
|
|
void Start(){
|
|
|
|
|
Init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Init(){
|
|
|
|
|
rectTransform = GetComponent<RectTransform>();
|
|
|
|
|
state = State.停;
|
2021-12-23 01:19:03 +08:00
|
|
|
|
if(FindObjectsOfType<Blcak>().Length > 2) Destroy(rectTransform.parent.gameObject);
|
|
|
|
|
DontDestroyOnLoad(rectTransform.parent.gameObject);
|
2021-12-22 11:17:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnCall(Type type){
|
|
|
|
|
StartCoroutine(Perform(type));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IEnumerator Perform(Type type){
|
|
|
|
|
//修改状态
|
|
|
|
|
state = State.入;
|
|
|
|
|
//执行“入”的Tween动画
|
|
|
|
|
if(type == Type.水平){
|
|
|
|
|
Tweener tweener = rectTransform.DOLocalMoveX(
|
|
|
|
|
0,
|
|
|
|
|
1f
|
|
|
|
|
).OnStepComplete(
|
|
|
|
|
() => {
|
|
|
|
|
state = State.全;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if(type == Type.竖直){
|
|
|
|
|
Tweener tweener = rectTransform.DOLocalMoveY(
|
|
|
|
|
0,
|
|
|
|
|
1f
|
|
|
|
|
).OnStepComplete(
|
|
|
|
|
() => {
|
|
|
|
|
state = State.全;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
yield return new WaitForSeconds(2f);
|
|
|
|
|
//执行“出”的Tween动画
|
|
|
|
|
state = State.出;
|
|
|
|
|
if(type == Type.水平){
|
|
|
|
|
Tweener tweener = rectTransform.DOLocalMoveX(
|
|
|
|
|
-3358,
|
|
|
|
|
1f
|
|
|
|
|
).OnStepComplete(
|
|
|
|
|
() =>{
|
|
|
|
|
//恢复黑块位置
|
|
|
|
|
rectTransform.localPosition = new Vector3(
|
2021-12-23 01:19:03 +08:00
|
|
|
|
1421,-6,0
|
2021-12-22 11:17:21 +08:00
|
|
|
|
);
|
2021-12-23 01:19:03 +08:00
|
|
|
|
//寻找游戏物体“开幕演出”,得到其Stage组件,并开始运行
|
|
|
|
|
GameObject.Find("开幕演出").GetComponent<Stage>().OnCall();
|
|
|
|
|
//恢复黑块状态
|
|
|
|
|
state = State.停;
|
2021-12-22 11:17:21 +08:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if(type == Type.竖直){
|
|
|
|
|
Tweener tweener = rectTransform.DOLocalMoveY(
|
|
|
|
|
2723,
|
|
|
|
|
1f
|
|
|
|
|
).OnStepComplete(
|
|
|
|
|
() =>{
|
|
|
|
|
//恢复黑块位置
|
|
|
|
|
rectTransform.localPosition = new Vector3(
|
|
|
|
|
0,-2722,0
|
|
|
|
|
);
|
2021-12-23 01:19:03 +08:00
|
|
|
|
//寻找游戏物体“开幕演出”,得到其Stage组件,并开始运行
|
|
|
|
|
GameObject.Find("开幕演出").GetComponent<Stage>().OnCall();
|
|
|
|
|
//恢复黑块状态
|
|
|
|
|
state = State.停;
|
2021-12-22 11:17:21 +08:00
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|