88 lines
2.3 KiB
C#
88 lines
2.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class HealingMinigame : MonoBehaviour
|
|
{
|
|
[Serializable]
|
|
public class WaveDesc
|
|
{
|
|
public float amp;
|
|
public float freq;
|
|
public Color col1;
|
|
public Color col2;
|
|
public WaveDesc()
|
|
{
|
|
amp = 1f;
|
|
freq = 1f;
|
|
col1 = Color.blue;
|
|
col2 = Color.blue * 0.7f;
|
|
}
|
|
}
|
|
public WaveDesc[] m_waves;
|
|
public Button[] m_buttons;
|
|
public Material[] m_buttonMaterials;
|
|
public Material m_waveMaterial;
|
|
public int m_selectedId = -1;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
m_buttonMaterials = new Material[m_buttons.Length];
|
|
|
|
for (int i=0; i<m_buttons.Length; i++)
|
|
{
|
|
int id = i;
|
|
m_buttons[i].onClick.AddListener(() => OnButtonPressed(id));
|
|
m_buttonMaterials[i] = m_buttons[i].image.material;
|
|
}
|
|
UpdateMaterials();
|
|
|
|
}
|
|
|
|
void UpdateMaterials()
|
|
{
|
|
Vector4 freqVec = Vector4.zero;
|
|
Vector4 ampVec = Vector4.zero;
|
|
for (int i = 0; i < m_waves.Length; i++)
|
|
{
|
|
m_buttonMaterials[i].SetColor("P1ColorIn", m_waves[i].col1);
|
|
m_buttonMaterials[i].SetColor("P1ColorOut", m_waves[i].col2);
|
|
m_waveMaterial.SetColor("P" + (i + 1) + "ColorIn", m_waves[i].col1);
|
|
m_waveMaterial.SetColor("P" + (i + 1) + "ColorOut", m_waves[i].col2);
|
|
|
|
m_buttonMaterials[i].SetFloat("Amplitude", m_waves[i].amp);
|
|
m_buttonMaterials[i].SetFloat("Frequency", m_waves[i].freq);
|
|
freqVec[i] = m_waves[i].freq;
|
|
ampVec[i] = m_waves[i].amp;
|
|
}
|
|
|
|
m_waveMaterial.SetVector("Frequencies", freqVec);
|
|
m_waveMaterial.SetVector("Amplitudes", ampVec);
|
|
}
|
|
|
|
public void OnTouched(Vector2 pos)
|
|
{
|
|
|
|
if (m_selectedId >=0)
|
|
{
|
|
m_waves[m_selectedId].amp = pos.y * 0.5f;
|
|
m_waves[m_selectedId].freq = ((pos.x + 1f) * .5f) * 5f;
|
|
UpdateMaterials();
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
void OnButtonPressed(int id)
|
|
{
|
|
m_selectedId = id;
|
|
Debug.Log("Button pressed: "+id);
|
|
}
|
|
}
|