Esempio n. 1
0
    //打开合成界面
    void OpenRecipe(GameObject go)
    {
        //获取合成配方
        recipe = recipeMap.GetRecipeByID(int.Parse(go.name));
        if (recipe.Name == null)
        {
            Debug.Log("Can't GetRecipe!");
            return;
        }

    #if _Debug
        Debug.Log(recipe.Name);
    #endif

        //打开合成界面,隐藏合成菜单界面
        MenuUI.SetActive(false);
        recipeUI.SetActive(true);
        btn_Compose.gameObject.SetActive(false);

        SetSlot(recipe);

        btn_Close.transform.Find("Text").GetComponent <Text>().text       = "返回";
        btn_startRecipe.transform.Find("Text").GetComponent <Text>().text = "合成";
        EventTriggerListener.Get(btn_Close.gameObject).onClick            = CloseRecipe;

        EventTriggerListener.Get(btn_startRecipe.gameObject).onClick = StartRecipe;
    }
Esempio n. 2
0
    void SetRecipeName()
    {
        for (int i = 0; i < recipeMap.ReicipeList.Count; i++)
        {
            GameObject button = Instantiate(recipeButton);
            button.transform.SetParent(_fitter.transform, false);

            Recipe.RecipeMap _map = (Recipe.RecipeMap)recipeMap.ReicipeList[i];

            button.name = _map.ID.ToString();
            button.transform.Find("Text").GetComponent <Text>().text = _map.Name;
            int _t = _map.Target[0].ToString() == "0" ? 0 : 1;
            int _i = int.Parse(_map.Target.Substring(_map.Target.IndexOf(",") + 1));

            button.transform.Find("Image").GetComponent <Image>().sprite = Materiral.GetMaterialIcon(_t, _i);

            //设置点击事件
            //button.GetComponent<Button>().onClick.AddListener(OpenRecipe);
            OnClickInScorll.Get(button.transform).onClick = OpenRecipe;
        }
    }
Esempio n. 3
0
    public ArrayList loadRecipeXmlToArray()
    {
        //保存路径
        string filepath = "Config/Materiral/Recipe";

        string _result = Resources.Load(filepath).ToString();

        ArrayList recipeList = new ArrayList();

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(_result);

        XmlNodeList nodeList = xmlDoc.SelectSingleNode("RecipeList").ChildNodes;

        foreach (XmlElement recipe in nodeList)
        {
            Recipe.RecipeMap _recipe = new Recipe.RecipeMap();

            //读取node内属性,把string转化为对应的属性
            if (recipe.GetAttribute("ID") != "")
            {
                _recipe.ID = int.Parse(recipe.GetAttribute("ID"));
            }
            if (recipe.GetAttribute("Name") != "")
            {
                _recipe.Name = recipe.GetAttribute("Name");
            }
            if (recipe.GetAttribute("Target") != "")
            {
                _recipe.Target = recipe.GetAttribute("Target");
            }
            if (recipe.GetAttribute("Mar1Qua") != "")
            {
                _recipe.EffetBox.Eft1.NeedQuality = int.Parse(recipe.GetAttribute("Mar1Qua"));
            }
            if (recipe.GetAttribute("Mar1Eft") != "")
            {
                _recipe.EffetBox.Eft1.EftID = int.Parse(recipe.GetAttribute("Mar1Eft"));
            }
            if (recipe.GetAttribute("Mar2Qua") != "")
            {
                _recipe.EffetBox.Eft2.NeedQuality = int.Parse(recipe.GetAttribute("Mar2Qua"));
            }
            if (recipe.GetAttribute("Mar2Eft") != "")
            {
                _recipe.EffetBox.Eft2.EftID = int.Parse(recipe.GetAttribute("Mar2Eft"));
            }
            if (recipe.GetAttribute("Mar3Qua") != "")
            {
                _recipe.EffetBox.Eft3.NeedQuality = int.Parse(recipe.GetAttribute("Mar3Qua"));
            }
            if (recipe.GetAttribute("Mar3Eft") != "")
            {
                _recipe.EffetBox.Eft3.EftID = int.Parse(recipe.GetAttribute("Mar3Eft"));
            }

            _recipe.Slots = new Recipe.Slot[recipe.ChildNodes.Count];

            for (int i = 0; i < recipe.ChildNodes.Count; i++)
            {
                XmlElement element  = (XmlElement)recipe.ChildNodes[i];
                string     slotName = "Slot" + (i + 1).ToString();

                if (element.Name == slotName)
                {
                    if (element.GetAttribute("NeedNum") != "")
                    {
                        _recipe.Slots[i].Num = int.Parse(element.GetAttribute("NeedNum"));
                    }

                    string mat = element.InnerText;

                    //解析材料内容
                    if (mat[0] == char.Parse("T"))
                    {
                        _recipe.Slots[i].SlotType = (Recipe.SlotTypeList) 1;
                        string mat_str = mat.Substring(mat.IndexOf(":") + 1);
                        _recipe.Slots[i].MatType = int.Parse(mat_str);
                        _recipe.Slots[i].MatId   = -1;
                    }
                    else if (mat[0] == char.Parse("M"))
                    {
                        _recipe.Slots[i].SlotType = (Recipe.SlotTypeList) 0;

                        string mat_type = mat.Substring(mat.IndexOf(":") + 1, mat.IndexOf(",") - 2);
                        string mat_str  = mat.Substring(mat.IndexOf(",") + 1);
                        _recipe.Slots[i].MatType = int.Parse(mat_type);
                        _recipe.Slots[i].MatId   = int.Parse(mat_str);
                    }
                }
            }

            //添加进itemList中
            recipeList.Add(_recipe);
        }
        return(recipeList);
    }
