public static ShowItemInfo Create(Type itemLogicType, object userData)
        {
            ShowItemInfo showItemInfo = ReferencePool.Acquire <ShowItemInfo>();

            showItemInfo.m_ItemLogicType = itemLogicType;
            showItemInfo.m_UserData      = userData;
            return(showItemInfo);
        }
        /// <summary>
        /// 创建显示物体成功事件。
        /// </summary>
        /// <param name="e">内部事件。</param>
        /// <returns>创建的显示物体成功事件。</returns>
        public static ShowItemSuccessEventArgs Create(GameFramework.Item.ShowItemSuccessEventArgs e)
        {
            ShowItemInfo             showItemInfo             = (ShowItemInfo)e.UserData;
            ShowItemSuccessEventArgs showItemSuccessEventArgs = ReferencePool.Acquire <ShowItemSuccessEventArgs>();

            showItemSuccessEventArgs.ItemLogicType = showItemInfo.ItemLogicType;
            showItemSuccessEventArgs.Item          = (Item)e.Item;
            showItemSuccessEventArgs.Duration      = e.Duration;
            showItemSuccessEventArgs.UserData      = showItemInfo.UserData;
            ReferencePool.Release(showItemInfo);
            return(showItemSuccessEventArgs);
        }
        /// <summary>
        /// 创建显示物体更新事件。
        /// </summary>
        /// <param name="e">内部事件。</param>
        /// <returns>创建的显示物体更新事件。</returns>
        public static ShowItemUpdateEventArgs Create(GameFramework.Item.ShowItemUpdateEventArgs e)
        {
            ShowItemInfo            showItemInfo            = (ShowItemInfo)e.UserData;
            ShowItemUpdateEventArgs showItemUpdateEventArgs = ReferencePool.Acquire <ShowItemUpdateEventArgs>();

            showItemUpdateEventArgs.ItemId        = e.ItemId;
            showItemUpdateEventArgs.ItemLogicType = showItemInfo.ItemLogicType;
            showItemUpdateEventArgs.ItemAssetName = e.ItemAssetName;
            showItemUpdateEventArgs.ItemGroupName = e.ItemGroupName;
            showItemUpdateEventArgs.Progress      = e.Progress;
            showItemUpdateEventArgs.UserData      = showItemInfo.UserData;
            return(showItemUpdateEventArgs);
        }
        /// <summary>
        /// 创建显示物体失败事件。
        /// </summary>
        /// <param name="e">内部事件。</param>
        /// <returns>创建的显示物体失败事件。</returns>
        public static ShowItemFailureEventArgs Create(GameFramework.Item.ShowItemFailureEventArgs e)
        {
            ShowItemInfo             showItemInfo             = (ShowItemInfo)e.UserData;
            ShowItemFailureEventArgs showItemFailureEventArgs = ReferencePool.Acquire <ShowItemFailureEventArgs>();

            showItemFailureEventArgs.ItemId        = e.ItemId;
            showItemFailureEventArgs.ItemLogicType = showItemInfo.ItemLogicType;
            showItemFailureEventArgs.ItemAssetName = e.ItemAssetName;
            showItemFailureEventArgs.ItemGroupName = e.ItemGroupName;
            showItemFailureEventArgs.ErrorMessage  = e.ErrorMessage;
            showItemFailureEventArgs.UserData      = showItemInfo.UserData;
            ReferencePool.Release(showItemInfo);
            return(showItemFailureEventArgs);
        }
        /// <summary>
        /// 创建显示物体时加载依赖资源事件。
        /// </summary>
        /// <param name="e">内部事件。</param>
        /// <returns>创建的显示物体时加载依赖资源事件。</returns>
        public static ShowItemDependencyAssetEventArgs Create(GameFramework.Item.ShowItemDependencyAssetEventArgs e)
        {
            ShowItemInfo showItemInfo = (ShowItemInfo)e.UserData;
            ShowItemDependencyAssetEventArgs showItemDependencyAssetEventArgs = ReferencePool.Acquire <ShowItemDependencyAssetEventArgs>();

            showItemDependencyAssetEventArgs.ItemId              = e.ItemId;
            showItemDependencyAssetEventArgs.ItemLogicType       = showItemInfo.ItemLogicType;
            showItemDependencyAssetEventArgs.ItemAssetName       = e.ItemAssetName;
            showItemDependencyAssetEventArgs.ItemGroupName       = e.ItemGroupName;
            showItemDependencyAssetEventArgs.DependencyAssetName = e.DependencyAssetName;
            showItemDependencyAssetEventArgs.LoadedCount         = e.LoadedCount;
            showItemDependencyAssetEventArgs.TotalCount          = e.TotalCount;
            showItemDependencyAssetEventArgs.UserData            = showItemInfo.UserData;
            return(showItemDependencyAssetEventArgs);
        }
        /// <summary>
        /// 物品显示。
        /// </summary>
        /// <param name="userData">用户自定义数据。</param>
        public void OnShow(object userData)
        {
            ShowItemInfo showItemInfo = (ShowItemInfo)userData;

            if (m_ItemLogic == null)
            {
                return;
            }

            try
            {
                m_ItemLogic.OnShow(showItemInfo.UserData);
            }
            catch (Exception exception)
            {
                Log.Error("Item '[{0}]{1}' OnShow with exception '{2}'.", m_Id.ToString(), m_ItemAssetName, exception.ToString());
            }
        }
 /// <summary>
 /// 显示物体。
 /// </summary>
 /// <param name="itemId">物体编号。</param>
 /// <param name="itemLogicType">物体逻辑类型。</param>
 /// <param name="itemAssetName">物体资源名称。</param>
 /// <param name="itemGroupName">物体组名称。</param>
 /// <param name="priority">加载物体资源的优先级。</param>
 /// <param name="userData">用户自定义数据。</param>
 public void ShowItem(int itemId, Type itemLogicType, string itemAssetName, string itemGroupName, int priority, object userData)
 {
     m_ItemManager.ShowItem(itemId, itemAssetName, itemGroupName, priority, ShowItemInfo.Create(itemLogicType, userData));
 }
        /// <summary>
        /// 物品初始化。
        /// </summary>
        /// <param name="itemId">物品编号。</param>
        /// <param name="itemAssetName">物品资源名称。</param>
        /// <param name="itemGroup">物品所属的物品组。</param>
        /// <param name="isNewInstance">是否是新实例。</param>
        /// <param name="userData">用户自定义数据。</param>
        public void OnInit(int itemId, string itemAssetName, IItemGroup itemGroup, bool isNewInstance, object userData)
        {
            m_Id            = itemId;
            m_ItemAssetName = itemAssetName;
            if (isNewInstance)
            {
                m_ItemGroup = itemGroup;
            }
            else if (m_ItemGroup != itemGroup)
            {
                Log.Error("Item group is inconsistent for non-new-instance item.");
                return;
            }

            initRoot     = transform.parent;
            initPosition = transform.localPosition;
            initRotation = transform.eulerAngles;
            initScale    = transform.localScale;

            ShowItemInfo showItemInfo  = (ShowItemInfo)userData;
            Type         itemLogicType = showItemInfo.ItemLogicType;

            if (m_ItemLogic != null)
            {
                if (m_ItemLogic.GetType() == itemLogicType)
                {
                    m_ItemLogic.enabled = true;
                    return;
                }

                Destroy(m_ItemLogic);
                m_ItemLogic = null;
            }

            if (itemLogicType == null)
            {
                return;
            }

            m_ItemLogic = gameObject.GetComponent(itemLogicType) as ItemLogic;

            if (m_ItemLogic == null)
            {
                m_ItemLogic = gameObject.AddComponent(itemLogicType) as ItemLogic;
            }

            if (m_ItemLogic == null)
            {
                Log.Error("Item '{0}' can not add item logic.", itemAssetName);
                return;
            }

            try
            {
                m_ItemLogic.OnInit(showItemInfo.UserData);
            }
            catch (Exception exception)
            {
                Log.Error("Item '[{0}]{1}' OnInit with exception '{2}'.", m_Id.ToString(), m_ItemAssetName, exception.ToString());
            }
        }