AssetBundleGraph.Asset.CreateNewAssetFromLoader C# (CSharp) Method

CreateNewAssetFromLoader() public static method

public static CreateNewAssetFromLoader ( string absoluteAssetPath, string importFrom ) : Asset
absoluteAssetPath string
importFrom string
return Asset
        public static Asset CreateNewAssetFromLoader(string absoluteAssetPath, string importFrom)
        {
            return new Asset(
                guid: Guid.NewGuid(),
                assetDatabaseId:AssetDatabase.AssetPathToGUID(importFrom),
                absoluteAssetPath:absoluteAssetPath,
                importFrom:importFrom,
                assetType:TypeUtility.GetTypeOfAsset(importFrom)
            );
        }

Usage Example

Example #1
0
        public void Run(string nodeName, string nodeId, string connectionIdToNextNode, Dictionary <string, List <Asset> > unused, List <string> alreadyCached, Action <string, string, Dictionary <string, List <Asset> >, List <string> > Output)
        {
            ValidateLoadPath(
                loadFilePath,
                loadFilePath,
                () => {
                //throw new AssetBundleGraphBuildException(nodeName + ": Load Path is empty.");
            },
                () => {
                throw new AssetBundleGraphBuildException(nodeName + ": Directory not found: " + loadFilePath);
            }
                );

            // SOMEWHERE_FULLPATH/PROJECT_FOLDER/Assets/
            var assetsFolderPath = Application.dataPath + AssetBundleGraphSettings.UNITY_FOLDER_SEPARATOR;

            var outputSource = new List <Asset>();

            try {
                var targetFilePaths = FileUtility.FilePathsInFolder(loadFilePath);

                foreach (var targetFilePath in targetFilePaths)
                {
                    if (targetFilePath.Contains(AssetBundleGraphSettings.ASSETBUNDLEGRAPH_PATH))
                    {
                        continue;
                    }

                    // already contained into Assets/ folder.
                    // imported path is Assets/SOMEWHERE_FILE_EXISTS.
                    if (targetFilePath.StartsWith(assetsFolderPath))
                    {
                        var importFrom = targetFilePath.Replace(assetsFolderPath, AssetBundleGraphSettings.ASSETS_PATH);

                        outputSource.Add(Asset.CreateNewAssetFromLoader(targetFilePath, importFrom));
                        continue;
                    }

                    throw new AssetBundleGraphSetupException(nodeName + ": Invalid target file path. Path needs to be set under Assets/ :" + targetFilePath);
                }

                var outputDir = new Dictionary <string, List <Asset> > {
                    { "0", outputSource }
                };

                Output(nodeId, connectionIdToNextNode, outputDir, new List <string>());
            } catch (Exception e) {
                throw new NodeException(e.Message, nodeId);
            }
        }
All Usage Examples Of AssetBundleGraph.Asset::CreateNewAssetFromLoader