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);
        }
Esempio n. 2
0
        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);
        }