예제 #1
0
        BGAInst CreateBGA(int id)
        {
            if (_sectionDescs.ContainsKey(id))
            {
                SectionDesc sectiondesc = _sectionDescs[id];

                GameObject bga_go = new GameObject("BGA " + id.ToString() + " : " + sectiondesc.name);
                bga_go.transform.parent        = bga_group_go.transform;
                bga_go.transform.localPosition = Vector3.zero;

                BGAInst inst = bga_go.AddComponent <BGAInst>();
                inst.audioSrc.path        = sectiondesc.bgaDesc.path;
                inst.audioSrc.playOnReset = false;

                bga[id] = inst;
                return(inst);
            }
            return(null);
        }
예제 #2
0
        public void LoadConfig()
        {
            string path = Application.streamingAssetsPath + "/ambient.xml";

            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(path);
                _sectionDescs = new Dictionary <int, SectionDesc>();
                foreach (XmlNode node in xmldoc.DocumentElement.ChildNodes)
                {
                    if (node.Name == "SECTION")
                    {
                        SectionDesc section = new SectionDesc();
                        int         id      = XmlConvert.ToInt32(node.Attributes["id"].Value);
                        string      name    = node.Attributes["name"].Value;
                        section.id   = id;
                        section.name = name;
                        List <SPOTDesc> spotlist = new List <SPOTDesc> ();
                        foreach (XmlNode childnode in node.ChildNodes)
                        {
                            if (childnode.Name == "BGM" && section.bgmDesc == null)
                            {
                                section.bgmDesc            = new BGMDesc();
                                section.bgmDesc.path       = childnode.Attributes["path"].Value;
                                section.bgmDesc.musicCount = XmlConvert.ToInt32(childnode.Attributes["musiccnt"].Value);
                                section.bgmDesc.changeTime = StrToRange(childnode.Attributes["changetime"].Value);
                            }
                            else if (childnode.Name == "BGA" && section.bgaDesc == null)
                            {
                                section.bgaDesc      = new BGADesc();
                                section.bgaDesc.path = childnode.Attributes["path"].Value;
                            }
                            else if (childnode.Name == "SPOT")
                            {
                                SPOTDesc desc = new SPOTDesc();
                                desc.path         = childnode.Attributes["path"].Value;
                                desc.density      = XmlConvert.ToSingle(childnode.Attributes["density"].Value);
                                desc.heightRange  = StrToRange(childnode.Attributes["height"].Value);
                                desc.minDistRange = StrToRange(childnode.Attributes["mindistance"].Value);
                                desc.maxDistRange = StrToRange(childnode.Attributes["maxdistance"].Value);
                                spotlist.Add(desc);
                            }
                        }
                        section.spotDesc = new SPOTDesc[spotlist.Count];

                        for (int i = 0; i < spotlist.Count; ++i)
                        {
                            section.spotDesc[i] = spotlist[i];
                        }

                        _sectionDescs[section.id] = section;
                    }
                }
            }
            catch (Exception)
            {
                Debug.LogWarning("Load ambient.xml failed");
                _sectionDescs = new Dictionary <int, SectionDesc>();
            }
        }