Пример #1
0
 protected virtual UnityPath GetAssetPath(UnityPath prefabPath, UnityEngine.Object o)
 {
     if (o is Material)
     {
         var materialDir  = prefabPath.GetAssetFolder(".Materials");
         var materialPath = materialDir.Child(o.name.EscapeFilePath() + ".asset");
         return(materialPath);
     }
     else if (o is Texture2D)
     {
         var textureDir  = prefabPath.GetAssetFolder(".Textures");
         var texturePath = textureDir.Child(o.name.EscapeFilePath() + ".asset");
         return(texturePath);
     }
     else if (o is Mesh && !MeshAsSubAsset)
     {
         var meshDir  = prefabPath.GetAssetFolder(".Meshes");
         var meshPath = meshDir.Child(o.name.EscapeFilePath() + ".asset");
         return(meshPath);
     }
     else
     {
         return(default(UnityPath));
     }
 }
Пример #2
0
        /// <summary>
        /// Extract images from glb or gltf out of Assets folder.
        /// </summary>
        /// <param name="prefabPath"></param>
        public void ExtractImages(UnityPath prefabPath)
        {
            var prefabParentDir = prefabPath.Parent;

            // glb buffer
            var folder = prefabPath.GetAssetFolder(".Textures");

            //
            // https://answers.unity.com/questions/647615/how-to-update-import-settings-for-newly-created-as.html
            //
            int created = 0;

            //for (int i = 0; i < GLTF.textures.Count; ++i)
            for (int i = 0; i < GLTF.images.Count; ++i)
            {
                folder.EnsureFolder();

                //var x = GLTF.textures[i];
                var image = GLTF.images[i];
                var src   = Storage.GetPath(image.uri);
                if (UnityPath.FromFullpath(src).IsUnderAssetsFolder)
                {
                    // asset is exists.
                }
                else
                {
                    string textureName;
                    var    byteSegment = GLTF.GetImageBytes(Storage, i, out textureName);

                    // path
                    var dst = folder.Child(textureName + image.GetExt());
                    File.WriteAllBytes(dst.FullPath, byteSegment.ToArray());
                    dst.ImportAsset();

                    // make relative path from PrefabParentDir
                    image.uri = dst.Value.Substring(prefabParentDir.Value.Length + 1);
                    ++created;
                }
            }

            if (created > 0)
            {
                AssetDatabase.Refresh();
            }

            CreateTextureItems(prefabParentDir);
        }