Created
January 11, 2021 20:35
-
-
Save noir-neo/91e7a09e87e15280c1b2c70648b833f1 to your computer and use it in GitHub Desktop.
Unity で Info.plist に Custom UTI を設定する PostProcess の例 (VRM)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using UnityEditor; | |
using UnityEditor.Callbacks; | |
using UnityEditor.iOS.Xcode; | |
namespace Plugins.iOS.Editor | |
{ | |
public static class PostProcess | |
{ | |
[PostProcessBuild] | |
public static void OnPostProcessBuild(BuildTarget target, string path) | |
{ | |
if (target != BuildTarget.iOS) return; | |
var plistPath = path + "/Info.plist"; | |
var plist = new PlistDocument(); | |
plist.ReadFromString(File.ReadAllText(plistPath)); | |
var rootDict = plist.root; | |
// <key>UTExportedTypeDeclarations</key> | |
// <array> | |
// <dict> | |
// <key>UTTypeConformsTo</key> | |
// <array> | |
// <string>public.data</string> | |
// </array> | |
// <key>UTTypeDescription</key> | |
// <string>VRM</string> | |
// <key>UTTypeIconFiles</key> | |
// <array/> | |
// <key>UTTypeIdentifier</key> | |
// <string>com.neoneobeam.hatracker.custom</string> | |
// <key>UTTypeTagSpecification</key> | |
// <dict> | |
// <key>public.filename-extension</key> | |
// <array> | |
// <string>vrm</string> | |
// </array> | |
// </dict> | |
// </dict> | |
// </array> | |
var exportedTypeDeclarations = rootDict.CreateArray("UTExportedTypeDeclarations"); | |
var exportedTypeDeclarationsDict = exportedTypeDeclarations.AddDict(); | |
var typeConformsTo = exportedTypeDeclarationsDict.CreateArray("UTTypeConformsTo"); | |
typeConformsTo.AddString("public.data"); | |
exportedTypeDeclarationsDict.SetString("UTTypeDescription", "VRM"); | |
exportedTypeDeclarationsDict.CreateArray("UTTypeIconFiles"); | |
var typeIdentifier = $"{PlayerSettings.applicationIdentifier}.custom"; | |
exportedTypeDeclarationsDict.SetString("UTTypeIdentifier", typeIdentifier); | |
var typeTagSpecification = exportedTypeDeclarationsDict.CreateDict("UTTypeTagSpecification"); | |
var typeTagSpecificationArray = typeTagSpecification.CreateArray("public.filename-extension"); | |
typeTagSpecificationArray.AddString("vrm"); | |
// <key>CFBundleDocumentTypes</key> | |
// <array> | |
// <dict> | |
// <key>CFBundleTypeName</key> | |
// <string>VRM</string> | |
// <key>CFBundleTypeRole</key> | |
// <string>Viewer</string> | |
// <key>LSHandlerRank</key> | |
// <string>Alternate</string> | |
// <key>LSItemContentTypes</key> | |
// <array> | |
// <string>com.neoneobeam.hatracker.custom</string> | |
// </array> | |
// </dict> | |
// </array> | |
var documentTypes = rootDict.CreateArray("CFBundleDocumentTypes"); | |
var documentTypesDict = documentTypes.AddDict(); | |
documentTypesDict.SetString("CFBundleTypeName", "VRM"); | |
documentTypesDict.SetString("CFBundleTypeRole", "Viewer"); | |
documentTypesDict.SetString("LSHandlerRank", "Alternate"); | |
var itemContentTypes = documentTypesDict.CreateArray("LSItemContentTypes"); | |
itemContentTypes.AddString(typeIdentifier); | |
File.WriteAllText(plistPath, plist.WriteToString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment