Upload from upload_mods.ps1
This commit is contained in:
94
Scripts/XUIC/XUiC_MainMenuBackgroundRebirth.cs
Normal file
94
Scripts/XUIC/XUiC_MainMenuBackgroundRebirth.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class XUiC_MainMenuBackgroundRebirth : XUiController
|
||||
{
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
this.mainMenuTexture = (base.GetChildById("menuBG").ViewComponent as XUiV_Texture);
|
||||
}
|
||||
|
||||
private XUiV_Texture mainMenuTexture;
|
||||
|
||||
public override bool ParseAttribute(string _name, string _value, XUiController _parent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void GetImage()
|
||||
{
|
||||
string ModsBasePath = GameIO.GetUserGameDataDir() + "/Mods";
|
||||
string ModsBasePathLegacy = Application.platform != UnityEngine.RuntimePlatform.OSXPlayer ? (Application.dataPath + "/../Mods") : (Application.dataPath + "/../../Mods");
|
||||
string imagePath = "";
|
||||
|
||||
if (Directory.Exists(ModsBasePathLegacy + "/zzz_REBIRTH__Utils"))
|
||||
{
|
||||
imagePath = ModsBasePathLegacy + "/zzz_REBIRTH__Utils" + "/Resources/Backgrounds/";
|
||||
}
|
||||
else
|
||||
{
|
||||
imagePath = ModsBasePath + "/zzz_REBIRTH__Utils" + "/Resources/Backgrounds/";
|
||||
}
|
||||
|
||||
string[] backgroundsPNG = Directory.GetFiles(imagePath, "Menu*.jpg");
|
||||
int randomIndex = 0;
|
||||
|
||||
//Log.Out("XUiC_MainMenuBackgroundRebirth-OnOpen backgroundsPNG.Length: " + backgroundsPNG.Length);
|
||||
|
||||
|
||||
if (backgroundLeft.Count == 0)
|
||||
{
|
||||
for (int i = 0; i < 81; i++)
|
||||
{
|
||||
backgroundLeft.Add(i);
|
||||
}
|
||||
}
|
||||
|
||||
//Log.Out("XUiC_MainMenuBackgroundRebirth-OnOpen backgroundLeft.Count: " + backgroundLeft.Count);
|
||||
|
||||
int num = UnityEngine.Random.Range(0, backgroundLeft.Count - 1);
|
||||
|
||||
//Log.Out("XUiC_MainMenuBackgroundRebirth-OnOpen num: " + num);
|
||||
|
||||
randomIndex = backgroundLeft[num];
|
||||
|
||||
//Log.Out("XUiC_MainMenuBackgroundRebirth-OnOpen randomIndex: " + randomIndex);
|
||||
|
||||
backgroundLeft.Remove(randomIndex);
|
||||
|
||||
//Log.Out("XUiC_MainMenuBackgroundRebirth-OnOpen prefabImagePath: " + imagePath);
|
||||
if (File.Exists(backgroundsPNG[randomIndex]))
|
||||
{
|
||||
//Log.Out("XUiC_MainMenuBackgroundRebirth-OnOpen EXISTS");
|
||||
|
||||
Texture2D texture = new Texture2D(0, 0, TextureFormat.RGB24, false);
|
||||
texture.LoadImage(File.ReadAllBytes(backgroundsPNG[randomIndex]));
|
||||
|
||||
mainMenuTexture.Texture = texture;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update(float _dt)
|
||||
{
|
||||
float menuBackgroundTick = 20f;
|
||||
if ((Time.time - RebirthVariables.menuBackgroundCheck) > menuBackgroundTick)
|
||||
{
|
||||
RebirthVariables.menuBackgroundCheck = Time.time;
|
||||
GetImage();
|
||||
}
|
||||
|
||||
base.Update(_dt);
|
||||
}
|
||||
|
||||
public override void OnOpen()
|
||||
{
|
||||
//Log.Out("XUiC_MainMenuBackgroundRebirth-OnOpen START");
|
||||
//Log.Out("XUiC_MainMenuBackgroundRebirth-OnOpen Size: " + mainMenuTexture.Size);
|
||||
|
||||
GetImage();
|
||||
|
||||
base.OnOpen();
|
||||
}
|
||||
|
||||
private static List<int> backgroundLeft = new List<int>();
|
||||
}
|
||||
Reference in New Issue
Block a user