public static void OnPostprocessAllAssets( string[] importedAssets , string[] deletedAssets , string[] movedAssets , string[] movedFromAssetPaths) { foreach (string assetName in importedAssets) { if (assetName.EndsWith(".gaf")) { byte [] fileBytes = null; using (BinaryReader freader = new BinaryReader(File.OpenRead(assetName))) { fileBytes = freader.ReadBytes((int)freader.BaseStream.Length); } if (fileBytes.Length > sizeof(int)) { int header = System.BitConverter.ToInt32(fileBytes.Take(4).ToArray(), 0); if (GAFHeader.isCorrectHeader((GAFHeader.CompressionType)header)) { GAFAnimationAsset animationAsset = ScriptableObject.CreateInstance <GAFAnimationAsset>(); animationAsset = GAFAssetUtils.saveAsset(animationAsset, Path.GetDirectoryName(assetName) + "/" + Path.GetFileNameWithoutExtension(assetName) + ".asset"); animationAsset.init(fileBytes); GAFTracking.sendAssetCreatedRequest(assetName); } } } } }
public void Load( byte [] _AssetData , ref GAFAnimationData _SharedData) { #if !UNITY_PRO_LICENSE && GAF_SUPPORT_COMPRESSED && UNITY_EDITOR if (PlayerSettings.apiCompatibilityLevel == ApiCompatibilityLevel.NET_2_0_Subset && Application.platform != RuntimePlatform.WindowsEditor && Application.platform != RuntimePlatform.WindowsPlayer) { GAFUtils.Warning("GAF! You are using compressed 'gaf' in free unity. Set API compatibility level as '.NET'!"); } #endif // !UNITY_PRO_LICENSE && GAF_SUPPORT_COMPRESSED && UNITY_EDITOR GAFHeader header = new GAFHeader(); MemoryStream fstream = new MemoryStream(_AssetData); using (BinaryReader freader = new BinaryReader(fstream)) { if (freader.BaseStream.Length > GAFHeader.headerDataOffset) { header.Read(freader); if (header.isValid) { _SharedData = new GAFAnimationData(); _SharedData.majorVersion = header.majorVersion; _SharedData.minorVersion = header.minorVersion; switch (header.compression) { case GAFHeader.CompressionType.CompressedNone: Read(freader, ref _SharedData); break; case GAFHeader.CompressionType.CompressedZip: #if GAF_SUPPORT_COMPRESSED using (ZlibStream zlibStream = new ZlibStream(fstream, CompressionMode.Decompress)) { byte [] uncompressedBuffer = new byte[header.fileLength]; zlibStream.Read(uncompressedBuffer, 0, uncompressedBuffer.Length); using (BinaryReader reader = new BinaryReader(new MemoryStream(uncompressedBuffer))) { Read(reader, ref _SharedData); } } break; #else GAFUtils.Assert(false, "GAF. Compressed gaf format is not supported in your plugin!"); break; #endif // GAF_SUPPORT_COMPRESSED } } } } }
public static void OnPostprocessAllAssets( string[] importedAssets , string[] deletedAssets , string[] movedAssets , string[] movedFromAssetPaths) { foreach (string assetName in importedAssets) { if (assetName.EndsWith(".gaf")) { byte[] fileBytes = null; using (BinaryReader freader = new BinaryReader(File.OpenRead(assetName))) { fileBytes = freader.ReadBytes((int)freader.BaseStream.Length); } if (fileBytes.Length > sizeof(int)) { int header = System.BitConverter.ToInt32(fileBytes.Take(4).ToArray(), 0); if (GAFHeader.isCorrectHeader((GAFHeader.CompressionType)header)) { var path = Path.GetDirectoryName(assetName) + "/" + Path.GetFileNameWithoutExtension(assetName) + ".asset"; var asset = AssetDatabase.LoadAssetAtPath(path, typeof(GAFAnimationAsset)) as GAFAnimationAsset; if (asset == null) { asset = ScriptableObject.CreateInstance <GAFAnimationAsset>(); AssetDatabase.CreateAsset(asset, path); asset = AssetDatabase.LoadAssetAtPath(path, typeof(GAFAnimationAsset)) as GAFAnimationAsset; } asset.name = Path.GetFileNameWithoutExtension(assetName); asset.initialize(fileBytes, AssetDatabase.AssetPathToGUID(path)); EditorUtility.SetDirty(asset); AssetDatabase.SaveAssets(); GAFResourceManagerInternal.instance.createResources <GAFTexturesResource>(asset); EditorUtility.SetDirty(asset); AssetDatabase.SaveAssets(); } } } } }
public static void OnPostprocessAllAssets( string[] importedAssets , string[] deletedAssets , string[] movedAssets , string[] movedFromAssetPaths) { foreach (string assetName in importedAssets) { if (assetName.EndsWith(".gaf")) { byte[] fileBytes = null; using (BinaryReader freader = new BinaryReader(File.OpenRead(assetName))) { fileBytes = freader.ReadBytes((int)freader.BaseStream.Length); } if (fileBytes.Length > sizeof(int)) { int header = System.BitConverter.ToInt32(fileBytes.Take(4).ToArray(), 0); if (GAFHeader.isCorrectHeader((GAFHeader.CompressionType)header)) { var path = Path.GetDirectoryName(assetName) + "/" + Path.GetFileNameWithoutExtension(assetName) + ".asset"; asset = AssetDatabase.LoadAssetAtPath(path, typeof(GAFAnimationAsset)) as GAFAnimationAsset; if (asset == null) { asset = ScriptableObject.CreateInstance <GAFAnimationAsset>(); AssetDatabase.CreateAsset(asset, path); asset = AssetDatabase.LoadAssetAtPath(path, typeof(GAFAnimationAsset)) as GAFAnimationAsset; findAsset = false; } var assetDir = Path.GetDirectoryName(path); assetDir = assetDir == "Assets" ? string.Empty : assetDir.Substring("Assets/".Length, assetDir.Length - "Assets/".Length); asset.name = Path.GetFileNameWithoutExtension(assetName); asset.initialize(fileBytes, AssetDatabase.AssetPathToGUID(path), assetDir == string.Empty ? assetDir : assetDir + "/"); EditorUtility.SetDirty(asset); AssetDatabase.SaveAssets(); GAFResourceManagerInternal.initInstance <GAFResourceManager>(); GAFResourceManagerInternal.instance.createResources <GAFTexturesResource>(asset); GAFResourceManagerInternal.instance.createMecanimResources(asset); GAFResourceManagerInternal.instance.defineAudioResources(asset); EditorUtility.SetDirty(asset); AssetDatabase.SaveAssets(); } } } else if (assetName.EndsWith(".asset")) { if (findAsset) { #if UNITY_5 asset = AssetDatabase.LoadAssetAtPath <GAFAnimationAsset>(assetName); #else asset = AssetDatabase.LoadAssetAtPath(assetName, typeof(GAFAnimationAsset)) as GAFAnimationAsset; #endif if (asset != null) { findAsset = false; } if (asset != null && ((asset.resourcesPaths == null || asset.resourcesPaths.Count == 0) || (asset.audioResources.Count == 0 && asset.sharedData.audioClips.Count > 0))) { GAFResourceManagerInternal.initInstance <GAFResourceManager>(); GAFResourceManagerInternal.instance.createResources <GAFTexturesResource>(asset); GAFResourceManagerInternal.instance.createMecanimResources(asset); GAFResourceManagerInternal.instance.defineAudioResources(asset); EditorUtility.SetDirty(asset); AssetDatabase.SaveAssets(); } } } } }