| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 | using System;using System.Collections;using System.Collections.Generic;using UnityEngine;public abstract class BaseCreateViewerCtrl : MonoBehaviour{	protected void CreateViewer<K, V>(Dictionary<K, V> dicData)	{		this.CreateViewer<K, V>(dicData, false);	}	public void CreateViewerWhenDataNotExist<K, V>(Dictionary<K, V> dicData)	{		this.CreateViewer<K, V>(dicData, true);	}	private void CreateViewer<K, V>(Dictionary<K, V> dicData, bool CanCreateWhenDataNotExist)	{		if (!CanCreateWhenDataNotExist && !this.HasDicData<K, V>(dicData))		{			return;		}		this.ExecuteTemplateOperation();	}	public void CreateViewer<T>(List<T> listData)	{		if (listData == null || listData.Count == 0)		{			return;		}		this.ExecuteTemplateOperation();	}	public void CreateViewer<T>(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<UITable>();		if (component)		{			component.Reposition();			return;		}		UIGrid component2 = this.m_goUnitParent.GetComponent<UIGrid>();		if (component2)		{			component2.Reposition();			return;		}	}	public static void Reposition(GameObject parent)	{		UITable component = parent.GetComponent<UITable>();		if (component)		{			component.Reposition();			return;		}		UIGrid component2 = parent.GetComponent<UIGrid>();		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<K, V>(Dictionary<K, V> dicData)	{		return dicData != null && dicData.Count != 0;	}	public bool HasListData<T>(List<T> 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;}
 |