Ejemplo n.º 1
0
        //创建一些道具
        public void GenerateItems(int itemCount)
        {
            int randomCount = Mathf.Min(itemCount, normalGrids.Count);

            if (randomCount <= 0)
            {
                return;
            }

            List <GridUnit> tempGrids = new List <GridUnit>(normalGrids);

            for (int i = 0; i < randomCount; i++)
            {
                //随机一种道具类型
                int            randomItemId = Random.Range(5000, 5002);
                int            randomIdx    = Random.Range(0, tempGrids.Count);
                SO_PackageItem item         = PackageItemManager.Instance.GetItem(randomItemId);
                if (item == null)
                {
                    UtilityHelper.LogError(string.Format("Generate items failed. ID = {0} ", randomItemId));
                    continue;
                }
                else
                {
                    tempGrids[randomIdx].gridItem       = new GridItem();
                    tempGrids[randomIdx].gridItem.item  = item;
                    tempGrids[randomIdx].gridItem.count = 2;
                    tempGrids.RemoveAt(randomIdx);
                }
            }
        }
 public void BattleUnitUseItem(BattleUnit battleUnit, SO_PackageItem item, int count)
 {
     if (battleUnit == null ||
         battleUnit.battleUnitRenderer == null ||
         !battleUnit.battleUnitRenderer.Equals(manualOperatingBattleUnitRenderer))
     {
         UtilityHelper.LogError("Battle unit use item failed.");
         HideManualActionList();
         return;
     }
     battleUnit.UseItem(item.itemID, count);
     ManualOperationComplete();
 }
Ejemplo n.º 3
0
        //初始化道具
        private void InitItems()
        {
            Object[] items = GetAssetsFromBundle("scriptableobjects/packageitem.unity3d", typeof(SO_PackageItem));
            if (items != null)
            {
                for (int i = 0; i < items.Length; ++i)
                {
                    SO_PackageItem item = items[i] as SO_PackageItem;
                    if (item == null)
                    {
                        continue;
                    }

                    dicPackageItems.Add(item.itemID, item);
                }
            }
        }
Ejemplo n.º 4
0
        public void RefreshItemIcon(int itemID, int itemCount)
        {
            SO_PackageItem gridItem = null;

            if (itemCount > 0)
            {
                gridItem = PackageItemManager.Instance.GetItem(itemID);
            }

            itemIconRenderer.enabled = gridItem != null;
            if (gridItem == null)
            {
                itemIconRenderer.sprite  = null;
                itemIconRenderer.enabled = false;
            }
            else
            {
                itemIconRenderer.sprite  = gridItem.icon;
                itemIconRenderer.enabled = true;
            }
        }
Ejemplo n.º 5
0
 public void Reset()
 {
     item  = null;
     count = 0;
 }
 //使用道具
 public void UseItem(BattleUnit battleUnit, SO_PackageItem item, int count)
 {
 }
Ejemplo n.º 7
0
 public void BattleUnitUseItem(BattleUnit battleUnit, SO_PackageItem item, int count)
 {
     manualOperationHelper.BattleUnitUseItem(battleUnit, item, count);
 }
Ejemplo n.º 8
0
        //TODO:刷新Item和skill在逻辑上非常重复,以后提出通用部分

        private static void RefreshItemObject()
        {
            //先保存已有的
            Dictionary <string, SO_PackageItem> exists = new Dictionary <string, SO_PackageItem>(System.StringComparer.CurrentCultureIgnoreCase);
            List <string> newList    = new List <string>();
            List <string> removeList = new List <string>();

            string[] existObject = Directory.GetFiles(SO_ItemFolder, "*.asset", SearchOption.AllDirectories).Where(delegate(string filePath)
            {
                if (filePath.ToLower().Contains("meta"))
                {
                    return(false);
                }
                return(true);
            }).ToArray();
            foreach (var item in existObject)
            {
                SO_PackageItem packageItem = AssetDatabase.LoadAssetAtPath <SO_PackageItem>(item);
                if (packageItem != null)
                {
                    exists.Add(packageItem.name, packageItem);
                }
            }

            TextAsset textAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(string.Format("{0}/item.json", JsonFolder));
            var       items     = JsonMapper.ToObject(textAsset.text);

            if (items.IsArray)
            {
                foreach (var item in items)
                {
                    JsonData itemData = item as JsonData;
                    if (itemData == null)
                    {
                        continue;
                    }

                    string         objName   = ParseFromJson(itemData, "objName", string.Empty);
                    SO_PackageItem assetItem = null;
                    //尝试从存在的列表中获取
                    if (exists.ContainsKey(objName))
                    {
                        assetItem = exists[objName];
                        //移除,后面要删除没有找到的
                        exists.Remove(objName);
                    }

                    if (assetItem == null)
                    {
                        newList.Add(objName);
                        string assetPath = string.Format("{0}/{1}.asset", SO_ItemFolder, objName);
                        assetItem = ScriptableObject.CreateInstance <SO_PackageItem>();
                        AssetDatabase.CreateAsset(assetItem, assetPath);
                    }

                    assetItem.itemID   = ParseFromJson(itemData, "ID", 0);
                    assetItem.itemName = ParseFromJson(itemData, "itemName", string.Empty);

                    //设置图片
                    string bundleName = ParseFromJson(itemData, "IconBundle", string.Empty);
                    string assetName  = ParseFromJson(itemData, "itemIcon", string.Empty);
                    assetItem.icon = GetTextureAsset <Sprite>(bundleName, assetName);

                    string itemType = ParseFromJson(itemData, "itemType", string.Empty);
                    if (string.Compare(itemType, "Recovery", true) == 0)
                    {
                        assetItem.itemType = PackageItemType.Recover;
                    }

                    assetItem.hpRecovery     = ParseFromJson(itemData, "HPRecovery", 0);
                    assetItem.energyRecovery = ParseFromJson(itemData, "EnergyRecovery", 0);

                    EditorUtility.SetDirty(assetItem);
                }
            }

            //需要删除没有的
            if (exists.Count > 0)
            {
                if (EditorUtility.DisplayDialog("警告", string.Format("存在{0}个配置外的道具, 是否删除", exists.Keys.Count), "是", "否"))
                {
                    removeList = new List <string>(exists.Keys);
                    foreach (var item in exists)
                    {
                        AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(item.Value));
                    }
                    exists.Clear();
                }
            }

            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
            stringBuilder.AppendFormat("道具生成结束,新增:{0},删除{1}\n", newList.Count, removeList.Count);
            stringBuilder.AppendFormat("  新增:\n");
            for (int i = 0; i < newList.Count; i++)
            {
                stringBuilder.AppendFormat("    {0}.{1}\n", i, newList[i]);
            }

            stringBuilder.AppendFormat("  删除:\n");
            for (int i = 0; i < removeList.Count; i++)
            {
                stringBuilder.AppendFormat("    {0}.{1}\n", i, removeList[i]);
            }
            Debug.Log(stringBuilder.ToString());
        }