private void LoadAssetSuccessCallback(string ItemAssetName, object ItemAsset, float duration, object userData)
        {
            ShowItemInfo showItemInfo = (ShowItemInfo)userData;

            if (showItemInfo == null)
            {
                throw new GameFrameworkException("Show Item info is invalid.");
            }

            if (m_ItemsToReleaseOnLoad.Contains(showItemInfo.SerialId))
            {
                m_ItemsToReleaseOnLoad.Remove(showItemInfo.SerialId);
                ReferencePool.Release(showItemInfo);
                m_ItemHelper.ReleaseItem(ItemAsset, null);
                return;
            }

            m_ItemsBeingLoaded.Remove(showItemInfo.ItemId);
            ItemInstanceObject itemInstanceObject = ItemInstanceObject.Create(ItemAssetName, ItemAsset, m_ItemHelper.InstantiateItem(ItemAsset), m_ItemHelper);

            showItemInfo.ItemGroup.RegisterItemInstanceObject(itemInstanceObject, true);

            InternalShowItem(showItemInfo.ItemId, ItemAssetName, showItemInfo.ItemGroup, itemInstanceObject.Target, true, duration, showItemInfo.UserData);
            ReferencePool.Release(showItemInfo);
        }
        /// <summary>
        /// 显示物品。
        /// </summary>
        /// <param name="itemId">物品编号。</param>
        /// <param name="itemAssetName">物品资源名称。</param>
        /// <param name="itemGroupName">物品组名称。</param>
        /// <param name="priority">加载物品资源的优先级。</param>
        /// <param name="userData">用户自定义数据。</param>
        public void ShowItem(int itemId, string itemAssetName, string itemGroupName, int priority, object userData)
        {
            if (m_ResourceManager == null)
            {
                throw new GameFrameworkException("You must set resource manager first.");
            }

            if (m_ItemHelper == null)
            {
                throw new GameFrameworkException("You must set item helper first.");
            }

            if (string.IsNullOrEmpty(itemAssetName))
            {
                throw new GameFrameworkException("Item asset name is invalid.");
            }

            if (string.IsNullOrEmpty(itemGroupName))
            {
                throw new GameFrameworkException("Item group name is invalid.");
            }

            if (HasItem(itemId))
            {
                throw new GameFrameworkException(Utility.Text.Format("Item id '{0}' is already exist.", itemId.ToString()));
            }

            if (IsLoadingItem(itemId))
            {
                throw new GameFrameworkException(Utility.Text.Format("Item '{0}' is already being loaded.", itemId.ToString()));
            }

            ItemGroup itemGroup = (ItemGroup)GetItemGroup(itemGroupName);

            if (itemGroup == null)
            {
                throw new GameFrameworkException(Utility.Text.Format("Item group '{0}' is not exist.", itemGroupName));
            }

            ItemInstanceObject itemInstanceObject = itemGroup.SpawnItemInstanceObject(itemAssetName);

            if (itemInstanceObject == null)
            {
                int serialId = ++m_Serial;
                m_ItemsBeingLoaded.Add(itemId, serialId);
                m_ResourceManager.LoadAsset(itemAssetName, priority, m_LoadAssetCallbacks, ShowItemInfo.Create(serialId, itemId, itemGroup, userData));
                return;
            }

            InternalShowItem(itemId, itemAssetName, itemGroup, itemInstanceObject.Target, false, 0f, userData);
        }
Exemplo n.º 3
0
            public static ItemInstanceObject Create(string name, object itemAsset, object itemInstance, IItemHelper itemHelper)
            {
                if (itemAsset == null)
                {
                    throw new GameFrameworkException("Item asset is invalid.");
                }

                if (itemHelper == null)
                {
                    throw new GameFrameworkException("Item helper is invalid.");
                }

                ItemInstanceObject itemInstanceObject = ReferencePool.Acquire <ItemInstanceObject>();

                itemInstanceObject.Initialize(name, itemInstance);
                itemInstanceObject.m_ItemAsset  = itemAsset;
                itemInstanceObject.m_ItemHelper = itemHelper;
                return(itemInstanceObject);
            }
 public void RegisterItemInstanceObject(ItemInstanceObject obj, bool spawned)
 {
     m_InstancePool.Register(obj, spawned);
 }