objective-c - 使用基于 Unity3d 的项目升级 Xcode Objective-C IOS 游戏
问题描述
我有一个多年前推出的旧 Xcode/ObC 问答游戏,在 swift 之前,它已经并且仍然对我来说非常成功。至少本地版本。
我现在正在终点线用 Unity3d c# 重写这个游戏。
我最近一直在考虑的是如何维护保存在 IOS 的 plist 文件中的“旧”统计信息。我一直在谷歌上搜索,但我需要更多信息才能真正了解如何进行。
当我使用基于 Unity 的新项目升级当前 Xcode/ObC 时,stats-plist 文件会发生什么情况,它是否仍然存在并且是否可以轻松找到它?这个特定的 plist 在添加第一个玩家时添加,然后使用统计数据和新玩家进行更新。
是否有一种从 Unity 读取 plist 并转换为普通文本文件的好方法?
为了能够从 Unity 中找到该文件,我正在考虑启动基于 ObC 的游戏的维护版本,并且仅将此 plist 文件复制到另一个目录(文档)以准备新的大版本。第一次启动基于 Unity 的游戏时,我可以读取复制的文件并进行处理,这样玩家就不会丢失他/她的统计数据。
我遇到的问题是,在过去的 5 到 6 年中,我唯一一次更新了实际的 ObC 代码是当我将应用程序从 32 位更新到 64 位时,所以我目前在 ObC 方面的技能非常有限。
我一直在考虑为 plist 使用类似的东西:
NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];
if ([filemgr copyItemAtPath: @"/tmp/myfile.txt" toPath: @"/Users/demo/newfile.txt" error: NULL] == YES)
NSLog (@"Copy successful");
else
NSLog (@"Copy failed");
我真的很感激一些建议我应该如何处理这个。
解决方案
这是一些可用于列出文档和应用程序支持内容的代码。我用#define 来保护它,因为我不想在最终的应用程序中使用它。我还用它来执行一些清理(注释掉的东西),如果你需要删除一些东西,你可以使用它们。
#ifdef DEBUG
// Auxiliary function to list directory contents
+ (void) docList
{
NSFileManager * fileManager = NSFileManager.defaultManager;
NSURL * docUrl = [NSFileManager.defaultManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].firstObject;
NSString * docPath = docUrl.path;
NSLog( @"User document directory" );
NSLog( @"%@ listing follows", docPath );
[fmUtil traverse:docPath tab:@"\t" fileManager:fileManager];
}
// Auxiliary function to list application support path
+ (void) supList
{
NSFileManager * fileManager = NSFileManager.defaultManager;
NSURL * docUrl = [NSFileManager.defaultManager URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask].firstObject;
NSString * docPath = docUrl.path;
NSLog( @"Application support directory" );
NSLog( @"\t%@", docPath );
NSLog( @"\tAppending bundle identifier" );
docPath = [docPath stringByAppendingPathComponent:NSBundle.mainBundle.bundleIdentifier];
NSLog( @"\t%@", docPath );
NSLog( @"%@ listing follows", docPath );
[fmUtil traverse:docPath tab:@"\t" fileManager:fileManager];
}
+ (void) traverse:(NSString *)root tab:(NSString *)tab fileManager:(NSFileManager *)fileManager
{
NSArray * dir = [fileManager contentsOfDirectoryAtPath:root error:NULL];
for ( NSString * s in dir )
{
// See if this is a directory or not
NSString * t = [root stringByAppendingPathComponent:s];
BOOL isDir = NO;
[fileManager fileExistsAtPath:t isDirectory:& isDir];
if ( isDir )
{
// Report
NSLog(@"%@%@/",tab,s);
// Traverse
[fmUtil traverse:t tab:[tab stringByAppendingString:@"\t"]
fileManager:fileManager];
}
else
{
// Get size of normal file
NSDictionary * fa = [fileManager attributesOfItemAtPath:t error:NULL];
NSNumber * fz = [fa objectForKey:NSFileSize];
NSDate * fm = [fa objectForKey:NSFileModificationDate];
unsigned long long n = fz.unsignedLongLongValue;
// Some formatting
NSString * f = s;
while ( f.length < 50 )
{
f = [f stringByAppendingString:@" "];
}
NSLog(@"%@%@ %15llu bytes (%@)", tab, f, n, [fm descriptionWithLocale:NSLocale.currentLocale] );
// To delete something for test purposes ...
/*
if ( [t.lastPathComponent isEqualToString:@"P5041-1-BuildingStatistics"] && [fileManager removeItemAtPath:t error:NULL] )
{
NSLog( @"%@%@ now xxxxxxxxxxxxxxxxxx", tab, f );
}
if ( [t.lastPathComponent isEqualToString:@"index"] && [fileManager removeItemAtPath:t error:NULL] )
{
NSLog( @"%@%@ now xxxxxxxxxxxxxxxxxx", tab, f );
}
*/
}
}
}
#endif
把它放在你的应用程序委托中,例如里面application:didFinishLaunchingWithOptions:
。
推荐阅读
- mysql - 极高的 MySQL CPU%
- apache-kafka - Flink 数据流中的反序列化
- kubernetes - 无法在 docker 或本地构建或测试 kubernetes
- css - 显示覆盖另一个 div 的 div 边框
- python - 我们可以从异常中获取堆栈跟踪吗?
- java - 异常:JTA 事务意外回滚(可能是由于超时)
- javascript - 在脚本中获得 Postman 的响应
- r - 连接到 europewest.services.azureml.net:443 的未知 SSL 协议错误(使用 RCurl)
- python - 使用python从json数据中提取值
- javascript - 如何将一种格式的日期字符串转换为另一种格式的字符串(带有时区偏移的字符串)?