Exemplo n.º 1
0
        public static void Load(string path)
        {
            TextAsset text = Resources.Load(path) as TextAsset;

            if (text != null)
            {
                XmlDocument       xmlDoc   = new XmlDocument();
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreComments   = true;
                settings.IgnoreWhitespace = true;
                XmlReader reader = XmlReader.Create(new StringReader(text.text), settings);
                xmlDoc.Load(reader);

                XmlElement element = xmlDoc.SelectSingleNode("CaveInfo") as XmlElement;
                foreach (XmlElement e in element.GetElementsByTagName("Cave"))
                {
                    float cx = XmlUtil.GetAttributeFloat(e, "centerX");
                    float cz = XmlUtil.GetAttributeFloat(e, "centerZ");

                    float sx = XmlUtil.GetAttributeFloat(e, "caveWidthX") + 32.0f;
                    float sz = XmlUtil.GetAttributeFloat(e, "caveWidthz") + 32.0f;

                    CaveData data = new CaveData();
                    data.center = new Vector2(cx, cz);
                    data.size   = new Vector2(sx, sz);

                    s_CaveData.Add(data);
                }

                reader.Close();
            }
        }
Exemplo n.º 2
0
        private static void LoadCaves(XmlDocument document)
        {
            XmlNodeList entities = document.GetElementsByTagName("rock");

            foreach (XmlElement element in entities)
            {
                string name      = element.GetAttribute("name");
                string shortName = element.GetAttribute("shortname");

                Debug.Log("Loading cave data " + name);

                bool unique = VerifyShortName(shortName);
                if (!unique)
                {
                    Debug.LogWarning("Shortname " + shortName + " already exists, aborting");
                    continue;
                }

                TextureReference texture  = TextureReference.GetTextureReference(element.GetAttribute("tex"));
                string           type     = element.GetAttribute("type");
                bool             wall     = type == "wall";
                bool             entrance = type == "entrance";

                List <string[]> categories = new List <string[]>();
                bool            show       = true;

                foreach (XmlElement child in element)
                {
                    switch (child.LocalName)
                    {
                    case "category":
                        categories.Add(child.InnerText.Split('/'));
                        break;

                    case "hidden":
                        show = false;
                        break;
                    }
                }

                CaveData data = ScriptableObject.CreateInstance <CaveData>();
                data.Initialize(texture, name, shortName, wall, show, entrance);
                Database.Caves[shortName] = data;
                foreach (string[] category in categories)
                {
                    GuiManager.Instance.CavesTree.Add(data, category);
                }
            }
        }
Exemplo n.º 3
0
    void UpdateCavePosition()
    {
        if (layerGridGraph != null && PeCreature.Instance.mainPlayer != null)
        {
            PeEntity mainPlayer = PeCreature.Instance.mainPlayer;
            Vector2  v2         = new Vector2(mainPlayer.position.x, mainPlayer.position.z);

            //Vector2 center, size;
            //if(CaveData.GetCenter(v2, out center, out size))
            //{
            //    Vector3 v = new Vector3(center.x, 0.0f, center.y);
            //    Vector3 d = v - layerGridGraph.center;
            //    if(d != Vector3.zero)
            //    {
            //        layerGridGraph.center += d;
            //        layerGridGraph.GenerateMatrix();
            //    }

            //    int width = (int)size.x;
            //    int depth = (int)size.y;

            //    if(layerGridGraph.width != width || layerGridGraph.depth != depth)
            //    {
            //        layerGridGraph.width = width;
            //        layerGridGraph.depth = depth;

            //        layerGridGraph.UpdateSizeFromWidthDepth();
            //    }
            //}

            CaveData data = CaveData.Get(v2);
            if (data != null)
            {
                Vector3 v3  = new Vector3(data.center.x, 0.0f, data.center.y);
                Vector3 dir = v3 - layerGridGraph.center;
                if (dir != Vector3.zero)
                {
                    layerGridGraph.center += dir;
                    layerGridGraph.GenerateMatrix();
                }
            }
        }
    }
