Browse Source

Improve InvokeMethod type find and error log

InvokeMethod now explicitily searches all assemblies to find matching fully qualified name.
InvokeMethodEditor now logs error if targeted type cannot be found, rather than null ref error
master
Steve Halliwell 4 years ago
parent
commit
519b6eabbb
  1. 13
      Assets/Fungus/Scripts/Commands/InvokeMethod.cs
  2. 12
      Assets/Fungus/Scripts/Editor/InvokeMethodEditor.cs
  3. 2
      Assets/FungusExamples/FirstPerson/FirstPersonDemo.unity

13
Assets/Fungus/Scripts/Commands/InvokeMethod.cs

@ -8,6 +8,7 @@ using System.Collections.Generic;
using System;
using UnityEngine.Events;
using MarkerMetro.Unity.WinLegacy.Reflection;
using System.Linq;
namespace Fungus
{
@ -403,14 +404,16 @@ namespace Fungus
{
static Dictionary<string, System.Type> types = new Dictionary<string, System.Type>();
public static System.Type GetType(string typeName)
public static System.Type GetType(string AssemblyQualifiedNameTypeName)
{
if (types.ContainsKey(typeName))
return types[typeName];
if (types.ContainsKey(AssemblyQualifiedNameTypeName) && types[AssemblyQualifiedNameTypeName] != null)
return types[AssemblyQualifiedNameTypeName];
types[typeName] = System.Type.GetType(typeName);
types[AssemblyQualifiedNameTypeName] = AppDomain.CurrentDomain.GetAssemblies().
SelectMany(x => x.GetTypes())
.FirstOrDefault(x => x.AssemblyQualifiedName == AssemblyQualifiedNameTypeName);
return types[typeName];
return types[AssemblyQualifiedNameTypeName];
}
}
}

12
Assets/Fungus/Scripts/Editor/InvokeMethodEditor.cs

@ -84,7 +84,17 @@ namespace Fungus.EditorUtils
var saveReturnValueProp = objTarget.FindProperty("saveReturnValue");
var returnValueKeyProp = objTarget.FindProperty("returnValueVariableKey");
var objComponent = gameObject.GetComponent(ReflectionHelper.GetType(component));
var t = ReflectionHelper.GetType(component);
Component objComponent = null;
if (t != null)
{
objComponent = gameObject.GetComponent(t);
}
else
{
Debug.LogError("InvokeMethod command has attempted to locate a type that cannot be found: " + component);
}
var bindingFlags = BindingFlags.Default | BindingFlags.Public | BindingFlags.Instance;
if (!showInheritedProp.boolValue)

2
Assets/FungusExamples/FirstPerson/FirstPersonDemo.unity

@ -795,7 +795,7 @@ MonoBehaviour:
indentLevel: 0
description:
targetObject: {fileID: 1377282257}
targetComponentAssemblyName: Fungus.Examples.LookingAtDoor, Assembly-CSharp, Version=0.0.0.0,
targetComponentAssemblyName: Fungus.Examples.LookingAtDoor, FungusExamples, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
targetComponentFullname: UnityEngine.Component[]
targetComponentText: LookingAtDoor

Loading…
Cancel
Save