2023-01-12 01:42:12 +00:00
|
|
|
using System;
|
2022-01-03 22:42:43 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2023-01-12 01:42:12 +00:00
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
using System.IO.Compression;
|
|
|
|
using System.Text;
|
|
|
|
|
2022-01-03 22:42:43 +00:00
|
|
|
using UnityEngine;
|
2022-02-05 04:40:33 +00:00
|
|
|
using UnityEngine.Audio;
|
2022-01-03 22:42:43 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio
|
2022-01-03 22:42:43 +00:00
|
|
|
{
|
2023-05-07 20:33:15 +00:00
|
|
|
public class GameInitializer : MonoBehaviour
|
2022-01-03 22:42:43 +00:00
|
|
|
{
|
2023-03-11 04:51:22 +00:00
|
|
|
[SerializeField] RenderTexture gameRenderTexture;
|
|
|
|
[SerializeField] RenderTexture overlayRenderTexture;
|
|
|
|
|
2023-05-07 20:33:15 +00:00
|
|
|
[SerializeField] HeavenStudio.Editor.Editor editorGO;
|
|
|
|
[SerializeField] String debug_cmdFile;
|
|
|
|
|
|
|
|
[SerializeField] GameManager gameManager;
|
|
|
|
|
|
|
|
[SerializeField] GameObject MainCamera;
|
|
|
|
[SerializeField] GameObject CursorCamera;
|
|
|
|
[SerializeField] GameObject OverlayCamera;
|
|
|
|
[SerializeField] GameObject StaticCamera;
|
|
|
|
[SerializeField] GameObject Cursor;
|
|
|
|
|
|
|
|
[SerializeField] GameObject Profiler;
|
|
|
|
|
2022-01-06 00:11:33 +00:00
|
|
|
public bool debugUI;
|
|
|
|
|
|
|
|
public bool playOnStart = false;
|
2023-05-07 20:33:15 +00:00
|
|
|
public bool fromCmd = false;
|
2022-01-03 22:42:43 +00:00
|
|
|
|
2023-01-12 01:42:12 +00:00
|
|
|
string json = "";
|
|
|
|
string ext = "";
|
|
|
|
|
2022-01-03 22:42:43 +00:00
|
|
|
private void Start()
|
|
|
|
{
|
2023-01-12 01:42:12 +00:00
|
|
|
string input = "";
|
2023-05-07 20:33:15 +00:00
|
|
|
if (debug_cmdFile != string.Empty)
|
|
|
|
{
|
|
|
|
if (debug_cmdFile.IndexOfAny(Path.GetInvalidPathChars()) == -1)
|
2023-01-12 01:42:12 +00:00
|
|
|
{
|
2023-05-07 20:33:15 +00:00
|
|
|
if (File.Exists(debug_cmdFile))
|
2023-01-12 01:42:12 +00:00
|
|
|
{
|
2023-05-07 20:33:15 +00:00
|
|
|
input = debug_cmdFile;
|
|
|
|
fromCmd = true;
|
2023-01-12 01:42:12 +00:00
|
|
|
playOnStart = true;
|
|
|
|
}
|
|
|
|
}
|
2023-05-07 20:33:15 +00:00
|
|
|
}
|
|
|
|
else if (OpeningManager.OnOpenFile is not null or "")
|
|
|
|
{
|
|
|
|
if (editorGO == null && OpeningManager.OnOpenFile.IndexOfAny(Path.GetInvalidPathChars()) == -1)
|
2023-01-12 01:42:12 +00:00
|
|
|
{
|
2023-05-07 20:33:15 +00:00
|
|
|
if (File.Exists(OpeningManager.OnOpenFile))
|
|
|
|
{
|
|
|
|
input = OpeningManager.OnOpenFile;
|
|
|
|
fromCmd = true;
|
|
|
|
playOnStart = true;
|
|
|
|
}
|
2023-01-12 01:42:12 +00:00
|
|
|
}
|
2023-05-07 20:33:15 +00:00
|
|
|
OpeningManager.OnOpenFile = null;
|
2023-01-12 01:42:12 +00:00
|
|
|
}
|
|
|
|
|
2022-01-03 22:42:43 +00:00
|
|
|
GameObject Games = new GameObject();
|
|
|
|
Games.name = "Games";
|
|
|
|
|
2022-01-15 22:52:53 +00:00
|
|
|
gameManager.playOnStart = playOnStart;
|
2022-01-03 22:42:43 +00:00
|
|
|
|
|
|
|
gameManager.GamesHolder = Games;
|
|
|
|
gameManager.CircleCursor = Cursor.transform.GetChild(0).GetComponent<CircleCursor>();
|
|
|
|
gameManager.GameCamera = MainCamera.GetComponent<Camera>();
|
|
|
|
gameManager.CursorCam = CursorCamera.GetComponent<Camera>();
|
2022-06-04 03:15:05 +00:00
|
|
|
gameManager.OverlayCamera = OverlayCamera.GetComponent<Camera>();
|
2023-03-11 04:51:22 +00:00
|
|
|
gameManager.StaticCamera = StaticCamera.GetComponent<Camera>();
|
2022-01-03 22:42:43 +00:00
|
|
|
|
2023-05-07 20:33:15 +00:00
|
|
|
if (!debugUI && Profiler != null)
|
2022-01-06 00:11:33 +00:00
|
|
|
{
|
|
|
|
Profiler.GetComponent<DebugUI>().enabled = false;
|
|
|
|
Profiler.transform.GetChild(0).gameObject.SetActive(false);
|
|
|
|
}
|
2022-01-03 22:42:43 +00:00
|
|
|
|
|
|
|
GameObject Conductor = new GameObject();
|
|
|
|
Conductor.name = "Conductor";
|
2022-01-15 22:52:53 +00:00
|
|
|
AudioSource source = Conductor.AddComponent<AudioSource>();
|
2022-01-03 22:42:43 +00:00
|
|
|
Conductor.AddComponent<Conductor>();
|
2022-01-15 22:52:53 +00:00
|
|
|
Conductor.GetComponent<Conductor>().musicSource = source;
|
2022-02-05 04:40:33 +00:00
|
|
|
source.outputAudioMixerGroup = Settings.GetMusicMixer();
|
2022-01-07 11:36:23 +00:00
|
|
|
// Conductor.AddComponent<AudioDspTimeKeeper>();
|
2022-01-06 00:11:33 +00:00
|
|
|
|
2023-03-11 04:51:22 +00:00
|
|
|
GlobalGameManager.GameRenderTexture = gameRenderTexture;
|
|
|
|
GlobalGameManager.OverlayRenderTexture = overlayRenderTexture;
|
|
|
|
GlobalGameManager.ResetGameRenderTexture();
|
|
|
|
|
2023-05-07 20:33:15 +00:00
|
|
|
if (editorGO == null)
|
2022-01-15 22:52:53 +00:00
|
|
|
{
|
2023-01-12 01:42:12 +00:00
|
|
|
OpenCmdRemix(input);
|
|
|
|
Debug.Log(json);
|
|
|
|
gameManager.txt = json;
|
|
|
|
gameManager.ext = ext;
|
2022-01-15 22:52:53 +00:00
|
|
|
gameManager.Init();
|
|
|
|
}
|
2023-05-07 20:33:15 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
editorGO.Init();
|
|
|
|
}
|
2022-01-03 22:42:43 +00:00
|
|
|
}
|
2023-01-12 01:42:12 +00:00
|
|
|
|
|
|
|
public void OpenCmdRemix(string path)
|
|
|
|
{
|
|
|
|
if (path == string.Empty) return;
|
|
|
|
if (!File.Exists(path)) return;
|
|
|
|
byte[] MusicBytes;
|
|
|
|
bool loadedMusic = false;
|
|
|
|
string extension = path.GetExtension();
|
|
|
|
|
|
|
|
using var zipFile = File.Open(path, FileMode.Open);
|
|
|
|
using var archive = new ZipArchive(zipFile, ZipArchiveMode.Read);
|
|
|
|
|
|
|
|
foreach (var entry in archive.Entries)
|
|
|
|
switch (entry.Name)
|
|
|
|
{
|
|
|
|
case "remix.json":
|
|
|
|
{
|
|
|
|
using var stream = entry.Open();
|
|
|
|
using var reader = new StreamReader(stream);
|
|
|
|
json = reader.ReadToEnd();
|
|
|
|
ext = extension;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "song.ogg":
|
|
|
|
{
|
|
|
|
using var stream = entry.Open();
|
|
|
|
using var memoryStream = new MemoryStream();
|
|
|
|
stream.CopyTo(memoryStream);
|
|
|
|
MusicBytes = memoryStream.ToArray();
|
|
|
|
Conductor.instance.musicSource.clip = OggVorbis.VorbisPlugin.ToAudioClip(MusicBytes, "music");
|
|
|
|
loadedMusic = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!loadedMusic)
|
|
|
|
{
|
|
|
|
Conductor.instance.musicSource.clip = null;
|
|
|
|
MusicBytes = null;
|
|
|
|
}
|
|
|
|
}
|
2022-01-03 22:42:43 +00:00
|
|
|
}
|
|
|
|
}
|