This repository has been archived on 2026-01-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
AW_2025/Assets/Scripts/SimulationManager.cs
2025-03-06 17:51:47 +09:00

112 lines
2.3 KiB
C#

using UnityEngine;
public class SimulationManager : MonoBehaviour
{
Animator[] allAnimator;
public bool isSpeedUp;
public float upSpeedValue = 5;
Panel_Property property;
Panel_Result resultUI;
private void Awake()
{
property = FindAnyObjectByType<Panel_Property>();
allAnimator = FindObjectsByType<Animator>(FindObjectsSortMode.None);
resultUI = FindAnyObjectByType<Panel_Result>();
resultUI.gameObject.SetActive(false);
AnimationPlay(false);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Keypad1))
{
property.Activate(0);
}
if (Input.GetKeyDown(KeyCode.Keypad2))
{
property.Activate(1);
}
if (Input.GetKeyDown(KeyCode.Keypad3))
{
property.Activate(2);
}
if (Input.GetKeyDown(KeyCode.Keypad4))
{
property.Activate(3);
}
if (Input.GetKeyDown(KeyCode.Keypad5))
{
property.Activate(4);
}
if (Input.GetKeyDown(KeyCode.Keypad6))
{
property.Activate(5);
}
if (Input.GetKeyDown(KeyCode.Keypad7))
{
property.Activate(6);
}
if (Input.GetKeyDown(KeyCode.S))
{
ToggleAnimationSpeedUp();
}
if (Input.GetKeyDown(KeyCode.Space))
{
AnimationPlay(false);
ShowResultUI();
}
}
public void AnimationPlay(bool playing)
{
foreach (Animator animator in allAnimator)
{
if (playing)
{
animator.Play(animator.GetCurrentAnimatorStateInfo(0).fullPathHash);
animator.speed = Random.Range(0.5f, 1.5f);
}
else
{
animator.speed = 0;
}
}
}
void ToggleAnimationSpeedUp()
{
isSpeedUp = !isSpeedUp;
if (isSpeedUp)
{
foreach (Animator animator in allAnimator)
{
animator.speed *= upSpeedValue;
}
}
else
{
foreach (Animator animator in allAnimator)
{
animator.speed /= upSpeedValue;
}
}
}
void ShowResultUI()
{
resultUI.gameObject.SetActive(true);
}
}