-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2436c5a
commit 1536f0c
Showing
9 changed files
with
254 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
Unity/Packages/com.fragcolor.chainblocks/Editor/Build/BuilderBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* SPDX-License-Identifier: BUSL-1.1 */ | ||
/* Copyright © 2022 Fragcolor Pte. Ltd. */ | ||
|
||
#nullable enable | ||
|
||
using Fragcolor.Chainblocks.UnityEditor.Settings; | ||
|
||
using UnityEngine; | ||
|
||
namespace Fragcolor.Chainblocks.UnityEditor.Build | ||
{ | ||
internal abstract class BuilderBase : ScriptableObject, IBuilder | ||
{ | ||
public abstract string Name { get; } | ||
|
||
protected static ChainblocksSettings? Settings | ||
{ | ||
get { return ChainblocksSettingsDefaultObject.Settings; } | ||
} | ||
|
||
internal abstract void Build(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Unity/Packages/com.fragcolor.chainblocks/Editor/Build/BuilderBase.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
110 changes: 110 additions & 0 deletions
110
Unity/Packages/com.fragcolor.chainblocks/Editor/Build/DefaultBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* SPDX-License-Identifier: BUSL-1.1 */ | ||
/* Copyright © 2022 Fragcolor Pte. Ltd. */ | ||
|
||
#nullable enable | ||
|
||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
using Fragcolor.Chainblocks.UnityEditor.Settings; | ||
|
||
using Newtonsoft.Json; | ||
|
||
using UnityEditor; | ||
using UnityEditor.Build.Reporting; | ||
|
||
using UnityEngine; | ||
|
||
namespace Fragcolor.Chainblocks.UnityEditor.Build | ||
{ | ||
internal sealed class DefaultBuilder : BuilderBase | ||
{ | ||
public override string Name => "Default"; | ||
|
||
[InitializeOnLoadMethod] | ||
private static void Initialize() | ||
{ | ||
BuildPlayerWindow.RegisterBuildPlayerHandler(BuidWithOptions); | ||
} | ||
|
||
[MenuItem("Chainblocks/Build/Default")] | ||
private static void BuildFromMenu() | ||
{ | ||
var builder = Settings!.builders!.Find(x => x.Name == "Default"); | ||
builder.Build(); | ||
} | ||
|
||
[MenuItem("Chainblocks/Build/Default", true)] | ||
private static bool CanBuildFromMenu() | ||
{ | ||
return Settings != null; | ||
} | ||
|
||
internal override void Build() | ||
{ | ||
if (Settings == null) return; | ||
|
||
BuidWithOptions(BuildPlayerWindow.DefaultBuildMethods.GetBuildPlayerOptions(default)); | ||
} | ||
|
||
private static void BuidWithOptions(BuildPlayerOptions options) | ||
{ | ||
if (Settings == null) | ||
{ | ||
// Do a regular build | ||
BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(options); | ||
return; | ||
} | ||
|
||
#if false | ||
// HACK: artificially mark all scenes as dirty to force a rebuild | ||
foreach (var scenePath in options.scenes) | ||
{ | ||
var scene = AssetDatabase.LoadAssetAtPath<SceneAsset>(scenePath); | ||
EditorUtility.SetDirty(scene); | ||
} | ||
AssetDatabase.SaveAssets(); | ||
#endif | ||
options.options |= BuildOptions.DetailedBuildReport | BuildOptions.StrictMode; | ||
#if UNITY_2021_2_OR_NEWER | ||
options.options |= BuildOptions.CleanBuildCache | ||
#endif | ||
var report = BuildPipeline.BuildPlayer(options); | ||
var summary = report.summary; | ||
switch (summary.result) | ||
{ | ||
case BuildResult.Succeeded: | ||
Debug.Log("Build succeeded: " + summary.totalSize + " bytes"); | ||
var foundEntries = new List<ChainblocksAssetEntry>(); | ||
foreach (var asset in report.scenesUsingAssets.SelectMany(s => s.list)) | ||
{ | ||
var guid = AssetDatabase.AssetPathToGUID(asset.assetPath); | ||
if (Settings.TryFindAssetEntry(guid, out var entry)) | ||
{ | ||
foundEntries.Add(entry); | ||
} | ||
} | ||
|
||
foreach (var entry in foundEntries) | ||
{ | ||
Debug.Log($"{entry.guid} - {entry.localPath}"); | ||
} | ||
|
||
if (foundEntries.Count > 0) | ||
{ | ||
var json = JsonConvert.SerializeObject(foundEntries, Formatting.Indented); | ||
var basePath = Path.GetDirectoryName(options.locationPathName); | ||
File.WriteAllText(Path.Combine(basePath, "FragInfo.data"), json); | ||
} | ||
|
||
break; | ||
|
||
case BuildResult.Failed: | ||
case BuildResult.Cancelled: | ||
Debug.Log("Build failed or cancelled."); | ||
break; | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Unity/Packages/com.fragcolor.chainblocks/Editor/Build/DefaultBuilder.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
Unity/Packages/com.fragcolor.chainblocks/Editor/Build/IBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* SPDX-License-Identifier: BUSL-1.1 */ | ||
/* Copyright © 2022 Fragcolor Pte. Ltd. */ | ||
|
||
#nullable enable | ||
|
||
namespace Fragcolor.Chainblocks.UnityEditor.Build | ||
{ | ||
internal interface IBuilder | ||
{ | ||
string Name { get; } | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Unity/Packages/com.fragcolor.chainblocks/Editor/Build/IBuilder.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters