File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayManager : MonoBehaviour
{
//public Animator animatorOne;
//public Animator animatorPreviewOne;
public Animator[] animatorArray;
public Animator[] animatorPreviewArray;
public RuntimeAnimatorController[] acArray;
public Slider sliderPlay;
public Slider sliderInput;
public Slider sliderLoopFront;
public Slider sliderLoopEnd;
public GameObject[] goCharacterArray;
public GameObject[] goCharacterPreviewArray;
public int currentCharacterIndex = 0;
public int currentTKIndex;
public GameObject goPlayUI;
public GameObject goPauseUI;
private float speedOffset = 0.05f;
private float previewOffset = 0.03f;
public Button btnShowPreview;
public Image[] imgShowPreview;
public bool isShowPreview;
public bool isPause;
private float[] speedArray = { 0.25f, 0.5f, 1f, 1.5f, 2f };
public int currentSpeedIndex = 2;
public Toggle[] tgContents;
public bool isUseLoop = false;
// Start is called before the first frame update
void Start()
{
isShowPreview = false;
imgShowPreview[0].enabled = true;
imgShowPreview[1].enabled = false;
isPause = false;
//animatorOne.runtimeAnimatorController = acArray[1];
//animatorOne.Play("Take 001");
//for(int i = 0; i < animatorArray.Length; i++)
//{
// animatorArray[i].runtimeAnimatorController = acArray[1];
// animatorArray[i].Play("Take 001");
//}
//animatorPreviewOne.runtimeAnimatorController = acArray[1];
//animatorPreviewOne.Play("Take 001");
//for (int i = 0; i < animatorPreviewArray.Length; i++)
//{
// animatorPreviewArray[i].runtimeAnimatorController = acArray[1];
// animatorPreviewArray[i].Play("Take 001");
//}
goPlayUI.SetActive(true);
goPauseUI.SetActive(false);
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorArray[i].gameObject.SetActive(false);
animatorPreviewArray[i].gameObject.SetActive(false);
}
}
public int currentToggleIndex = 1;
public void SetToggle(int _index)
{
for(int i = 0; i < tgContents.Length; i++)
{
tgContents[i].isOn = false;
}
tgContents[_index].isOn = true;
currentToggleIndex = _index;
}
public void SetToggleController()
{
for (int i = 0; i < tgContents.Length; i++)
{
tgContents[i].isOn = false;
}
tgContents[0].isOn = true;
}
public void SetPreview()
{
isShowPreview = !isShowPreview;
if(isShowPreview)
{
imgShowPreview[0].enabled = false;
imgShowPreview[1].enabled = true;
//animatorPreviewOne.gameObject.SetActive(true);
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].gameObject.SetActive(true);
}
//animatorOne.Play("Take 001", 0, sliderPlay.value);
//animatorPreviewOne.Play("Take 001", 0, sliderPlay.value + previewOffset);
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].Play("Take 001", 0, sliderPlay.value);
}
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].Play("Take 001", 0, sliderPlay.value + previewOffset);
}
}
else
{
imgShowPreview[0].enabled = true;
imgShowPreview[1].enabled = false;
//animatorPreviewOne.gameObject.SetActive(false);
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].gameObject.SetActive(false);
}
}
}
public void SetSpeedSlow()
{
if(currentSpeedIndex > 2)
{
currentSpeedIndex = 3;
}
currentSpeedIndex--;
if(currentSpeedIndex < 0)
{
currentSpeedIndex = 2;
}
//animatorOne.speed = speedArray[currentSpeedIndex];
//animatorPreviewOne.speed = speedArray[currentSpeedIndex];
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].speed = speedArray[currentSpeedIndex];
}
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].speed = speedArray[currentSpeedIndex];
}
Debug.Log(speedArray[currentSpeedIndex]);
}
public void SetSpeedFast()
{
if (currentSpeedIndex < 2)
{
currentSpeedIndex = 1;
}
currentSpeedIndex++;
if(currentSpeedIndex > 4)
{
currentSpeedIndex = 2;
}
//animatorOne.speed = speedArray[currentSpeedIndex];
//animatorPreviewOne.speed = speedArray[currentSpeedIndex];
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].speed = speedArray[currentSpeedIndex];
}
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].speed = speedArray[currentSpeedIndex];
}
Debug.Log(speedArray[currentSpeedIndex]);
}
public void ResetAll()
{
currentSpeedIndex = 2;
sliderPlay.value = 0f;
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].Play("Take 001", 0, sliderPlay.value);
}
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].Play("Take 001", 0, sliderPlay.value + previewOffset);
}
//animatorOne.Play("Take 001", 0, sliderPlay.value);
//animatorPreviewOne.Play("Take 001", 0, sliderPlay.value + previewOffset);
isUseLoop = false;
sliderLoopFront.value = 0f;
sliderLoopEnd.value = 1f;
}
public void ResetLoop()
{
currentSpeedIndex = 2;
//animatorOne.speed = speedArray[currentSpeedIndex];
//animatorPreviewOne.speed = speedArray[currentSpeedIndex];
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].speed = speedArray[currentSpeedIndex];
}
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].speed = speedArray[currentSpeedIndex];
}
sliderLoopFront.value = 0f;
sliderLoopEnd.value = 1f;
}
public void SetLoopFront()
{
if(isUseLoop == false)
{
isUseLoop = true;
sliderLoopFront.value = animatorArray[0].GetCurrentAnimatorStateInfo(0).normalizedTime;
}
else
{
isUseLoop = false;
sliderLoopFront.value = 0f;
sliderLoopEnd.value = 1f;
}
Debug.Log("1111111111111111111111");
// sliderLoopFront.value = animatorOne.GetCurrentAnimatorStateInfo(0).normalizedTime;
// sliderLoopFront.value = animatorArray[0].GetCurrentAnimatorStateInfo(0).normalizedTime;
}
public void SetLoopEnd()
{
Debug.Log("2222222222222222222222222");
// sliderLoopEnd.value = animatorOne.GetCurrentAnimatorStateInfo(0).normalizedTime;
sliderLoopEnd.value = animatorArray[0].GetCurrentAnimatorStateInfo(0).normalizedTime;
//for (int i = 0; i < animatorArray.Length; i++)
//{
// animatorArray[i].Play("Take 001", 0, sliderPlay.value);
//}
//for (int i = 0; i < animatorPreviewArray.Length; i++)
//{
// animatorPreviewArray[i].Play("Take 001", 0, sliderPlay.value + previewOffset);
//}
//sliderPlay.value = sliderLoopFront.value;
//for (int i = 0; i < animatorArray.Length; i++)
//{
// animatorArray[i].Play("Take 001", 0, sliderPlay.value);
//}
//for (int i = 0; i < animatorPreviewArray.Length; i++)
//{
// animatorPreviewArray[i].Play("Take 001", 0, sliderPlay.value + previewOffset);
//}
}
public void SetGotoFront()
{
float temp = sliderPlay.value;
sliderPlay.value = temp + speedOffset;
//sliderPlay.value += speedOffset;
//animatorOne.Play("Take 001", 0, sliderPlay.value);
//animatorPreviewOne.Play("Take 001", 0, sliderPlay.value + previewOffset);
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].Play("Take 001", 0, sliderPlay.value);
}
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].Play("Take 001", 0, sliderPlay.value + previewOffset);
}
}
public void SetGotoEnd()
{
float temp = sliderPlay.value;
sliderPlay.value = temp - speedOffset;
//sliderPlay.value -= speedOffset;
//animatorOne.Play("Take 001", 0, sliderPlay.value);
//animatorPreviewOne.Play("Take 001", 0, sliderPlay.value + previewOffset);
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].Play("Take 001", 0, sliderPlay.value);
}
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].Play("Take 001", 0, sliderPlay.value + previewOffset);
}
sliderPlay.value = sliderInput.value;
//animatorOne.Play("Take 001", 0, sliderPlay.value);
//animatorPreviewOne.Play("Take 001", 0, sliderPlay.value + previewOffset);
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].Play("Take 001", 0, sliderPlay.value);
}
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].Play("Take 001", 0, sliderPlay.value + previewOffset);
}
}
// Update is called once per frame
void Update()
{
//SetSlider();
if (Input.GetKeyDown(KeyCode.Alpha0))
{
ResetAll();
}
if (Input.GetKeyDown(KeyCode.Alpha1))
{
SetLoopFront();
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
SetLoopEnd();
}
if(Input.GetKeyDown(KeyCode.Alpha3))
{
SetGotoFront();
}
if (Input.GetKeyDown(KeyCode.Alpha4))
{
SetGotoEnd();
}
if (sliderPlay.value > sliderLoopEnd.value)
{
sliderPlay.value = sliderLoopFront.value;
//animatorOne.Play("Take 001", 0, sliderPlay.value);
//animatorPreviewOne.Play("Take 001", 0, sliderPlay.value + previewOffset);
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].Play("Take 001", 0, sliderPlay.value);
}
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].Play("Take 001", 0, sliderPlay.value + previewOffset);
}
}
// sliderPlay.value = animatorOne.GetCurrentAnimatorStateInfo(0).normalizedTime;
sliderPlay.value = animatorArray[0].GetCurrentAnimatorStateInfo(0).normalizedTime;
if(animatorArray[0].GetCurrentAnimatorStateInfo(0).normalizedTime > 0.98f)
{
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].Play("Take 001", 0, 0f);
}
sliderPlay.value = 0f;
}
}
public void SetPlayOrPause()
{
if(isPause)
{
Play();
}
else
{
Pause();
}
}
public void Play()
{
if(isPause)
{
isPause = false;
goPlayUI.SetActive(true);
goPauseUI.SetActive(false);
//animatorOne.speed = 1f;
//animatorPreviewOne.speed = 1f;
currentSpeedIndex = 2;
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].speed = speedArray[currentSpeedIndex];
}
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].speed = speedArray[currentSpeedIndex];
}
}
}
public void Pause()
{
if (isPause == false)
{
isPause = true;
goPlayUI.SetActive(false);
goPauseUI.SetActive(true);
//animatorOne.speed = 0f;
//animatorPreviewOne.speed = 0f;
currentSpeedIndex = 0;
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].speed = 0f;
}
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].speed = 0f;
}
}
}
public void SetCharacter(int _value)
{
//currentCharacterIndex = _value;
//for (int i = 0; i < goCharacterArray.Length; i++)
//{
// goCharacterArray[i].SetActive(false);
// goCharacterPreviewArray[i].SetActive(false);
//}
//goCharacterArray[currentCharacterIndex].SetActive(true);
////goCharacterPreviewArray[currentCharacterIndex].SetActive(true);
//animatorOne = goCharacterArray[currentCharacterIndex].GetComponent<Animator>();
//animatorPreviewOne = goCharacterPreviewArray[currentCharacterIndex].GetComponent<Animator>();
//for (int i = 0; i < animatorArray.Length; i++)
//{
// animatorArray[i] = goCharacterArray[currentCharacterIndex].GetComponent<Animator>();
//}
//for (int i = 0; i < animatorPreviewArray.Length; i++)
//{
// animatorPreviewArray[i] = goCharacterPreviewArray[currentCharacterIndex].GetComponent<Animator>();
//}
////animator.gameObject.SetActive(true);
//animatorOne.runtimeAnimatorController = acArray[currentTKIndex];
//animatorOne.Play("Take 001");
//animatorPreviewOne.runtimeAnimatorController = acArray[currentTKIndex];
//animatorPreviewOne.Play("Take 001", 0, previewOffset);
//for (int i = 0; i < animatorArray.Length; i++)
//{
// animatorArray[i].runtimeAnimatorController = acArray[currentTKIndex];
// animatorArray[i].Play("Take 001");
//}
//for (int i = 0; i < animatorPreviewArray.Length; i++)
//{
// animatorPreviewArray[i].runtimeAnimatorController = acArray[currentTKIndex];
// animatorPreviewArray[i].Play("Take 001", 0, previewOffset);
//}
}
public void Stop()
{
//for (int i = 0; i < goCharacterArray.Length; i++)
//{
// goCharacterArray[i].SetActive(false);
// goCharacterPreviewArray[i].SetActive(false);
//}
//goCharacterArray[currentCharacterIndex].SetActive(true);
////goCharacterPreviewArray[currentCharacterIndex].SetActive(true);
////animatorOne = goCharacterArray[currentCharacterIndex].GetComponent<Animator>();
////animatorPreviewOne = goCharacterPreviewArray[currentCharacterIndex].GetComponent<Animator>();
//for (int i = 0; i < animatorArray.Length; i++)
//{
// animatorArray[i] = goCharacterArray[currentCharacterIndex].GetComponent<Animator>();
//}
//for (int i = 0; i < animatorPreviewArray.Length; i++)
//{
// animatorPreviewArray[i] = goCharacterPreviewArray[currentCharacterIndex].GetComponent<Animator>();
//}
//animatorOne.speed = 1f;
//animatorOne.runtimeAnimatorController = acArray[currentTKIndex];
//animatorOne.Play("Take 001");
//animatorPreviewOne.speed = 1f;
//animatorPreviewOne.runtimeAnimatorController = acArray[currentTKIndex];
//animatorPreviewOne.Play("Take 001", 0, previewOffset);
currentSpeedIndex = 2;
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].speed = speedArray[currentSpeedIndex];
animatorArray[i].runtimeAnimatorController = acArray[currentTKIndex];
animatorArray[i].Play("Take 001", 0, 0f);
}
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].speed = speedArray[currentSpeedIndex];
animatorPreviewArray[i].runtimeAnimatorController = acArray[currentTKIndex];
animatorPreviewArray[i].Play("Take 001", 0, previewOffset);
}
//isPause = false;
//goPlayUI.SetActive(true);
//goPauseUI.SetActive(false);
}
public void OnSliderChange()
{
isUseLoop = false;
//sliderLoopFront.value = 0f;
//sliderLoopEnd.value = 1f;
sliderPlay.value = sliderInput.value;
//animatorOne.Play("Take 001", 0, sliderPlay.value);
//animatorPreviewOne.Play("Take 001", 0, sliderPlay.value + previewOffset);
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].Play("Take 001", 0, sliderPlay.value);
}
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].Play("Take 001", 0, sliderPlay.value + previewOffset);
}
}
public void SetPoomsea(int _value)
{
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorArray[i].gameObject.SetActive(true);
}
currentTKIndex = _value;
currentSpeedIndex = 2;
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].speed = speedArray[currentSpeedIndex];
}
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
animatorPreviewArray[i].speed = speedArray[currentSpeedIndex];
}
Debug.Log(currentTKIndex);
//for (int i = 0; i < goCharacterArray.Length; i++)
//{
// goCharacterArray[i].SetActive(false);
// goCharacterPreviewArray[i].SetActive(false);
//}
//goCharacterArray[currentCharacterIndex].SetActive(true);
//animatorOne = goCharacterArray[currentCharacterIndex].GetComponent<Animator>();
//animatorOne.runtimeAnimatorController = acArray[currentTKIndex];
//animatorOne.Play("Take 001");
//animatorPreviewOne = goCharacterPreviewArray[currentCharacterIndex].GetComponent<Animator>();
//animatorPreviewOne.runtimeAnimatorController = acArray[currentTKIndex];
//animatorPreviewOne.Play("Take 001", 0, previewOffset);
Debug.Log(animatorArray.Length);
for (int i = 0; i < animatorArray.Length; i++)
{
//animatorArray[i] = goCharacterArray[currentCharacterIndex].GetComponent<Animator>();
animatorArray[i].runtimeAnimatorController = acArray[currentTKIndex];
animatorArray[i].Play("Take 001");
}
for (int i = 0; i < animatorPreviewArray.Length; i++)
{
// animatorPreviewArray[i] = goCharacterPreviewArray[currentCharacterIndex].GetComponent<Animator>();
animatorPreviewArray[i].runtimeAnimatorController = acArray[currentTKIndex];
animatorPreviewArray[i].Play("Take 001", 0, previewOffset);
}
isPause = false;
isUseLoop = false;
sliderLoopFront.value = 0f;
sliderLoopEnd.value = 1f;
}
void SetSlider()
{
// sliderPlay.value = animatorOne.GetCurrentAnimatorStateInfo(0).normalizedTime;
sliderPlay.value = animatorArray[0].GetCurrentAnimatorStateInfo(0).normalizedTime;
for (int i = 0; i < animatorArray.Length; i++)
{
animatorArray[i].Play("Take 001", 0, sliderPlay.value);
}
//if (isDoneLoad && isPause == false)
//{
// slider_Anim.value = animator.GetCurrentAnimatorStateInfo(0).normalizedTime;
// if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 0.98f)
// {
// RePlay();
// }
// if (slider_Anim.value > slider_LoopEnd.value)
// {
// animator.Play("Take 001", 0, slider_LoopStart.value);
// animator2.Play("Take 001", 0, slider_LoopStart.value + previewOffset);
// }
// //if (playSpeedOffset != 0)
// //{
// // lbPlayCurrent.text = "" + ((int)(animator.GetCurrentAnimatorStateInfo(0).length * slider_Anim.value / 59f)).ToString("0") + " : " +
// // ((animator.GetCurrentAnimatorStateInfo(0).length * slider_Anim.value % 59f)).ToString("00");
// //}
//}
}
}