owned this note
owned this note
Published
Linked with GitHub
# 實驗室框架修正
:::info
實驗室框架使用 Unity 引擎版本 2019.2.10f1。
如欲使用新版 Unity 版本,請參閱 [升級 Unity 引擎版本](/Vdw7uwrOSxGLSiuze7rXPA)
:::
## LabTools
:::info
Application.persistentDataPath 對應的位置在 pico 裡是 `Android\data\{安裝包名}\files`
:::
```csharp=27
public static string DataPath =>
#if UNITY_ANDROID
Application.persistentDataPath
#else
Application.dataPath
#endif
;
```
## LabDataManager
```csharp=34
private string labDataSavePath => LabTools.DataPath + "/TestData";
```
```csharp=72
_saveDataPath = LabTools.DataPath + "/Output";
```
```csharp=95
string testStorePath = Path.Combine(LabTools.DataPath, "TestStore");
if (!Directory.Exists(testStorePath))
{
Directory.CreateDirectory(testStorePath);
}
_applicationLifecycle = new SimpleApplicationLifecycle();
_client = new DataSyncClient(new UnityApplicationFolderProvider(testStorePath),
_applicationLifecycle, options, _userId);
```
:::info
Android 用 StreamWriter 寫檔可能會有斷尾情事。
可以改最底下 LabDataWriter
```csharp=216
public class LabDataWriter
{
private string path;
public LabDataWriter(string path)
{
this.path = path;
}
public void WriteData(LabDataBase data)
{
File.AppendAllText(path, data.ToJson());
}
public void WriterDispose()
{
}
}
```
:::
## LabExtension
```csharp=16
return JsonConvert.SerializeObject(o, new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore, // 改 ignore 避免循環引用 (Force 會直接閃退不報錯)
NullValueHandling = NullValueHandling.Include
})
```
## 變更 PlayerSettings

## SpVoice
<!-- > 實驗室眾人踩到的無底陷坑 -->
如果你的 code 有出現
```csharp
using SpeechLib;
```
或
```csharp
SpVoice
```
請註解掉!!!
它會讓其所處的函式炸掉,但又不會報錯,非常噁心。
<!-- 並且請將 Plugins/Interop.SpeechLip 除外 -->
替代方案請見峰銘筆記:https://hackmd.io/nmp_AZA6T5eK_424x8h5LA#%E6%8A%8ASPVoice%E8%A8%BB%E8%A7%A3%EF%BC%8C%E6%9B%BF%E6%8F%9B%E6%88%90google%E8%AA%9E%E9%9F%B3
---
## TroubleShoot
### 進到 MainUI 畫面空白,報錯 数据文件不存在!

改 LabTools 的 `GetData()`
```csharp=188
public static T GetData<T>(string dataName, string filePath = "/GameData") where T : LabDataBase
{
// folder
string path = DataPath + filePath;
if(filePath.StartsWith("/StreamingAssets/")) // Android 的 Streaming Assets
{
path = Path.Combine(Application.streamingAssetsPath, filePath.Replace("/StreamingAssets/", ""));
}
// combine file name
path = Path.Combine(path, typeof(T).Name, dataName + ".json");
// StreamReader sr = new StreamReader(path);
// var data = JsonConvert.DeserializeObject<T>(sr.ReadToEnd());
// sr.Close();
var req = UnityWebRequest.Get(path);
req.SendWebRequest();
while (!req.isDone) { }
if(req.isNetworkError || req.isHttpError)
{
Debug.LogError("数据文件不存在!"+path);
Debug.LogError("Reason: "+req.error);
return default;
}
var data = JsonConvert.DeserializeObject<T>(req.downloadHandler.text);
return data;
}
```
### LabDataManager 欄位空白
:::warning
在某些舊版框架,資料蒐集之 `LabDataManager` 可能不在 `GameDataManager` 底下,有遇過在 `LabDataTestComponent`底下的情形
```csharp
LabDataTestComponent.LabDataManager.SendData(new LabLeftEyeData(Vector3.zero, Vector3.zero, -1, leftEyeopenness, leftEyePosition));
LabDataTestComponent.LabDataManager.SendData(new LabRightEyeData(Vector3.zero, Vector3.zero, -1, leftEyeopenness, rightEyePosition));
LabDataTestComponent.LabDataManager.SendData(new LabCombinedEyeData(combinedEyeGazePoint, combinedEyeGazeVector, -1, -1, Vector3.zero));
```
:::