示例#1
0
    public IReinitable CreateCarouselItem(IData data)
    {
        IReinitable view = TryGetMessageFromPool(data) ?? CreateNewMessage(data);

        AnimateMessage(view);
        return(view);
    }
示例#2
0
    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);
    }
示例#3
0
    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);
    }
示例#4
0
    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);
    }
示例#5
0
    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);
        }
    }
示例#6
0
 public void OnCarouselItemUpdate(IReinitable item)
 {
     AnimateMessage(item);
 }
示例#7
0
 public void DisposeCarouselItem(IReinitable item)
 {
     pool.Put(item, item.Data.GetType());
 }