public void CreateAsync <T>(ViewLink link, Action <T> onLoad, Action <Exception> error = null) where T : class, IView { if (pools.TryGetValue(link.GetHashCode(), out Pool pool)) { onLoad(pool.Take <T>()); return; } link.Load(prefab => { if (pools.TryGetValue(link.GetHashCode(), out Pool p)) { onLoad(p.Take <T>()); return; } if (prefab == null) { Exception e = new NullReferenceException($"Cannot load view of type {typeof(T).Name}: {link}"); Debug.LogException(e); error?.Invoke(e); return; } pool = Pool.Create(() => Create <T>(prefab.GetRoot())); pools.Add(link.GetHashCode(), pool); onLoad(pool.Take <T>()); }, error); }
public T Create <T>(ViewLink link) where T : class, IView { if (IsLoaded(link)) { return(pools[link.GetHashCode()].Take <T>()); } if (AssetCache.Loaded(link.GetPath())) { Pool pool = Pool.Create(() => Create <T>(link.Value.GetRoot())); pools.Add(link.GetHashCode(), pool); return(pool.Take <T>()); } Debug.LogError($"Cannot create view {link} synchronously. Not loaded yet. Use CreateAsync or WarmUp"); return(null); }
public T GetOrCreateView <T>(ViewLink link) where T : class, IView { if (pools.TryGetValue(link.GetHashCode(), out Pool pool)) { foreach (var item in pool.GetActiveItems <T>()) { return(item); } } return(Create <T>(link)); }
private T TakeFromPool <T>(ViewLink link) where T : class, IView { return(pools[link.GetHashCode()].Take <T>()); }