mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-23 04:23:04 +00:00
Merge remote-tracking branch 'origin/dev' into feature/ragdoll
This commit is contained in:
commit
a713853140
11 changed files with 6540 additions and 1 deletions
1537
Assets/Resources/font1.fontsettings
Normal file
1537
Assets/Resources/font1.fontsettings
Normal file
File diff suppressed because it is too large
Load diff
8
Assets/Resources/font1.fontsettings.meta
Normal file
8
Assets/Resources/font1.fontsettings.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7c5ccbd714744f3458810b3b22ff28e3
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1537
Assets/Resources/font2.fontsettings
Normal file
1537
Assets/Resources/font2.fontsettings
Normal file
File diff suppressed because it is too large
Load diff
8
Assets/Resources/font2.fontsettings.meta
Normal file
8
Assets/Resources/font2.fontsettings.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dccb1a4f8300b42429e5a620c0b24128
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1537
Assets/Resources/font3.fontsettings
Normal file
1537
Assets/Resources/font3.fontsettings
Normal file
File diff suppressed because it is too large
Load diff
8
Assets/Resources/font3.fontsettings.meta
Normal file
8
Assets/Resources/font3.fontsettings.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 062f46c440806994b8db0dec1efca937
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1537
Assets/Resources/font4.fontsettings
Normal file
1537
Assets/Resources/font4.fontsettings
Normal file
File diff suppressed because it is too large
Load diff
8
Assets/Resources/font4.fontsettings.meta
Normal file
8
Assets/Resources/font4.fontsettings.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9f98aca85edd9284fb38d69f2aab2d12
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -92,6 +92,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
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 ),
|
||||
|
@ -224,7 +225,10 @@ namespace SanAndreasUnity.Behaviours
|
|||
Debug.LogException (ex);
|
||||
}
|
||||
|
||||
|
||||
private static void StepLoadFonts()
|
||||
{
|
||||
FontsImporter.LoadFonts();
|
||||
}
|
||||
private static void StepLoadConfig ()
|
||||
{
|
||||
Config.Load ();
|
||||
|
|
344
Assets/Scripts/Importing/FontsImporter.cs
Normal file
344
Assets/Scripts/Importing/FontsImporter.cs
Normal file
|
@ -0,0 +1,344 @@
|
|||
using SanAndreasUnity.Importing.Conversion;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
public static 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)
|
||||
{
|
||||
//79 O
|
||||
case 79:
|
||||
//81 Q
|
||||
case 81: return 11;
|
||||
|
||||
//77 M
|
||||
case 77:
|
||||
// 87 W
|
||||
case 87: return 12;
|
||||
|
||||
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(true, true);
|
||||
|
||||
return flipped;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Importing/FontsImporter.cs.meta
Normal file
11
Assets/Scripts/Importing/FontsImporter.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f4566b7e12411374c8c0faf6b02dea70
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in a new issue