Browse Source

Added generation of texture names to load directly

-Added texture names array to generated script. These files all
specifically loaded rather than looping through a particular folder.
-Renamed some functions for better clarity
master
Zach Vinless 8 years ago
parent
commit
3d431cc591
  1. 35
      Assets/Fungus/Scripts/Editor/FungusEditorResources.cs
  2. 18
      Assets/Fungus/Scripts/Editor/FungusEditorResourcesGenerated.cs

35
Assets/Fungus/Scripts/Editor/FungusEditorResources.cs

@ -16,15 +16,30 @@ namespace Fungus.EditorUtils
static FungusEditorResources()
{
LoadResourceAssets();
LoadTexturesFromNames();
}
private static void LoadResourceAssets()
private static void LoadTexturesFromNames()
{
var baseDirectories = AssetDatabase.FindAssets("\"Fungus Editor Resources\"").Select(
guid => AssetDatabase.GUIDToAssetPath(guid)
).ToArray();
foreach (var name in resourceNames)
{
LoadTexturesFromGUIDs(AssetDatabase.FindAssets(name + " t:Texture2D", baseDirectories));
}
}
private static void LoadAllTexturesInFolder()
{
// Get first folder named "Fungus Editor Resources"
var rootGuid = AssetDatabase.FindAssets("\"Fungus Editor Resources\"")[0];
var root = AssetDatabase.GUIDToAssetPath(rootGuid);
var guids = AssetDatabase.FindAssets("t:Texture2D", new [] { root });
LoadTexturesFromGUIDs(AssetDatabase.FindAssets("t:Texture2D", new [] { root }));
}
private static void LoadTexturesFromGUIDs(string[] guids)
{
var paths = guids.Select(guid => AssetDatabase.GUIDToAssetPath(guid)).OrderBy(path => path.ToLower().Contains("/pro/"));
foreach (var path in paths)
@ -41,6 +56,9 @@ namespace Fungus.EditorUtils
[MenuItem("Tools/Fungus/Utilities/Update Editor Resources Script")]
private static void GenerateResourcesScript()
{
textures.Clear();
LoadAllTexturesInFolder();
var guid = AssetDatabase.FindAssets("FungusEditorResources t:MonoScript")[0];
var relativePath = AssetDatabase.GUIDToAssetPath(guid).Replace("FungusEditorResources.cs", "FungusEditorResourcesGenerated.cs");
var absolutePath = Application.dataPath + relativePath.Substring("Assets".Length);
@ -56,6 +74,15 @@ namespace Fungus.EditorUtils
writer.WriteLine("{");
writer.WriteLine("\tinternal static partial class FungusEditorResources");
writer.WriteLine("\t{");
writer.WriteLine("\t\tprivate static readonly string[] resourceNames = new [] {");
foreach (var pair in textures)
{
writer.WriteLine("\t\t\t\"" + pair.Key + "\",");
}
writer.WriteLine("\t\t};");
writer.WriteLine("");
foreach (var pair in textures)
{

18
Assets/Fungus/Scripts/Editor/FungusEditorResourcesGenerated.cs

@ -7,6 +7,24 @@ namespace Fungus.EditorUtils
{
internal static partial class FungusEditorResources
{
private static readonly string[] resourceNames = new [] {
"add",
"add_small",
"delete",
"down",
"duplicate",
"up",
"choice_node_off",
"choice_node_on",
"command_background",
"event_node_off",
"event_node_on",
"play_big",
"play_small",
"process_node_off",
"process_node_on",
};
public static Texture2D Add { get { return GetTexture("add"); } }
public static Texture2D AddSmall { get { return GetTexture("add_small"); } }
public static Texture2D Delete { get { return GetTexture("delete"); } }

Loading…
Cancel
Save