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

158 lines
3.8 KiB
C#
Raw Normal View History

2025-06-17 09:31:12 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Serialization;
public class Book_M : MonoBehaviour
{
[SerializeField]
private PlayableDirector playable;
[SerializeField]
List<float > times=new List<float>();
[SerializeField]
int number=0;
public List<Renderer> renders = new List<Renderer>();
public Renderer[] insideRenders;
public Renderer box5;
// Update is called once per frame
void Update()
{
#if UNITY_EDITOR
if (Input.GetKeyDown(KeyCode.A))
{
// Next();
}
if (Input.GetKeyDown(KeyCode.D))
{
// Last();
}
#endif
}
public void SetIndex(int ind)
{
StopAllCoroutines();
if (number==4&&(ind==2||ind==1))
{
this.number = ind;
StartCoroutine(PlayNext(1));
return;
}
if (this.number<ind)// 1 3 4
{
this.number = ind;
if (ind == 4)
StartCoroutine(PlayCloseBook());
else if(ind==3)
StartCoroutine(PlayNext(2));
else if(ind==1)
StartCoroutine(PlayNext(1));
}
else if(this.number>ind)// 0 2 3
{
this.number = ind;
if (ind == 3)
StartCoroutine(PlayOpenBook());
else if(ind==2||ind==1)
StartCoroutine(PlayLast(1));
else if(ind==0)
StartCoroutine(PlayLast(0));
}
}
// public void Next()
// {
// StopAllCoroutines();
// StartCoroutine(PlayNext());
// }
//
// public void Last()
// {
// StopAllCoroutines();
// StartCoroutine(PlayLast());
// }
//
// public void CloseBook()
// {
// StopAllCoroutines();
// StartCoroutine(PlayCloseBook());
// }
public void ChangeTexture(Texture tex)
{
foreach(var rend in renders)
{
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;
}
float currentTime=0;
IEnumerator PlayNext(int index)
{
if(index==2)
box5.enabled=false;
playable.timeUpdateMode = DirectorUpdateMode.Manual;
while (currentTime<times[index])
{
playable.time+=Time.deltaTime;
playable.DeferredEvaluate();
currentTime=(float)playable.time;
yield return null;
}
}
IEnumerator PlayLast(int index)
{
playable.timeUpdateMode = DirectorUpdateMode.Manual;
while (currentTime>times[index])
{
playable.time-=Time.deltaTime;
playable.DeferredEvaluate();
currentTime=(float)playable.time;
yield return null;
}
// EventManager.Instance.FireNow(this,new OpenDecalUIArgs());
}
IEnumerator PlayCloseBook()
{
playable.timeUpdateMode = DirectorUpdateMode.Manual;
while (currentTime>times[0])
{
playable.time-=Time.deltaTime;
playable.DeferredEvaluate();
currentTime=(float)playable.time;
yield return null;
}
box5.enabled=true;
}
IEnumerator PlayOpenBook()
{
box5.enabled=false;
playable.timeUpdateMode = DirectorUpdateMode.Manual;
while (currentTime<times[2])
{
playable.time+=Time.deltaTime;
playable.DeferredEvaluate();
currentTime=(float)playable.time;
yield return null;
}
}
}