Skip to content

Commit

Permalink
Merge branch 'NyxTheShield-master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed May 11, 2023
2 parents e098a5d + 7c02feb commit e2131ac
Show file tree
Hide file tree
Showing 13 changed files with 724 additions and 33 deletions.
39 changes: 39 additions & 0 deletions Assets/Art/DummyBackgroundTexture.renderTexture
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
8 changes: 8 additions & 0 deletions Assets/Art/DummyBackgroundTexture.renderTexture.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/Art/Textures/PlayMode/Black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 123 additions & 0 deletions Assets/Art/Textures/PlayMode/Black.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 93 additions & 0 deletions Assets/BackgroundManager.cs
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
}
11 changes: 11 additions & 0 deletions Assets/BackgroundManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Nyx.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e2131ac

Please sign in to comment.