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 times=new List(); [SerializeField] int number=0; public List renders = new List(); 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.numberind)// 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 (currentTimetimes[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