- Home /
Question by
PegasiStudios · Jul 25, 2017 at 07:52 AM ·
.netwindows store appdelegatedefinition
Delegate does not contain a definition for 'CreateDelegate'
file included if text cannot be interpreted[link text][1]
I am trying to export my game to UWP, but every attempt, I get this error
I am using the .NET scripting backend, and have read that issues can arise from it with this sort of thing? Any ideas on how to fix this? Code: using UnityEngine; using System; using System.Collections; using System.Collections.Generic; using System.Reflection;'Delegate' does not contain a definition for 'CreateDelegate'
public class SuperStateMachine : MonoBehaviour {
protected float timeEnteredState;
public class State { public Action DoSuperUpdate = DoNothing; public Action enterState = DoNothing; public Action exitState = DoNothing;
public Enum currentState; }
public State state = new State();
public Enum currentState { get { return state.currentState; } set { if (state.currentState == value) return;
ChangingState(); state.currentState = value; ConfigureCurrentState(); } }
[HideInInspector] public Enum lastState;
void ChangingState() { lastState = state.currentState; timeEnteredState = Time.time; }
void ConfigureCurrentState() { if (state.exitState != null) { state.exitState(); }
//Now we need to configure all of the methods state.DoSuperUpdate = ConfigureDelegate("SuperUpdate", DoNothing); state.enterState = ConfigureDelegate("EnterState", DoNothing); state.exitState = ConfigureDelegate("ExitState", DoNothing); if (state.enterState != null) { state.enterState(); } } Dictionary > cache = new Dictionary >(); T ConfigureDelegate(string methodRoot, T Default) where T : class { Dictionary lookup; if (! cache.TryGetValue(state.currentState, out lookup)) { cache[state.currentState] = lookup = new Dictionary (); } Delegate returnValue; if (!lookup.TryGetValue(methodRoot, out returnValue)) { var mtd = GetType().GetMethod(state.currentState.ToString() + " " + methodRoot, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod); if (mtd != null) { returnValue = Delegate.CreateDelegate(typeof(T), this, mtd); } else { returnValue = Default as Delegate; } lookup[methodRoot] = returnValue; } return returnValue as T; } void SuperUpdate() { EarlyGlobalSuperUpdate(); state.DoSuperUpdate(); LateGlobalSuperUpdate(); } protected void DelegateMethod(string method, object[] parameters) { var mtd = GetType().GetMethod(state.currentState.ToString() + "" + method, BindingFlags.Instance | BindingFlags.NonPublic); if (mtd == null) { mtd = GetType().GetMethod("Global" + " " + method, BindingFlags.Instance | BindingFlags.NonPublic); } mtd.Invoke(this, parameters); } protected virtual void EarlyGlobalSuperUpdate() { } protected virtual void LateGlobalSuperUpdate() { } static void DoNothing() { } } tried multiple times to get code to display properly, but it keeps showing up like this [1]: /storage/temp/98338-superstatemachine.txt
superstatemachine.txt
(3.3 kB)
Comment
Answer by Kumo-Kairo · Jul 25, 2017 at 08:09 AM
Delegate.CreateDelegate()
Is not available on UWP platforms. You'll need to use
methidInfo.CreateDelegate(..)
UWP subset of .NET is tricky and will cause a lot of trouble. Try going with IL2CPP scripting backend, as far as I know it's available on UWP platform now.