Added font importing

This commit is contained in:
Spider134 2021-01-04 23:29:18 +02:00
parent 93809fd9d3
commit 31f3463097
13 changed files with 7029 additions and 477 deletions

View file

@ -66,12 +66,12 @@ MonoBehaviour:
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 22
m_Font: {fileID: 12800000, guid: 7c5ccbd714744f3458810b3b22ff28e3, type: 2}
m_FontSize: 26
m_FontStyle: 0
m_BestFit: 1
m_MinSize: 0
m_MaxSize: 22
m_MaxSize: 26
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7c5ccbd714744f3458810b3b22ff28e3
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: dccb1a4f8300b42429e5a620c0b24128
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 062f46c440806994b8db0dec1efca937
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9f98aca85edd9284fb38d69f2aab2d12
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

View file

@ -15,436 +15,428 @@ using SanAndreasUnity.Importing.GXT;
namespace SanAndreasUnity.Behaviours
{
public class Loader : MonoBehaviour
{
public static bool HasLoaded { get; private set; }
public static bool IsLoading { get; private set; }
public static bool HasLoaded { get; private set; }
public static bool IsLoading { get; private set; }
public static string LoadingStatus { get; private set; }
public static string LoadingStatus { get; private set; }
private static int m_currentStepIndex = 0;
private static int m_currentStepIndex = 0;
private static float m_totalEstimatedLoadingTime = 0;
private static float m_totalEstimatedLoadingTime = 0;
private static bool m_hasErrors = false;
private static System.Exception m_loadException;
private static bool m_hasErrors = false;
private static System.Exception m_loadException;
private static IArchive[] s_archives;
private static IArchive[] s_archives;
public class LoadingStep
{
public IEnumerator Coroutine { get; private set; }
public System.Action LoadFunction { get; private set; }
public string Description { get; set; }
public bool StopLoadingOnException { get; private set; }
public float TimeElapsed { get; internal set; }
public float EstimatedTime { get; private set; }
public class LoadingStep
{
public IEnumerator Coroutine { get; private set; }
public System.Action LoadFunction { get; private set; }
public string Description { get; set; }
public bool StopLoadingOnException { get; private set; }
public float TimeElapsed { get; internal set; }
public float EstimatedTime { get; private set; }
public LoadingStep (System.Action loadFunction, string description, float estimatedTime = 0f, bool stopLoadingOnException = true)
{
this.LoadFunction = loadFunction;
this.Description = description;
this.EstimatedTime = estimatedTime;
this.StopLoadingOnException = stopLoadingOnException;
}
public LoadingStep(System.Action loadFunction, string description, float estimatedTime = 0f, bool stopLoadingOnException = true)
{
this.LoadFunction = loadFunction;
this.Description = description;
this.EstimatedTime = estimatedTime;
this.StopLoadingOnException = stopLoadingOnException;
}
public LoadingStep (IEnumerator coroutine, string description, float estimatedTime = 0f, bool stopLoadingOnException = true)
{
this.Coroutine = coroutine;
this.Description = description;
this.EstimatedTime = estimatedTime;
this.StopLoadingOnException = stopLoadingOnException;
}
}
public LoadingStep(IEnumerator coroutine, string description, float estimatedTime = 0f, bool stopLoadingOnException = true)
{
this.Coroutine = coroutine;
this.Description = description;
this.EstimatedTime = estimatedTime;
this.StopLoadingOnException = stopLoadingOnException;
}
}
private static List<LoadingStep> m_loadingSteps = new List<LoadingStep> ();
private static List<LoadingStep> m_loadingSteps = new List<LoadingStep>();
public static Texture2D CurrentSplashTex { get; set; }
public static Texture2D SplashTex1 { get; set; }
public static Texture2D SplashTex2 { get; set; }
public static Texture2D CurrentSplashTex { get; set; }
public static Texture2D SplashTex1 { get; set; }
public static Texture2D SplashTex2 { get; set; }
private static bool m_showFileBrowser = false;
private static FileBrowser m_fileBrowser = null;
private static bool m_showFileBrowser = false;
private static FileBrowser m_fileBrowser = null;
public static event System.Action onLoadSpecialTextures = delegate { };
public static event System.Action onLoadSpecialTextures = delegate { };
private void Start()
{
AddLoadingSteps();
StartCoroutine(LoadCoroutine());
}
void Start ()
{
AddLoadingSteps ();
StartCoroutine (LoadCoroutine ());
}
private static void AddLoadingSteps ()
{
LoadingStep[] steps = new LoadingStep[] {
new LoadingStep ( StepLoadConfig, "Loading config", 0.02f ),
new LoadingStep ( StepSelectGTAPath(), "Select path to GTA", 0.0f ),
new LoadingStep ( StepLoadArchives, "Loading archives", 1.7f ),
new LoadingStep ( StepLoadSplashScreen, "Loading splash screen", 0.06f ),
new LoadingStep ( StepSetSplash1, "Set splash 1" ),
new LoadingStep ( StepLoadAudio, "Loading audio" ),
new LoadingStep ( StepLoadCollision, "Loading collision files", 0.9f ),
new LoadingStep ( StepLoadItemInfo, "Loading item info", 2.4f ),
new LoadingStep ( StepLoadHandling, "Loading handling", 0.01f ),
private static void AddLoadingSteps()
{
LoadingStep[] steps = new LoadingStep[] {
new LoadingStep ( StepLoadConfig, "Loading config", 0.02f ),
new LoadingStep ( StepSelectGTAPath(), "Select path to GTA", 0.0f ),
new LoadingStep ( StepLoadArchives, "Loading archives", 1.7f ),
new LoadingStep ( StepLoadSplashScreen, "Loading splash screen", 0.06f ),
new LoadingStep ( StepSetSplash1, "Set splash 1" ),
new LoadingStep ( StepLoadAudio, "Loading audio" ),
new LoadingStep ( StepLoadFonts, "Loading fonts" ),
new LoadingStep ( StepLoadCollision, "Loading collision files", 0.9f ),
new LoadingStep ( StepLoadItemInfo, "Loading item info", 2.4f ),
new LoadingStep ( StepLoadHandling, "Loading handling", 0.01f ),
//new LoadingStep ( () => { throw new System.Exception ("testing error handling"); }, "testing error handling", 0.01f ),
new LoadingStep ( StepLoadAnimGroups, "Loading animation groups", 0.02f ),
new LoadingStep ( StepLoadCarColors, "Loading car colors", 0.04f ),
new LoadingStep ( StepLoadWeaponsData, "Loading weapons data", 0.05f ),
new LoadingStep ( StepSetSplash2, "Set splash 2" ),
new LoadingStep ( StepLoadMap, "Loading map", 2.1f ),
new LoadingStep ( StepLoadSpecialTextures, "Loading special textures", 0.01f ),
new LoadingStep ( StepLoadCarColors, "Loading car colors", 0.04f ),
new LoadingStep ( StepLoadWeaponsData, "Loading weapons data", 0.05f ),
new LoadingStep ( StepSetSplash2, "Set splash 2" ),
new LoadingStep ( StepLoadMap, "Loading map", 2.1f ),
new LoadingStep ( StepLoadSpecialTextures, "Loading special textures", 0.01f ),
// new LoadingStep ( StepLoadGXT, "Loading GXT", 0.15f),
};
for (int i = 0; i < steps.Length; i++) {
AddLoadingStep (steps [i]);
}
if (Cell.Instance != null) {
// add steps for cell
AddLoadingStep( new LoadingStep( () => Cell.Instance.CreateStaticGeometry (), "Creating static geometry", 5.8f ) );
AddLoadingStep( new LoadingStep( () => Cell.Instance.InitStaticGeometry (), "Init static geometry", 0.35f ) );
AddLoadingStep( new LoadingStep( () => Cell.Instance.LoadParkedVehicles (), "Loading parked vehicles", 0.2f ) );
AddLoadingStep( new LoadingStep( () => Cell.Instance.CreateEnexes (), "Creating enexes", 0.1f ) );
AddLoadingStep( new LoadingStep( () => Cell.Instance.AddMapObjectsToDivisions (), "Adding map objects to divisions", 0.85f ) );
AddLoadingStep( new LoadingStep( () => Cell.Instance.LoadWater (), "Loading water", 0.08f ) );
AddLoadingStep( new LoadingStep( () => Cell.Instance.FinalizeLoad (), "Finalize world loading", 0.01f ) );
}
}
private static void AddLoadingStep (LoadingStep step)
{
m_loadingSteps.AddIfNotPresent (step);
}
private static IEnumerator LoadCoroutine ()
{
var stopwatch = System.Diagnostics.Stopwatch.StartNew ();
IsLoading = true;
Debug.Log("Started loading GTA");
// wait a few frames - to "unblock" the program, and to let other scripts initialize before
// registering their loading steps
yield return null;
yield return null;
// calculate total loading time
m_totalEstimatedLoadingTime = m_loadingSteps.Sum( step => step.EstimatedTime );
var stopwatchForSteps = new System.Diagnostics.Stopwatch ();
foreach (var step in m_loadingSteps) {
// update description
LoadingStatus = step.Description;
yield return null;
stopwatchForSteps.Restart ();
var en = step.Coroutine;
if (en != null) {
// this step uses coroutine
bool hasNext = true;
while (hasNext) {
hasNext = false;
try {
hasNext = en.MoveNext ();
} catch (System.Exception ex) {
HandleExceptionDuringLoad (ex);
if (step.StopLoadingOnException) {
yield break;
}
}
// update description
LoadingStatus = step.Description;
yield return null;
}
} else {
// this step uses a function
try {
step.LoadFunction ();
} catch(System.Exception ex) {
HandleExceptionDuringLoad (ex);
if (step.StopLoadingOnException) {
yield break;
}
}
}
// step finished it's work
step.TimeElapsed = stopwatchForSteps.ElapsedMilliseconds;
m_currentStepIndex++;
Debug.LogFormat ("{0} - finished in {1} ms", step.Description, step.TimeElapsed);
}
// all steps finished loading
HasLoaded = true;
IsLoading = false;
Debug.Log("GTA loading finished in " + stopwatch.Elapsed.TotalSeconds + " seconds");
// notify all scripts
F.SendMessageToObjectsOfType<MonoBehaviour>( "OnLoaderFinished" );
}
private static void HandleExceptionDuringLoad (System.Exception ex)
{
m_hasErrors = true;
m_loadException = ex;
Debug.LogException (ex);
}
private static void StepLoadConfig ()
{
Config.Load ();
TextureDictionary.DontLoadTextures = Config.Get<bool>("dontLoadTextures");
}
private static IEnumerator StepSelectGTAPath ()
{
yield return null;
string path = Config.GetPath(Config.const_game_dir);
if (string.IsNullOrEmpty (path)) {
// path is not set
// show file browser to user to select path
m_showFileBrowser = true;
} else {
yield break;
}
// wait until user selects a path
while (m_showFileBrowser) {
yield return null;
}
// refresh path
path = Config.GetPath(Config.const_game_dir);
if (string.IsNullOrEmpty (path)) {
// path was not set
throw new System.Exception ("Path to GTA was not set");
}
}
private static void StepLoadArchives ()
{
string[] archivePaths = Config.GetPaths("archive_paths");
List<IArchive> listArchives = new List<IArchive>();
foreach (var path in archivePaths)
{
if (File.Exists(path))
{
listArchives.Add(ArchiveManager.LoadImageArchive(path));
}
else if (Directory.Exists(path))
{
listArchives.Add(ArchiveManager.LoadLooseArchive(path));
}
else
{
// try to get case-sensitive file path
string caseSensitivePath = ArchiveManager.GetCaseSensitiveFilePath(Path.GetFileName(path));
listArchives.Add(ArchiveManager.LoadImageArchive(caseSensitivePath));
// throw new System.Exception("Archive not found: " + path);
}
}
s_archives = listArchives.FindAll(a => a != null).ToArray();
}
private static void StepLoadSplashScreen ()
{
var txd = TextureDictionary.Load ("LOADSCS");
int index1 = Random.Range (1, 15);
int index2 = Random.Range (1, 15);
SplashTex1 = txd.GetDiffuse ("loadsc" + index1).Texture;
SplashTex2 = txd.GetDiffuse ("loadsc" + index2).Texture;
}
private static void StepSetSplash1 ()
{
CurrentSplashTex = SplashTex1;
}
private static void StepSetSplash2 ()
{
CurrentSplashTex = SplashTex2;
}
private static void StepLoadAudio ()
{
Audio.AudioManager.InitFromLoader ();
}
private static void StepLoadCollision ()
{
int numCollisionFiles = 0;
foreach (var archive in s_archives)
{
foreach (var colFile in archive.GetFileNamesWithExtension(".col"))
{
CollisionFile.Load(colFile);
numCollisionFiles++;
}
}
Debug.Log("Number of collision files " + numCollisionFiles);
}
private static void StepLoadItemInfo ()
{
foreach (var p in Config.GetPaths("item_paths"))
{
string path = ArchiveManager.PathToCaseSensitivePath(p);
var ext = Path.GetExtension(path).ToLower();
switch (ext)
{
case ".dat":
Item.ReadLoadList(path);
break;
case ".ide":
Item.ReadIde(path);
break;
case ".ipl":
Item.ReadIpl(path);
break;
}
}
}
private static void StepLoadHandling ()
{
Handling.Load(ArchiveManager.PathToCaseSensitivePath(Config.GetPath("handling_path")));
}
private static void StepLoadAnimGroups ()
{
foreach (var path in Config.GetPaths("anim_groups_paths"))
{
AnimationGroup.Load(ArchiveManager.PathToCaseSensitivePath(path));
}
// load custom anim groups from resources
TextAsset textAsset = Resources.Load<TextAsset>("Data/auxanimgrp");
AnimationGroup.LoadFromStreamReader( new StreamReader(new MemoryStream(textAsset.bytes)) );
}
private static void StepLoadCarColors ()
{
CarColors.Load(ArchiveManager.PathToCaseSensitivePath(Config.GetPath("car_colors_path")));
}
private static void StepLoadWeaponsData ()
{
Importing.Weapons.WeaponData.Load(ArchiveManager.PathToCaseSensitivePath(Config.GetPath("weapons_path")));
}
private static void StepLoadMap ()
{
MiniMap.Instance.Load ();
}
private static void StepLoadSpecialTextures ()
{
// Load mouse cursor texture
Texture2D mouse = TextureDictionary.Load("fronten_pc").GetDiffuse("mouse",
new TextureLoadParams(){makeNoLongerReadable = false}).Texture;
Texture2D mouseFix = new Texture2D(mouse.width, mouse.height);
for (int x = 0; x < mouse.width; x++)
for (int y = 0; y < mouse.height; y++)
mouseFix.SetPixel(x, mouse.height - y - 1, mouse.GetPixel(x, y));
mouseFix.Apply();
Cursor.SetCursor(mouseFix, Vector2.zero, CursorMode.Auto);
// fist texture
Weapon.FistTexture = TextureDictionary.Load("hud").GetDiffuse("fist").Texture;
onLoadSpecialTextures();
}
private static void StepLoadGXT()
{
GXT.Load();
}
public static float GetProgressPerc ()
{
if (m_currentStepIndex <= 0)
return 0f;
if (m_currentStepIndex >= m_loadingSteps.Count)
return 1f;
float estimatedTimePassed = 0f;
for (int i = 0; i < m_currentStepIndex; i++) {
estimatedTimePassed += m_loadingSteps [i].EstimatedTime;
}
return Mathf.Clamp01 (estimatedTimePassed / m_totalEstimatedLoadingTime);
}
for (int i = 0; i < steps.Length; i++)
{
AddLoadingStep(steps[i]);
}
if (Cell.Instance != null)
{
// add steps for cell
AddLoadingStep(new LoadingStep(() => Cell.Instance.CreateStaticGeometry(), "Creating static geometry", 5.8f));
AddLoadingStep(new LoadingStep(() => Cell.Instance.InitStaticGeometry(), "Init static geometry", 0.35f));
AddLoadingStep(new LoadingStep(() => Cell.Instance.LoadParkedVehicles(), "Loading parked vehicles", 0.2f));
AddLoadingStep(new LoadingStep(() => Cell.Instance.CreateEnexes(), "Creating enexes", 0.1f));
AddLoadingStep(new LoadingStep(() => Cell.Instance.AddMapObjectsToDivisions(), "Adding map objects to divisions", 0.85f));
AddLoadingStep(new LoadingStep(() => Cell.Instance.LoadWater(), "Loading water", 0.08f));
AddLoadingStep(new LoadingStep(() => Cell.Instance.FinalizeLoad(), "Finalize world loading", 0.01f));
}
}
private static void AddLoadingStep(LoadingStep step)
{
m_loadingSteps.AddIfNotPresent(step);
}
private static IEnumerator LoadCoroutine()
{
var stopwatch = System.Diagnostics.Stopwatch.StartNew();
IsLoading = true;
Debug.Log("Started loading GTA");
// wait a few frames - to "unblock" the program, and to let other scripts initialize before
// registering their loading steps
yield return null;
yield return null;
// calculate total loading time
m_totalEstimatedLoadingTime = m_loadingSteps.Sum(step => step.EstimatedTime);
var stopwatchForSteps = new System.Diagnostics.Stopwatch();
foreach (var step in m_loadingSteps)
{
// update description
LoadingStatus = step.Description;
yield return null;
stopwatchForSteps.Restart();
var en = step.Coroutine;
if (en != null)
{
// this step uses coroutine
bool hasNext = true;
while (hasNext)
{
hasNext = false;
try
{
hasNext = en.MoveNext();
}
catch (System.Exception ex)
{
HandleExceptionDuringLoad(ex);
if (step.StopLoadingOnException)
{
yield break;
}
}
// update description
LoadingStatus = step.Description;
yield return null;
}
}
else
{
// this step uses a function
try
{
step.LoadFunction();
}
catch (System.Exception ex)
{
HandleExceptionDuringLoad(ex);
if (step.StopLoadingOnException)
{
yield break;
}
}
}
// step finished it's work
step.TimeElapsed = stopwatchForSteps.ElapsedMilliseconds;
m_currentStepIndex++;
Debug.LogFormat("{0} - finished in {1} ms", step.Description, step.TimeElapsed);
}
// all steps finished loading
HasLoaded = true;
IsLoading = false;
Debug.Log("GTA loading finished in " + stopwatch.Elapsed.TotalSeconds + " seconds");
// notify all scripts
F.SendMessageToObjectsOfType<MonoBehaviour>("OnLoaderFinished");
}
private static void HandleExceptionDuringLoad(System.Exception ex)
{
m_hasErrors = true;
m_loadException = ex;
Debug.LogException(ex);
}
private static void StepLoadConfig()
{
Config.Load();
TextureDictionary.DontLoadTextures = Config.Get<bool>("dontLoadTextures");
}
private static void StepLoadFonts()
{
FontsImporter.LoadFonts();
}
private static IEnumerator StepSelectGTAPath()
{
yield return null;
string path = Config.GetPath(Config.const_game_dir);
if (string.IsNullOrEmpty(path))
{
// path is not set
// show file browser to user to select path
m_showFileBrowser = true;
}
else
{
yield break;
}
// wait until user selects a path
while (m_showFileBrowser)
{
yield return null;
}
// refresh path
path = Config.GetPath(Config.const_game_dir);
if (string.IsNullOrEmpty(path))
{
// path was not set
throw new System.Exception("Path to GTA was not set");
}
}
private static void StepLoadArchives()
{
string[] archivePaths = Config.GetPaths("archive_paths");
List<IArchive> listArchives = new List<IArchive>();
foreach (var path in archivePaths)
{
if (File.Exists(path))
{
listArchives.Add(ArchiveManager.LoadImageArchive(path));
}
else if (Directory.Exists(path))
{
listArchives.Add(ArchiveManager.LoadLooseArchive(path));
}
else
{
// try to get case-sensitive file path
string caseSensitivePath = ArchiveManager.GetCaseSensitiveFilePath(Path.GetFileName(path));
listArchives.Add(ArchiveManager.LoadImageArchive(caseSensitivePath));
// throw new System.Exception("Archive not found: " + path);
}
}
s_archives = listArchives.FindAll(a => a != null).ToArray();
}
private static void StepLoadSplashScreen()
{
var txd = TextureDictionary.Load("LOADSCS");
int index1 = Random.Range(1, 15);
int index2 = Random.Range(1, 15);
SplashTex1 = txd.GetDiffuse("loadsc" + index1).Texture;
SplashTex2 = txd.GetDiffuse("loadsc" + index2).Texture;
}
private static void StepSetSplash1()
{
CurrentSplashTex = SplashTex1;
}
private static void StepSetSplash2()
{
CurrentSplashTex = SplashTex2;
}
private static void StepLoadAudio()
{
Audio.AudioManager.InitFromLoader();
}
private static void StepLoadCollision()
{
int numCollisionFiles = 0;
foreach (var archive in s_archives)
{
foreach (var colFile in archive.GetFileNamesWithExtension(".col"))
{
CollisionFile.Load(colFile);
numCollisionFiles++;
}
}
Debug.Log("Number of collision files " + numCollisionFiles);
}
private static void StepLoadItemInfo()
{
foreach (var p in Config.GetPaths("item_paths"))
{
string path = ArchiveManager.PathToCaseSensitivePath(p);
var ext = Path.GetExtension(path).ToLower();
switch (ext)
{
case ".dat":
Item.ReadLoadList(path);
break;
case ".ide":
Item.ReadIde(path);
break;
case ".ipl":
Item.ReadIpl(path);
break;
}
}
}
private static void StepLoadHandling()
{
Handling.Load(ArchiveManager.PathToCaseSensitivePath(Config.GetPath("handling_path")));
}
private static void StepLoadAnimGroups()
{
foreach (var path in Config.GetPaths("anim_groups_paths"))
{
AnimationGroup.Load(ArchiveManager.PathToCaseSensitivePath(path));
}
// load custom anim groups from resources
TextAsset textAsset = Resources.Load<TextAsset>("Data/auxanimgrp");
AnimationGroup.LoadFromStreamReader(new StreamReader(new MemoryStream(textAsset.bytes)));
}
private static void StepLoadCarColors()
{
CarColors.Load(ArchiveManager.PathToCaseSensitivePath(Config.GetPath("car_colors_path")));
}
private static void StepLoadWeaponsData()
{
Importing.Weapons.WeaponData.Load(ArchiveManager.PathToCaseSensitivePath(Config.GetPath("weapons_path")));
}
private static void StepLoadMap()
{
MiniMap.Instance.Load();
}
private static void StepLoadSpecialTextures()
{
// Load mouse cursor texture
Texture2D mouse = TextureDictionary.Load("fronten_pc").GetDiffuse("mouse",
new TextureLoadParams() { makeNoLongerReadable = false }).Texture;
Texture2D mouseFix = new Texture2D(mouse.width, mouse.height);
for (int x = 0; x < mouse.width; x++)
for (int y = 0; y < mouse.height; y++)
mouseFix.SetPixel(x, mouse.height - y - 1, mouse.GetPixel(x, y));
mouseFix.Apply();
Cursor.SetCursor(mouseFix, Vector2.zero, CursorMode.Auto);
// fist texture
Weapon.FistTexture = TextureDictionary.Load("hud").GetDiffuse("fist").Texture;
onLoadSpecialTextures();
}
private static void StepLoadGXT()
{
GXT.Load();
}
public static float GetProgressPerc()
{
if (m_currentStepIndex <= 0)
return 0f;
if (m_currentStepIndex >= m_loadingSteps.Count)
return 1f;
float estimatedTimePassed = 0f;
for (int i = 0; i < m_currentStepIndex; i++)
{
estimatedTimePassed += m_loadingSteps[i].EstimatedTime;
}
return Mathf.Clamp01(estimatedTimePassed / m_totalEstimatedLoadingTime);
}
private void Update()
{
}
private void OnGUI()
@ -452,94 +444,96 @@ namespace SanAndreasUnity.Behaviours
if (HasLoaded)
return;
// background
// background
if (CurrentSplashTex != null) {
GUIUtils.DrawTextureWithYFlipped (new Rect (0, 0, Screen.width, Screen.height), CurrentSplashTex);
} else {
GUIUtils.DrawRect (new Rect (0, 0, Screen.width, Screen.height), Color.black);
}
if (CurrentSplashTex != null)
{
GUIUtils.DrawTextureWithYFlipped(new Rect(0, 0, Screen.width, Screen.height), CurrentSplashTex);
}
else
{
GUIUtils.DrawRect(new Rect(0, 0, Screen.width, Screen.height), Color.black);
}
// display loading progress
GUILayout.BeginArea(new Rect(10, 5, 400, Screen.height - 5));
GUILayout.BeginArea(new Rect(10, 5, 400, Screen.height - 5));
// current status
GUILayout.Label("<size=25>" + LoadingStatus + "</size>");
// current status
GUILayout.Label("<size=25>" + LoadingStatus + "</size>");
// progress bar
GUILayout.Space (10);
DisplayProgressBar ();
// progress bar
GUILayout.Space(10);
DisplayProgressBar();
// display error
if (m_hasErrors) {
GUILayout.Space (20);
GUILayout.Label("<size=20>" + "The following exception occured during the current step:" + "</size>");
GUILayout.TextArea( m_loadException.ToString () );
GUILayout.Space (30);
if (GUIUtils.ButtonWithCalculatedSize("Exit", 80, 30)) {
GameManager.ExitApplication();
}
GUILayout.Space(5);
}
// display error
if (m_hasErrors)
{
GUILayout.Space(20);
GUILayout.Label("<size=20>" + "The following exception occured during the current step:" + "</size>");
GUILayout.TextArea(m_loadException.ToString());
GUILayout.Space(30);
if (GUIUtils.ButtonWithCalculatedSize("Exit", 80, 30))
{
GameManager.ExitApplication();
}
GUILayout.Space(5);
}
// display all steps
// GUILayout.Space (10);
// DisplayAllSteps ();
// display all steps
// GUILayout.Space (10);
// DisplayAllSteps ();
GUILayout.EndArea();
DisplayFileBrowser ();
DisplayFileBrowser();
}
private static void DisplayAllSteps ()
{
private static void DisplayAllSteps()
{
int i = 0;
foreach (var step in m_loadingSteps)
{
GUILayout.Label(step.Description + (m_currentStepIndex > i ? (" - " + step.TimeElapsed + " ms") : ""));
i++;
}
}
int i=0;
foreach (var step in m_loadingSteps) {
GUILayout.Label( step.Description + (m_currentStepIndex > i ? (" - " + step.TimeElapsed + " ms") : "") );
i++;
}
private static void DisplayProgressBar()
{
float width = 200;
float height = 12;
}
// Rect rect = GUILayoutUtility.GetLastRect ();
// rect.position += new Vector2 (0, rect.height);
// rect.size = new Vector2 (width, height);
private static void DisplayProgressBar ()
{
float width = 200;
float height = 12;
Rect rect = GUILayoutUtility.GetRect(width, height);
rect.width = width;
// Rect rect = GUILayoutUtility.GetLastRect ();
// rect.position += new Vector2 (0, rect.height);
// rect.size = new Vector2 (width, height);
float progressPerc = GetProgressPerc();
GUIUtils.DrawBar(rect, progressPerc, new Vector4(149, 185, 244, 255) / 256.0f, new Vector4(92, 147, 237, 255) / 256.0f, 2f);
}
Rect rect = GUILayoutUtility.GetRect( width, height );
rect.width = width;
private static void DisplayFileBrowser()
{
if (!m_showFileBrowser)
return;
float progressPerc = GetProgressPerc ();
GUIUtils.DrawBar( rect, progressPerc, new Vector4(149, 185, 244, 255) / 256.0f, new Vector4(92, 147, 237, 255) / 256.0f, 2f );
if (null == m_fileBrowser)
{
Rect rect = GUIUtils.GetCenteredRect(FileBrowser.GetRecommendedSize());
}
private static void DisplayFileBrowser ()
{
if (!m_showFileBrowser)
return;
if (null == m_fileBrowser) {
Rect rect = GUIUtils.GetCenteredRect (FileBrowser.GetRecommendedSize());
m_fileBrowser = new FileBrowser(rect, "Select path to GTA", (string path) => {
m_showFileBrowser = false;
Config.SetString (Config.const_game_dir, path);
Config.SaveUserConfigSafe ();
} );
m_fileBrowser.BrowserType = FileBrowserType.Directory;
}
m_fileBrowser.OnGUI ();
}
m_fileBrowser = new FileBrowser(rect, "Select path to GTA", (string path) =>
{
m_showFileBrowser = false;
Config.SetString(Config.const_game_dir, path);
Config.SaveUserConfigSafe();
});
m_fileBrowser.BrowserType = FileBrowserType.Directory;
}
m_fileBrowser.OnGUI();
}
}
}
}

