266 lines
14 KiB
C#
266 lines
14 KiB
C#
using CG.Framework;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using DG.Tweening;
|
|
/*******************************************************************************
|
|
*Create By CG
|
|
*Function 操作步骤栏控制
|
|
*******************************************************************************/
|
|
namespace ZXK.GYJQR
|
|
{
|
|
public abstract class OperationStepPanel : UIBase
|
|
{
|
|
protected Transform _stepContent = null;
|
|
protected GameObject _stepItemPrefab = null;
|
|
protected GameObject _stepBigItemPrefab = null;
|
|
protected GameObject _stepSmallItemPrefab = null;
|
|
|
|
private Transform _curSelectStepBtn = null;
|
|
|
|
protected const float _smallItemSizeY = 25.0f;//每个子项大小
|
|
protected const float _smallItemIntervalY = 5.0f;//每个子项之间间隔
|
|
protected const float _smallParentInitPosY = -40.0f;//子项父物体初始位置
|
|
private const float _openCloseAnmSpeed = 0.01f;//开合动画播放速度控制
|
|
private Vector2 _focusInitSize = new Vector2(296.0f, 96.0f);
|
|
private Vector2 _stepsParentInitSize = new Vector2(296.0f, 462.0f);
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
|
|
_stepContent = GetWedage("StepContent_N").transform;
|
|
_stepItemPrefab = GetWedage("StepItemPrefab_N");
|
|
_stepBigItemPrefab = GetWedage("StepBigItemPrefab_N");
|
|
_stepSmallItemPrefab = GetWedage("StepSmallItemPrefab_N");
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
DOTween.Kill("OpenSequence");
|
|
DOTween.Kill("CloseSequence");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 实例化数据到流程栏(带有二级菜单功能)
|
|
/// </summary>
|
|
/// <param name="partsInfo">[id,stepName,stepchildrenName]</param>
|
|
protected List<GameObject> InitStepSecondMenuDataUI(List<string[]> partsInfo)
|
|
{
|
|
string curShowGeo = GameManager.Instance._DataBJCJHandler._ShowPartsName.Value;
|
|
string bigStep = "";
|
|
int bigStepIndex = 0;
|
|
float extensionTxt = 0;
|
|
RectTransform smallParent = null;
|
|
RectTransform stepBigRect = null;
|
|
List<GameObject> stepChildrens = new List<GameObject>();
|
|
foreach (string[] item in partsInfo)
|
|
{
|
|
if (!item[1].Equals(bigStep)&& !item[1].Equals("OVER"))
|
|
{
|
|
bigStepIndex++;
|
|
GameObject stepBigGeo = Instantiate(_stepBigItemPrefab, _stepContent);
|
|
stepBigRect = stepBigGeo.GetComponent<RectTransform>();
|
|
smallParent = stepBigGeo.transform.Find("StepSmallParent").GetComponent<RectTransform>();
|
|
stepBigGeo.name = curShowGeo+"_"+item[1];
|
|
stepBigGeo.transform.Find("TextIndex").GetComponent<Text>().text = bigStepIndex.ToString();
|
|
stepBigGeo.transform.Find("IsSelectBG/TextDetail").GetComponent<Text>().text = item[1];
|
|
Button bigBtn = null;
|
|
if(!stepBigGeo.transform.Find("BigBtnTri").TryGetComponent<Button>(out bigBtn))
|
|
{
|
|
bigBtn = stepBigGeo.transform.Find("BigBtnTri").gameObject.AddComponent<Button>();
|
|
}
|
|
bigBtn.onClick.AddListener(() =>
|
|
{//点击大步骤,直接选择对应第一个小步骤
|
|
Button smallStepBtn = bigBtn.transform.parent.Find("StepSmallParent").GetChild(1).GetComponent<Button>();
|
|
smallStepBtn.onClick.Invoke();
|
|
WDebug.Log("小步骤:" + bigBtn.transform.parent.Find("StepSmallParent").GetChild(1).name);
|
|
});
|
|
Button bigOpenClose = stepBigGeo.transform.Find("OpenCloseBtn").GetComponent<Button>();
|
|
bigOpenClose.GetComponent<Button>().onClick.AddListener(() =>
|
|
{
|
|
OnClickBigStep(bigOpenClose.transform.parent.GetComponent<RectTransform>());
|
|
});
|
|
bigStep = item[1];
|
|
stepBigGeo.SetActive(true);
|
|
extensionTxt = 0;
|
|
}
|
|
GameObject stepSmallGeo = Instantiate(_stepSmallItemPrefab, smallParent.transform);
|
|
stepSmallGeo.name = item[0];
|
|
|
|
int indexTemp = item[2].IndexOf("、");
|
|
string indexStr = item[2].Substring(0, indexTemp);
|
|
string contentStr = item[2].Substring(indexTemp + 1, item[2].Length - indexTemp - 1);
|
|
stepSmallGeo.transform.Find("TextIndex").GetComponent<Text>().text = indexStr;
|
|
stepSmallGeo.transform.Find("TextContent").GetComponent<Text>().text = contentStr;
|
|
|
|
RectTransform stepSmallRectTran = stepSmallGeo.GetComponent<RectTransform>();
|
|
int smallNumber = smallParent.childCount - 2;//多减掉一个隐藏的预制体
|
|
stepSmallRectTran.anchoredPosition = new Vector2(stepSmallRectTran.anchoredPosition.x, -(_smallItemSizeY + _smallItemIntervalY) * smallNumber- extensionTxt);
|
|
if (CG.UTility.UtilitiesMng.GetTransCharNum(contentStr) > 25)
|
|
{
|
|
extensionTxt+= _smallItemSizeY;
|
|
stepSmallRectTran.sizeDelta = new Vector2(stepSmallRectTran.sizeDelta.x, _smallItemSizeY + _smallItemSizeY);
|
|
}
|
|
stepBigRect.sizeDelta = new Vector2(stepBigRect.sizeDelta.x, -_smallParentInitPosY - _smallItemIntervalY + _smallItemSizeY + (_smallItemSizeY + _smallItemIntervalY) * smallNumber + extensionTxt);
|
|
smallParent.sizeDelta = new Vector2(smallParent.sizeDelta.x, _smallItemSizeY + (_smallItemSizeY + _smallItemIntervalY) * smallNumber + extensionTxt);
|
|
stepSmallGeo.SetActive(true);
|
|
stepChildrens.Add(stepSmallGeo);
|
|
}
|
|
return stepChildrens;
|
|
}
|
|
/// <summary>
|
|
/// 实例化数据到流程栏(只有一级菜单功能)
|
|
/// </summary>
|
|
/// <param name="partsInfo">[id,stepName]</param>
|
|
protected List<GameObject> InitStepDataUI(List<string[]> partsInfo)
|
|
{
|
|
string stepName = "";
|
|
int stepIndex = 0;
|
|
List<GameObject> steps = new List<GameObject>();
|
|
foreach (string[] item in partsInfo)
|
|
{
|
|
if (!item[1].Equals(stepName) && !item[1].Equals("OVER"))
|
|
{
|
|
stepIndex++;
|
|
GameObject stepGeo = Instantiate(_stepItemPrefab, _stepContent);
|
|
stepGeo.name = item[1];
|
|
stepGeo.transform.Find("TextIndex").GetComponent<Text>().text = stepIndex.ToString();
|
|
stepGeo.transform.Find("IsSelectBG/TextDetail").GetComponent<Text>().text = item[1];
|
|
stepGeo.SetActive(true);
|
|
steps.Add(stepGeo);
|
|
stepName = item[1];
|
|
}
|
|
}
|
|
return steps;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 收回步骤流程面板
|
|
/// </summary>
|
|
protected void ShrinkPanel(string focusShowStr)
|
|
{
|
|
//延伸面板变化
|
|
GameObject stepGroupGeo = GetWedage("StepGroupTitle_N");
|
|
GetWedage("ShrinkBtn_N").SetActive(false);
|
|
stepGroupGeo.GetComponent<RectTransform>().
|
|
DOSizeDelta(_focusInitSize, 0.3f).OnComplete(() =>
|
|
{
|
|
stepGroupGeo.SetActive(false);
|
|
//聚焦面板变化
|
|
GameObject focusGeo = GetWedage("FocusStep_N");
|
|
int indexTemp = focusShowStr.IndexOf("、");
|
|
focusGeo.transform.Find("StepIndex").GetComponent<Text>().text = focusShowStr.Substring(0, indexTemp);
|
|
focusGeo.transform.Find("Stepdetail").GetComponent<Text>().text = focusShowStr.Substring(indexTemp+1, focusShowStr.Length- indexTemp-1);
|
|
GetWedage("FocusStep_N").SetActive(true);
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 伸展步骤流程面板
|
|
/// </summary>
|
|
protected void Extpanel()
|
|
{
|
|
//延伸面板变化
|
|
GameObject stepGroupGeo = GetWedage("StepGroupTitle_N");
|
|
stepGroupGeo.SetActive(true);
|
|
GameObject focusGeo = GetWedage("FocusStep_N");
|
|
focusGeo.SetActive(false);
|
|
stepGroupGeo.GetComponent<RectTransform>().
|
|
DOSizeDelta(_stepsParentInitSize, 0.3f).OnComplete(() =>
|
|
{
|
|
//聚焦面板变化
|
|
GetWedage("ShrinkBtn_N").SetActive(true);
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 焦点步骤发生变化
|
|
/// </summary>
|
|
/// <param name="groupName">相当于大步骤名字</param>
|
|
/// <param name="id">小步骤</param>
|
|
protected void ItemChanged(string groupName, string id)
|
|
{
|
|
WDebug.Log("当前步骤" + id);
|
|
if (_curSelectStepBtn)
|
|
{
|
|
_curSelectStepBtn.Find("TextIndex").GetComponent<Text>().color = Color.white;
|
|
_curSelectStepBtn.Find("TextContent").GetComponent<Text>().color = Color.white;
|
|
_curSelectStepBtn.parent.parent.Find("IsSelectBG").GetComponent<Image>().enabled = false;
|
|
}
|
|
Transform TempParent = _stepContent.Find(groupName+ "/StepSmallParent");
|
|
bool isFind = false;
|
|
int a = 0;
|
|
Transform btnTran = null;
|
|
do
|
|
{
|
|
btnTran = TempParent.Find(id);
|
|
isFind = btnTran == null ? false : true;
|
|
a++;
|
|
int tempid = int.Parse(id) - 1;
|
|
id = tempid.ToString();
|
|
} while (!isFind&&a< TempParent.childCount);
|
|
if (btnTran)
|
|
{
|
|
btnTran.Find("TextIndex").GetComponent<Text>().color = new Color(113 / 255.0f, 186 / 255.0f, 255 / 255.0f, 1);
|
|
btnTran.Find("TextContent").GetComponent<Text>().color = new Color(113 / 255.0f, 186 / 255.0f, 255 / 255.0f, 1);
|
|
btnTran.parent.parent.Find("IsSelectBG").GetComponent<Image>().enabled = true;
|
|
}
|
|
_curSelectStepBtn = btnTran;
|
|
}
|
|
protected void ItemChanged(string stepName)
|
|
{
|
|
if (_curSelectStepBtn)
|
|
{
|
|
_curSelectStepBtn.Find("IsSelectBG").GetComponent<Image>().enabled = false;
|
|
}
|
|
Transform btnTran = _stepContent.Find(stepName);
|
|
btnTran.Find("IsSelectBG").GetComponent<Image>().enabled = true;
|
|
_curSelectStepBtn = btnTran;
|
|
}
|
|
/// <summary>
|
|
/// 点击大步骤,控制大步骤展开合并
|
|
/// </summary>
|
|
/// <param name="stepBigRect"></param>
|
|
private void OnClickBigStep(RectTransform stepBigRect)
|
|
{
|
|
RectTransform smallItemParent = stepBigRect.transform.Find("StepSmallParent").GetComponent<RectTransform>();
|
|
if (smallItemParent.sizeDelta.y > 0)
|
|
{//处于展开状态
|
|
//关闭动画
|
|
DOTween.Kill("OpenSequence");
|
|
Sequence closeSequence = DOTween.Sequence();
|
|
closeSequence.Append(stepBigRect.DOSizeDelta(new Vector2(stepBigRect.sizeDelta.x, -_smallParentInitPosY- _smallItemIntervalY), _openCloseAnmSpeed * smallItemParent.childCount));
|
|
closeSequence.Insert(0, stepBigRect.Find("OpenCloseBtn").DORotate(Vector3.forward * -90.0f, _openCloseAnmSpeed * smallItemParent.childCount));
|
|
closeSequence.Insert(0, smallItemParent.DOSizeDelta(new Vector2(smallItemParent.sizeDelta.x, 0), _openCloseAnmSpeed * smallItemParent.childCount));
|
|
for (int i = 0; i < smallItemParent.GetComponentsInChildren<Button>().Length; i++)
|
|
{
|
|
RectTransform item = smallItemParent.GetComponentsInChildren<Button>()[i].GetComponent<RectTransform>();
|
|
closeSequence.Insert(0, item.DOAnchorPosY(0, _openCloseAnmSpeed * (i + 1)));
|
|
}
|
|
closeSequence.Insert(0, smallItemParent.DOAnchorPosY(0, _openCloseAnmSpeed * smallItemParent.childCount)).OnComplete(() =>
|
|
{
|
|
smallItemParent.gameObject.SetActive(false);
|
|
}).SetId("CloseSequence");
|
|
}
|
|
else
|
|
{//处于合并状态
|
|
//展开动画
|
|
DOTween.Kill("CloseSequence");
|
|
Sequence openSequence = DOTween.Sequence();
|
|
float smallItemParentSizeY = _smallItemSizeY + (_smallItemSizeY + _smallItemIntervalY) * (smallItemParent.childCount - 2);//多减掉一个隐藏的预制体
|
|
openSequence.Append(stepBigRect.DOSizeDelta(new Vector2(stepBigRect.sizeDelta.x, -_smallParentInitPosY - _smallItemIntervalY+ smallItemParentSizeY), _openCloseAnmSpeed * smallItemParent.childCount));
|
|
openSequence.Insert(0, stepBigRect.Find("OpenCloseBtn").DORotate(Vector3.forward * 0.0f, _openCloseAnmSpeed * smallItemParent.childCount));
|
|
openSequence.Insert(0, smallItemParent.DOSizeDelta(new Vector2(smallItemParent.sizeDelta.x, smallItemParentSizeY), _openCloseAnmSpeed * smallItemParent.childCount));
|
|
for (int i = 0; i < smallItemParent.GetComponentsInChildren<Button>().Length; i++)
|
|
{
|
|
RectTransform item = smallItemParent.GetComponentsInChildren<Button>()[i].GetComponent<RectTransform>();
|
|
openSequence.Insert(0, item.DOAnchorPosY(-(_smallItemSizeY+_smallItemIntervalY) * i, _openCloseAnmSpeed * (i + 1)));
|
|
}
|
|
openSequence.Insert(0, smallItemParent.DOAnchorPosY(_smallParentInitPosY, _openCloseAnmSpeed * smallItemParent.childCount)).OnStart(() =>
|
|
{
|
|
smallItemParent.gameObject.SetActive(true);
|
|
}).SetId("OpenSequence");
|
|
}
|
|
}
|
|
}
|
|
} |