关闭

《组合变身小宠物游戏》TeamEditor出战队伍选择(修改更新中)【初学者】

94人阅读 评论(0) 收藏 举报
分类:
using UnityEngine;
using System.Collections;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;


public class TeamEditor : MonoBehaviour {


    public static TeamEditor self;
    public GameObject parentObj;
    public GameObject TeamBox1;
    public GameObject TeamBox2;
    public GameObject TeamBox3;
    public Text TextRemindChooseThree;


    public IEnumerator RemindChoose()//选三个宠物才能出战 提示
    {
        TextRemindChooseThree.gameObject.SetActive(true);
        yield return new WaitForSeconds(1);
        TextRemindChooseThree.gameObject.SetActive(false);
    }
    public int ItemNumber
    {
        get
        {
            return Fighting.self.PlayerPetItemList.Count;
        }
    }
    private List<GameObject> gridItemobj = new List<GameObject>();
   
    private Hashtable recordPetData = new Hashtable();
    void Awake()
    {
        self = this;
    }


    void OnEnable()
    {
        recordPetData = DataRecord.GetPetList();
       
        InitPetHaveData();
    }
    public void InitPetHaveData()//在格子中加载宠物预制体
    {
        recordPetData = DataRecord.GetPetList();
        foreach (GameObject obj in gridItemobj)
        {
            Destroy(obj);
        }
        gridItemobj.Clear();
        GameObject BoxgridItem = Resources.Load("Prefabs/item/BoxGrid", typeof(GameObject)) as GameObject;
        GameObject PetgridItem = Resources.Load("Prefabs/item/PlayerPetChooseItem", typeof(GameObject)) as GameObject;
        foreach (DictionaryEntry itemx in recordPetData)//加载已拥有宠物
        {
            //GameObject BoxgridItem = Resources.Load("Prefabs/item/BoxGrid", typeof(GameObject)) as GameObject;
            if (itemx.Value == null)
                continue;
            //加载格子
            Hashtable data = itemx.Value as Hashtable;//类型转换
            GameObject gridobj = GameObject.Instantiate(BoxgridItem) as GameObject;
            gridobj.name = "BoxGrid" + (gridItemobj.Count + 1).ToString();//添加的预制体的名字,如“BoxGrid1”
            gridobj.transform.parent = parentObj.transform;
            gridobj.transform.localPosition = Vector3.zero;
            gridobj.transform.localScale = Vector3.one;


            gridItemobj.Add(gridobj);
            //加载数据
            GameObject petobj = GameObject.Instantiate(PetgridItem) as GameObject; ;//寻找如“BoxGrid”父物体
            petobj.GetComponent<PlayerPetChooseItem>().UpdatePlayerPetChooseItemData(int.Parse(itemx.Key.ToString()), DataRecord.TranslateData(data));
            petobj.transform.parent = gridobj.transform;
            petobj.transform.localPosition = Vector3.zero;
            petobj.transform.localScale = Vector3.one;
        }
    }








    public void OnClickSureTeam()
    {


        int id1 = 0, id2 = 0, id3 = 0;
        int recordid1 = 0, recordid2 = 0, recordid3 = 0;
        if (TeamBox1.transform.FindChild("PlayerPetChooseItem(Clone)") != null)
        {
            id1 = TeamBox1.transform.FindChild("PlayerPetChooseItem(Clone)").gameObject.GetComponent<PlayerPetChooseItem>().data.id;
            recordid1 = TeamBox1.transform.FindChild("PlayerPetChooseItem(Clone)").gameObject.GetComponent<PlayerPetChooseItem>().recordId;
        }
        else
        {
            Debug.Log("error");
            StartCoroutine(RemindChoose());
            return;
        }
        if (TeamBox2.transform.FindChild("PlayerPetChooseItem(Clone)")!=null)
        {
            id2 = TeamBox2.transform.FindChild("PlayerPetChooseItem(Clone)").gameObject.GetComponent<PlayerPetChooseItem>().data.id;
             recordid2 = TeamBox2.transform.FindChild("PlayerPetChooseItem(Clone)").gameObject.GetComponent<PlayerPetChooseItem>().recordId;
        }
        else
        {
            Debug.Log("error");
            StartCoroutine(RemindChoose());
            return;
        }




        if (TeamBox3.transform.FindChild("PlayerPetChooseItem(Clone)")!= null)
        {
            id3 = TeamBox3.transform.FindChild("PlayerPetChooseItem(Clone)").gameObject.GetComponent<PlayerPetChooseItem>().data.id;
             recordid3 = TeamBox3.transform.FindChild("PlayerPetChooseItem(Clone)").gameObject.GetComponent<PlayerPetChooseItem>().recordId;
        }
        else
        {
            Debug.Log("error");
            StartCoroutine(RemindChoose());
            return;
        }
        //if (DataRecord.SetFight(recordid1, 1) &&//判断是否选中重复出战的宠物
        //DataRecord.SetFight(recordid2, 2) &&
        //DataRecord.SetFight(recordid3, 3))
        //{
        DataRecord.SetFight(recordid1, 1);
        DataRecord.SetFight(recordid2, 2);
        DataRecord.SetFight(recordid3, 3);
        recordPetData = DataRecord.GetPetList();
        InitPetHaveData();
        UIManager.instance.HidePanel(UIPanelNames.TeamEditorPanel);
        Destroy(TeamBox1.transform.FindChild("PlayerPetChooseItem(Clone)").gameObject);
        Destroy(TeamBox2.transform.FindChild("PlayerPetChooseItem(Clone)").gameObject);
        Destroy(TeamBox3.transform.FindChild("PlayerPetChooseItem(Clone)").gameObject);
        RoleControl.self.IsCanMove = false;      
    }
    public void OnClickBtnBack()
    {
        UIManager.instance.HidePanel(UIPanelNames.TeamEditorPanel);
        if (TeamBox1.transform.FindChild("PlayerPetChooseItem(Clone)") != null)
            Destroy(TeamBox1.transform.FindChild("PlayerPetChooseItem(Clone)").gameObject);
        if (TeamBox2.transform.FindChild("PlayerPetChooseItem(Clone)") != null)
            Destroy(TeamBox2.transform.FindChild("PlayerPetChooseItem(Clone)").gameObject);
        if (TeamBox3.transform.FindChild("PlayerPetChooseItem(Clone)") != null)
            Destroy(TeamBox3.transform.FindChild("PlayerPetChooseItem(Clone)").gameObject);
        RoleControl.self.IsCanMove = false;
    }

}


0
0

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