Files
JJBB/Assets/Project/Script/GUI/Base/UIContainerSlideStep.cs

78 lines
2.3 KiB
C#
Raw Normal View History

2024-08-23 15:49:34 +08:00
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System;
using Module.Log;
public class UIContainerSlideStep : UIContainerBase
{
#region
private float _StepHeight = 0;
private float _StepHeightHalf = 0;
private float _ContentYMin = 0;
private float _ContentYMax = 0;
private int _StepMin = 0;
private int _StepMax = 0;
private int _SelectedStepDelta = 0;
private int _SelectedStep = 0;
public int SelectedStep
{
get
{
return _SelectedStep;
}
set
{
_SelectedStep = value;
SetSelectedIdx(_SelectedStep);
}
}
#endregion
public override void InitContentItem(IEnumerable valueList, UIItemBase.ItemClick onClick = null, Hashtable exhash = null, UIItemBase.PanelClick onPanelClick = null)
{
base.InitContentItem(valueList, onClick, exhash, onPanelClick);
_StepHeight = _LayoutGroup.cellSize.y + _LayoutGroup.spacing.y;
_StepHeightHalf = _LayoutGroup.cellSize.y * 0.5f;
_ContentYMin = -_ScrollTransform.sizeDelta.y * 0.5f;
_StepMin = (int)(_ContentYMin / _StepHeight);
_StepMax = _StepMin + _ValueList.Count - 1;
_ContentYMax = _StepMax * _StepHeight;
_SelectedStepDelta = -_StepMin;
_SelectedStep = _SelectedStepDelta;
}
public override void ShowItems()
{
int step = (int)(_ContainerObj.localPosition.y / _StepHeight);
step = Mathf.Clamp(step, _StepMin, _StepMax);
_SelectedStep = step + _SelectedStepDelta;
float posY = Mathf.Clamp(step * _StepHeight, _ContentYMin, _ContentYMax);
_ContainerObj.localPosition = new Vector3(_ContainerObj.localPosition.x, posY, _ContainerObj.localPosition.z);
base.ShowItems();
}
public void SetSelectedIdx(int idx)
{
int step = idx - _SelectedStepDelta;
step = Mathf.Clamp(step, _StepMin, _StepMax);
LogModule.DebugLog("ShowItems selectedStep:" + (_SelectedStep + 40));
float posY = Mathf.Clamp(step * _StepHeight, _ContentYMin, _ContentYMax);
_ContainerObj.localPosition = new Vector3(_ContainerObj.localPosition.x, posY, _ContainerObj.localPosition.z);
base.ShowItems();
}
}