当前位置: 首页>>代码示例>>C#>>正文


C# AstarSerializer.SetUpGraphRefs方法代码示例

本文整理汇总了C#中Pathfinding.AstarSerializer.SetUpGraphRefs方法的典型用法代码示例。如果您正苦于以下问题:C# AstarSerializer.SetUpGraphRefs方法的具体用法?C# AstarSerializer.SetUpGraphRefs怎么用?C# AstarSerializer.SetUpGraphRefs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pathfinding.AstarSerializer的用法示例。


在下文中一共展示了AstarSerializer.SetUpGraphRefs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeserializeGraphsPart

        /** Deserializes all graphs and also user connections \deprecated */
        public void DeserializeGraphsPart(AstarSerializer serializer)
        {
            if (serializer.error != AstarSerializer.SerializerError.Nothing) {
                data_backup = (serializer.readerStream.BaseStream as System.IO.MemoryStream).ToArray ();
                Debug.Log ("Error encountered : "+serializer.error+"\nWriting data to AstarData.data_backup");
                graphs = new NavGraph[0];
                return;
            }

            try {
                int count1 = serializer.readerStream.ReadInt32 ();
                int count2 = serializer.readerStream.ReadInt32 ();

                if (count1 != count2) {
                    Debug.LogError ("Data is corrupt ("+count1 +" != "+count2+")");
                    graphs = new NavGraph[0];
                    return;
                }

                NavGraph[] _graphs = new NavGraph[count1];
                //graphs = new NavGraph[count1];

                for (int i=0;i<_graphs.Length;i++) {

                    if (!serializer.MoveToAnchor ("Graph"+i)) {
                        Debug.LogError ("Couldn't find graph "+i+" in the data");
                        Debug.Log ("Logging... "+serializer.anchors.Count);
                        foreach (KeyValuePair<string,int> value in serializer.anchors) {
                            Debug.Log ("KeyValuePair "+value.Key);
                        }
                        _graphs[i] = null;
                        continue;
                    }
                    string graphType = serializer.readerStream.ReadString ();

                    graphType = graphType.Replace ("ListGraph","PointGraph");

                    Guid guid = new Guid (serializer.readerStream.ReadString ());

                    //Search for existing graphs with the same GUID. If one is found, that means that we are loading another version of that graph
                    //Use that graph then and just load it with some new settings
                    NavGraph existingGraph = GuidToGraph (guid);

                    if (existingGraph != null) {
                        _graphs[i] = existingGraph;
                        //Replace
                        //graph.guid = new System.Guid ();
                        //serializer.loadedGraphGuids[i] = graph.guid.ToString ();
                    } else {
                        _graphs[i] = CreateGraph (graphType);
                    }

                    NavGraph graph = _graphs[i];

                    if (graph == null) {
                        Debug.LogError ("One of the graphs saved was of an unknown type, the graph was of type '"+graphType+"'");
                        data_backup = data;
                        graphs = new NavGraph[0];
                        return;
                    }

                    _graphs[i].guid = guid;

                    //Set an unique prefix for all variables in this graph
                    serializer.sPrefix = i.ToString ();
                    serializer.DeSerializeSettings (graph,active);
                }

                serializer.SetUpGraphRefs (_graphs);

                for (int i=0;i<_graphs.Length;i++) {

                    NavGraph graph = _graphs[i];

                    if (serializer.MoveToAnchor ("GraphNodes_Graph"+i)) {
                        serializer.mask = serializer.readerStream.ReadInt32 ();
                        serializer.sPrefix = i.ToString ()+"N";
                        serializer.DeserializeNodes (graph,_graphs,i,active);
                        serializer.sPrefix = "";
                    }

                    //Debug.Log ("Graph "+i+" has loaded "+(graph.nodes != null ? graph.nodes.Length.ToString () : "null")+" nodes");

                }

                userConnections = serializer.DeserializeUserConnections ();

                //Remove null graphs
                List<NavGraph> tmp = new List<NavGraph>(_graphs);
                for (int i=0;i<_graphs.Length;i++) {
                    if (_graphs[i] == null) {
                        tmp.Remove (_graphs[i]);
                    }
                }

                graphs = tmp.ToArray ();
            } catch (System.Exception e) {
                data_backup = (serializer.readerStream.BaseStream as System.IO.MemoryStream).ToArray ();
                Debug.LogWarning ("Deserializing Error Encountered - Writing data to AstarData.data_backup:\n"+e.ToString ());
//.........这里部分代码省略.........
开发者ID:rmkeezer,项目名称:fpsgame,代码行数:101,代码来源:AstarData.cs


注:本文中的Pathfinding.AstarSerializer.SetUpGraphRefs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。