关闭

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

89人阅读 评论(0) 收藏 举报
分类:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Sprites;
using System.Collections.Generic;
public class Fighting : MonoBehaviour {
    public Text TextPlayerBlood;
    public Text TextMonsterBlood;
    public Text TextPlayerAttack;
    public Text TextMonsterAttack;
    public Image PlayerPetImage;
    public Image MonsterPetImage;
    public GameObject parentObj_player;
    public GameObject parentObj_monster;
    public GameObject[] gridItemObj_player = new GameObject[3];
    public GameObject[] gridItemObj_monster = new GameObject[2];
    public static Fighting self;
    public List<PlayerPetItem> PlayerPetItemList = new List<PlayerPetItem>();
    public List<MonsterPetItem> MonsterPetItemList = new List<MonsterPetItem>();//#001#
    public PetXmlData CatchPetData;//记录被捕捉的怪物(胜利时捕捉)
    


    void OnEnable()
    {
        PlayerPetItemList.Clear();
        MonsterPetItemList.Clear();
        InitPlayerPetItem();
        InitMonsterPetItem();
       // CatchPetData = gridItemObj_monster[1].GetComponent<MonsterPetItem>().MonsterPetXmlVO;//这里导致捕捉宠物血量为战斗后的0
        
    }


    void Awake()
    {
        self = this;
    }
    void Start()
    {


    }
  public void InitPlayerPetItem()//人物宠物显示固定加载3个
  {
      UnityEngine.Object gridItem = Resources.Load("Prefabs/item/" + "PlayerPetItem");
      for (int i = 0; i < gridItemObj_player.Length; i++)//
      {
          gridItemObj_player[i] = GameObject.Instantiate(gridItem) as GameObject;
          gridItemObj_player[i].name = "PlayerPetItem" + (i + 1).ToString();//添加的预制体的名字
          gridItemObj_player[i].transform.parent = parentObj_player.transform;
          gridItemObj_player[i].transform.localPosition = Vector3.zero;
          gridItemObj_player[i].transform.localScale = Vector3.one;
          PlayerPetItemList.Add(gridItemObj_player[i].GetComponent<PlayerPetItem>());
          gridItemObj_player[i].GetComponent<PlayerPetItem>().index = i + 1;
      }


  }
  public void InitMonsterPetItem() //怪物宠物显示固定加载2个
  {
      UnityEngine.Object gridItem = Resources.Load("Prefabs/item/" + "MonsterPetItem");
      for (int i = 0; i < gridItemObj_monster.Length; i++)
      {
          gridItemObj_monster[i] = GameObject.Instantiate(gridItem) as GameObject;
          gridItemObj_monster[i].name = "MonsterPetItem" + (i + 1).ToString();//添加的预制体的名字
          gridItemObj_monster[i].transform.parent = parentObj_monster.transform;
          gridItemObj_monster[i].transform.localPosition = Vector3.zero;
          gridItemObj_monster[i].transform.localScale = Vector3.one;
          MonsterPetItemList.Add(gridItemObj_monster[i].GetComponent<MonsterPetItem>());
          gridItemObj_monster[i].GetComponent<MonsterPetItem>().index = i + 1;
         // CatchPetData = gridItemObj_monster[i].GetComponent<MonsterPetItem>().MonsterPetXmlVO;//一轮加载后,取的是最后一个作为被抓怪物
      }
      
  }




    
    public void escape()//逃跑
    {
        UIManager.instance.HidePanel(UIPanelNames.FightingPanel);//隐藏战斗UI
        DestoryItem();//销毁加载的预制体
        RoleControl.self.IsInFight= false;//战斗状态切换
       // RunPanel.self.TeamShowitem();//更新RunPanel队伍显示


        if (GameMonster.self.gameCount == 10)//游戏完成
        {
            UIManager.instance.ShowPanel(UIPanelNames.ComPletePanel);
        }
       
    }


    public void OnClose()//关闭
    {
        UIManager.instance.HidePanel(UIPanelNames.FightingPanel);//隐藏战斗UI
        DestoryItem();//销毁加载的预制体
        RoleControl.self.IsInFight = false;//战斗状态切换
        //RunPanel.self.TeamShowitem();//更新RunPanel队伍显示
        
    }


    public void DestoryItem()//(退出战斗界面时需要)清除加载的宠物和怪物预制体
    {
        for (int i = 0; i < parentObj_player.transform.childCount; i++)
        {
            GameObject go = parentObj_player.transform.GetChild(i).gameObject;
            Destroy(go);
        }
        for (int i = 0; i < parentObj_monster.transform.childCount; i++)
        {
            GameObject go = parentObj_monster.transform.GetChild(i).gameObject;
            Destroy(go);
        }
    }

}














0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:8132次
    • 积分:414
    • 等级:
    • 排名:千里之外
    • 原创:34篇
    • 转载:1篇
    • 译文:0篇
    • 评论:7条
    心灵鸡汤
    我想,你总觉得自己活得不快乐的原因,大体应该是:既无法忍受目前的状态,又没有能力改变眼前这一切;你虽然可以像只猪一样懒,缺无法像只猪一样懒得心安理得。
    交流学习
    QQ1987885497
    文章分类