FM/Assets/ABigFile/XLZ/Scripts/Book_M.cs

202 lines
5.0 KiB
C#
Raw Normal View History

2025-06-17 09:31:12 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
2025-07-08 22:07:35 +08:00
using Runtime;
2025-06-17 09:31:12 +08:00
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Serialization;
2025-07-08 22:07:35 +08:00
using ZGame;
2025-06-17 09:31:12 +08:00
public class Book_M : MonoBehaviour
{
2025-07-08 22:07:35 +08:00
[SerializeField] private PlayableDirector playable;
[SerializeField] List<float> times = new List<float>();
[SerializeField] int number = 0;
2025-06-17 09:31:12 +08:00
public List<Renderer> renders = new List<Renderer>();
2025-07-08 22:07:35 +08:00
2025-06-17 09:31:12 +08:00
public Renderer[] insideRenders;
public Renderer box5;
2025-07-08 22:07:35 +08:00
private void Awake()
{
EventManager.Instance.Subscribe(ProductIsShowDesignCoverEventArgs.EventId, ProductIsShowDesignCoverEvent);
}
private void OnDestroy()
{
EventManager.Instance.Unsubscribe(ProductIsShowDesignCoverEventArgs.EventId, ProductIsShowDesignCoverEvent);
}
private void ProductIsShowDesignCoverEvent(object sender, GameEventArgs e)
{
var args = e as ProductIsShowDesignCoverEventArgs;
box5.enabled = !args.isShow;
}
// Update is number - 1 once per frame
2025-06-17 09:31:12 +08:00
void Update()
{
#if UNITY_EDITOR
if (Input.GetKeyDown(KeyCode.A))
{
// Next();
}
2025-07-08 22:07:35 +08:00
2025-06-17 09:31:12 +08:00
if (Input.GetKeyDown(KeyCode.D))
{
2025-07-08 22:07:35 +08:00
// Last();
2025-06-17 09:31:12 +08:00
}
#endif
}
public void SetIndex(int ind)
{
StopAllCoroutines();
2025-07-08 22:07:35 +08:00
if (number == 4 && (ind == 2 || ind == 1))
2025-06-17 09:31:12 +08:00
{
this.number = ind;
2025-07-08 22:07:35 +08:00
StartCoroutine(PlayNext(1));
return;
2025-06-17 09:31:12 +08:00
}
2025-07-08 22:07:35 +08:00
if (this.number < ind) // 1 3 4
2025-06-17 09:31:12 +08:00
{
this.number = ind;
if (ind == 4)
StartCoroutine(PlayCloseBook());
2025-07-08 22:07:35 +08:00
else if (ind == 3)
2025-06-17 09:31:12 +08:00
StartCoroutine(PlayNext(2));
2025-07-08 22:07:35 +08:00
else if (ind == 1)
2025-06-17 09:31:12 +08:00
StartCoroutine(PlayNext(1));
}
2025-07-08 22:07:35 +08:00
else if (this.number > ind) // 0 2 3
2025-06-17 09:31:12 +08:00
{
this.number = ind;
if (ind == 3)
StartCoroutine(PlayOpenBook());
2025-07-08 22:07:35 +08:00
else if (ind == 2 || ind == 1)
2025-06-17 09:31:12 +08:00
StartCoroutine(PlayLast(1));
2025-07-08 22:07:35 +08:00
else if (ind == 0)
2025-06-17 09:31:12 +08:00
StartCoroutine(PlayLast(0));
}
}
// public void Next()
// {
// StopAllCoroutines();
// StartCoroutine(PlayNext());
// }
//
// public void Last()
// {
// StopAllCoroutines();
// StartCoroutine(PlayLast());
// }
//
// public void CloseBook()
// {
// StopAllCoroutines();
// StartCoroutine(PlayCloseBook());
// }
2025-07-08 22:07:35 +08:00
2025-06-17 09:31:12 +08:00
public void ChangeTexture(Texture tex)
{
2025-07-08 22:07:35 +08:00
foreach (var rend in renders)
2025-06-17 09:31:12 +08:00
{
rend.material.mainTexture = tex;
}
//mainModel.material.mainTexture = tex;
}
public void ChangeLineTexture(Texture tex)
{
foreach (var rend in insideRenders)
{
rend.material.mainTexture = tex;
}
//mainModel.material.mainTexture = tex;
}
2025-07-08 22:07:35 +08:00
void PlayStart()
{
Debug.Log($"start {number}");
if (number == 3)
EventManager.Instance.FireNow(this, new ProductIsShowDesignCoverEventArgs(false));
}
void PlayFinish()
{
Debug.Log($"finish {number}");
if (number == 2|| number == 1)
EventManager.Instance.FireNow(this, new ProductIsShowDesignCoverEventArgs(true));
}
float currentTime = 0;
2025-06-17 09:31:12 +08:00
IEnumerator PlayNext(int index)
{
2025-07-02 10:24:01 +08:00
// if(index==2)
// box5.enabled=false;
2025-07-08 22:07:35 +08:00
PlayStart();
2025-06-17 09:31:12 +08:00
playable.timeUpdateMode = DirectorUpdateMode.Manual;
2025-07-08 22:07:35 +08:00
while (currentTime < times[index])
2025-06-17 09:31:12 +08:00
{
2025-07-08 22:07:35 +08:00
playable.time += Time.deltaTime;
2025-06-17 09:31:12 +08:00
playable.DeferredEvaluate();
2025-07-08 22:07:35 +08:00
currentTime = (float)playable.time;
2025-06-17 09:31:12 +08:00
yield return null;
}
2025-07-08 22:07:35 +08:00
PlayFinish();
2025-06-17 09:31:12 +08:00
}
IEnumerator PlayLast(int index)
{
2025-07-08 22:07:35 +08:00
PlayStart();
2025-06-17 09:31:12 +08:00
playable.timeUpdateMode = DirectorUpdateMode.Manual;
2025-07-08 22:07:35 +08:00
while (currentTime > times[index])
2025-06-17 09:31:12 +08:00
{
2025-07-08 22:07:35 +08:00
playable.time -= Time.deltaTime;
2025-06-17 09:31:12 +08:00
playable.DeferredEvaluate();
2025-07-08 22:07:35 +08:00
currentTime = (float)playable.time;
2025-06-17 09:31:12 +08:00
yield return null;
}
2025-07-08 22:07:35 +08:00
2025-06-17 09:31:12 +08:00
// EventManager.Instance.FireNow(this,new OpenDecalUIArgs());
2025-07-08 22:07:35 +08:00
PlayFinish();
2025-06-17 09:31:12 +08:00
}
2025-07-08 22:07:35 +08:00
2025-06-17 09:31:12 +08:00
IEnumerator PlayCloseBook()
{
2025-07-08 22:07:35 +08:00
PlayStart();
2025-06-17 09:31:12 +08:00
playable.timeUpdateMode = DirectorUpdateMode.Manual;
2025-07-08 22:07:35 +08:00
while (currentTime > times[0])
2025-06-17 09:31:12 +08:00
{
2025-07-08 22:07:35 +08:00
playable.time -= Time.deltaTime;
2025-06-17 09:31:12 +08:00
playable.DeferredEvaluate();
2025-07-08 22:07:35 +08:00
currentTime = (float)playable.time;
2025-06-17 09:31:12 +08:00
yield return null;
}
2025-07-08 22:07:35 +08:00
2025-07-02 10:24:01 +08:00
// box5.enabled=true;
2025-07-08 22:07:35 +08:00
PlayFinish();
2025-06-17 09:31:12 +08:00
}
IEnumerator PlayOpenBook()
{
2025-07-02 10:24:01 +08:00
// box5.enabled=false;
2025-07-08 22:07:35 +08:00
PlayStart();
2025-06-17 09:31:12 +08:00
playable.timeUpdateMode = DirectorUpdateMode.Manual;
2025-07-08 22:07:35 +08:00
while (currentTime < times[2])
2025-06-17 09:31:12 +08:00
{
2025-07-08 22:07:35 +08:00
playable.time += Time.deltaTime;
2025-06-17 09:31:12 +08:00
playable.DeferredEvaluate();
2025-07-08 22:07:35 +08:00
currentTime = (float)playable.time;
2025-06-17 09:31:12 +08:00
yield return null;
}
2025-07-08 22:07:35 +08:00
PlayFinish();
2025-06-17 09:31:12 +08:00
}
2025-07-08 22:07:35 +08:00
}