106 lines
3.5 KiB
C#
106 lines
3.5 KiB
C#
using BrewMonster.Assets.PerfectWorld.Scripts.UI;
|
|
using BrewMonster.Common;
|
|
using BrewMonster.Managers;
|
|
using BrewMonster.Scripts;
|
|
using BrewMonster.Scripts.Managers;
|
|
using BrewMonster.UI;
|
|
using CSNetwork.GPDataType;
|
|
using Cysharp.Threading.Tasks.Triggers;
|
|
using PerfectWorld.Scripts.Managers;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
public class SettingInterface : MonoBehaviour
|
|
{
|
|
[Header("Slider")]
|
|
[SerializeField] private Slider slider_foresight;
|
|
[SerializeField] private Slider slider_distance_npc_and_mst;
|
|
[SerializeField] private Slider slider_distance_player_other;
|
|
|
|
[Header("Slider Value Level")]
|
|
private float valueLevel1 = 0;
|
|
private float valueLevel2 = 0.194f;
|
|
private float valueLevel3 = 0.409f;
|
|
private float valueLevel4 = 0.603f;
|
|
private float valueLevel5 = 0.793f;
|
|
private float valueLevel6 = 1f;
|
|
|
|
[Header("slider Text Level")]
|
|
[SerializeField] private TextMeshProUGUI txt_level_of_foresight;
|
|
[SerializeField] private TextMeshProUGUI txt_level_of_distance_npc_and_mst;
|
|
[SerializeField] private TextMeshProUGUI txt_level_of_distance_player_other;
|
|
|
|
private void OnEnable()
|
|
{
|
|
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
slider_foresight.onValueChanged.RemoveListener(OnForessightSliderChange);
|
|
slider_distance_npc_and_mst.onValueChanged.RemoveListener(OnDisNPCandMstSliderChange);
|
|
slider_distance_player_other.onValueChanged.RemoveListener(OnDisPlayerOtherSliderChange);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
UpdateSliderText(slider_foresight, txt_level_of_foresight);
|
|
UpdateSliderText(slider_distance_npc_and_mst, txt_level_of_distance_npc_and_mst);
|
|
UpdateSliderText(slider_distance_player_other, txt_level_of_distance_player_other);
|
|
}
|
|
|
|
private void OnForessightSliderChange(float value)
|
|
{
|
|
UpdateSliderText(slider_foresight, txt_level_of_foresight);
|
|
}
|
|
|
|
private void OnDisNPCandMstSliderChange(float value)
|
|
{
|
|
UpdateSliderText(slider_distance_npc_and_mst, txt_level_of_distance_npc_and_mst);
|
|
}
|
|
|
|
private void OnDisPlayerOtherSliderChange(float value)
|
|
{
|
|
UpdateSliderText(slider_distance_player_other, txt_level_of_distance_player_other);
|
|
}
|
|
|
|
private void UpdateSliderText(Slider slider, TextMeshProUGUI text)
|
|
{
|
|
if (slider == null || text == null)
|
|
return;
|
|
|
|
int level = GetLevelFromValue(slider.value);
|
|
text.text = $"Mức {level}";
|
|
}
|
|
|
|
private int GetLevelFromValue(float value)
|
|
{
|
|
float t12 = (valueLevel1 + valueLevel2) * 0.5f;
|
|
float t23 = (valueLevel2 + valueLevel3) * 0.5f;
|
|
float t34 = (valueLevel3 + valueLevel4) * 0.5f;
|
|
float t45 = (valueLevel4 + valueLevel5) * 0.5f;
|
|
float t56 = (valueLevel5 + valueLevel6) * 0.5f;
|
|
|
|
if (value < t12)
|
|
return 1;
|
|
else if (value < t23)
|
|
return 2;
|
|
else if (value < t34)
|
|
return 3;
|
|
else if (value < t45)
|
|
return 4;
|
|
else if (value < t56)
|
|
return 5;
|
|
else
|
|
return 6;
|
|
}
|
|
}
|
|
}
|