1
This commit is contained in:
@@ -0,0 +1,193 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using NodeCanvas.Framework;
|
||||
using NodeCanvas.Framework.Internal;
|
||||
using ParadoxNotion;
|
||||
using ParadoxNotion.Design;
|
||||
using ParadoxNotion.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Name("Execute Function", 10)]
|
||||
[Category("✫ Reflected")]
|
||||
[Description("Execute a function on a script and save the return if any.\nIf function is an IEnumerator it will execute as a coroutine.")]
|
||||
public class ExecuteFunction_Multiplatform : ActionTask, IReflectedWrapper
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
protected SerializedMethodInfo method;
|
||||
[SerializeField]
|
||||
protected List<BBObjectParameter> parameters = new List<BBObjectParameter>();
|
||||
[SerializeField, BlackboardOnly]
|
||||
protected BBObjectParameter returnValue;
|
||||
|
||||
private object[] args;
|
||||
private bool routineRunning;
|
||||
private bool[] parameterIsByRef;
|
||||
|
||||
private MethodInfo targetMethod => method;
|
||||
|
||||
public override System.Type agentType {
|
||||
get
|
||||
{
|
||||
if ( targetMethod == null ) { return typeof(Transform); }
|
||||
return targetMethod.IsStatic ? null : targetMethod.RTReflectedOrDeclaredType();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string info {
|
||||
get
|
||||
{
|
||||
if ( method == null ) { return "No Method Selected"; }
|
||||
if ( targetMethod == null ) { return method.AsString().FormatError(); }
|
||||
var returnInfo = targetMethod.ReturnType == typeof(void) || targetMethod.ReturnType == typeof(IEnumerator) ? "" : returnValue.ToString() + " = ";
|
||||
var paramInfo = "";
|
||||
for ( var i = 0; i < parameters.Count; i++ ) { paramInfo += ( i != 0 ? ", " : "" ) + parameters[i].ToString(); }
|
||||
var mInfo = targetMethod.IsStatic ? targetMethod.RTReflectedOrDeclaredType().FriendlyName() : agentInfo;
|
||||
return string.Format("{0}{1}.{2}({3})", returnInfo, mInfo, targetMethod.Name, paramInfo);
|
||||
}
|
||||
}
|
||||
|
||||
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return method; }
|
||||
|
||||
public override void OnValidate(ITaskSystem ownerSystem) {
|
||||
if ( method != null && method.HasChanged() ) { SetMethod(method); }
|
||||
}
|
||||
|
||||
//store the method info on init
|
||||
protected override string OnInit() {
|
||||
if ( method == null ) { return "No Method selected"; }
|
||||
if ( targetMethod == null ) { return string.Format("Missing Method '{0}'", method.AsString()); }
|
||||
|
||||
if ( args == null ) {
|
||||
var methodParameters = targetMethod.GetParameters();
|
||||
args = new object[methodParameters.Length];
|
||||
parameterIsByRef = new bool[methodParameters.Length];
|
||||
for ( var i = 0; i < methodParameters.Length; i++ ) {
|
||||
parameterIsByRef[i] = methodParameters[i].ParameterType.IsByRef;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
//do it by calling delegate or invoking method
|
||||
protected override void OnExecute() {
|
||||
|
||||
for ( var i = 0; i < parameters.Count; i++ ) {
|
||||
args[i] = parameters[i].value;
|
||||
}
|
||||
|
||||
var instance = targetMethod.IsStatic ? null : agent;
|
||||
if ( targetMethod.ReturnType == typeof(IEnumerator) ) {
|
||||
StartCoroutine(InternalCoroutine((IEnumerator)targetMethod.Invoke(instance, args)));
|
||||
return;
|
||||
}
|
||||
|
||||
returnValue.value = targetMethod.Invoke(instance, args);
|
||||
|
||||
for ( var i = 0; i < parameters.Count; i++ ) {
|
||||
if ( parameterIsByRef[i] ) {
|
||||
parameters[i].value = args[i];
|
||||
}
|
||||
}
|
||||
|
||||
EndAction();
|
||||
}
|
||||
|
||||
protected override void OnStop() {
|
||||
routineRunning = false;
|
||||
}
|
||||
|
||||
IEnumerator InternalCoroutine(IEnumerator routine) {
|
||||
routineRunning = true;
|
||||
while ( routineRunning && routine.MoveNext() ) {
|
||||
if ( routineRunning == false ) {
|
||||
yield break;
|
||||
}
|
||||
yield return routine.Current;
|
||||
}
|
||||
|
||||
if ( routineRunning ) {
|
||||
EndAction();
|
||||
}
|
||||
}
|
||||
|
||||
void SetMethod(MethodInfo method) {
|
||||
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
|
||||
if ( method == null ) { return; }
|
||||
this.method = new SerializedMethodInfo(method);
|
||||
this.parameters.Clear();
|
||||
var methodParameters = method.GetParameters();
|
||||
for ( var i = 0; i < methodParameters.Length; i++ ) {
|
||||
var p = methodParameters[i];
|
||||
var pType = p.ParameterType;
|
||||
var newParam = new BBObjectParameter(pType.IsByRef ? pType.GetElementType() : pType) { bb = blackboard };
|
||||
if ( p.IsOptional ) { newParam.value = p.DefaultValue; }
|
||||
parameters.Add(newParam);
|
||||
}
|
||||
|
||||
if ( method.ReturnType != typeof(void) && targetMethod.ReturnType != typeof(IEnumerator) ) {
|
||||
this.returnValue = new BBObjectParameter(method.ReturnType) { bb = blackboard };
|
||||
} else { this.returnValue = null; }
|
||||
}
|
||||
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
///---------------------------------------UNITY EDITOR-------------------------------------------
|
||||
#if UNITY_EDITOR
|
||||
|
||||
protected override void OnTaskInspectorGUI() {
|
||||
|
||||
if ( !Application.isPlaying && GUILayout.Button("Select Method") ) {
|
||||
var menu = new UnityEditor.GenericMenu();
|
||||
if ( agent != null ) {
|
||||
foreach ( var comp in agent.GetComponents(typeof(Component)).Where(c => !c.hideFlags.HasFlag(HideFlags.HideInInspector)) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(object), typeof(object), SetMethod, 10, false, false, menu);
|
||||
}
|
||||
menu.AddSeparator("/");
|
||||
}
|
||||
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
|
||||
menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 10, false, false, menu);
|
||||
if ( typeof(UnityEngine.Component).IsAssignableFrom(t) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 10, false, false, menu);
|
||||
}
|
||||
}
|
||||
menu.ShowAsBrowser("Select Method", this.GetType());
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
|
||||
if ( targetMethod != null ) {
|
||||
GUILayout.BeginVertical("box");
|
||||
UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedOrDeclaredType().FriendlyName());
|
||||
UnityEditor.EditorGUILayout.LabelField("Method", targetMethod.Name);
|
||||
UnityEditor.EditorGUILayout.LabelField("Returns", targetMethod.ReturnType.FriendlyName());
|
||||
UnityEditor.EditorGUILayout.HelpBox(XMLDocs.GetMemberSummary(targetMethod), UnityEditor.MessageType.None);
|
||||
|
||||
if ( targetMethod.ReturnType == typeof(IEnumerator) ) {
|
||||
GUILayout.Label("<b>This will execute as a Coroutine!</b>");
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
var paramNames = targetMethod.GetParameters().Select(p => p.Name.SplitCamelCase()).ToArray();
|
||||
for ( var i = 0; i < paramNames.Length; i++ ) {
|
||||
NodeCanvas.Editor.BBParameterEditor.ParameterField(paramNames[i], parameters[i]);
|
||||
}
|
||||
|
||||
if ( targetMethod.ReturnType != typeof(void) && targetMethod.ReturnType != typeof(IEnumerator) ) {
|
||||
NodeCanvas.Editor.BBParameterEditor.ParameterField("Save Return Value", returnValue, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,118 @@
|
||||
using System.Reflection;
|
||||
using NodeCanvas.Framework;
|
||||
using NodeCanvas.Framework.Internal;
|
||||
using ParadoxNotion;
|
||||
using ParadoxNotion.Design;
|
||||
using ParadoxNotion.Serialization;
|
||||
using ParadoxNotion.Serialization.FullSerializer;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
//previous versions
|
||||
class GetField_0
|
||||
{
|
||||
[SerializeField] public System.Type targetType = null;
|
||||
[SerializeField] public string fieldName = null;
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
[Category("✫ Reflected")]
|
||||
[Description("Get a variable of a script and save it to the blackboard")]
|
||||
[Name("Get Field", 6)]
|
||||
[fsMigrateVersions(typeof(GetField_0))]
|
||||
public class GetField : ActionTask, IReflectedWrapper, IMigratable<GetField_0>
|
||||
{
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
void IMigratable<GetField_0>.Migrate(GetField_0 model) {
|
||||
this.field = new SerializedFieldInfo(model.targetType?.RTGetField(model.fieldName));
|
||||
}
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
[SerializeField]
|
||||
protected SerializedFieldInfo field;
|
||||
[SerializeField, BlackboardOnly]
|
||||
protected BBObjectParameter saveAs;
|
||||
|
||||
private FieldInfo targetField => field;
|
||||
|
||||
public override System.Type agentType {
|
||||
get
|
||||
{
|
||||
if ( targetField == null ) { return typeof(Transform); }
|
||||
return targetField.IsStatic ? null : targetField.RTReflectedOrDeclaredType();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string info {
|
||||
get
|
||||
{
|
||||
if ( field == null ) { return "No Field Selected"; }
|
||||
if ( targetField == null ) { return field.AsString().FormatError(); }
|
||||
var mInfo = targetField.IsStatic ? targetField.RTReflectedOrDeclaredType().FriendlyName() : agentInfo;
|
||||
return string.Format("{0} = {1}.{2}", saveAs.ToString(), mInfo, targetField.Name);
|
||||
}
|
||||
}
|
||||
|
||||
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return field; }
|
||||
|
||||
protected override string OnInit() {
|
||||
if ( field == null ) { return "No Field Selected"; }
|
||||
if ( targetField == null ) { return field.AsString().FormatError(); }
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnExecute() {
|
||||
saveAs.value = targetField.GetValue(targetField.IsStatic ? null : agent);
|
||||
EndAction();
|
||||
}
|
||||
|
||||
void SetTargetField(FieldInfo newField) {
|
||||
if ( newField != null ) {
|
||||
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
|
||||
field = new SerializedFieldInfo(newField);
|
||||
saveAs.SetType(newField.FieldType);
|
||||
}
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
///---------------------------------------UNITY EDITOR-------------------------------------------
|
||||
#if UNITY_EDITOR
|
||||
protected override void OnTaskInspectorGUI() {
|
||||
|
||||
if ( !Application.isPlaying && GUILayout.Button("Select Field") ) {
|
||||
var menu = new UnityEditor.GenericMenu();
|
||||
if ( agent != null ) {
|
||||
foreach ( var comp in agent.GetComponents(typeof(Component)).Where(c => !c.hideFlags.HasFlag(HideFlags.HideInInspector)) ) {
|
||||
menu = EditorUtils.GetInstanceFieldSelectionMenu(comp.GetType(), typeof(object), SetTargetField, menu);
|
||||
}
|
||||
menu.AddSeparator("/");
|
||||
}
|
||||
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
|
||||
menu = EditorUtils.GetStaticFieldSelectionMenu(t, typeof(object), SetTargetField, menu);
|
||||
if ( typeof(Component).IsAssignableFrom(t) ) {
|
||||
menu = EditorUtils.GetInstanceFieldSelectionMenu(t, typeof(object), SetTargetField, menu);
|
||||
}
|
||||
}
|
||||
menu.ShowAsBrowser("Select Field", this.GetType());
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
if ( targetField != null ) {
|
||||
GUILayout.BeginVertical("box");
|
||||
UnityEditor.EditorGUILayout.LabelField("Type", targetField.RTReflectedOrDeclaredType().FriendlyName());
|
||||
UnityEditor.EditorGUILayout.LabelField("Field", targetField.Name);
|
||||
UnityEditor.EditorGUILayout.LabelField("Field Type", targetField.FieldType.FriendlyName());
|
||||
UnityEditor.EditorGUILayout.HelpBox(XMLDocs.GetMemberSummary(targetField), UnityEditor.MessageType.None);
|
||||
GUILayout.EndVertical();
|
||||
NodeCanvas.Editor.BBParameterEditor.ParameterField("Save As", saveAs, true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,108 @@
|
||||
using System.Reflection;
|
||||
using NodeCanvas.Framework;
|
||||
using NodeCanvas.Framework.Internal;
|
||||
using ParadoxNotion;
|
||||
using ParadoxNotion.Design;
|
||||
using ParadoxNotion.Serialization;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Name("Get Property", 8)]
|
||||
[Category("✫ Reflected")]
|
||||
[Description("Get a property of a script and save it to the blackboard")]
|
||||
public class GetProperty_Multiplatform : ActionTask, IReflectedWrapper
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
protected SerializedMethodInfo method;
|
||||
[SerializeField, BlackboardOnly]
|
||||
protected BBObjectParameter returnValue;
|
||||
|
||||
private MethodInfo targetMethod => method;
|
||||
public override System.Type agentType {
|
||||
get
|
||||
{
|
||||
if ( targetMethod == null ) { return typeof(Transform); }
|
||||
return targetMethod.IsStatic ? null : targetMethod.RTReflectedOrDeclaredType();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string info {
|
||||
get
|
||||
{
|
||||
if ( method == null ) { return "No Property Selected"; }
|
||||
if ( targetMethod == null ) { return method.AsString().FormatError(); }
|
||||
var mInfo = targetMethod.IsStatic ? targetMethod.RTReflectedOrDeclaredType().FriendlyName() : agentInfo;
|
||||
return string.Format("{0} = {1}.{2}", returnValue.ToString(), mInfo, targetMethod.Name);
|
||||
}
|
||||
}
|
||||
|
||||
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return method; }
|
||||
|
||||
public override void OnValidate(ITaskSystem ownerSystem) {
|
||||
if ( method != null && method.HasChanged() ) { SetMethod(method); }
|
||||
}
|
||||
|
||||
protected override string OnInit() {
|
||||
if ( method == null ) { return "No Property selected"; }
|
||||
if ( targetMethod == null ) { return string.Format("Missing Property '{0}'", method.AsString()); }
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnExecute() {
|
||||
returnValue.value = targetMethod.Invoke(targetMethod.IsStatic ? null : agent, null);
|
||||
EndAction();
|
||||
}
|
||||
|
||||
void SetMethod(MethodInfo method) {
|
||||
if ( method != null ) {
|
||||
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
|
||||
this.method = new SerializedMethodInfo(method);
|
||||
this.returnValue.SetType(method.ReturnType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
///---------------------------------------UNITY EDITOR-------------------------------------------
|
||||
#if UNITY_EDITOR
|
||||
|
||||
protected override void OnTaskInspectorGUI() {
|
||||
|
||||
if ( !Application.isPlaying && GUILayout.Button("Select Property") ) {
|
||||
var menu = new UnityEditor.GenericMenu();
|
||||
if ( agent != null ) {
|
||||
foreach ( var comp in agent.GetComponents(typeof(Component)).Where(c => !c.hideFlags.HasFlag(HideFlags.HideInInspector)) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(object), typeof(object), SetMethod, 0, true, true, menu);
|
||||
}
|
||||
menu.AddSeparator("/");
|
||||
}
|
||||
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
|
||||
menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 0, true, true, menu);
|
||||
if ( typeof(UnityEngine.Component).IsAssignableFrom(t) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 0, true, true, menu);
|
||||
}
|
||||
}
|
||||
menu.ShowAsBrowser("Select Property", this.GetType());
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
if ( targetMethod != null ) {
|
||||
GUILayout.BeginVertical("box");
|
||||
UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedOrDeclaredType().FriendlyName());
|
||||
UnityEditor.EditorGUILayout.LabelField("Property", targetMethod.Name);
|
||||
UnityEditor.EditorGUILayout.LabelField("Property Type", targetMethod.ReturnType.FriendlyName());
|
||||
UnityEditor.EditorGUILayout.HelpBox(XMLDocs.GetMemberSummary(targetMethod), UnityEditor.MessageType.None);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
NodeCanvas.Editor.BBParameterEditor.ParameterField("Save As", returnValue, true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,139 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using NodeCanvas.Framework;
|
||||
using NodeCanvas.Framework.Internal;
|
||||
using ParadoxNotion;
|
||||
using ParadoxNotion.Design;
|
||||
using ParadoxNotion.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Name("Implemented Action", 9)]
|
||||
[Category("✫ Reflected")]
|
||||
[Description("Calls a function that has signature of 'public Status NAME()' or 'public Status NAME(T)'. You should return Status.Success, Failure or Running within that function.")]
|
||||
public class ImplementedAction_Multiplatform : ActionTask, IReflectedWrapper
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
private SerializedMethodInfo method;
|
||||
[SerializeField]
|
||||
private List<BBObjectParameter> parameters = new List<BBObjectParameter>();
|
||||
|
||||
private Status actionStatus = Status.Resting;
|
||||
private object[] args;
|
||||
|
||||
private MethodInfo targetMethod => method;
|
||||
|
||||
public override System.Type agentType {
|
||||
get
|
||||
{
|
||||
if ( targetMethod == null ) { return typeof(Transform); }
|
||||
return targetMethod.IsStatic ? null : targetMethod.RTReflectedOrDeclaredType();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string info {
|
||||
get
|
||||
{
|
||||
if ( method == null ) { return "No Action Selected"; }
|
||||
if ( targetMethod == null ) { return method.AsString().FormatError(); }
|
||||
var mInfo = targetMethod.IsStatic ? targetMethod.RTReflectedOrDeclaredType().FriendlyName() : agentInfo;
|
||||
return string.Format("[ {0}.{1}({2}) ]", mInfo, targetMethod.Name, parameters.Count == 1 ? parameters[0].ToString() : "");
|
||||
}
|
||||
}
|
||||
|
||||
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return method; }
|
||||
|
||||
public override void OnValidate(ITaskSystem ownerSystem) {
|
||||
if ( method != null && method.HasChanged() ) { SetMethod(method); }
|
||||
}
|
||||
|
||||
protected override string OnInit() {
|
||||
if ( method == null ) { return "No method selected"; }
|
||||
if ( targetMethod == null ) { return string.Format("Missing method '{0}'", method.AsString()); }
|
||||
|
||||
if ( args == null ) {
|
||||
args = new object[targetMethod.GetParameters().Length];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnUpdate() {
|
||||
for ( var i = 0; i < parameters.Count; i++ ) {
|
||||
args[i] = parameters[i].value;
|
||||
}
|
||||
|
||||
actionStatus = (Status)targetMethod.Invoke(targetMethod.IsStatic ? null : agent, args);
|
||||
|
||||
if ( actionStatus == Status.Success ) {
|
||||
EndAction(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( actionStatus == Status.Failure ) {
|
||||
EndAction(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnStop() {
|
||||
actionStatus = Status.Resting;
|
||||
}
|
||||
|
||||
void SetMethod(MethodInfo method) {
|
||||
if ( method != null ) {
|
||||
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
|
||||
this.method = new SerializedMethodInfo(method);
|
||||
this.parameters.Clear();
|
||||
foreach ( var p in method.GetParameters() ) {
|
||||
var newParam = new BBObjectParameter(p.ParameterType) { bb = blackboard };
|
||||
parameters.Add(newParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
///---------------------------------------UNITY EDITOR-------------------------------------------
|
||||
#if UNITY_EDITOR
|
||||
|
||||
protected override void OnTaskInspectorGUI() {
|
||||
|
||||
if ( !Application.isPlaying && GUILayout.Button("Select Action Method") ) {
|
||||
var menu = new UnityEditor.GenericMenu();
|
||||
if ( agent != null ) {
|
||||
foreach ( var comp in agent.GetComponents(typeof(Component)).Where(c => !c.hideFlags.HasFlag(HideFlags.HideInInspector)) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(Status), typeof(object), SetMethod, 1, false, true, menu);
|
||||
}
|
||||
menu.AddSeparator("/");
|
||||
}
|
||||
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
|
||||
menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(Status), typeof(object), SetMethod, 1, false, true, menu);
|
||||
if ( typeof(UnityEngine.Component).IsAssignableFrom(t) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(Status), typeof(object), SetMethod, 1, false, true, menu);
|
||||
}
|
||||
}
|
||||
menu.ShowAsBrowser("Select Action Method", this.GetType());
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
if ( targetMethod != null ) {
|
||||
GUILayout.BeginVertical("box");
|
||||
UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedOrDeclaredType().FriendlyName());
|
||||
UnityEditor.EditorGUILayout.LabelField("Selected Action Method:", targetMethod.Name);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
if ( targetMethod.GetParameters().Length == 1 ) {
|
||||
var paramName = targetMethod.GetParameters()[0].Name.SplitCamelCase();
|
||||
NodeCanvas.Editor.BBParameterEditor.ParameterField(paramName, parameters[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Category("✫ Reflected")]
|
||||
[Description("SendMessage to the agent, optionaly with an argument")]
|
||||
public class SendMessage : ActionTask<Transform>
|
||||
{
|
||||
|
||||
[RequiredField]
|
||||
public BBParameter<string> methodName;
|
||||
|
||||
protected override string info {
|
||||
get { return string.Format("Message {0}()", methodName); }
|
||||
}
|
||||
|
||||
protected override void OnExecute() {
|
||||
agent.SendMessage(methodName.value);
|
||||
EndAction();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Category("✫ Reflected")]
|
||||
[Description("SendMessage to the agent, optionaly with an argument")]
|
||||
public class SendMessage<T> : ActionTask<Transform>
|
||||
{
|
||||
|
||||
[RequiredField]
|
||||
public BBParameter<string> methodName;
|
||||
public BBParameter<T> argument;
|
||||
|
||||
protected override string info {
|
||||
get { return string.Format("Message {0}({1})", methodName, argument.ToString()); }
|
||||
}
|
||||
|
||||
protected override void OnExecute() {
|
||||
if ( argument.isNull ) {
|
||||
agent.SendMessage(methodName.value);
|
||||
} else {
|
||||
agent.SendMessage(methodName.value, argument.value);
|
||||
}
|
||||
|
||||
EndAction();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
using NodeCanvas.Framework;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Category("✫ Reflected")]
|
||||
[Description("Send a Unity message to all game objects with a component of the specified type.\nNotice: This is slow and should not be called per-fame.")]
|
||||
public class SendMessageToType<T> : ActionTask where T : Component
|
||||
{
|
||||
|
||||
[RequiredField]
|
||||
public BBParameter<string> message;
|
||||
[BlackboardOnly]
|
||||
public BBParameter<object> argument;
|
||||
|
||||
protected override string info {
|
||||
get { return string.Format("Message {0}({1}) to all {2}s", message, argument, typeof(T).Name); }
|
||||
}
|
||||
|
||||
protected override void OnExecute() {
|
||||
|
||||
var objects = Object.FindObjectsOfType<T>();
|
||||
if ( objects.Length == 0 ) {
|
||||
EndAction(false);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( var o in objects ) {
|
||||
o.gameObject.SendMessage(message.value, argument.value);
|
||||
}
|
||||
|
||||
EndAction(true);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,119 @@
|
||||
using System.Reflection;
|
||||
using NodeCanvas.Framework;
|
||||
using NodeCanvas.Framework.Internal;
|
||||
using ParadoxNotion;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using ParadoxNotion.Serialization;
|
||||
using ParadoxNotion.Serialization.FullSerializer;
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
//previous versions
|
||||
class SetField_0
|
||||
{
|
||||
[SerializeField] public System.Type targetType = null;
|
||||
[SerializeField] public string fieldName = null;
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
[Category("✫ Reflected")]
|
||||
[Description("Set a variable on a script")]
|
||||
[Name("Set Field", 5)]
|
||||
[fsMigrateVersions(typeof(SetField_0))]
|
||||
public class SetField : ActionTask, IReflectedWrapper, IMigratable<SetField_0>
|
||||
{
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
void IMigratable<SetField_0>.Migrate(SetField_0 model) {
|
||||
this.field = new SerializedFieldInfo(model.targetType?.RTGetField(model.fieldName));
|
||||
}
|
||||
///----------------------------------------------------------------------------------------------
|
||||
|
||||
[SerializeField]
|
||||
protected SerializedFieldInfo field;
|
||||
[SerializeField]
|
||||
protected BBObjectParameter setValue;
|
||||
|
||||
private FieldInfo targetField => field;
|
||||
|
||||
public override System.Type agentType {
|
||||
get
|
||||
{
|
||||
if ( targetField == null ) { return typeof(Transform); }
|
||||
return targetField.IsStatic ? null : targetField.RTReflectedOrDeclaredType();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string info {
|
||||
get
|
||||
{
|
||||
if ( field == null ) { return "No Field Selected"; }
|
||||
if ( targetField == null ) { return field.AsString().FormatError(); }
|
||||
var mInfo = targetField.IsStatic ? targetField.RTReflectedOrDeclaredType().FriendlyName() : agentInfo;
|
||||
return string.Format("{0}.{1} = {2}", mInfo, targetField.Name, setValue);
|
||||
}
|
||||
}
|
||||
|
||||
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return field; }
|
||||
|
||||
protected override string OnInit() {
|
||||
if ( field == null ) { return "No Field Selected"; }
|
||||
if ( targetField == null ) { return field.AsString().FormatError(); }
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnExecute() {
|
||||
targetField.SetValue(targetField.IsStatic ? null : agent, setValue.value);
|
||||
EndAction();
|
||||
}
|
||||
|
||||
void SetTargetField(FieldInfo newField) {
|
||||
if ( newField != null ) {
|
||||
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
|
||||
field = new SerializedFieldInfo(newField);
|
||||
setValue.SetType(newField.FieldType);
|
||||
}
|
||||
}
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
///---------------------------------------UNITY EDITOR-------------------------------------------
|
||||
#if UNITY_EDITOR
|
||||
|
||||
protected override void OnTaskInspectorGUI() {
|
||||
|
||||
if ( !Application.isPlaying && GUILayout.Button("Select Field") ) {
|
||||
var menu = new UnityEditor.GenericMenu();
|
||||
if ( agent != null ) {
|
||||
foreach ( var comp in agent.GetComponents(typeof(Component)).Where(c => !c.hideFlags.HasFlag(HideFlags.HideInInspector)) ) {
|
||||
menu = EditorUtils.GetInstanceFieldSelectionMenu(comp.GetType(), typeof(object), SetTargetField, menu);
|
||||
}
|
||||
menu.AddSeparator("/");
|
||||
}
|
||||
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
|
||||
menu = EditorUtils.GetStaticFieldSelectionMenu(t, typeof(object), SetTargetField, menu);
|
||||
if ( typeof(Component).IsAssignableFrom(t) ) {
|
||||
menu = EditorUtils.GetInstanceFieldSelectionMenu(t, typeof(object), SetTargetField, menu);
|
||||
}
|
||||
}
|
||||
menu.ShowAsBrowser("Select Field", this.GetType());
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
if ( targetField != null ) {
|
||||
GUILayout.BeginVertical("box");
|
||||
UnityEditor.EditorGUILayout.LabelField("Type", targetField.RTReflectedOrDeclaredType().FriendlyName());
|
||||
UnityEditor.EditorGUILayout.LabelField("Field", targetField.Name);
|
||||
UnityEditor.EditorGUILayout.LabelField("Field Type", targetField.FieldType.FriendlyName());
|
||||
UnityEditor.EditorGUILayout.HelpBox(XMLDocs.GetMemberSummary(targetField), UnityEditor.MessageType.None);
|
||||
GUILayout.EndVertical();
|
||||
NodeCanvas.Editor.BBParameterEditor.ParameterField("Set Value", setValue);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,108 @@
|
||||
using System.Reflection;
|
||||
using NodeCanvas.Framework;
|
||||
using NodeCanvas.Framework.Internal;
|
||||
using ParadoxNotion;
|
||||
using ParadoxNotion.Design;
|
||||
using ParadoxNotion.Serialization;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Name("Set Property", 7)]
|
||||
[Category("✫ Reflected")]
|
||||
[Description("Set a property on a script")]
|
||||
public class SetProperty_Multiplatform : ActionTask, IReflectedWrapper
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
protected SerializedMethodInfo method;
|
||||
[SerializeField]
|
||||
protected BBObjectParameter parameter;
|
||||
|
||||
private MethodInfo targetMethod => method;
|
||||
|
||||
public override System.Type agentType {
|
||||
get
|
||||
{
|
||||
if ( targetMethod == null ) { return typeof(Transform); }
|
||||
return targetMethod.IsStatic ? null : targetMethod.RTReflectedOrDeclaredType();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string info {
|
||||
get
|
||||
{
|
||||
if ( method == null ) { return "No Property Selected"; }
|
||||
if ( targetMethod == null ) { return method.AsString().FormatError(); }
|
||||
var mInfo = targetMethod.IsStatic ? targetMethod.RTReflectedOrDeclaredType().FriendlyName() : agentInfo;
|
||||
return string.Format("{0}.{1} = {2}", mInfo, targetMethod.Name, parameter.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return method; }
|
||||
|
||||
public override void OnValidate(ITaskSystem ownerSystem) {
|
||||
if ( method != null && method.HasChanged() ) { SetMethod(method); }
|
||||
}
|
||||
|
||||
protected override string OnInit() {
|
||||
if ( method == null ) { return "No property selected"; }
|
||||
if ( targetMethod == null ) { return string.Format("Missing property '{0}'", method.AsString()); }
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnExecute() {
|
||||
targetMethod.Invoke(targetMethod.IsStatic ? null : agent, ReflectionTools.SingleTempArgsArray(parameter.value));
|
||||
EndAction();
|
||||
}
|
||||
|
||||
void SetMethod(MethodInfo method) {
|
||||
if ( method != null ) {
|
||||
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
|
||||
this.method = new SerializedMethodInfo(method);
|
||||
this.parameter.SetType(method.GetParameters()[0].ParameterType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
///---------------------------------------UNITY EDITOR-------------------------------------------
|
||||
#if UNITY_EDITOR
|
||||
|
||||
protected override void OnTaskInspectorGUI() {
|
||||
|
||||
if ( !Application.isPlaying && GUILayout.Button("Select Property") ) {
|
||||
var menu = new UnityEditor.GenericMenu();
|
||||
if ( agent != null ) {
|
||||
foreach ( var comp in agent.GetComponents(typeof(Component)).Where(c => !c.hideFlags.HasFlag(HideFlags.HideInInspector)) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(void), typeof(object), SetMethod, 1, true, false, menu);
|
||||
}
|
||||
menu.AddSeparator("/");
|
||||
}
|
||||
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
|
||||
menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(void), typeof(object), SetMethod, 1, true, false, menu);
|
||||
if ( typeof(UnityEngine.Component).IsAssignableFrom(t) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(void), typeof(object), SetMethod, 1, true, false, menu);
|
||||
}
|
||||
}
|
||||
menu.ShowAsBrowser("Select Property", this.GetType());
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
if ( targetMethod != null ) {
|
||||
GUILayout.BeginVertical("box");
|
||||
UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedOrDeclaredType().FriendlyName());
|
||||
UnityEditor.EditorGUILayout.LabelField("Property", targetMethod.Name);
|
||||
UnityEditor.EditorGUILayout.LabelField("Set Type", parameter.varType.FriendlyName());
|
||||
UnityEditor.EditorGUILayout.HelpBox(XMLDocs.GetMemberSummary(targetMethod), UnityEditor.MessageType.None);
|
||||
GUILayout.EndVertical();
|
||||
NodeCanvas.Editor.BBParameterEditor.ParameterField("Set Value", parameter);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,188 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using NodeCanvas.Framework;
|
||||
using NodeCanvas.Framework.Internal;
|
||||
using ParadoxNotion;
|
||||
using ParadoxNotion.Design;
|
||||
using ParadoxNotion.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Name("Execute Function (Desktop Only)", 10)]
|
||||
[Category("✫ Reflected/Faster Versions (Desktop Platforms Only)")]
|
||||
[Description("This version works in destop/JIT platform only.\n\nExecute a function on a script, of up to 6 parameters and save the return if any. If function is an IEnumerator it will execute as a coroutine.")]
|
||||
public class ExecuteFunction : ActionTask, IReflectedWrapper
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
protected ReflectedWrapper functionWrapper;
|
||||
|
||||
private bool routineRunning;
|
||||
|
||||
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return functionWrapper?.GetSerializedMethod(); }
|
||||
|
||||
private MethodInfo targetMethod { get { return functionWrapper != null ? functionWrapper.GetMethod() : null; } }
|
||||
|
||||
public override System.Type agentType {
|
||||
get
|
||||
{
|
||||
if ( targetMethod == null ) { return typeof(Transform); }
|
||||
return targetMethod.IsStatic ? null : targetMethod.RTReflectedOrDeclaredType();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string info {
|
||||
get
|
||||
{
|
||||
if ( functionWrapper == null ) { return "No Method Selected"; }
|
||||
if ( targetMethod == null ) { return functionWrapper.AsString().FormatError(); }
|
||||
|
||||
var variables = functionWrapper.GetVariables();
|
||||
var returnInfo = "";
|
||||
var paramInfo = "";
|
||||
if ( targetMethod.ReturnType == typeof(void) ) {
|
||||
for ( var i = 0; i < variables.Length; i++ ) {
|
||||
paramInfo += ( i != 0 ? ", " : "" ) + variables[i].ToString();
|
||||
}
|
||||
} else {
|
||||
returnInfo = targetMethod.ReturnType == typeof(void) || targetMethod.ReturnType == typeof(IEnumerator) || variables[0].isNone ? "" : variables[0] + " = ";
|
||||
for ( var i = 1; i < variables.Length; i++ ) {
|
||||
paramInfo += ( i != 1 ? ", " : "" ) + variables[i].ToString();
|
||||
}
|
||||
}
|
||||
|
||||
var mInfo = targetMethod.IsStatic ? targetMethod.RTReflectedOrDeclaredType().FriendlyName() : agentInfo;
|
||||
return string.Format("{0}{1}.{2}({3})", returnInfo, mInfo, targetMethod.Name, paramInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnValidate(ITaskSystem ownerSystem) {
|
||||
if ( functionWrapper != null && functionWrapper.HasChanged() ) {
|
||||
SetMethod(functionWrapper.GetMethod());
|
||||
}
|
||||
}
|
||||
|
||||
//store the method info on init
|
||||
protected override string OnInit() {
|
||||
if ( functionWrapper == null ) { return "No Method selected"; }
|
||||
if ( targetMethod == null ) { return string.Format("Missing Method '{0}'", functionWrapper.AsString()); }
|
||||
|
||||
try {
|
||||
functionWrapper.Init(targetMethod.IsStatic ? null : agent);
|
||||
return null;
|
||||
}
|
||||
catch { return "ExecuteFunction Error"; }
|
||||
}
|
||||
|
||||
//do it by calling delegate or invoking method
|
||||
protected override void OnExecute() {
|
||||
|
||||
if ( targetMethod == null ) {
|
||||
EndAction(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( targetMethod.ReturnType == typeof(IEnumerator) ) {
|
||||
StartCoroutine(InternalCoroutine((IEnumerator)( (ReflectedFunctionWrapper)functionWrapper ).Call()));
|
||||
return;
|
||||
}
|
||||
|
||||
if ( targetMethod.ReturnType == typeof(void) ) {
|
||||
( (ReflectedActionWrapper)functionWrapper ).Call();
|
||||
} else {
|
||||
( (ReflectedFunctionWrapper)functionWrapper ).Call();
|
||||
}
|
||||
|
||||
EndAction(true);
|
||||
}
|
||||
|
||||
protected override void OnStop() {
|
||||
routineRunning = false;
|
||||
}
|
||||
|
||||
IEnumerator InternalCoroutine(IEnumerator routine) {
|
||||
routineRunning = true;
|
||||
while ( routineRunning && routine.MoveNext() ) {
|
||||
if ( routineRunning == false ) {
|
||||
yield break;
|
||||
}
|
||||
yield return routine.Current;
|
||||
}
|
||||
|
||||
if ( routineRunning ) {
|
||||
EndAction();
|
||||
}
|
||||
}
|
||||
|
||||
void SetMethod(MethodInfo method) {
|
||||
if ( method != null ) {
|
||||
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
|
||||
functionWrapper = ReflectedWrapper.Create(method, blackboard);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
///---------------------------------------UNITY EDITOR-------------------------------------------
|
||||
#if UNITY_EDITOR
|
||||
|
||||
protected override void OnTaskInspectorGUI() {
|
||||
|
||||
if ( !Application.isPlaying && GUILayout.Button("Select Method") ) {
|
||||
var menu = new UnityEditor.GenericMenu();
|
||||
if ( agent != null ) {
|
||||
foreach ( var comp in agent.GetComponents(typeof(Component)).Where(c => !c.hideFlags.HasFlag(HideFlags.HideInInspector)) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(object), typeof(object), SetMethod, 6, false, false, menu);
|
||||
}
|
||||
menu.AddSeparator("/");
|
||||
}
|
||||
|
||||
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
|
||||
menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 6, false, false, menu);
|
||||
if ( typeof(UnityEngine.Component).IsAssignableFrom(t) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 6, false, false, menu);
|
||||
}
|
||||
}
|
||||
menu.ShowAsBrowser("Select Method", this.GetType());
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
var m = targetMethod;
|
||||
if ( m != null ) {
|
||||
GUILayout.BeginVertical("box");
|
||||
UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedOrDeclaredType().FriendlyName());
|
||||
UnityEditor.EditorGUILayout.LabelField("Method", m.Name);
|
||||
UnityEditor.EditorGUILayout.LabelField("Returns", m.ReturnType.FriendlyName());
|
||||
UnityEditor.EditorGUILayout.HelpBox(XMLDocs.GetMemberSummary(targetMethod), UnityEditor.MessageType.None);
|
||||
|
||||
if ( m.ReturnType == typeof(IEnumerator) ) {
|
||||
GUILayout.Label("<b>This will execute as a Coroutine!</b>");
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
var paramNames = m.GetParameters().Select(p => p.Name.SplitCamelCase()).ToArray();
|
||||
var variables = functionWrapper.GetVariables();
|
||||
if ( m.ReturnType == typeof(void) ) {
|
||||
for ( var i = 0; i < paramNames.Length; i++ ) {
|
||||
NodeCanvas.Editor.BBParameterEditor.ParameterField(paramNames[i], variables[i]);
|
||||
}
|
||||
} else {
|
||||
for ( var i = 0; i < paramNames.Length; i++ ) {
|
||||
NodeCanvas.Editor.BBParameterEditor.ParameterField(paramNames[i], variables[i + 1]);
|
||||
}
|
||||
|
||||
if ( m.ReturnType != typeof(IEnumerator) ) {
|
||||
NodeCanvas.Editor.BBParameterEditor.ParameterField("Save Return Value", variables[0], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,118 @@
|
||||
using System.Reflection;
|
||||
using NodeCanvas.Framework;
|
||||
using NodeCanvas.Framework.Internal;
|
||||
using ParadoxNotion;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Name("Get Property (Desktop Only)", 8)]
|
||||
[Category("✫ Reflected/Faster Versions (Desktop Platforms Only)")]
|
||||
[Description("This version works in destop/JIT platform only.\n\nGet a property of a script and save it to the blackboard")]
|
||||
public class GetProperty : ActionTask, IReflectedWrapper
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
protected ReflectedFunctionWrapper functionWrapper;
|
||||
|
||||
private MethodInfo targetMethod { get { return functionWrapper != null ? functionWrapper.GetMethod() : null; } }
|
||||
|
||||
public override System.Type agentType {
|
||||
get
|
||||
{
|
||||
if ( targetMethod == null ) { return typeof(Transform); }
|
||||
return targetMethod.IsStatic ? null : targetMethod.RTReflectedOrDeclaredType();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string info {
|
||||
get
|
||||
{
|
||||
if ( functionWrapper == null ) { return "No Property Selected"; }
|
||||
if ( targetMethod == null ) { return functionWrapper.AsString().FormatError(); }
|
||||
var mInfo = targetMethod.IsStatic ? targetMethod.RTReflectedOrDeclaredType().FriendlyName() : agentInfo;
|
||||
return string.Format("{0} = {1}.{2}", functionWrapper.GetVariables()[0], mInfo, targetMethod.Name);
|
||||
}
|
||||
}
|
||||
|
||||
ParadoxNotion.Serialization.ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return functionWrapper?.GetSerializedMethod(); }
|
||||
|
||||
public override void OnValidate(ITaskSystem ownerSystem) {
|
||||
if ( functionWrapper != null && functionWrapper.HasChanged() ) {
|
||||
SetMethod(functionWrapper.GetMethod());
|
||||
}
|
||||
}
|
||||
|
||||
protected override string OnInit() {
|
||||
if ( targetMethod == null ) { return "Missing Property"; }
|
||||
|
||||
try {
|
||||
functionWrapper.Init(targetMethod.IsStatic ? null : agent);
|
||||
return null;
|
||||
}
|
||||
catch { return "Get Property Error"; }
|
||||
}
|
||||
|
||||
//do it by invoking method
|
||||
protected override void OnExecute() {
|
||||
|
||||
if ( functionWrapper == null ) {
|
||||
EndAction(false);
|
||||
return;
|
||||
}
|
||||
|
||||
functionWrapper.Call();
|
||||
EndAction();
|
||||
}
|
||||
|
||||
void SetMethod(MethodInfo method) {
|
||||
if ( method != null ) {
|
||||
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
|
||||
functionWrapper = ReflectedFunctionWrapper.Create(method, blackboard);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
///---------------------------------------UNITY EDITOR-------------------------------------------
|
||||
#if UNITY_EDITOR
|
||||
|
||||
protected override void OnTaskInspectorGUI() {
|
||||
|
||||
if ( !Application.isPlaying && GUILayout.Button("Select Property") ) {
|
||||
var menu = new UnityEditor.GenericMenu();
|
||||
if ( agent != null ) {
|
||||
foreach ( var comp in agent.GetComponents(typeof(Component)).Where(c => !c.hideFlags.HasFlag(HideFlags.HideInInspector)) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(object), typeof(object), SetMethod, 0, true, true, menu);
|
||||
}
|
||||
menu.AddSeparator("/");
|
||||
}
|
||||
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
|
||||
menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 0, true, true, menu);
|
||||
if ( typeof(UnityEngine.Component).IsAssignableFrom(t) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 0, true, true, menu);
|
||||
}
|
||||
}
|
||||
menu.ShowAsBrowser("Select Property", this.GetType());
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
|
||||
if ( targetMethod != null ) {
|
||||
GUILayout.BeginVertical("box");
|
||||
UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedOrDeclaredType().FriendlyName());
|
||||
UnityEditor.EditorGUILayout.LabelField("Property", targetMethod.Name);
|
||||
UnityEditor.EditorGUILayout.LabelField("Property Type", targetMethod.ReturnType.FriendlyName());
|
||||
UnityEditor.EditorGUILayout.HelpBox(XMLDocs.GetMemberSummary(targetMethod), UnityEditor.MessageType.None);
|
||||
GUILayout.EndVertical();
|
||||
NodeCanvas.Editor.BBParameterEditor.ParameterField("Save As", functionWrapper.GetVariables()[0], true);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,133 @@
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using NodeCanvas.Framework;
|
||||
using NodeCanvas.Framework.Internal;
|
||||
using ParadoxNotion;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Name("Implemented Action (Desktop Only)", 9)]
|
||||
[Category("✫ Reflected/Faster Versions (Desktop Platforms Only)")]
|
||||
[Description("This version works in destop/JIT platform only.\n\nCalls a function that has signature of 'public Status NAME()' or 'public Status NAME(T)'. You should return Status.Success, Failure or Running within that function.")]
|
||||
public class ImplementedAction : ActionTask, IReflectedWrapper
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
protected ReflectedFunctionWrapper functionWrapper;
|
||||
|
||||
private Status actionStatus = Status.Resting;
|
||||
|
||||
private MethodInfo targetMethod { get { return functionWrapper != null ? functionWrapper.GetMethod() : null; } }
|
||||
|
||||
public override System.Type agentType {
|
||||
get
|
||||
{
|
||||
if ( targetMethod == null ) { return typeof(Transform); }
|
||||
return targetMethod.IsStatic ? null : targetMethod.RTReflectedOrDeclaredType();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string info {
|
||||
get
|
||||
{
|
||||
if ( functionWrapper == null ) { return "No Action Selected"; }
|
||||
if ( targetMethod == null ) { return functionWrapper.AsString().FormatError(); }
|
||||
var mInfo = targetMethod.IsStatic ? targetMethod.RTReflectedOrDeclaredType().FriendlyName() : agentInfo;
|
||||
return string.Format("[ {0}.{1}({2}) ]", mInfo, targetMethod.Name, functionWrapper.GetVariables().Length == 2 ? functionWrapper.GetVariables()[1].ToString() : "");
|
||||
}
|
||||
}
|
||||
|
||||
ParadoxNotion.Serialization.ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return functionWrapper?.GetSerializedMethod(); }
|
||||
|
||||
public override void OnValidate(ITaskSystem ownerSystem) {
|
||||
if ( functionWrapper != null && functionWrapper.HasChanged() ) {
|
||||
SetMethod(functionWrapper.GetMethod());
|
||||
}
|
||||
}
|
||||
|
||||
protected override string OnInit() {
|
||||
if ( targetMethod == null ) { return "Missing Method"; }
|
||||
|
||||
try {
|
||||
functionWrapper.Init(targetMethod.IsStatic ? null : agent);
|
||||
return null;
|
||||
}
|
||||
catch { return "ImplementedAction Error"; }
|
||||
}
|
||||
|
||||
protected override void OnUpdate() {
|
||||
if ( functionWrapper == null ) {
|
||||
EndAction(false);
|
||||
return;
|
||||
}
|
||||
|
||||
actionStatus = (Status)functionWrapper.Call();
|
||||
|
||||
if ( actionStatus == Status.Success ) {
|
||||
EndAction(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( actionStatus == Status.Failure ) {
|
||||
EndAction(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnStop() {
|
||||
actionStatus = Status.Resting;
|
||||
}
|
||||
|
||||
void SetMethod(MethodInfo method) {
|
||||
if ( method != null ) {
|
||||
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
|
||||
functionWrapper = ReflectedFunctionWrapper.Create(method, blackboard);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
///---------------------------------------UNITY EDITOR-------------------------------------------
|
||||
#if UNITY_EDITOR
|
||||
|
||||
protected override void OnTaskInspectorGUI() {
|
||||
|
||||
if ( !Application.isPlaying && GUILayout.Button("Select Action Method") ) {
|
||||
var menu = new UnityEditor.GenericMenu();
|
||||
if ( agent != null ) {
|
||||
foreach ( var comp in agent.GetComponents(typeof(Component)).Where(c => !c.hideFlags.HasFlag(HideFlags.HideInInspector)) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(Status), typeof(object), SetMethod, 1, false, true, menu);
|
||||
}
|
||||
menu.AddSeparator("/");
|
||||
}
|
||||
|
||||
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
|
||||
menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(Status), typeof(object), SetMethod, 1, false, true, menu);
|
||||
if ( typeof(UnityEngine.Component).IsAssignableFrom(t) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(Status), typeof(object), SetMethod, 1, false, true, menu);
|
||||
}
|
||||
}
|
||||
menu.ShowAsBrowser("Select Action Method", this.GetType());
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
if ( targetMethod != null ) {
|
||||
GUILayout.BeginVertical("box");
|
||||
UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedOrDeclaredType().FriendlyName());
|
||||
UnityEditor.EditorGUILayout.LabelField("Selected Action Method:", targetMethod.Name);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
if ( targetMethod.GetParameters().Length == 1 ) {
|
||||
var paramName = targetMethod.GetParameters()[0].Name.SplitCamelCase();
|
||||
NodeCanvas.Editor.BBParameterEditor.ParameterField(paramName, functionWrapper.GetVariables()[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,118 @@
|
||||
using System.Reflection;
|
||||
using NodeCanvas.Framework;
|
||||
using NodeCanvas.Framework.Internal;
|
||||
using ParadoxNotion;
|
||||
using ParadoxNotion.Design;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace NodeCanvas.Tasks.Actions
|
||||
{
|
||||
|
||||
[Name("Set Property (Desktop Only)", 7)]
|
||||
[Category("✫ Reflected/Faster Versions (Desktop Platforms Only)")]
|
||||
[Description("This version works in destop/JIT platform only.\n\nSet a property on a script.")]
|
||||
public class SetProperty : ActionTask, IReflectedWrapper
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
protected ReflectedActionWrapper functionWrapper;
|
||||
|
||||
private MethodInfo targetMethod { get { return functionWrapper != null ? functionWrapper.GetMethod() : null; } }
|
||||
|
||||
public override System.Type agentType {
|
||||
get
|
||||
{
|
||||
if ( targetMethod == null ) { return typeof(Transform); }
|
||||
return targetMethod.IsStatic ? null : targetMethod.RTReflectedOrDeclaredType();
|
||||
}
|
||||
}
|
||||
|
||||
protected override string info {
|
||||
get
|
||||
{
|
||||
if ( functionWrapper == null ) { return "No Property Selected"; }
|
||||
if ( targetMethod == null ) { return functionWrapper.AsString().FormatError(); }
|
||||
var mInfo = targetMethod.IsStatic ? targetMethod.RTReflectedOrDeclaredType().FriendlyName() : agentInfo;
|
||||
return string.Format("{0}.{1} = {2}", mInfo, targetMethod.Name, functionWrapper.GetVariables()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
ParadoxNotion.Serialization.ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return functionWrapper?.GetSerializedMethod(); }
|
||||
|
||||
public override void OnValidate(ITaskSystem ownerSystem) {
|
||||
if ( functionWrapper != null && functionWrapper.HasChanged() ) {
|
||||
SetMethod(functionWrapper.GetMethod());
|
||||
}
|
||||
}
|
||||
|
||||
//store the method info on init for performance
|
||||
protected override string OnInit() {
|
||||
if ( targetMethod == null ) { return "Missing Property"; }
|
||||
|
||||
try {
|
||||
functionWrapper.Init(targetMethod.IsStatic ? null : agent);
|
||||
return null;
|
||||
}
|
||||
catch { return "SetProperty Error"; }
|
||||
}
|
||||
|
||||
//do it by invoking method
|
||||
protected override void OnExecute() {
|
||||
|
||||
if ( functionWrapper == null ) {
|
||||
EndAction(false);
|
||||
return;
|
||||
}
|
||||
|
||||
functionWrapper.Call();
|
||||
EndAction();
|
||||
}
|
||||
|
||||
void SetMethod(MethodInfo method) {
|
||||
if ( method != null ) {
|
||||
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
|
||||
functionWrapper = ReflectedActionWrapper.Create(method, blackboard);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///----------------------------------------------------------------------------------------------
|
||||
///---------------------------------------UNITY EDITOR-------------------------------------------
|
||||
#if UNITY_EDITOR
|
||||
|
||||
protected override void OnTaskInspectorGUI() {
|
||||
|
||||
if ( !Application.isPlaying && GUILayout.Button("Select Property") ) {
|
||||
var menu = new UnityEditor.GenericMenu();
|
||||
if ( agent != null ) {
|
||||
foreach ( var comp in agent.GetComponents(typeof(Component)).Where(c => !c.hideFlags.HasFlag(HideFlags.HideInInspector)) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(void), typeof(object), SetMethod, 1, true, false, menu);
|
||||
}
|
||||
menu.AddSeparator("/");
|
||||
}
|
||||
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
|
||||
menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(void), typeof(object), SetMethod, 1, true, false, menu);
|
||||
if ( typeof(UnityEngine.Component).IsAssignableFrom(t) ) {
|
||||
menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(void), typeof(object), SetMethod, 1, true, false, menu);
|
||||
}
|
||||
}
|
||||
menu.ShowAsBrowser("Select Property", this.GetType());
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
if ( targetMethod != null ) {
|
||||
GUILayout.BeginVertical("box");
|
||||
UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedOrDeclaredType().FriendlyName());
|
||||
UnityEditor.EditorGUILayout.LabelField("Property", targetMethod.Name);
|
||||
UnityEditor.EditorGUILayout.LabelField("Set Type", functionWrapper.GetVariables()[0].varType.FriendlyName());
|
||||
UnityEditor.EditorGUILayout.HelpBox(XMLDocs.GetMemberSummary(targetMethod), UnityEditor.MessageType.None);
|
||||
GUILayout.EndVertical();
|
||||
NodeCanvas.Editor.BBParameterEditor.ParameterField("Set Value", functionWrapper.GetVariables()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user