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 } }
void OnValidate() { if (streamDescriptor == null || abcStream == null) { return; } if (streamDescriptor.abcStartTime == double.MinValue || streamDescriptor.abcEndTime == double.MaxValue) { abcStream.GetTimeRange(ref streamDescriptor.abcStartTime, ref streamDescriptor.abcEndTime); } startTime = Mathf.Clamp((float)startTime, (float)streamDescriptor.abcStartTime, (float)streamDescriptor.abcEndTime); endTime = Mathf.Clamp((float)endTime, (float)startTime, (float)streamDescriptor.abcEndTime); ClampTime(); forceUpdate = true; }