Tanoda
InterfaceMaker.cs
Go to the documentation of this file.
1using System;
3using UnityEngine;
4using Object = UnityEngine.Object;
5
7{
8 public static class InterfaceMaker
9 {
10 // These all need to be held as static properties, including textures, to prevent UnloadUnusedAssets from destroying them
11 private static Texture2D _boxBackground;
12 private static Texture2D _winBackground;
13 private static GUISkin _customSkin;
14
15 public static void EatInputInRect(Rect eatRect)
16 {
17 if (eatRect.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)))
18 Input.ResetInputAxes();
19 }
20
21 public static GUISkin CustomSkin
22 {
23 get
24 {
25 if (_customSkin == null)
26 {
27 try
28 {
29 _customSkin = CreateSkin();
30 }
31 catch (Exception ex)
32 {
33 RuntimeUnityEditorCore.Logger.Log(LogLevel.Warning, "Could not load custom GUISkin - " + ex.Message);
34 _customSkin = GUI.skin;
35 }
36 }
37
38 return _customSkin;
39 }
40 }
41
42 private static GUISkin CreateSkin()
43 {
44 var newSkin = Object.Instantiate(GUI.skin);
45 Object.DontDestroyOnLoad(newSkin);
46
47 // Load the custom skin from resources
48 var texData = ResourceUtils.GetEmbeddedResource("guisharp-box.png");
49 _boxBackground = UnityFeatureHelper.LoadTexture(texData);
50 Object.DontDestroyOnLoad(_boxBackground);
51 newSkin.box.onNormal.background = null;
52 newSkin.box.normal.background = _boxBackground;
53 newSkin.box.normal.textColor = Color.white;
54
55 texData = ResourceUtils.GetEmbeddedResource("guisharp-window.png");
56 _winBackground = UnityFeatureHelper.LoadTexture(texData);
57 Object.DontDestroyOnLoad(_winBackground);
58 newSkin.window.onNormal.background = null;
59 newSkin.window.normal.background = _winBackground;
60 newSkin.window.padding = new RectOffset(6, 6, 22, 6);
61 newSkin.window.border = new RectOffset(10, 10, 20, 10);
62 newSkin.window.normal.textColor = Color.white;
63
64 newSkin.button.padding = new RectOffset(4, 4, 3, 3);
65 newSkin.button.normal.textColor = Color.white;
66
67 newSkin.textField.normal.textColor = Color.white;
68
69 newSkin.label.normal.textColor = Color.white;
70
71 return newSkin;
72 }
73 }
74}
UnityEngine.Color Color
Definition: TestScript.cs:32
void Log(LogLevel logLogLevel, object content)
UnityEngine.Object Object