《组合变身小宠物游戏》PlayerPetItem(修改更新中)【初学者】

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine.EventSystems;
                                         
public class PlayerPetItem : MonoBehaviour, IPointerClickHandler
{
    public static PlayerPetItem self;
    public PetXmlData PlayerPetXmlVO;
    public Image HeadImage;
    public Image ImageMask;
    public Text Text_Hp;
    public Text Text_Attack;
    public Text Text_Lv;
    public int index;
    public int recordId = -1;
	// Use this for initialization

    void Awake()
    {
        self = this;
    }
    void Start()
    {
        int id = Random.Range(6, 20);
        UpdatePlayerPetItemData(id);
        if (DataRecord.GetPetHp(recordId) <= 0)
        {
            ImageMask.gameObject.SetActive(true);
        }
   
    }

    void Update()
    {
        if (DataRecord.GetPetHp(recordId) <= 0)
        {
            ImageMask.gameObject.SetActive(true);
        }
    }
      public  void UpdatePlayerPetItemData(int id)//给空的PlayerPetItem加载数据(Lv,Hp,ATK,Headimage)
    {
        Hashtable data = DataRecord.GetFightData(index);
        if (data == null)
        {
            PlayerPetXmlVO = ConfigManager.Instance.GetPetData(id);
            recordId = DataRecord.AddPet(PlayerPetXmlVO);
            DataRecord.SetFight(recordId, index);
        }
        else
        {
            recordId = DataRecord.GetRecordIdByPos(index);
            PlayerPetXmlVO.id = int.Parse(data["id"].ToString());
            PlayerPetXmlVO.hp = int.Parse(data["curHp"].ToString());
            PlayerPetXmlVO.level = int.Parse(data["level"].ToString());
            PlayerPetXmlVO.name = data["name"].ToString();
            PlayerPetXmlVO.headImage = data["headImage"].ToString();
            PlayerPetXmlVO.attack = int.Parse(data["attack"].ToString());
        }
            Text_Attack.text = PlayerPetXmlVO.attack.ToString();//攻击力
            Text_Hp.text = PlayerPetXmlVO.hp.ToString();//血量
            Text_Lv.text = PlayerPetXmlVO.level.ToString();//等级
            HeadImage.sprite = Resources.Load<Sprite>("Images/" + PlayerPetXmlVO.headImage);//头像
            GameFSM.self.playerData.Add(PlayerPetXmlVO);


    }

      public void OnPointerClick(PointerEventData eventData)// 点击预制体宠物: 相应头像变换 + 战斗
      {
          if ( DataRecord.GetPetHp(recordId)<= 0)
          {
              ImageMask.gameObject.SetActive(true);
          }
          if (DataRecord.GetPetHp(recordId) <= 0)
               return;
 
          Fighting.self.PlayerPetImage.sprite = Resources.Load<Sprite>("Images/" + PlayerPetXmlVO.headImage);//点击出战的宠物,战斗UI上的图片PlayerPetImage刷新成当前点击战斗宠物 

          GameFSM.self.PlayerAttack(PlayerPetXmlVO.id, index);//首先 角色攻击怪物

      }



    public void updateUI(int var)
    {
        PlayerPetXmlVO.hp -= var;
        if (PlayerPetXmlVO.hp <0)//hp为负数时置为0
        {
            PlayerPetXmlVO.hp = 0;
        }
        Text_Hp.text = PlayerPetXmlVO.hp.ToString();//血量
    }
}

阅读更多
版权声明:本文为博主“等木鱼的猫”原创文章,转载请注明出处 http://blog.csdn.net/u012761191 https://blog.csdn.net/u012761191/article/details/52459540
个人分类: unity
上一篇《组合变身小宠物游戏》PetCatch(修改更新中)【初学者】
下一篇《组合变身小宠物游戏》MonsterPetItem(修改更新中)【初学者】
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