public IReinitable CreateCarouselItem(IData data) { IReinitable view = TryGetMessageFromPool(data) ?? CreateNewMessage(data); AnimateMessage(view); return(view); }
private IReinitable TryGetMessageFromPool(IData data) { IReinitable view = pool.Get(data.GetType()); if (view != null) { view.Data = data; var trans = (view as MonoBehaviour).transform; trans.SetParent(carousel.ScrollingPanel.transform); } return(view); }
private IReinitable CreateNewMessage(IData data) { IReinitable view = null; Type viewType = typeof(BlankMessageView); var attribute = data.GetType().GetAttribute <TypeMapAttribute>(); if (attribute != null && attribute.Type != null) { viewType = attribute.Type; } var vmType = viewType.BaseType().GetGenericArguments().First(); var vm = ViewModel.CreateMessageViewModel(vmType, data); view = Use <IGuiManager>().CreateView(viewType, carousel.ScrollingPanel, null, vm) as IReinitable; return(view); }
public void Put(IReinitable vm, Type type) { var transform = (vm as MonoBehaviour).transform; HOTween.Kill(transform); (transform as RectTransform).localScale = Vector3.one; transform.SetParent(parent); if (!pool.ContainsKey(type)) { pool.Add(type, new Stack <IReinitable>()); } if (pool[type].Count >= maxStackCount) { Object.Destroy(transform.gameObject); return; } pool[type].Push(vm); }
private void AnimateMessage(IReinitable view) { var v = view as IAnimatedMessage; if (v == null) { return; } var data = view.Data; if (ViewModel.AddedAnimationsMessagesId.Contains(data.Id)) { v.StartShowAnimation(); ViewModel.AddedAnimationsMessagesId.Remove(data.Id); } else if (ViewModel.DeletedAnimationsMessagesId.Contains(data.Id)) { v.StartHideAnimation(); ViewModel.DeletedAnimationsMessagesId.Remove(data.Id); } }
public void OnCarouselItemUpdate(IReinitable item) { AnimateMessage(item); }
public void DisposeCarouselItem(IReinitable item) { pool.Put(item, item.Data.GetType()); }