//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, April 10, 2018
|
//--------------------------------------------------------
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using System.Text.RegularExpressions;
|
using System.Text;
|
using Snxxz.UI;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
|
public class AnimationFadeOut : MonoBehaviour
|
{
|
[Header("每列个数")]
|
public int LINE = 4;
|
[SerializeField] Transform m_OblNull;
|
[SerializeField] LineFadeOut m_LineFadeOut1;
|
[SerializeField] LineFadeOut m_LineFadeOut2;
|
[SerializeField] LineFadeOut m_LineFadeOut3;
|
[SerializeField] Animator m_Animator;
|
|
[SerializeField] CanvasGroup m_CanvasGroup;
|
|
Dictionary<int, List<Transform>> AnimationFadeOutDic = new Dictionary<int, List<Transform>>();
|
Dictionary<int, Transform> tranDic = new Dictionary<int, Transform>();
|
|
public void Init()
|
{
|
|
PositionReduction();
|
Classify();
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChange;
|
}
|
public void Unit()
|
{
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChange;
|
}
|
|
public void FadeOut()//淡出
|
{
|
m_Animator.Play("MainFadeIn");
|
}
|
public void FadeIn()//淡入
|
{
|
m_Animator.Play("MainFadeOut");
|
}
|
|
public void ImmediatelyAppear()//立刻出现
|
{
|
m_Animator.Play("ImmediatelyAppear", 0, 1);
|
}
|
|
public void FadeAtOnce()//立刻消失
|
{
|
m_Animator.Play("FadeAtOnce", 0, 1);
|
}
|
|
public bool GetIsFadeIn()//是否淡入
|
{
|
if (m_CanvasGroup.alpha < 0.5)
|
{
|
return false;
|
}
|
else
|
{
|
return true;
|
}
|
}
|
|
private void OnFuncStateChange(int obj)
|
{
|
PositionReduction();
|
Classify();
|
}
|
|
private void Classify()
|
{
|
SetGroup();
|
SetfatherNode();
|
|
}
|
|
private void SetGroup()//进行分组
|
{
|
AnimationFadeOutDic.Clear();
|
tranDic.Clear();
|
int Index = 0;
|
for (int i = 0; i < m_OblNull.childCount; i++)
|
{
|
if (m_OblNull.GetChild(i).GetComponent<UIFuncOpen>() != null && !FuncOpen.Instance.IsFuncOpen(m_OblNull.GetChild(i).GetComponent<UIFuncOpen>().id))
|
{
|
|
}
|
else
|
{
|
if (m_OblNull.GetChild(i).GetComponent<PositionIndex>() != null)
|
{
|
if (!tranDic.ContainsKey(m_OblNull.GetChild(i).GetComponent<PositionIndex>().Index))
|
{
|
int index = m_OblNull.GetChild(i).GetComponent<PositionIndex>().Index;
|
tranDic.Add(index, m_OblNull.GetChild(i));
|
}
|
|
}
|
Index += 1;
|
int line = Mathf.CeilToInt((float)Index / LINE);
|
if (!AnimationFadeOutDic.ContainsKey(line))
|
{
|
List<Transform> tran = new List<Transform>();
|
tran.Add(m_OblNull.GetChild(i).transform);
|
AnimationFadeOutDic.Add(line, tran);
|
}
|
else
|
{
|
AnimationFadeOutDic[line].Add(m_OblNull.GetChild(i).transform);
|
}
|
}
|
}
|
|
}
|
|
private void SetfatherNode()//设置父节点
|
{
|
if (AnimationFadeOutDic.Count != 0)
|
{
|
foreach (var key in AnimationFadeOutDic.Keys)
|
{
|
SwithSome(key, AnimationFadeOutDic[key]);
|
}
|
}
|
else
|
{
|
m_LineFadeOut1.gameObject.SetActive(false);
|
m_LineFadeOut2.gameObject.SetActive(false);
|
m_LineFadeOut3.gameObject.SetActive(false);
|
}
|
}
|
|
|
private void SwithSome(int key, List<Transform> list)
|
{
|
switch (key)
|
{
|
case 1:
|
m_LineFadeOut1.gameObject.SetActive(true);
|
for (int i = 0; i < list.Count; i++)
|
{
|
int index = i;
|
Node(m_LineFadeOut1, index, list[index]);
|
}
|
break;
|
case 2:
|
m_LineFadeOut2.gameObject.SetActive(true);
|
for (int i = 0; i < list.Count; i++)
|
{
|
int index = i;
|
Node(m_LineFadeOut2, index, list[index]);
|
}
|
break;
|
case 3:
|
m_LineFadeOut3.gameObject.SetActive(true);
|
for (int i = 0; i < list.Count; i++)
|
{
|
int index = i;
|
Node(m_LineFadeOut3, index, list[index]);
|
}
|
break;
|
}
|
}//进行分列
|
private void Node(LineFadeOut lineFadeOut, int index, Transform tran)//设置进空盒子中
|
{
|
switch (index)
|
{
|
case 0:
|
tran.SetParent(lineFadeOut.OneParent);
|
tran.localPosition = Vector3.zero;
|
break;
|
case 1:
|
|
tran.SetParent(lineFadeOut.TwoParent);
|
tran.localPosition = Vector3.zero;
|
break;
|
case 2:
|
tran.SetParent(lineFadeOut.ThreeParent);
|
tran.localPosition = Vector3.zero;
|
break;
|
case 3:
|
tran.SetParent(lineFadeOut.FourParent);
|
tran.localPosition = Vector3.zero;
|
break;
|
default:
|
break;
|
}
|
}
|
|
private void PositionReduction()//还原位置(把盒子中的位置全部重新拉出来)
|
{
|
if (tranDic.Count <= 0)
|
{
|
return;
|
}
|
foreach (var key in tranDic.Keys)
|
{
|
tranDic[key].SetParent(m_OblNull);
|
tranDic[key].SetSiblingIndex(key);
|
}
|
}
|
|
|
}
|
|
|
|
}
|
|
|
|