Exemplo n.º 4
0
        public static CaveData Get(Vector2 v2)
        {
            float    sqrDis = 0.0f;
            CaveData cave   = null;

            if (s_CaveData.Count > 0)
            {
                cave   = s_CaveData[0];
                sqrDis = Vector2.SqrMagnitude(v2 - s_CaveData[0].center);

                foreach (CaveData data in s_CaveData)
                {
                    float fd = Vector2.SqrMagnitude(v2 - data.center);
                    if (fd < sqrDis)
                    {
                        cave   = data;
                        sqrDis = fd;
                    }
                }
            }

            return(cave);
        }
Exemplo n.º 5
0
    void Awake()
    {
        if (PeGameMgr.IsStory)
        {
            CaveData.Add(storyCaves);
        }

        CaveData.Load("Cave/CaveData");

        if (AstarPath.active == null)
        {
            throw new System.Exception("There is no AstarPath object in the scene");
        }

        layerGridGraph = AstarPath.active.astarData.layerGridGraph;

        if (layerGridGraph == null)
        {
            throw new System.Exception("The AstarPath object has no GridGraph");
        }

        UpdateCavePosition();
    }
Exemplo n.º 6
0
 private void Update()
 {
     if (LocalPlayer.IsInCaves && !LocalPlayer.ActiveAreaInfo.IsLeavingCaves)
     {
         if (this.UseSharedCaveScene && (CaveOptimizer.CanLoadOnRope || !LocalPlayer.AnimControl.onRope) && !this.Shared.LoadedOrLoading)
         {
             base.StartCoroutine(this.Shared.LoadIn());
         }
         if (LocalPlayer.ActiveAreaInfo.CurrentCave == CaveNames.NotInCaves)
         {
             for (int i = 0; i < this.Caves.Length; i++)
             {
                 CaveData caveData = this.Caves[i];
                 if (!LocalPlayer.IsInEndgame || caveData.AllowInEndgame)
                 {
                     if (!caveData.LoadedOrLoading)
                     {
                         base.StartCoroutine(caveData.LoadIn());
                     }
                 }
                 else if (caveData.LoadedOrLoading)
                 {
                     caveData.Unload();
                 }
             }
         }
         else if ((CaveOptimizer.CanLoadOnRope || !LocalPlayer.AnimControl.onRope) && LocalPlayer.ActiveAreaInfo.CurrentCave != this.LastestCave)
         {
             CaveOptimizer.CanLoadOnRope = false;
             if (this.LastestCave != CaveNames.NotInCaves)
             {
                 for (int j = 0; j < this.Caves.Length; j++)
                 {
                     if (j != (int)LocalPlayer.ActiveAreaInfo.CurrentCave)
                     {
                         this.Caves[j].Unload();
                     }
                 }
             }
             if ((CaveNames)this.Caves.Length > LocalPlayer.ActiveAreaInfo.CurrentCave)
             {
                 CaveData caveData2 = this.Caves[(int)LocalPlayer.ActiveAreaInfo.CurrentCave];
                 if (!LocalPlayer.IsInEndgame || caveData2.AllowInEndgame)
                 {
                     if (!caveData2.LoadedOrLoading)
                     {
                         base.StartCoroutine(caveData2.LoadIn());
                         this.LastestCave = LocalPlayer.ActiveAreaInfo.CurrentCave;
                     }
                 }
                 else if (caveData2.LoadedOrLoading)
                 {
                     caveData2.Unload();
                 }
             }
         }
     }
     else
     {
         bool flag = false;
         if (this.UseSharedCaveScene && this.Shared.LoadedOrLoading)
         {
             this.Shared.Unload();
             flag = true;
         }
         for (int k = 0; k < this.Caves.Length; k++)
         {
             if (this.Caves[k].LoadedOrLoading)
             {
                 this.Caves[k].Unload();
                 flag = true;
             }
         }
         if (flag)
         {
             this.LastestCave            = LocalPlayer.ActiveAreaInfo.CurrentCave;
             CaveOptimizer.CanLoadOnRope = true;
             base.Invoke("CleanUp", 0.1f);
         }
     }
 }