使用Application.persistentDataPath的替代方法
Unity 2021.2之后的版本中,Application.persistenDataPath的行为经过了改变,因此可能不再能正常工作。可以使用以下代码示例来替代:
string persistentDataPath = Application.persistentDataPath; #if UNITY_ANDROID && !UNITY_EDITOR persistentDataPath = Application.dataPath + "/../files"; #endif
使用此代码,可以在Android设备上正常使用Application.persistentDataPath。在其他平台上,仍可正常使用原来的Application.persistentDataPath。