<commit_before>#if UNITY_2017_1_OR_NEWER

using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine.Rendering;
using Object = UnityEngine.Object;

namespace UTJ.Alembic
{
    public class AlembicAssetModificationProcessor : UnityEditor.AssetModificationProcessor
    {
        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;
        } 
    }
        
    [ScriptedImporter(1, "abc")]
    public class AlembicImporter : ScriptedImporter
    {
        [SerializeField] public AlembicStreamSettings streamSettings = new AlembicStreamSettings();
        [SerializeField] public float scaleFactor = 0.01f;
        [SerializeField] public int startFrame;
        [SerializeField] public int endFrame;        
        [SerializeField] public float AbcStartTime;
        [SerializeField] public float AbcEndTime;
        [SerializeField] public int AbcFrameCount;
        [SerializeField] public string importWarning;
        [SerializeField] public List<string> varyingTopologyMeshNames = new List<string>();

        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 = destPath;
            streamDescriptor.minFrame = startFrame;
            streamDescriptor.maxFrame = endFrame;
            streamDescriptor.settings = streamSettings;

            using (var abcStream = new AlembicStream(go, streamDescriptor))
            {
                abcStream.AbcLoad(true);
                AbcStartTime = abcStream.AbcStartTime;
                AbcEndTime = abcStream.AbcEndTime;
                AbcFrameCount = abcStream.AbcFrameCount;

                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);<commit_msg>fixed issue with importer default time range being 0-0<commit_after>#if UNITY_2017_1_OR_NEWER

using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine.Rendering;
using Object = UnityEngine.Object;

namespace UTJ.Alembic
{
    public class AlembicAssetModificationProcessor : UnityEditor.AssetModificationProcessor
    {
        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;
        } 
    }
        
    [ScriptedImporter(1, "abc")]
    public class AlembicImporter : ScriptedImporter
    {
        [SerializeField] public AlembicStreamSettings streamSettings = new AlembicStreamSettings();
        [SerializeField] public float scaleFactor = 0.01f;
        [SerializeField] public int startFrame =-1;
        [SerializeField] public int endFrame =-1;        
        [SerializeField] public float AbcStartTime;
        [SerializeField] public float AbcEndTime;
        [SerializeField] public int AbcFrameCount;
        [SerializeField] public string importWarning;
        [SerializeField] public List<string> varyingTopologyMeshNames = new List<string>();

        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 = destPath;
            streamDescriptor.settings = streamSettings;

            using (var abcStream = new AlembicStream(go, streamDescriptor))
            {
                abcStream.AbcLoad(true);
                AbcStartTime = abcStream.AbcStartTime;
                AbcEndTime = abcStream.AbcEndTime;
                AbcFrameCount = abcStream.AbcFrameCount;

                startFrame = startFrame ==-1 ? 0 : startFrame;
                endFrame = endFrame ==-1 ? AbcFrameCount : 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);
{'fraction_non_alphanumeric': 0.08094985875706215, 'fraction_numerical': 0.0022069209039548023, 'mean_word_length': 2.438239757207891, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2277394', 'n_tokens_mistral': 2828, 'n_tokens_neox': 2760, 'n_words': 509}