Tanoda
pb_BuiltinResource.cs
Go to the documentation of this file.
1using UnityEngine;
2using System.Collections;
3using System.Collections.Generic;
4
5namespace GILES
6{
17 public static class pb_BuiltinResource
18 {
19 const string REQUIRED_PATH = "Required/";
20
22 public const string mat_UnlitVertexColor = "Material/UnlitVertexColor";
24 public const string mat_UnlitVertexColorWavy = "Material/UnlitVertexColorWavy";
26 public const string mat_Wireframe = "Material/Wireframe";
28 public const string mat_Highlight = "Material/Highlight";
30 public const string mat_HandleOpaque = "Handles/Material/HandleOpaqueMaterial";
32 public const string mat_RotateHandle = "Handles/Material/HandleRotateMaterial";
34 public const string mat_HandleTransparent = "Handles/Material/HandleTransparentMaterial";
36 public const string mat_LightGizmo = "Gizmos/Light";
38 public const string mat_CameraGizmo = "Gizmos/Camera";
40 public const string mat_WeaponPickupGizmo = "Gizmos/WeaponPickup";
42 public const string mat_AmmoPickupGizmo = "Gizmos/AmmoPickup";
44 public const string mat_HealthPickupGizmo = "Gizmos/HealthPickup";
46 public const string mat_PlayerSpawnGizmo = "Gizmos/PlayerSpawn";
48 public const string mat_EnemySpawnGizmo = "Gizmos/EnemySpawn";
49
51 public const string mesh_Cone = "Handles/Mesh/ConeMesh.asset";
52
54 public const string img_WhiteTexture = "Image/White";
55
56 static Dictionary<string, UnityEngine.Object> pool = null;
57
58 static pb_BuiltinResource()
59 {
60 pool = new Dictionary<string, UnityEngine.Object>();
61 }
62
66 public static void EmptyPool()
67 {
68 foreach(KeyValuePair<string, UnityEngine.Object> kvp in pool)
69 pb_ObjectUtility.Destroy(kvp.Value);
70
71 pool.Clear();
72 pool = null;
73 }
74
79 public static Material GetMaterial(string materialPath)
80 {
81 return LoadResource<Material>(materialPath);
82 }
83
87 public static T LoadResource<T>(string path) where T : UnityEngine.Object
88 {
89 Object val = null;
90
91 if(pool.TryGetValue(path, out val))
92 {
93 if( val != null && val is T )
94 return (T) val;
95 }
96
97 T obj = Resources.Load<T>(REQUIRED_PATH + path);
98
99 if(obj == null)
100 {
101 Debug.LogWarning("Built-in resource \"" + (REQUIRED_PATH + path) + "\" not found!");
102 }
103 else
104 {
105 T instance = GameObject.Instantiate(obj);
106 pool.Add(path, instance);
107 return instance;
108 }
109
110 return null;
111 }
112
117 public static T GetResource<T>(string path) where T : UnityEngine.Object
118 {
119 Object val = null;
120
121 if(pool.TryGetValue(path, out val))
122 {
123 if( val != null && val is T )
124 return (T) val;
125 }
126
127 T obj = Resources.Load<T>(REQUIRED_PATH + path);
128
129 if(obj == null)
130 {
131 Debug.LogWarning("Built-in resource \"" + (REQUIRED_PATH + path) + "\" not found!");
132 }
133 else
134 {
135 pool.Add(path, obj);
136 return obj;
137 }
138
139 return null;
140 }
141 }
142}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
UnityEngine.Object Object