Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 public static IView GetOrCreateItemView(this IPrefable item, bool isActiveDefault = true)
 {
     return(GetOrCreateItemView <IView>(item, isActiveDefault));
 }