Esempio n. 4
0
    //设置合成界面槽的信息和位置
    void SetSlot(Recipe.RecipeMap map)
    {
        int num = map.Slots.Length;

        //TODO:游戏道具的名称和ID,以及按钮的表现效果
        Vector3 base_point  = new Vector3(0, -100, 0);
        int     targetAngel = 0;

        SlotList = new Dictionary <int, SlotBox>();

        for (int i = 0; i < num; i++)
        {
            GameObject recipeSlot = Instantiate(btn_recipeSlot);
            recipeSlot.transform.SetParent(recipeSlotsList.transform, false);

            //设置按钮位置
            targetAngel = 360 / num * i;

            Vector3 target_pos = Quaternion.Euler(0, 0, targetAngel) * base_point;
            recipeSlot.transform.localPosition = target_pos;

            //判断slot中材料的类型,0为固定材料,1为材料种类
            if (map.Slots[i].SlotType == Recipe.SlotTypeList.Material)
            {
                //固定材料
                if (map.Slots[i].MatType == 0)  //Item
                {
                    Materiral.Items _item = Materiral.FindItemByID(map.Slots[i].MatId);

                    recipeSlot.name = i.ToString();
                    recipeSlot.transform.Find("Text").GetComponent <Text>().text            = "[" + _item.Name + "]";
                    recipeSlot.transform.Find("Bottom/Image").GetComponent <Image>().sprite = Materiral.GetIconByName(_item.IMG);
                    recipeSlot.transform.Find("Bottom/Image").GetComponent <Image>().color  = new Color(1, 1, 1, 0.5f);
                }
                else if (map.Slots[i].MatType == 1)  //Mind
                {
                    Materiral.Minds _mind = Materiral.FindMindByID(map.Slots[i].MatId);
                    recipeSlot.name = i.ToString();
                    recipeSlot.transform.Find("Text").GetComponent <Text>().text            = "[" + _mind.Name + "]";
                    recipeSlot.transform.Find("Bottom/Image").GetComponent <Image>().sprite = Materiral.GetIconByName(_mind.IMG);
                    recipeSlot.transform.Find("Bottom/Image").GetComponent <Image>().color  = new Color(1, 1, 1, 0.5f);
                }
            }
            else if (map.Slots[i].SlotType == Recipe.SlotTypeList.MaterialType)
            {
                //材料类型
                recipeSlot.name = i.ToString();

                int typeID = map.Slots[i].MatType;
                Materiral.MaterialType type = Materiral.FindTypeNameByID(typeID);
                recipeSlot.transform.Find("Text").GetComponent <Text>().text            = "<color=red>[" + type.Name + "]\n(类型)</color>";
                recipeSlot.transform.Find("Bottom/Image").GetComponent <Image>().sprite = Materiral.GetIconByName(type.IMG);
                recipeSlot.transform.Find("Bottom/Image").GetComponent <Image>().color  = new Color(1, 1, 1, 0.5f);
            }
            else
            {
                Debug.Log("Can't find recipe slots!");
            }

            //设置参数容器中的参数
            Parameter.Box parameter = new Parameter.Box();
            parameter.ID       = i; //ID为slot的序号
            parameter.callback = ClickInBag;
            parameter.obj      = map.Slots[i];
            parameter.subobj   = SlotList;

            //添加记录到合成系统用容器中
            SlotBox slot = new SlotBox();
            slot.button = recipeSlot;
            SlotList.Add(i, slot);

            //设置点击事件
            GameObject _slot = recipeSlot.transform.Find("Bottom/Image").gameObject;
            EventTriggerListener.Get(_slot).parameter          = parameter;
            EventTriggerListener.Get(_slot).onClickByParameter = OpenBag;
        }
    }