當前位置: 首頁>>代碼示例>>C#>>正文


C# AstarSerializer.LoadFromFile方法代碼示例

本文整理匯總了C#中Pathfinding.AstarSerializer.LoadFromFile方法的典型用法代碼示例。如果您正苦於以下問題:C# AstarSerializer.LoadFromFile方法的具體用法?C# AstarSerializer.LoadFromFile怎麽用?C# AstarSerializer.LoadFromFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Pathfinding.AstarSerializer的用法示例。


在下文中一共展示了AstarSerializer.LoadFromFile方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DrawSerializationSettings


//.........這裏部分代碼省略.........

            GUILayout.Label ("Startup cached",thinHelpBox,GUILayout.Height (15));

            GUILayout.Space (20);

        }

        GUI.color = tmp2;

        GUILayout.EndHorizontal ();

        /** This displays the values of the serialization bitmask (what to save). Any values which has not got a name will be set to zero */
        EditorGUI.indentLevel++;
        for (int i=0;i<32;i++) {
            string bitName = AstarSerializer.SMask.BitName (i);

            //Bit is not used
            if (bitName == null) {
                serializationMask &= ~(1 << i);
                continue;
            }

            serializationMask = (serializationMask & ~(1 << i)) | (EditorGUILayout.Toggle (bitName,(serializationMask >> i & 1) != 0) ? 1 : 0) << i;
        }
        EditorGUI.indentLevel--;

        GUILayout.Space (5);

        bool preEnabled = GUI.enabled;

        script.astarData.cacheStartup = EditorGUILayout.Toggle (new GUIContent ("Cache startup","If enabled, will cache the graphs so they don't have to be scanned at startup"),script.astarData.cacheStartup);

        EditorGUILayout.LabelField ("Cache size",(script.astarData.data_cachedStartup != null ? EditorUtility.FormatBytes (script.astarData.data_cachedStartup.Length) : "null"));

        GUILayout.BeginHorizontal ();

        if (GUILayout.Button ("Generate cache")) {
            if (EditorUtility.DisplayDialog ("Scan before generating cache?","Do you want to scan the graphs before saving the cache","Scan","Don't scan")) {
        #if UNITY_EDITOR
                AstarPath.MenuScan ();
        #endif
            }
            script.astarData.SaveCacheData (serializationMask);
        }

        GUI.enabled = script.astarData.data_cachedStartup != null;
        if (GUILayout.Button ("Load from cache")) {
            if (EditorUtility.DisplayDialog ("Are you sure you want to load from cache?","Are you sure you want to load graphs from the cache, this will replace your current graphs?","Yes","Cancel")) {
                script.astarData.LoadFromCache ();
            }
        }

        GUILayout.EndHorizontal ();

        if (GUILayout.Button ("Clear Cache", GUILayout.MaxWidth (120))) {
            script.astarData.data_cachedStartup = null;
        }

        GUI.enabled = preEnabled;

        GUILayout.Label ("When using 'cache startup', the 'Nodes' toggle should always be enabled otherwise the graphs' nodes won't be saved and the caching is quite useless",helpBox);

        /*GUI.enabled = false;
        script.astarData.compress = EditorGUILayout.Toggle ("Compress",false);//script.astarData.compress);
        GUI.enabled = preEnabled;*/

        GUILayout.Space (5);

        GUILayout.BeginHorizontal ();
        if (GUILayout.Button ("Save to file")) {
            string path = EditorUtility.SaveFilePanel ("Save Graphs","","myGraph.graph","graph");

            if (path != "") {
                AstarSerializer serializer = new AstarSerializer (script);
                serializer.mask = serializationMask;
                byte[] bytes = SerializeGraphs (serializer);
                serializer.SaveToFile (path,bytes);
            }
        }
        if (GUILayout.Button ("Load from file")) {
            string path = EditorUtility.OpenFilePanel ("Load Graphs","","graph");

            if (path != "") {
                AstarSerializer serializer = new AstarSerializer (script);
                byte[] bytes = serializer.LoadFromFile (path);

                if (bytes != null) {
                    DeserializeGraphs (serializer,bytes);
                    CheckGraphEditors ();
                } else {
                    Debug.Log ("Error deserializing graph : "+serializer.error);
                }
            }

        }

        GUILayout.EndHorizontal ();

        GUILayoutx.EndFadeArea ();
    }
開發者ID:AlexisHenriquezB,項目名稱:SpaceMooney,代碼行數:101,代碼來源:AstarPathEditor.cs


注:本文中的Pathfinding.AstarSerializer.LoadFromFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。