public static void BindItemView <T>(this IPrefable item, T view) where T : IView { if (item.GlobalIndex.HasValue) { throw new InvalidDataException("Item already have view"); } if (ActiveViews.ContainsValue(view)) { throw new InvalidDataException("View already binded"); } item.GlobalIndex = view.Index; view.Name = string.Format("{0}#{1}", view.Name, view.Index); view.isActive = true; ActiveViews.Add(item.GlobalIndex.Value, view); item.GlobalIndex = view.Index; }
public static T GetOrCreateItemView <T>(this IPrefable item, bool isActiveDefault = true) where T : IView { if (item.GlobalIndex.HasValue) { ActiveViews.TryGetValue(item.GlobalIndex.Value, value: out var activeView); if (activeView != null) { return((T)activeView); } } var prefabPath = string.Format(GameConstants.DefaultFormat, item.PrefabPrefix + "/" + item.PrefabID); var view = GetOrCreateItemView <T>(prefabPath, isActiveDefault); if (view == null) { return(view); } item.GlobalIndex = view.Index; return(view); }
public static IView GetOrCreateItemView(this IPrefable item, bool isActiveDefault = true) { return(GetOrCreateItemView <IView>(item, isActiveDefault)); }