96 lines
2.5 KiB
C#
96 lines
2.5 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using Cysharp.Threading.Tasks.Linq;
|
|
|
|
using PMaker.Extension;
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using System.Linq;
|
|
|
|
using UnityEditor;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIBookEase : BaseBehaviour
|
|
{
|
|
[SerializeField]
|
|
private GameObject[] _pages;
|
|
|
|
[SerializeField]
|
|
private IndexController _indexController;
|
|
|
|
[SerializeField]
|
|
private AsyncReactiveProperty<int> _index;
|
|
|
|
public bool isHide = true;
|
|
|
|
private void Reset()
|
|
{
|
|
this._pages = this
|
|
.transform
|
|
.Find("root")
|
|
.Children()
|
|
//.Where(_ => _.GetComponent<BaseBehaviour>() == null)
|
|
//.Where(_ => _.GetComponent<Selectable>() == null)
|
|
.Select(_ => _.gameObject)
|
|
.ToArray();
|
|
this._indexController = this.GetComponentInChildren<IndexController>(true);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
var token = this.GetCancellationTokenOnDestroy();
|
|
_index = new AsyncReactiveProperty<int>(0);
|
|
var max = _pages.Length - 1;
|
|
_index
|
|
.Where(_ => _ >= 0 && _ <= max)
|
|
.Subscribe(_ => {
|
|
if (this.isHide == true)
|
|
{
|
|
if (_ == 0)
|
|
{
|
|
_indexController.SetActive(0, false);
|
|
}
|
|
else
|
|
{
|
|
_indexController.SetActive(0, true);
|
|
}
|
|
if (_ == max)
|
|
{
|
|
_indexController.SetActive(1, false);
|
|
}
|
|
else
|
|
{
|
|
_indexController.SetActive(1, true);
|
|
}
|
|
}
|
|
|
|
foreach (var item in _pages)
|
|
{
|
|
item.SetActive(false);
|
|
}
|
|
_pages[_].SetActive(true);
|
|
})
|
|
.AddTo(token);
|
|
_indexController.Bind(this._index, 0, max + 1, token);
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
public Sprite[] sprites;
|
|
|
|
[Button]
|
|
[ContextMenu("SetValue")]
|
|
private void SetValue()
|
|
{
|
|
var images = this.transform.Find("root").Children().Select(_ => _.GetComponent<Image>()).ToArray();
|
|
|
|
for (int i = 0; i < sprites.Length; i++)
|
|
{
|
|
images[i].sprite = sprites[i];
|
|
images[i].SetDirty();
|
|
}
|
|
this._pages = images.Select(_ => _.gameObject).ToArray();
|
|
}
|
|
#endif
|
|
} |