using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public abstract class BaseCreateViewerCtrl : MonoBehaviour { protected void CreateViewer(Dictionary dicData) { this.CreateViewer(dicData, false); } public void CreateViewerWhenDataNotExist(Dictionary dicData) { this.CreateViewer(dicData, true); } private void CreateViewer(Dictionary dicData, bool CanCreateWhenDataNotExist) { if (!CanCreateWhenDataNotExist && !this.HasDicData(dicData)) { return; } this.ExecuteTemplateOperation(); } public void CreateViewer(List listData) { if (listData == null || listData.Count == 0) { return; } this.ExecuteTemplateOperation(); } public void CreateViewer(T data) { if (data == null) { return; } this.ExecuteTemplateOperation(); } private void ExecuteTemplateOperation() { this.DelChildGameObject(this.m_goUnitParent); this.ValidateData(); this.m_goUnitPrefab = this.GetUnitPrefab(this.m_unitPrefabPath); this.SetDataForViewer(); this.Reposition(); } private GameObject GetUnitPrefab(string unitPrefabPath) { this.m_goUnitPrefab = (this.m_goUnitPrefab ?? (Resources.Load(unitPrefabPath) as GameObject)); return this.m_goUnitPrefab; } protected void DelChildGameObject(GameObject goParent) { IEnumerator enumerator = goParent.transform.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Transform transform = (Transform)obj; UnityEngine.Object.Destroy(transform.gameObject); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } goParent.transform.DetachChildren(); } protected void DelChildGameObject() { IEnumerator enumerator = this.m_goUnitParent.transform.GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; Transform transform = (Transform)obj; UnityEngine.Object.Destroy(transform.gameObject); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } this.m_goUnitParent.transform.DetachChildren(); } protected void Reposition() { UITable component = this.m_goUnitParent.GetComponent(); if (component) { component.Reposition(); return; } UIGrid component2 = this.m_goUnitParent.GetComponent(); if (component2) { component2.Reposition(); return; } } public static void Reposition(GameObject parent) { UITable component = parent.GetComponent(); if (component) { component.Reposition(); return; } UIGrid component2 = parent.GetComponent(); if (component2) { component2.Reposition(); return; } } protected virtual void ValidateData() { } protected void SetTransformInfo(GameObject copyPrefab) { this.SetTransformInfo(this.m_goUnitParent, copyPrefab); } protected void SetTransformInfo(GameObject parent, GameObject copyPrefabs) { copyPrefabs.transform.parent = parent.transform; copyPrefabs.transform.localScale = Vector3.one; copyPrefabs.transform.localPosition = Vector3.zero; copyPrefabs.transform.rotation = Quaternion.identity; } public bool HasDicData(Dictionary dicData) { return dicData != null && dicData.Count != 0; } public bool HasListData(List listData) { return listData != null && listData.Count > 0; } protected abstract void SetDataForViewer(); protected GameObject m_goUnitParent; protected GameObject m_goUnitPrefab; protected string m_unitPrefabPath; private const float DURATION_TO_FADE = 0.5f; }