Ejemplo n.º 1
0
        public static AssetMoveResult OnWillMoveAsset(string from, string to)
        {
            if (Path.GetExtension(from.ToLower()) != ".abc")
            {
                return(AssetMoveResult.DidNotMove);
            }

            try
            {
                var streamDstPath = AlembicImporter.MakeShortAssetPath(to);
                var streamSrcPath = AlembicImporter.MakeShortAssetPath(from);
                var dstPath       = Application.streamingAssetsPath + streamDstPath;
                var srcPath       = Application.streamingAssetsPath + streamSrcPath;

                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);
            }
            catch (System.Exception e)
            {
                Debug.LogWarning(e);
            }

            return(AssetMoveResult.DidNotMove);
        }
Ejemplo n.º 2
0
        public static AssetDeleteResult OnWillDeleteAsset(string assetPath, RemoveAssetOptions rao)
        {
            if (Path.GetExtension(assetPath.ToLower()) != ".abc")
            {
                return(AssetDeleteResult.DidNotDelete);
            }

            try
            {
                var streamingAssetPath     = AlembicImporter.MakeShortAssetPath(assetPath);
                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);
        }