using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class BoxLevel : MonoBehaviour { [SerializeField] Transform boxLevelArrowWeightSelects; [SerializeField] Transform boxLevelShootLevelSelects; readonly static float[] ArrowWeights = { 20f, 27f, 30.5f }; readonly static int[] ShootLevels = { 0, 1, 2 }; readonly string[] ShootLevelStrs = { "Easy", "Normal", "Hard" }; void OnEnable() { float arrowWeight = UserSettings.ins.actualArrowWeight; if (System.Array.IndexOf(ArrowWeights, arrowWeight) < 0) arrowWeight = ArrowWeights[0]; RenderArrowWeight(arrowWeight); int shootLevel = UserSettings.ins.shootLevel; if (System.Array.IndexOf(ShootLevels, shootLevel) < 0) shootLevel = ShootLevels[0]; RenderShootLevel(shootLevel); } public void OnClick_SelectArrowWeight(Transform target) { float oldValue = UserSettings.ins.actualArrowWeight; int index = target.GetSiblingIndex(); float newValue = ArrowWeights[index]; RenderArrowWeight(newValue); if (oldValue != newValue) { AudioMgr.ins.PlayBtn(); UserSettings.ins.actualArrowWeight = newValue; UserSettings.ins.Save(); } } public void OnClick_SelectShootLevel(Transform target) { int oldValue = UserSettings.ins.shootLevel; int index = target.GetSiblingIndex(); int newValue = ShootLevels[index]; RenderShootLevel(newValue); if (oldValue != newValue) { AudioMgr.ins.PlayBtn(); UserSettings.ins.shootLevel = newValue; UserSettings.ins.Save(); } } void RenderArrowWeight(float value) { for (int i = 0; i < ArrowWeights.Length; i++) { var itemValue = ArrowWeights[i]; var item = boxLevelArrowWeightSelects.GetChild(i); var text = item.GetComponentInChildren(); if (itemValue == value) { item.GetComponent().color = Color.black; text.color = Color.white; } else { item.GetComponent().color = new Color(1, 1, 1, 0); text.color = Color.black; } text.text = itemValue + "Grams"; } } void RenderShootLevel(int value) { for (int i = 0; i < ShootLevels.Length; i++) { var itemValue = ShootLevels[i]; var item = boxLevelShootLevelSelects.GetChild(i); var text = item.GetComponentInChildren(); if (itemValue == value) { item.GetComponent().color = Color.black; text.color = Color.white; } else { item.GetComponent().color = new Color(1, 1, 1, 0); text.color = Color.black; } text.text = ShootLevelStrs[i]; } } }