Browse Source

Fix compile errors on Windows Store builds #61

Moved the problematic call to GetCustomAttributes to Editor code.
master
chrisgregan 10 years ago
parent
commit
f30d5d5372
  1. 20
      Assets/Fungus/FungusScript/Editor/EventHandlerEditor.cs
  2. 12
      Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs
  3. 6
      Assets/Fungus/FungusScript/Editor/SequenceEditor.cs
  4. 26
      Assets/Fungus/FungusScript/Scripts/EventHandler.cs

20
Assets/Fungus/FungusScript/Editor/EventHandlerEditor.cs

@ -10,6 +10,24 @@ namespace Fungus
[CustomEditor (typeof(EventHandler), true)]
public class EventHandlerEditor : Editor
{
/**
* Returns the class attribute info for an event handler class.
*/
public static EventHandlerInfoAttribute GetEventHandlerInfo(System.Type eventHandlerType)
{
object[] attributes = eventHandlerType.GetCustomAttributes(typeof(EventHandlerInfoAttribute), false);
foreach (object obj in attributes)
{
EventHandlerInfoAttribute eventHandlerInfoAttr = obj as EventHandlerInfoAttribute;
if (eventHandlerInfoAttr != null)
{
return eventHandlerInfoAttr;
}
}
return null;
}
public virtual void DrawInspectorGUI()
{
// Users should not be able to change the MonoScript for the command using the usual Script field.
@ -31,7 +49,7 @@ namespace Fungus
}
EventHandler t = target as EventHandler;
EventHandlerInfoAttribute info = EventHandler.GetEventHandlerInfo(t.GetType());
EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(t.GetType());
if (info != null &&
info.HelpText.Length > 0)
{

12
Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs

@ -495,10 +495,22 @@ namespace Fungus
if (sequence.eventHandler != null)
{
string handlerSummary = sequence.eventHandler.GetSummary();
if (handlerSummary == "")
{
EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(sequence.eventHandler.GetType());
if (info != null)
{
handlerSummary = info.EventHandlerName;
}
}
nodeName = "(" + handlerSummary + ")\n";
}
nodeName += sequence.sequenceName;
// Make sure node is wide enough to fit the node name text
float width = nodeStyleCopy.CalcSize(new GUIContent(nodeName)).x;
sequence.nodeRect.width = Mathf.Max (sequence.nodeRect.width, width);
GUILayout.Box(nodeName, nodeStyleCopy, GUILayout.Width(sequence.nodeRect.width), GUILayout.Height(sequence.nodeRect.height));
if (sequence.description.Length > 0)
{

6
Assets/Fungus/FungusScript/Editor/SequenceEditor.cs

@ -117,7 +117,7 @@ namespace Fungus
string currentHandlerName = "<None>";
if (currentType != null)
{
EventHandlerInfoAttribute info = EventHandler.GetEventHandlerInfo(currentType);
EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(currentType);
currentHandlerName = info.EventHandlerName;
}
@ -135,7 +135,7 @@ namespace Fungus
// Add event handlers with no category first
foreach (System.Type type in eventHandlerTypes)
{
EventHandlerInfoAttribute info = EventHandler.GetEventHandlerInfo(type);
EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type);
if (info.Category.Length == 0)
{
SetEventHandlerOperation operation = new SetEventHandlerOperation();
@ -149,7 +149,7 @@ namespace Fungus
// Add event handlers with a category afterwards
foreach (System.Type type in eventHandlerTypes)
{
EventHandlerInfoAttribute info = EventHandler.GetEventHandlerInfo(type);
EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type);
if (info.Category.Length > 0)
{
SetEventHandlerOperation operation = new SetEventHandlerOperation();

26
Assets/Fungus/FungusScript/Scripts/EventHandler.cs

@ -36,24 +36,6 @@ namespace Fungus
[HideInInspector]
public Sequence parentSequence;
/**
* Returns the class attribute info for an event handler class.
*/
public static EventHandlerInfoAttribute GetEventHandlerInfo(System.Type eventHandlerType)
{
object[] attributes = eventHandlerType.GetCustomAttributes(typeof(EventHandlerInfoAttribute), false);
foreach (object obj in attributes)
{
EventHandlerInfoAttribute eventHandlerInfoAttr = obj as EventHandlerInfoAttribute;
if (eventHandlerInfoAttr != null)
{
return eventHandlerInfoAttr;
}
}
return null;
}
/**
* The Event Handler should call this method when the event is detected.
*/
@ -75,13 +57,7 @@ namespace Fungus
*/
public virtual string GetSummary()
{
EventHandlerInfoAttribute info = GetEventHandlerInfo(this.GetType());
if (info == null)
{
return "";
}
return info.EventHandlerName;
return "";
}
}
}

Loading…
Cancel
Save