Browse Source

Fixed compatibility with Unity 5.0

-Changed generic LoadAssetAtPath to non-generic version
-Added GetTexture wrapper function to avoid key not found errors when
moving things around
master
Zach Vinless 8 years ago
parent
commit
248096bbfe
  1. 21
      Assets/Fungus/Scripts/Editor/FungusEditorResources.cs
  2. 30
      Assets/Fungus/Scripts/Editor/FungusEditorResourcesGenerated.cs

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

@ -3,8 +3,8 @@
using UnityEngine;
using UnityEditor;
using System.IO;
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
@ -24,7 +24,7 @@ namespace Fungus.EditorUtils
// 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 string[] { root });
var guids = AssetDatabase.FindAssets("t:Texture2D", new [] { root });
var paths = guids.Select(guid => AssetDatabase.GUIDToAssetPath(guid)).OrderBy(path => path.ToLower().Contains("/pro/"));
foreach (var path in paths)
@ -33,7 +33,7 @@ namespace Fungus.EditorUtils
{
return;
}
var texture = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
var texture = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D;
textures[texture.name] = texture;
}
}
@ -43,7 +43,7 @@ namespace Fungus.EditorUtils
{
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);//
var absolutePath = Application.dataPath + relativePath.Substring("Assets".Length);
using (var writer = new StreamWriter(absolutePath))
{
@ -63,7 +63,7 @@ namespace Fungus.EditorUtils
var pascalCase = string.Join("", name.Split(new [] { '_' }, StringSplitOptions.RemoveEmptyEntries).Select(
s => s.Substring(0, 1).ToUpper() + s.Substring(1)).ToArray()
);
writer.WriteLine("\t\tpublic static Texture2D " + pascalCase + " { get { return textures[\"" + name + "\"]; } }");
writer.WriteLine("\t\tpublic static Texture2D " + pascalCase + " { get { return GetTexture(\"" + name + "\"); } }");
}
writer.WriteLine("\t}");
@ -72,5 +72,16 @@ namespace Fungus.EditorUtils
AssetDatabase.ImportAsset(relativePath);
}
private static Texture2D GetTexture(string name)
{
Texture2D texture;
if (!textures.TryGetValue(name, out texture))
{
Debug.LogWarning("Texture \"" + name + "\" not found!");
}
return texture;
}
}
}

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

@ -7,20 +7,20 @@ namespace Fungus.EditorUtils
{
internal static partial class FungusEditorResources
{
public static Texture2D Add { get { return textures["add"]; } }
public static Texture2D AddSmall { get { return textures["add_small"]; } }
public static Texture2D Delete { get { return textures["delete"]; } }
public static Texture2D Down { get { return textures["down"]; } }
public static Texture2D Duplicate { get { return textures["duplicate"]; } }
public static Texture2D Up { get { return textures["up"]; } }
public static Texture2D ChoiceNodeOff { get { return textures["choice_node_off"]; } }
public static Texture2D ChoiceNodeOn { get { return textures["choice_node_on"]; } }
public static Texture2D CommandBackground { get { return textures["command_background"]; } }
public static Texture2D EventNodeOff { get { return textures["event_node_off"]; } }
public static Texture2D EventNodeOn { get { return textures["event_node_on"]; } }
public static Texture2D PlayBig { get { return textures["play_big"]; } }
public static Texture2D PlaySmall { get { return textures["play_small"]; } }
public static Texture2D ProcessNodeOff { get { return textures["process_node_off"]; } }
public static Texture2D ProcessNodeOn { get { return textures["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"); } }
public static Texture2D Down { get { return GetTexture("down"); } }
public static Texture2D Duplicate { get { return GetTexture("duplicate"); } }
public static Texture2D Up { get { return GetTexture("up"); } }
public static Texture2D ChoiceNodeOff { get { return GetTexture("choice_node_off"); } }
public static Texture2D ChoiceNodeOn { get { return GetTexture("choice_node_on"); } }
public static Texture2D CommandBackground { get { return GetTexture("command_background"); } }
public static Texture2D EventNodeOff { get { return GetTexture("event_node_off"); } }
public static Texture2D EventNodeOn { get { return GetTexture("event_node_on"); } }
public static Texture2D PlayBig { get { return GetTexture("play_big"); } }
public static Texture2D PlaySmall { get { return GetTexture("play_small"); } }
public static Texture2D ProcessNodeOff { get { return GetTexture("process_node_off"); } }
public static Texture2D ProcessNodeOn { get { return GetTexture("process_node_on"); } }
}
}

Loading…
Cancel
Save