Exemple #1
0
        void OnAddBuff(object sender, EventArgs arg)
        {
            AddBuffEvtArg _arg   = arg as AddBuffEvtArg;
            int           buffID = _arg.buffID;

            if (Global.BuffData.ContainsKey(buffID))
            {
                BuffItem buff = Global.BuffData [buffID] as BuffItem;
                Debug.Log("buff icon = " + buff.iconName);
                if (buffIconMap.ContainsKey(buff.BuffID))
                {
                    return;
                }
                GameObject obj = Global.GetPrefab(buff.iconName);
                if (obj == null)
                {
                    Debug.LogWarning("未能读取到" + buff.iconName);
                    return;
                }

                Debug.Log(obj.name);
                GameObject imgObj = (GameObject)Instantiate(obj);
                Image      img    = obj.GetComponent <Image> ();
                img.enabled = false;
                buffIconMap.Add(buffID, imgObj);
                isDirty = true;
            }
            else
            {
                Debug.Log("OnAddBuff失败!没找到Buff");
            }
        }
Exemple #2
0
 static void ReadBuffData(string dirPath)
 {
     Debug.Log("读取" + dirPath + "目录");
     foreach (string path in Directory.GetFiles(dirPath))
     {
         if (System.IO.Path.GetExtension(path) == ".asset")
         {
             string buffResourcePath = "Assets/Resource/Data/Buff/" + System.IO.Path.GetFileName(path);
             Debug.Log("读取" + buffResourcePath);
             BuffItem item = AssetDatabase.LoadAssetAtPath <BuffItem>(buffResourcePath);
             if (item != null)
             {
                 BuffData.Add(item.BuffID, item);
             }
             else
             {
                 Debug.Log("读取" + buffResourcePath + "失败");
             }
         }
     }
 }
Exemple #3
0
        //移除buff
        public void RemoveBuff(int buffID, int count)
        {
            if (!buffMap.ContainsKey(buffID))
            {
                //没有此buff,不用移除
                return;
            }
            if (Global.BuffData.ContainsKey(buffID) == false)
            {
                return;
            }
            BuffItem buffItem = Global.BuffData [buffID] as BuffItem;

            if (buffItem.canBeRemoved == true)
            {
                //移除指定数量
                if (buffMap.ContainsKey(buffID))
                {
                    for (int i = buffMap[buffID].Count - 1; i >= 0; i--)
                    {
                        BaseBuff buff = buffMap [buffID] [i];
                        buff.OnRemoveBuff();
                        buffMap [buffID].Remove(buff);
                    }
                }
            }
            //判断是否为玩家单位
            if (Global.GetPlayer() == gameObject)
            {
                if (!buffMap.ContainsKey(buffID) || buffMap[buffID].Count == 0)
                {
                    RemoveBuffIconEvtArg arg = new RemoveBuffIconEvtArg();
                    arg.buffID = buffID;
                    FireEvent(this, EventType.EVT_REMOVE_BUFF_ICON, arg);
                }
            }
        }