-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/NyxTheShield/YARG into Ny…
…xTheShield-master
- Loading branch information
Showing
13 changed files
with
724 additions
and
33 deletions.
There are no files selected for viewing
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,39 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!84 &8400000 | ||
RenderTexture: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_Name: DummyBackgroundTexture | ||
m_ImageContentsHash: | ||
serializedVersion: 2 | ||
Hash: 00000000000000000000000000000000 | ||
m_ForcedFallbackFormat: 4 | ||
m_DownscaleFallback: 0 | ||
m_IsAlphaChannelOptional: 0 | ||
serializedVersion: 5 | ||
m_Width: 1920 | ||
m_Height: 1080 | ||
m_AntiAliasing: 1 | ||
m_MipCount: -1 | ||
m_DepthStencilFormat: 94 | ||
m_ColorFormat: 40 | ||
m_MipMap: 0 | ||
m_GenerateMips: 1 | ||
m_SRGB: 0 | ||
m_UseDynamicScale: 0 | ||
m_BindMS: 0 | ||
m_EnableCompatibleFormat: 1 | ||
m_TextureSettings: | ||
serializedVersion: 2 | ||
m_FilterMode: 1 | ||
m_Aniso: 0 | ||
m_MipBias: 0 | ||
m_WrapU: 1 | ||
m_WrapV: 1 | ||
m_WrapW: 1 | ||
m_Dimension: 2 | ||
m_VolumeDepth: 1 | ||
m_ShadowSamplingMode: 2 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using UnityEngine; | ||
using YARG.UI; | ||
|
||
#if UNITY_EDITOR | ||
using UnityEditor; | ||
#endif | ||
public class BackgroundManager : MonoBehaviour { | ||
|
||
public Camera mainCamera; | ||
public RenderTexture bgTexture; | ||
|
||
public AssetBundle bundle; | ||
// Start is called before the first frame update | ||
void Start() { | ||
//Move object out of the way just in case | ||
transform.position += Vector3.up * 1000; | ||
bgTexture = new RenderTexture(Screen.currentResolution.width, Screen.currentResolution.height, 16, RenderTextureFormat.ARGB32); | ||
bgTexture.Create(); | ||
mainCamera.targetTexture = bgTexture; | ||
GameUI.Instance.background.texture = bgTexture; | ||
} | ||
|
||
private void OnDestroy() { | ||
bgTexture.Release(); | ||
bundle.Unload(true); | ||
} | ||
|
||
GameObject tromboneBackground; | ||
|
||
//Code to export a background from the editor | ||
//This honestly should be on a different class (and ideally on a completely different project as a template) but as a quick dirty PoC it will do for now | ||
#if UNITY_EDITOR | ||
[ContextMenu("Export Background")] | ||
public void ExportBackground() { | ||
tromboneBackground = gameObject; | ||
string path = EditorUtility.SaveFilePanel("Save Background", string.Empty, "bg", | ||
"yarground"); | ||
|
||
BuildTargetGroup selectedBuildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup; | ||
BuildTarget activeBuildTarget = EditorUserBuildSettings.activeBuildTarget; | ||
|
||
GameObject clonedTromboneBackground = null; | ||
|
||
try { | ||
if (!string.IsNullOrEmpty(path)) { | ||
clonedTromboneBackground = Instantiate(tromboneBackground.gameObject); | ||
|
||
string fileName = Path.GetFileName(path); | ||
string folderPath = Path.GetDirectoryName(path); | ||
|
||
// serialize tromboners (this one is not unity's fault, it's base game weirdness) | ||
List<string> trombonePaths = new List<string>() { "Assets/_Background.prefab" }; | ||
|
||
|
||
PrefabUtility.SaveAsPrefabAsset(clonedTromboneBackground.gameObject, "Assets/_Background.prefab"); | ||
AssetBundleBuild assetBundleBuild = default; | ||
assetBundleBuild.assetBundleName = fileName; | ||
assetBundleBuild.assetNames = trombonePaths.ToArray(); | ||
|
||
BuildPipeline.BuildAssetBundles(Application.temporaryCachePath, | ||
new AssetBundleBuild[] { assetBundleBuild }, BuildAssetBundleOptions.ForceRebuildAssetBundle, | ||
EditorUserBuildSettings.activeBuildTarget); | ||
EditorPrefs.SetString("currentBuildingAssetBundlePath", folderPath); | ||
EditorUserBuildSettings.SwitchActiveBuildTarget(selectedBuildTargetGroup, activeBuildTarget); | ||
|
||
foreach (var asset in trombonePaths) { | ||
AssetDatabase.DeleteAsset(asset); | ||
} | ||
|
||
if (File.Exists(path)) File.Delete(path); | ||
|
||
// Unity seems to save the file in lower case, which is a problem on Linux, as file systems are case sensitive there | ||
File.Move(Path.Combine(Application.temporaryCachePath, fileName.ToLowerInvariant()), path); | ||
|
||
AssetDatabase.Refresh(); | ||
|
||
EditorUtility.DisplayDialog("Export Successful!", "Export Successful!", "OK"); | ||
|
||
if (clonedTromboneBackground != null) DestroyImmediate(clonedTromboneBackground); | ||
} | ||
} | ||
catch { | ||
if (clonedTromboneBackground != null) DestroyImmediate(clonedTromboneBackground); | ||
} | ||
|
||
} | ||
|
||
#endif | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.