・ScaleOnOffUIController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UniRx;
using HoloMonApp.ConditionSpace;
namespace HoloMonApp.MenuViewSpace
{
public class ScaleOnOffUIController : MonoBehaviour
{
[SerializeField]
private List<SwitchOnOffObjectController> p_SwichList;
[SerializeField]
private List<float> p_BorderList;
private void Start()
{
HoloMonConditionBodySingleton.Instance.IReadOnlyReactivePropertyHoloMonBodyStatus
.ObserveOnMainThread()
.Subscribe(status =>
{
CheckPower(status.BodyPower);
})
.AddTo(this);
}
<summary>
</summary>
public void CheckPower(float a_Power)
{
int nowOnIndex = 0;
for(int borderIndex = 0; borderIndex < p_BorderList.Count; borderIndex++)
{
if (a_Power > p_BorderList[borderIndex])
{
nowOnIndex = borderIndex + 1;
}
else
{
break;
}
}
for(int switchIndex = 0; switchIndex < p_SwichList.Count; switchIndex++)
{
if (switchIndex < nowOnIndex)
{
p_SwichList[switchIndex].ObjectSwitch(true);
}
else
{
p_SwichList[switchIndex].ObjectSwitch(false);
}
}
}
}
}
・SwitchOnOffObjectController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace HoloMonApp.MenuViewSpace
{
public class SwitchOnOffObjectController : MonoBehaviour
{
[SerializeField, Tooltip("現在のスイッチ状態")]
private bool p_SwitchFlg;
[SerializeField, Tooltip("True時オブジェクト")]
private GameObject p_TrueObject;
[SerializeField, Tooltip("False時オブジェクト")]
private GameObject p_FalseObject;
<summary>
</summary>
<param name="a_OnOff"></param>
public void ObjectSwitch(bool a_OnOff)
{
p_SwitchFlg = a_OnOff;
p_TrueObject.SetActive(a_OnOff);
p_FalseObject.SetActive(!a_OnOff);
}
}
}