예제 #1
0
 public void RemoveProp(PropVo prop)
 {
     if (bagInfoList.Contains(prop))
     {
         bagInfoList.Remove(prop);
     }
 }
예제 #2
0
    protected override void Update()
    {
        if (Input.GetKeyDown(KeyCode.F))
        {
            int    i    = UnityEngine.Random.Range(0, PropModel.Instance.propInfoList.Count);
            PropVo prop = PropModel.Instance.propInfoList[i].Clone();
            PropModel.Instance.AddProp(prop);
        }

        base.Update();
    }
예제 #3
0
    public virtual PropVo Clone()
    {
        PropVo prop = new PropVo();

        prop.id      = this.id;
        prop.name    = this.name;
        prop.desc    = this.desc;
        prop.max_num = this.max_num;
        prop.num     = 1;

        return(prop);
    }
예제 #4
0
    public void AddProp(PropVo prop)
    {
        for (int i = 0; i < bagInfoList.Count; i++)
        {
            if (prop.id == bagInfoList[i].id && bagInfoList[i].num < prop.max_num)
            {
                bagInfoList[i].num++;
                return;
            }
        }

        MyEventSystem.Dispatch(EventsNames.addProp, prop);
    }
    public void SetData(PropVo prop, Transform[] bagGrids)
    {
        selfProp = prop;

        if (propImg == null)
        {
            propImg = transform.GetComponent <Image>();
        }

        Sprite sprite = ResourceManager.Instance.Load <Sprite>("Prop/" + selfProp.id);

        propImg.sprite = sprite;

        this.bagGrids = bagGrids;
    }
예제 #6
0
    public void SetData(PropVo prop)
    {
        Image  descImg = transform.FindChild("DescImg").GetComponent <Image>();
        Sprite sprite  = ResourceManager.Instance.Load <Sprite>("Prop/" + prop.id);

        descImg.sprite = sprite;

        Text name = transform.FindChild("Name").GetComponent <Text>();

        name.text = prop.name;

        Text desc = transform.FindChild("Desc").GetComponent <Text>();

        desc.text = prop.desc;
    }
예제 #7
0
    void CreateItemXml(string path)
    {
        XmlDocument xmlDoc = new XmlDocument();
        XmlElement  root   = xmlDoc.CreateElement("root");

        for (int i = 0; i < bagInfoList.Count; i++)
        {
            PropVo prop = bagInfoList[i];

            //只需存储id和数量
            XmlElement item = xmlDoc.CreateElement("item");
            item.SetAttribute("id", prop.id.ToString());
            item.SetAttribute("num", prop.num.ToString());
            root.AppendChild(item);
        }

        xmlDoc.AppendChild(root);
        xmlDoc.Save(path);
    }
예제 #8
0
    public void LoadPropInfoFromXml()
    {
        //预先配置好的道具信息
        TextAsset xml = ResourceManager.Instance.Load <TextAsset>("Configs/Prop");

        XmlDocument XmlDoc = new XmlDocument();

        XmlDoc.LoadXml(xml.text);
        XmlNode     root = XmlDoc.SelectSingleNode("root");
        XmlNodeList list = root.SelectNodes("prop");

        for (int i = 0; i < list.Count; i++)
        {
            XmlElement element = list[i] as XmlElement;

            int    idVal = XmlTools.GetIntAttribute(element, "id");
            PropId id    = (PropId)idVal;
            PropVo prop  = PropFactory.GetProp(id, element);
            propInfoList.Add(prop);
        }
    }
예제 #9
0
    public void LoadBagInfoFromXml()
    {
        string path = accountPath + itemInfoPath;

        if (File.Exists(path))
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(path);
            XmlNode     root = xmlDoc.SelectSingleNode("root");
            XmlNodeList list = root.SelectNodes("item");

            //遍历所有物品存储的信息
            for (int i = 0; i < list.Count; i++)
            {
                XmlElement element = list[i] as XmlElement;
                int        id      = XmlTools.GetIntAttribute(element, "id");
                int        num     = XmlTools.GetIntAttribute(element, "num");

                //遍历物品模板信息
                for (int j = 0; j < propInfoList.Count; j++)
                {
                    //对比是否为同一种物品
                    PropVo prop = propInfoList[j];

                    if (id == prop.id)
                    {
                        PropVo newProp = prop.Clone();

                        //添加物品num次
                        for (int k = 0; k < num; k++)
                        {
                            AddProp(newProp);
                        }

                        break;
                    }
                }
            }
        }
    }
예제 #10
0
    void AddProp(System.Object obj)
    {
        PropVo newProp = (obj as PropVo).Clone();

        int index = GetFirstIndexOfEmpty();

        if (index != -1)
        {
            //生成预制物
            GameObject propPrefab = ResourceManager.Instance.Load("Prop/PropModel");
            GameObject propGo     = Instantiate(propPrefab);

            //设置父物体
            propGo.transform.SetParent(bagGrids[index]);
            propGo.transform.localPosition = Vector3.zero;
            propGo.transform.localScale    = Vector3.one;

            //添加管理脚本
            GridItemRenderer renderer = propGo.GetComponent <GridItemRenderer>();
            if (renderer == null)
            {
                renderer = propGo.AddComponent <GridItemRenderer>();
            }

            //设置脚本属性
            renderer.SetData(newProp, bagGrids);
            //加进背包信息容器
            PropModel.Instance.bagInfoList.Add(newProp);

            //更新物品数量
            count = PropModel.Instance.bagInfoList.Count;
        }

        else
        {
            //生成数量不足提示窗口
            print("背包已满,充值扩充背包!");
        }
    }
예제 #11
0
    public static PropVo GetProp(PropId id, XmlElement xml)
    {
        PropVo prop = null;

        switch (id)
        {
        case PropId.goldBox: prop = new PropGoldBoxVo(xml);
            break;

        case PropId.silverBox: prop = new PropSilverBoxVo(xml);
            break;

        case PropId.bronzeBox: prop = new PropBronzeBoxVo(xml);
            break;

        case PropId.goldKey: prop = new PropGoldKeyVo(xml);
            break;

        case PropId.silverkey: prop = new PropSilverKeyVo(xml);
            break;

        case PropId.bronzeKey: prop = new PropBronzeKeyVo(xml);
            break;

        case PropId.hp: prop = new PropHpVo(xml);
            break;

        case PropId.mp: prop = new PropMpVo(xml);
            break;

        default:
            break;
        }

        return(prop);
    }