Download Editor/FunctionGemmaBuildStaging.cs from Sky-Kim/com.sky.sentis.functiongemma.home: direct link, hf CLI and curl.
- Browser
- Download file 1.82 kB
-
https://huggingface.co/Sky-Kim/com.sky.sentis.functiongemma.home/resolve/main/Editor/FunctionGemmaBuildStaging.cs
- Command line
-
hf download hf://Sky-Kim/com.sky.sentis.functiongemma.home/Editor/FunctionGemmaBuildStaging.cs
-
curl -L -o FunctionGemmaBuildStaging.cs https://huggingface.co/Sky-Kim/com.sky.sentis.functiongemma.home/resolve/main/Editor/FunctionGemmaBuildStaging.cs
1.82 kB
| using System.IO; | |
| using UnityEditor; | |
| using UnityEditor.Build; | |
| using UnityEditor.Build.Reporting; | |
| using UnityEngine; | |
| namespace SentisSkills.Inference | |
| { | |
| /// <summary> | |
| /// Player builds read the model, tokenizer and developer block from StreamingAssets/FunctionGemmaHome (see | |
| /// <see cref="FunctionGemmaFiles"/>): before a build this copies them there from the package's Models~ folder, | |
| /// and after the build it removes the copy, so the Editor keeps reading the package and the project holds no | |
| /// second copy of the model. | |
| /// </summary> | |
| sealed class FunctionGemmaBuildStaging : IPreprocessBuildWithReport, IPostprocessBuildWithReport | |
| { | |
| public int callbackOrder => 0; | |
| static string Staged => Path.Combine(Application.streamingAssetsPath, FunctionGemmaFiles.StreamingFolder); | |
| public void OnPreprocessBuild(BuildReport report) | |
| { | |
| Clean(); | |
| if (FunctionGemmaFiles.Root == null) | |
| throw new BuildFailedException($"[FunctionGemma] {FunctionGemmaFiles.PackageName} not found in the package cache."); | |
| Directory.CreateDirectory(Staged); | |
| foreach (var file in FunctionGemmaFiles.All) | |
| File.Copy(FunctionGemmaFiles.PathOf(file), Path.Combine(Staged, file), true); | |
| } | |
| public void OnPostprocessBuild(BuildReport report) => Clean(); | |
| /// <summary>Removes a copy left behind by a build that failed before its postprocess step.</summary> | |
| [] | |
| static void CleanAfterFailedBuild() | |
| { | |
| if (!BuildPipeline.isBuildingPlayer) Clean(); | |
| } | |
| static void Clean() | |
| { | |
| if (Directory.Exists(Staged)) Directory.Delete(Staged, true); | |
| File.Delete(Staged + ".meta"); | |
| } | |
| } | |
| } | |