View file

@ -0,0 +1,367 @@
using SanAndreasUnity.Importing.Conversion;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System.Linq;
public class FontsImporter
{
private static List<Font> _loadedFonts = new List<Font>();
public static Font GetFont(int font)
{
return _loadedFonts.ElementAtOrDefault(font);
}
public static void LoadFonts()
{
for (int i = 1; i < 3; i++)
{
Texture2D fontTexture = TextureDictionary.Load("fonts").GetDiffuse($"font{i}", new TextureLoadParams() { makeNoLongerReadable = false }).Texture;
Texture2D flippedTexture = FlipTexture(fontTexture);
Font font = Resources.Load<Font>($"font{i}");
font.material = new Material(Shader.Find("Standard"))
{
mainTexture = flippedTexture
};
CharacterInfo[] characterInfo = new CharacterInfo[94];
float xSpacing = 32;
float ySpacing = 40;
float x = 1;
float y = 480;
float letterSize = 30f;
Rect vertRect = new Rect(0, 10, 10, -10);
//whitespace character
characterInfo[0].index = 32;
characterInfo[0].advance = 7;
characterInfo[0].vert = vertRect;
characterInfo[0].uv = new Rect(0, 0, letterSize / flippedTexture.width, letterSize / flippedTexture.height);
for (int j = 1; j < characterInfo.Length; j++)
{
characterInfo[j].index = 32 + j;
characterInfo[j].advance = GetAdvanceForIndex(i, characterInfo[j].index);
characterInfo[j].vert = vertRect;
if (i == 1)
{
characterInfo[j].uv = new Rect((x * xSpacing) / flippedTexture.width, (y - 4) / flippedTexture.height, letterSize / flippedTexture.width, letterSize / flippedTexture.height);
}
else
{
characterInfo[j].uv = new Rect((x * xSpacing) / flippedTexture.width, (y - 4) / flippedTexture.height, letterSize / flippedTexture.width, (letterSize + 5) / flippedTexture.height);
}
x++;
if (x >= 16)
{
x = 0;
y -= ySpacing;
}
}
font.characterInfo = characterInfo;
_loadedFonts.Add(font);
Font secondaryFont = Resources.Load<Font>($"font{i + 2}");
secondaryFont.material = font.material;
x = 0;
y = 120;
int index = 0;
bool skip = false;
for (int j = 1; j < 38; j++)
{
if (skip)
{
characterInfo[j].index = 96 + index;
}
else
{
characterInfo[j].index = 48 + index;
}
characterInfo[j].advance = GetAdvanceForIndexSecondary(i, characterInfo[j].index);
characterInfo[j].vert = vertRect;
characterInfo[j].uv = new Rect((x * xSpacing) / flippedTexture.width, (y - 7) / flippedTexture.height, letterSize / flippedTexture.width, (letterSize + 7) / flippedTexture.height);
x++;
if (x >= 16)
{
x = 0;
y -= ySpacing;
}
index++;
if (index == 10 && !skip)
{
skip = true;
index = 0;
}
}
index = 0;
x = 10;
y = 120;
//assign capital letters
for (int j = 38; j < 65; j++)
{
characterInfo[j].index = 64 + index;
characterInfo[j].advance = GetAdvanceForIndexSecondary(i, characterInfo[j].index);
characterInfo[j].vert = vertRect;
characterInfo[j].uv = new Rect((x * xSpacing) / flippedTexture.width, (y - 7) / flippedTexture.height, letterSize / flippedTexture.width, (letterSize + 7) / flippedTexture.height);
x++;
if (x >= 16)
{
x = 0;
y -= ySpacing;
}
index++;
}
secondaryFont.characterInfo = characterInfo;
_loadedFonts.Add(secondaryFont);
}
}
private static int GetAdvanceForIndexSecondary(int font, int index)
{
if (font == 1)
{
switch (index)
{
// 73 I
case 73:
// 105 i
case 105: return 3;
// 77 M
case 77:
// 109 m
case 109:
//87 W
case 87:
//119 w
case 119: return 10;
//76 L
case 76:
//108 l
case 108: return 5;
default: return 7;
}
}
else
{
switch (index)
{
// 73 I
case 73:
// 105 i
case 105: return 3;
// 77 M
case 77:
// 109 m
case 109:
//87 W
case 87:
//119 w
case 119: return 10;
//76 L
case 76:
//108 l
case 108: return 7;
default: return 8;
}
}
}
private static int GetAdvanceForIndex(int font, int index)
{
if (font == 1)
{
if (char.IsUpper((char)index))
{
switch (index)
{
//78 N
case 78:
//65 A
case 65: return 8;
// 73 I
case 73:
return 4;
//79 O
case 79:
//81 Q
case 81: return 9;
//77 M
case 77:
// 87 W
case 87: return 10;
//80 P
case 80:
//76 L
case 76:
//70 F
case 70:
// 69 E
case 69:
return 6;
//74 J
//case 106: return 2;
default: return 7;
}
}
else
{
switch (index)
{
// 109 m
case 109:
//119 w
case 119: return 10;
// 105 i
case 105:
//106 j
case 106: return 3;
//102 f
case 102:
//114 r
case 114:
//115 s
case 115:
// 99 c
case 99:
//116 t
case 116:
return 5;
//108 l
case 108: return 4;
default: return 7;
}
}
}
else
{
if (char.IsUpper((char)index))
{
switch (index)
{
////78 N
//case 78:
////65 A
//case 65: return 8;
//// 73 I
//case 73:
// return 4;
//79 O
case 79:
//81 Q
case 81: return 11;
//77 M
case 77:
// 87 W
case 87: return 12;
////80 P
//case 80:
////76 L
//case 76:
////70 F
//case 70:
//// 69 E
//case 69:
// return 6;
//74 J
//case 106: return 2;
default: return 9;
}
}
else
{
switch (index)
{
// 109 m
case 109:
//119 w
case 119: return 7;
//120 x
case 115: return 6;
// 105 i
case 105:
//106 j
case 106:
//102 f
case 102:
//114 r
case 114:
// 99 c
case 99:
//116 t
case 116:
return 4;
//108 l
case 108: return 3;
default: return 5;
}
}
}
}
private static Texture2D FlipTexture(Texture2D original, bool upSideDown = true)
{
Texture2D flipped = new Texture2D(original.width, original.height);
int xN = original.width;
int yN = original.height;
for (int i = 0; i < xN; i++)
{
for (int j = 0; j < yN; j++)
{
if (upSideDown)
{
flipped.SetPixel(j, xN - i - 1, original.GetPixel(j, i));
}
else
{
flipped.SetPixel(xN - i - 1, j, original.GetPixel(i, j));
}
}
}
flipped.Apply();
return flipped;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f4566b7e12411374c8c0faf6b02dea70
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.