unity读取二进制配置文件

移植h5游戏的项目,需要读取二进制的配置文件,bin文件比较大,放在streamingAssets总是读取失败。最后现在pc端读取二进制的数据类,通过ScriptObject类对数据进行一次封装,最后序列化ScriptObject类,unity读取ScriptObject类类还是比较成功的。不管放在resources文件夹还是拖拽进控制面板都可以了。

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class BuildDataTool : MonoBehaviour {


//ScriptableObject类文件
public LocalDataFish data;
//ScriptableObject类文件
public LocalDataFishNew dataNew;

void Start()
{
//先读取数据类
LocalFishData._instance.InitRes();
}

void OnGUI()
{
EditorGUILayout.BeginVertical();
if (GUILayout.Button(new GUIContent("SaveLocalDataFish")))
{
string stringholderpath = "Assets/" + "LocalDataFish" + ".asset";
data.data = LocalFishData._instance.fishesData;
AssetDatabase.CreateAsset(data, stringholderpath);
}
if (GUILayout.Button(new GUIContent("SaveLocalLocalDataFishNew")))
{
string stringholderpath = "Assets/" + "LocalDataFishNew" + ".asset";
dataNew.data = LocalFishData._instance.newFishBatches;
AssetDatabase.CreateAsset(dataNew, stringholderpath);
}
EditorGUILayout.EndVertical();
}
}

其他参考:http://www.xuanyusong.com/archives/4033

http://www.jianshu.com/p/c15a67aa3c93

posted @ 2017-10-18 13:00  任雪松  阅读(2393)  评论(0编辑  收藏  举报