Esempio n. 1
0
 private void InitDictionary()
 {
     Dictionary.Clear();
     ResourceManager.PrepareResource <TextAsset>("Table/Dictionary.txt", asset =>
     {
         if (asset == null)
         {
             Logger.Error("PreInit Dictionary Table error!!!");
             return;
         }
         TableInit.Table_Init(asset.bytes, Dictionary, TableType.Dictionary);
     }, true, false, true, true, false);
 }
Esempio n. 2
0
    public static void CreateObstacle()
    {
        //根据当前场景名字获得场景名称
        string curScene = EditorApplication.currentScene.Substring(EditorApplication.currentScene.LastIndexOf('/') + 1);

        curScene = curScene.Substring(0, curScene.IndexOf('.'));
        //首先获取当前场景的SceneClass
        SceneRecord sceneDefine = null;

        Debug.Log("Remember to add mesh collider to all the meshes.");

        var name = "Table/Scene.txt";
        var path = "Assets/Res/" + name;
        Dictionary <int, IRecord> Scene = new Dictionary <int, IRecord>();
        var txt = Resources.LoadAssetAtPath(path, typeof(TextAsset)) as TextAsset;

        TableInit.Table_Init(txt.bytes, Scene, TableType.Scene);
        {
            // foreach(var record in Scene)
            var __enumerator1 = (Scene).GetEnumerator();
            while (__enumerator1.MoveNext())
            {
                var record = __enumerator1.Current;
                {
                    if (((SceneRecord)record.Value).ResName == curScene)
                    {
                        sceneDefine = (SceneRecord)record.Value;
                        break;
                    }
                }
            }
        }

        if (null == sceneDefine)
        {
            Debug.LogError("Scene Table Not Find, SceneID:" + curScene);
            return;
        }

        int nLenth = sceneDefine.TerrainHeightMapLength;
        int nWidth = sceneDefine.TerrainHeightMapWidth;

        //初始化文件
        string obstacleFilePath = GetCurSceneObstacleFilePath();

        FileStream fileStream = new FileStream(obstacleFilePath, FileMode.Create, FileAccess.ReadWrite);
        int        nSeek      = 0;

        //先将地图的长和宽写入文件头
        fileStream.Seek(nSeek, SeekOrigin.Begin);
        byte[] byteLen = System.BitConverter.GetBytes(nLenth);
        fileStream.Write(byteLen, 0, byteLen.Length);
        nSeek += byteLen.Length;

        fileStream.Seek(nSeek, SeekOrigin.Begin);
        byte[] byteWid = System.BitConverter.GetBytes(nWidth);
        fileStream.Write(byteWid, 0, byteWid.Length);
        nSeek += byteWid.Length;

        bool ok = false;

        //对当前场景进行遍历,进行寻路检测,得到每一个点的可行走类型
        for (float fX = 0.0f; fX <= (float)nWidth; fX += 0.5f)
        {
            for (float fZ = 0.0f; fZ <= (float)nLenth; fZ += 0.5f)
            {
                ObstacleInfo nState = GetScenePosPathState(fX, fZ);
                byte[]       write  = Struct2Byte(nState);

                if (nState.Value == NRun || nState.Value == NWalk)
                {
                    ok = true;
                }

                fileStream.Seek(nSeek, SeekOrigin.Begin);
                fileStream.Write(write, 0, write.Length);
                nSeek += write.Length;
            }
        }
        fileStream.Close();

        if (!ok)
        {
            Debug.Log("1. Check tag has added to the objects.");
            Debug.Log("2. Check mesh collider has added to the objects.");
        }
        else
        {
            Debug.Log("Server Obstacle Create OK");
        }
    }
Esempio n. 3
0
    public static void ReloadSoundTable()
    {
        var res = Resources.LoadAssetAtPath <TextAsset>("Assets/Res/Table/Sound.txt");

        TableInit.Table_Init(res.bytes, SoundTable, TableType.Sound);
    }
Esempio n. 4
0
    public static void ReloadDictionaryTable()
    {
        var ta = Resources.LoadAssetAtPath("Assets/Res/Table/Dictionary.txt", typeof(TextAsset)) as TextAsset;

        TableInit.Table_Init(ta.bytes, Dictionary, TableType.Dictionary);
    }