public static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions rao) { if (Path.GetExtension(assetPath.ToLower()) != ".abc") { return(AssetDeleteResult.DidNotDelete); } var streamingAssetPath = AlembicImporter.MakeShortAssetPath(assetPath); AlembicStream.DisconnectStreamsWithPath(streamingAssetPath); try { var fullStreamingAssetPath = Application.streamingAssetsPath + streamingAssetPath; File.SetAttributes(fullStreamingAssetPath, FileAttributes.Normal); File.Delete(fullStreamingAssetPath); File.SetAttributes(fullStreamingAssetPath + ".meta", FileAttributes.Normal); File.Delete(fullStreamingAssetPath + ".meta"); } catch (System.Exception e) { Debug.LogWarning(e); } return(AssetDeleteResult.DidNotDelete); }
public override void OnImportAsset(AssetImportContext ctx) { var shortAssetPath = MakeShortAssetPath(ctx.assetPath); AlembicStream.DisconnectStreamsWithPath(shortAssetPath); var sourcePath = Application.dataPath + shortAssetPath; var destPath = Application.streamingAssetsPath + shortAssetPath; var directoryPath = Path.GetDirectoryName(destPath); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } if (File.Exists(destPath)) { File.SetAttributes(destPath, FileAttributes.Normal); } File.Copy(sourcePath, destPath, true); var fileName = Path.GetFileNameWithoutExtension(destPath); var go = new GameObject(fileName); var streamDescriptor = ScriptableObject.CreateInstance <AlembicStreamDescriptor>(); streamDescriptor.name = go.name + "_ABCDesc"; streamDescriptor.pathToAbc = shortAssetPath; streamDescriptor.settings = streamSettings; using (var abcStream = new AlembicStream(go, streamDescriptor)) { abcStream.AbcLoad(true); abcStream.GetTimeRange(ref startTime, ref endTime); streamDescriptor.abcStartTime = abcStartTime = startTime; streamDescriptor.abcEndTime = abcEndTime = endTime; var streamPlayer = go.AddComponent <AlembicStreamPlayer>(); streamPlayer.streamDescriptor = streamDescriptor; streamPlayer.startTime = startTime; streamPlayer.endTime = endTime; var subassets = new Subassets(ctx); subassets.Add(streamDescriptor.name, streamDescriptor); GenerateSubAssets(subassets, abcStream.abcTreeRoot, streamDescriptor); AlembicStream.ReconnectStreamsWithPath(shortAssetPath); #if UNITY_2017_3_OR_NEWER ctx.AddObjectToAsset(go.name, go); ctx.SetMainObject(go); #else ctx.SetMainAsset(go.name, go); #endif } }
public static AssetMoveResult OnWillMoveAsset(string from, string to) { if (Path.GetExtension(from.ToLower()) != ".abc") { return(AssetMoveResult.DidNotMove); } var streamDstPath = AlembicImporter.MakeShortAssetPath(to); var streamSrcPath = AlembicImporter.MakeShortAssetPath(from); AlembicStream.DisconnectStreamsWithPath(streamSrcPath); AlembicStream.RemapStreamsWithPath(streamSrcPath, streamDstPath); var dstPath = Application.streamingAssetsPath + streamDstPath; var srcPath = Application.streamingAssetsPath + streamSrcPath; try { var directoryPath = Path.GetDirectoryName(dstPath); if (File.Exists(dstPath)) { File.SetAttributes(dstPath + ".meta", FileAttributes.Normal); File.Delete(dstPath); } else if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } if (File.Exists(dstPath)) { File.SetAttributes(dstPath, FileAttributes.Normal); } File.Move(srcPath, dstPath); if (File.Exists(dstPath + ".meta")) { File.SetAttributes(dstPath + ".meta", FileAttributes.Normal); File.Move(srcPath + ".meta", dstPath + ".meta"); } AssetDatabase.Refresh(ImportAssetOptions.Default); AlembicStream.ReconnectStreamsWithPath(streamDstPath); } catch (System.Exception e) { Debug.LogWarning(e); } return(AssetMoveResult.DidNotMove); }
public static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions rao) { if (Path.GetExtension(assetPath.ToLower()) != ".abc") { return(AssetDeleteResult.DidNotDelete); } var streamingAssetPath = assetPath.Replace("Assets", ""); AlembicStream.DisconnectStreamsWithPath(streamingAssetPath); var fullStreamingAssetPath = Application.streamingAssetsPath + streamingAssetPath; File.SetAttributes(fullStreamingAssetPath, FileAttributes.Normal); File.Delete(fullStreamingAssetPath); File.SetAttributes(fullStreamingAssetPath + ".meta", FileAttributes.Normal); File.Delete(fullStreamingAssetPath + ".meta"); return(AssetDeleteResult.DidNotDelete); }
public static AssetMoveResult OnWillMoveAsset(string from, string to) { if (Path.GetExtension(from.ToLower()) != ".abc") { return(AssetMoveResult.DidNotMove); } var streamDestPath = to.Replace("Assets", ""); var streamSourcePath = from.Replace("Assets", ""); AlembicStream.DisconnectStreamsWithPath(streamSourcePath); AlembicStream.RemapStreamsWithPath(streamSourcePath, streamDestPath); var destPath = Application.streamingAssetsPath + streamDestPath; var sourcePath = Application.streamingAssetsPath + streamSourcePath; var directoryPath = Path.GetDirectoryName(destPath); if (File.Exists(destPath)) { File.SetAttributes(destPath + ".meta", FileAttributes.Normal); File.Delete(destPath); } else if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } if (File.Exists(destPath)) { File.SetAttributes(destPath, FileAttributes.Normal); } File.Move(sourcePath, destPath); if (File.Exists(destPath + ".meta")) { File.SetAttributes(destPath + ".meta", FileAttributes.Normal); File.Move(sourcePath + ".meta", destPath + ".meta"); } AssetDatabase.Refresh(ImportAssetOptions.Default); AlembicStream.ReconnectStreamsWithPath(streamDestPath); return(AssetMoveResult.DidNotMove); }
public override void OnImportAsset(AssetImportContext ctx) { var shortAssetPath = ctx.assetPath.Replace("Assets", ""); AlembicStream.DisconnectStreamsWithPath(shortAssetPath); var sourcePath = Application.dataPath + shortAssetPath; var destPath = Application.streamingAssetsPath + shortAssetPath; var directoryPath = Path.GetDirectoryName(destPath); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } if (File.Exists(destPath)) { File.SetAttributes(destPath, FileAttributes.Normal); } File.Copy(sourcePath, destPath, true); var fileName = Path.GetFileNameWithoutExtension(destPath); var go = new GameObject(fileName); go.transform.localScale *= scaleFactor; AlembicStreamDescriptor streamDescriptor = ScriptableObject.CreateInstance <AlembicStreamDescriptor>(); streamDescriptor.name = go.name + "_ABCDesc"; streamDescriptor.pathToAbc = shortAssetPath; streamDescriptor.settings = streamSettings; using (var abcStream = new AlembicStream(go, streamDescriptor)) { abcStream.AbcLoad(); AbcStartTime = abcStream.AbcStartTime; AbcEndTime = abcStream.AbcEndTime; AbcFrameCount = abcStream.AbcFrameCount; startFrame = startFrame < 0 ? 0 : startFrame; endFrame = endFrame > AbcFrameCount - 1 ? AbcFrameCount - 1 : endFrame; streamDescriptor.minFrame = startFrame; streamDescriptor.maxFrame = endFrame; streamDescriptor.abcFrameCount = AbcFrameCount; streamDescriptor.abcDuration = AbcEndTime - AbcStartTime; streamDescriptor.abcStartTime = AbcStartTime; var streamPlayer = go.AddComponent <AlembicStreamPlayer>(); streamPlayer.streamDescriptor = streamDescriptor; streamPlayer.startFrame = startFrame; streamPlayer.endFrame = endFrame; AddObjectToAsset(ctx, streamDescriptor.name, streamDescriptor); GenerateSubAssets(ctx, abcStream.alembicTreeRoot, streamDescriptor); AlembicStream.ReconnectStreamsWithPath(shortAssetPath); #if UNITY_2017_3_OR_NEWER ctx.AddObjectToAsset(go.name, go); ctx.SetMainObject(go); #else ctx.SetMainAsset(go.name, go); #endif } }