夏天的风

将来的你一定会感激现在努力的自己

《组合变身小宠物游戏》TeamEditor出战队伍选择(修改更新中)【初学者】
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;
    }

}


阅读更多
版权声明:本文为博主“等木鱼的猫”原创文章,转载请注明出处 http://blog.csdn.net/u012761191 https://blog.csdn.net/u012761191/article/details/52353709
个人分类: unity
想对作者说点什么? 我来说一句

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

不良信息举报

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

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