using System; using System.Collections; using System.Collections.Generic; namespace YooAsset.Editor { public class BuildContext { private readonly Dictionary _contextObjects = new Dictionary(); /// /// 清空所有情景对象 /// public void ClearAllContext() { _contextObjects.Clear(); } /// /// 设置情景对象 /// public void SetContextObject(IContextObject contextObject) { if (contextObject == null) throw new ArgumentNullException("contextObject"); var type = contextObject.GetType(); if (_contextObjects.ContainsKey(type)) throw new Exception($"Context object {type} is already existed."); _contextObjects.Add(type, contextObject); } /// /// 获取情景对象 /// public T GetContextObject() where T : IContextObject { var type = typeof(T); if (_contextObjects.TryGetValue(type, out IContextObject contextObject)) { return (T)contextObject; } else { throw new Exception($"Not found context object : {type}"); } } } }