first commit

This commit is contained in:
Chris
2025-03-12 14:22:16 -04:00
commit 0ad0c01249
1999 changed files with 189708 additions and 0 deletions

View File

@@ -0,0 +1,377 @@
using System.Reflection;
using System.Linq;
using NodeCanvas.Framework;
using ParadoxNotion;
using ParadoxNotion.Design;
using ParadoxNotion.Serialization;
using ParadoxNotion.Serialization.FullSerializer;
using UnityEngine;
namespace NodeCanvas.Tasks.Conditions
{
///----------------------------------------------------------------------------------------------
//previous versions
class CheckCSharpEvent_0
{
[SerializeField] public System.Type targetType = null;
[SerializeField] public string eventName = null;
}
class CheckCSharpEvent_0<T>
{
[SerializeField] public System.Type targetType = null;
[SerializeField] public string eventName = null;
}
class CheckCSharpEventValue_0<T>
{
[SerializeField] public System.Type targetType = null;
[SerializeField] public string eventName = null;
}
[fsMigrateTo(typeof(CheckCSharpEvent))]
class CheckStaticCSharpEvent
{
[SerializeField] public System.Type targetType = null;
[SerializeField] public string eventName = null;
}
[fsMigrateTo(typeof(CheckCSharpEvent<>))]
class CheckStaticCSharpEvent<T>
{
[SerializeField] public System.Type targetType = null;
[SerializeField] public string eventName = null;
}
//previous versions
///----------------------------------------------------------------------------------------------
[Category("✫ Reflected/Events")]
[Description("Will subscribe to a public event of Action type and return true when the event is raised.\n(eg public event System.Action [name])")]
[fsMigrateVersions(typeof(CheckCSharpEvent_0))]
public class CheckCSharpEvent : ConditionTask, IReflectedWrapper, IMigratable<CheckCSharpEvent_0>, IMigratable<CheckStaticCSharpEvent>
{
///----------------------------------------------------------------------------------------------
void IMigratable<CheckCSharpEvent_0>.Migrate(CheckCSharpEvent_0 model) {
var info = model.targetType?.RTGetEvent(model.eventName);
if ( info != null ) { this.eventInfo = new SerializedEventInfo(info); }
}
void IMigratable<CheckStaticCSharpEvent>.Migrate(CheckStaticCSharpEvent model) {
var info = model.targetType?.RTGetEvent(model.eventName);
if ( info != null ) { this.eventInfo = new SerializedEventInfo(info); }
}
///----------------------------------------------------------------------------------------------
[SerializeField]
private SerializedEventInfo eventInfo = null;
private System.Delegate handler;
private EventInfo targetEvent => eventInfo;
public override System.Type agentType {
get
{
if ( targetEvent == null ) { return typeof(Transform); }
return targetEvent.IsStatic() ? null : targetEvent.RTReflectedOrDeclaredType();
}
}
protected override string info {
get
{
if ( eventInfo == null ) { return "No Event Selected"; }
if ( targetEvent == null ) { return eventInfo.AsString().FormatError(); }
return string.Format("'{0}' Raised", targetEvent.Name);
}
}
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return eventInfo; }
protected override string OnInit() {
if ( eventInfo == null ) { return "No Event Selected"; }
if ( targetEvent == null ) { return eventInfo.AsString().FormatError(); }
var methodInfo = this.GetType().RTGetMethod("Raised");
this.handler = methodInfo.RTCreateDelegate(targetEvent.EventHandlerType, this);
return null;
}
protected override void OnEnable() {
if ( handler != null ) targetEvent.AddEventHandler(targetEvent.IsStatic() ? null : agent, handler);
}
protected override void OnDisable() {
if ( handler != null ) targetEvent.RemoveEventHandler(targetEvent.IsStatic() ? null : agent, handler);
}
public void Raised() { YieldReturn(true); }
protected override bool OnCheck() { return false; }
void SetTargetEvent(EventInfo info) {
if ( info != null ) {
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
eventInfo = new SerializedEventInfo(info);
}
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnTaskInspectorGUI() {
if ( !Application.isPlaying && GUILayout.Button("Select Event") ) {
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.GetInstanceEventSelectionMenu(comp.GetType(), null, SetTargetEvent, menu);
}
menu.AddSeparator("/");
}
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
menu = EditorUtils.GetStaticEventSelectionMenu(t, null, SetTargetEvent, menu);
if ( typeof(Component).IsAssignableFrom(t) ) {
menu = EditorUtils.GetInstanceEventSelectionMenu(t, null, SetTargetEvent, menu);
}
}
menu.ShowAsBrowser("Select Event", this.GetType());
Event.current.Use();
}
if ( targetEvent != null ) {
GUILayout.BeginVertical("box");
UnityEditor.EditorGUILayout.LabelField("Selected Type", targetEvent.DeclaringType.FriendlyName());
UnityEditor.EditorGUILayout.LabelField("Selected Event", targetEvent.Name);
GUILayout.EndVertical();
}
}
#endif
}
///----------------------------------------------------------------------------------------------
[Category("✫ Reflected/Events")]
[Description("Will subscribe to a public event of Action<T> type and return true when the event is raised.\n(eg public event System.Action<T> [name])")]
[fsMigrateVersions(typeof(CheckCSharpEvent_0<>))]
public class CheckCSharpEvent<T> : ConditionTask, IReflectedWrapper, IMigratable<CheckCSharpEvent_0<T>>, IMigratable<CheckStaticCSharpEvent<T>>
{
///----------------------------------------------------------------------------------------------
void IMigratable<CheckCSharpEvent_0<T>>.Migrate(CheckCSharpEvent_0<T> model) {
this.SetTargetEvent(model.targetType?.RTGetEvent(model.eventName));
}
void IMigratable<CheckStaticCSharpEvent<T>>.Migrate(CheckStaticCSharpEvent<T> model) {
this.SetTargetEvent(model.targetType?.RTGetEvent(model.eventName));
}
///----------------------------------------------------------------------------------------------
[SerializeField]
private SerializedEventInfo eventInfo = null;
[SerializeField, BlackboardOnly]
private BBParameter<T> saveAs = null;
private System.Delegate handler;
private EventInfo targetEvent => eventInfo;
public override System.Type agentType {
get
{
if ( targetEvent == null ) { return typeof(Transform); }
return targetEvent.IsStatic() ? null : targetEvent.RTReflectedOrDeclaredType();
}
}
protected override string info {
get
{
if ( eventInfo == null ) { return "No Event Selected"; }
if ( targetEvent == null ) { return eventInfo.AsString().FormatError(); }
return string.Format("'{0}' Raised", targetEvent.Name);
}
}
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return eventInfo; }
protected override string OnInit() {
if ( eventInfo == null ) { return "No Event Selected"; }
if ( targetEvent == null ) { return eventInfo.AsString().FormatError(); }
var methodInfo = this.GetType().RTGetMethod("Raised");
handler = methodInfo.RTCreateDelegate(targetEvent.EventHandlerType, this);
return null;
}
protected override void OnEnable() {
if ( handler != null ) targetEvent.AddEventHandler(targetEvent.IsStatic() ? null : agent, handler);
}
protected override void OnDisable() {
if ( handler != null ) targetEvent.RemoveEventHandler(targetEvent.IsStatic() ? null : agent, handler);
}
public void Raised(T eventValue) {
saveAs.value = eventValue;
YieldReturn(true);
}
protected override bool OnCheck() { return false; }
void SetTargetEvent(EventInfo info) {
if ( info != null ) {
eventInfo = new SerializedEventInfo(info);
}
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnTaskInspectorGUI() {
if ( !Application.isPlaying && GUILayout.Button("Select Event") ) {
var menu = new UnityEditor.GenericMenu();
if ( agent != null ) {
foreach ( var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags == 0) ) {
menu = EditorUtils.GetInstanceEventSelectionMenu(comp.GetType(), typeof(T), SetTargetEvent, menu);
}
menu.AddSeparator("/");
}
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
menu = EditorUtils.GetStaticEventSelectionMenu(t, typeof(T), SetTargetEvent, menu);
if ( typeof(Component).IsAssignableFrom(t) ) {
menu = EditorUtils.GetInstanceEventSelectionMenu(t, typeof(T), SetTargetEvent, menu);
}
}
menu.ShowAsBrowser("Select Event", this.GetType());
Event.current.Use();
}
if ( targetEvent != null ) {
GUILayout.BeginVertical("box");
UnityEditor.EditorGUILayout.LabelField("Selected Type", targetEvent.DeclaringType.FriendlyName());
UnityEditor.EditorGUILayout.LabelField("Selected Event", targetEvent.Name);
GUILayout.EndVertical();
NodeCanvas.Editor.BBParameterEditor.ParameterField("Save Value As", saveAs, true);
}
}
#endif
}
///----------------------------------------------------------------------------------------------
[Category("✫ Reflected/Events")]
[Description("Will subscribe to a public event of Action<T> type and return true when the event is raised and it's value is equal to provided value as well.\n(eg public event System.Action<T> [name])")]
[fsMigrateVersions(typeof(CheckCSharpEventValue_0<>))]
public class CheckCSharpEventValue<T> : ConditionTask, IReflectedWrapper, IMigratable<CheckCSharpEventValue_0<T>>
{
///----------------------------------------------------------------------------------------------
void IMigratable<CheckCSharpEventValue_0<T>>.Migrate(CheckCSharpEventValue_0<T> model) {
this.SetTargetEvent(model.targetType?.RTGetEvent(model.eventName));
}
///----------------------------------------------------------------------------------------------
[SerializeField]
private SerializedEventInfo eventInfo = null;
[SerializeField]
private BBParameter<T> checkValue = null;
private System.Delegate handler;
private EventInfo targetEvent => eventInfo;
public override System.Type agentType {
get
{
if ( targetEvent == null ) { return typeof(Transform); }
return targetEvent.IsStatic() ? null : targetEvent.RTReflectedOrDeclaredType();
}
}
protected override string info {
get
{
if ( eventInfo == null ) { return "No Event Selected"; }
if ( targetEvent == null ) { return eventInfo.AsString().FormatError(); }
return string.Format("'{0}' Raised && Value == {1}", targetEvent.Name, checkValue);
}
}
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return eventInfo; }
protected override string OnInit() {
if ( eventInfo == null ) { return "No Event Selected"; }
if ( targetEvent == null ) { return eventInfo.AsString().FormatError(); }
var methodInfo = this.GetType().RTGetMethod("Raised");
handler = methodInfo.RTCreateDelegate(targetEvent.EventHandlerType, this);
return null;
}
protected override void OnEnable() {
if ( handler != null ) targetEvent.AddEventHandler(targetEvent.IsStatic() ? null : agent, handler);
}
protected override void OnDisable() {
if ( handler != null ) targetEvent.RemoveEventHandler(targetEvent.IsStatic() ? null : agent, handler);
}
public void Raised(T eventValue) {
if ( ObjectUtils.AnyEquals(checkValue.value, eventValue) ) {
YieldReturn(true);
}
}
protected override bool OnCheck() { return false; }
void SetTargetEvent(EventInfo info) {
if ( info != null ) {
eventInfo = new SerializedEventInfo(info);
}
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnTaskInspectorGUI() {
if ( !Application.isPlaying && GUILayout.Button("Select Event") ) {
var menu = new UnityEditor.GenericMenu();
if ( agent != null ) {
foreach ( var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags == 0) ) {
menu = EditorUtils.GetInstanceEventSelectionMenu(comp.GetType(), typeof(T), SetTargetEvent, menu);
}
menu.AddSeparator("/");
}
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
menu = EditorUtils.GetStaticEventSelectionMenu(t, typeof(T), SetTargetEvent, menu);
if ( typeof(Component).IsAssignableFrom(t) ) {
menu = EditorUtils.GetInstanceEventSelectionMenu(t, typeof(T), SetTargetEvent, menu);
}
}
menu.ShowAsBrowser("Select Event", this.GetType());
Event.current.Use();
}
if ( targetEvent != null ) {
GUILayout.BeginVertical("box");
UnityEditor.EditorGUILayout.LabelField("Selected Type", targetEvent.DeclaringType.FriendlyName());
UnityEditor.EditorGUILayout.LabelField("Selected Event", targetEvent.Name);
GUILayout.EndVertical();
NodeCanvas.Editor.BBParameterEditor.ParameterField("Check Value", checkValue);
}
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: e6c7c29b64d410d49a2f2b6285d02827
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Tasks/Conditions/ScriptControl/CheckCSharpEvent.cs
uploadId: 704937

View File

@@ -0,0 +1,132 @@
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.Conditions
{
//previous versions
class CheckField_0
{
[SerializeField] public BBParameter checkValue = null;
[SerializeField] public System.Type targetType = null;
[SerializeField] public string fieldName = null;
}
///----------------------------------------------------------------------------------------------
[Name("Check Field", 8)]
[Category("✫ Reflected")]
[Description("Check a field on a script and return if it's equal or not to a value")]
[fsMigrateVersions(typeof(CheckField_0))]
public class CheckField : ConditionTask, IReflectedWrapper, IMigratable<CheckField_0>
{
///----------------------------------------------------------------------------------------------
void IMigratable<CheckField_0>.Migrate(CheckField_0 model) {
try { this.field = new SerializedFieldInfo(model.targetType?.RTGetField(model.fieldName)); }
finally { this.checkValue = new BBObjectParameter(model.checkValue); }
}
///----------------------------------------------------------------------------------------------
[SerializeField] protected BBObjectParameter checkValue;
[SerializeField] protected CompareMethod comparison;
[SerializeField] protected SerializedFieldInfo field;
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}{3}", mInfo, targetField.Name, OperationTools.GetCompareString(comparison), checkValue);
}
}
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return field; }
//store the field info on agent set for performance
protected override string OnInit() {
if ( field == null ) { return "No Field Selected"; }
if ( targetField == null ) { return field.AsString().FormatError(); }
return null;
}
//do it by invoking field
protected override bool OnCheck() {
if ( checkValue.varType == typeof(float) ) {
return OperationTools.Compare((float)targetField.GetValue(agent), (float)checkValue.value, comparison, 0.05f);
}
if ( checkValue.varType == typeof(int) ) {
return OperationTools.Compare((int)targetField.GetValue(agent), (int)checkValue.value, comparison);
}
return ObjectUtils.AnyEquals(targetField.GetValue(agent), checkValue.value);
}
void SetTargetField(FieldInfo newField) {
if ( newField != null ) {
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
field = new SerializedFieldInfo(newField);
checkValue.SetType(newField.FieldType);
comparison = CompareMethod.EqualTo;
}
}
///----------------------------------------------------------------------------------------------
///---------------------------------------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();
GUI.enabled = checkValue.varType == typeof(float) || checkValue.varType == typeof(int);
comparison = (CompareMethod)UnityEditor.EditorGUILayout.EnumPopup("Comparison", comparison);
GUI.enabled = true;
NodeCanvas.Editor.BBParameterEditor.ParameterField("Value", checkValue);
}
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 7637195a7276ebf40bf185672b76251e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Tasks/Conditions/ScriptControl/CheckField.cs
uploadId: 704937

View File

@@ -0,0 +1,172 @@
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.Conditions
{
[Name("Check Function", 10)]
[Category("✫ Reflected")]
[Description("Call a function on a component and return whether or not the return value is equal to the check value")]
public class CheckFunction_Multiplatform : ConditionTask, IReflectedWrapper
{
[SerializeField]
protected SerializedMethodInfo method;
[SerializeField]
protected List<BBObjectParameter> parameters = new List<BBObjectParameter>();
[SerializeField]
protected CompareMethod comparison;
[SerializeField, BlackboardOnly]
protected BBObjectParameter checkValue;
private object[] args;
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 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}", mInfo, targetMethod.Name, paramInfo, OperationTools.GetCompareString(comparison) + checkValue);
}
}
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return method; }
public override void OnValidate(ITaskSystem ownerSystem) {
if ( method != null && method.HasChanged() ) { SetMethod(method); }
}
//store the method info on agent set for performance
protected override string OnInit() {
if ( method == null ) { return "No Method Selected"; }
if ( targetMethod == null ) { return method.AsString(); }
if ( args == null ) {
var methodParameters = targetMethod.GetParameters();
args = new object[methodParameters.Length];
parameterIsByRef = new bool[methodParameters.Length];
for ( var i = 0; i < parameters.Count; i++ ) {
parameterIsByRef[i] = methodParameters[i].ParameterType.IsByRef;
}
}
return null;
}
//do it by invoking method
protected override bool OnCheck() {
for ( var i = 0; i < parameters.Count; i++ ) {
args[i] = parameters[i].value;
}
var instance = targetMethod.IsStatic ? null : agent;
bool result;
if ( checkValue.varType == typeof(float) ) {
result = OperationTools.Compare((float)targetMethod.Invoke(instance, args), (float)checkValue.value, comparison, 0.05f);
} else if ( checkValue.varType == typeof(int) ) {
result = OperationTools.Compare((int)targetMethod.Invoke(instance, args), (int)checkValue.value, comparison);
} else {
result = ObjectUtils.AnyEquals(targetMethod.Invoke(instance, args), checkValue.value);
}
for ( var i = 0; i < parameters.Count; i++ ) {
if ( parameterIsByRef[i] ) {
parameters[i].value = args[i];
}
}
return result;
}
void SetMethod(MethodInfo method) {
if ( method == null ) {
return;
}
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
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);
}
this.checkValue = new BBObjectParameter(method.ReturnType) { bb = blackboard };
comparison = CompareMethod.EqualTo;
}
///----------------------------------------------------------------------------------------------
///---------------------------------------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, true, menu);
}
menu.AddSeparator("/");
}
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 10, false, true, menu);
if ( typeof(UnityEngine.Component).IsAssignableFrom(t) ) {
menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 10, false, true, 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.HelpBox(XMLDocs.GetMemberSummary(targetMethod), UnityEditor.MessageType.None);
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]);
}
GUI.enabled = checkValue.varType == typeof(float) || checkValue.varType == typeof(int);
comparison = (CompareMethod)UnityEditor.EditorGUILayout.EnumPopup("Comparison", comparison);
GUI.enabled = true;
NodeCanvas.Editor.BBParameterEditor.ParameterField("Check Value", checkValue);
}
}
#endif
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: 2689248082fe6624ead37351e25d4d81
timeCreated: 1430482904
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Tasks/Conditions/ScriptControl/CheckFunction_Multiplatform.cs
uploadId: 704937

View File

@@ -0,0 +1,121 @@
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.Conditions
{
[Name("Check Property", 9)]
[Category("✫ Reflected")]
[Description("Check a property on a script and return if it's equal or not to the check value")]
public class CheckProperty_Multiplatform : ConditionTask, IReflectedWrapper
{
[SerializeField]
protected SerializedMethodInfo method;
[SerializeField]
protected BBObjectParameter checkValue;
[SerializeField]
protected CompareMethod comparison;
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, OperationTools.GetCompareString(comparison) + checkValue.ToString());
}
}
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return method; }
public override void OnValidate(ITaskSystem ownerSystem) {
if ( method != null && method.HasChanged() ) { SetMethod(method); }
}
//store the method info on agent set for performance
protected override string OnInit() {
if ( method == null ) { return "No Property Selected"; }
if ( targetMethod == null ) { return method.AsString(); }
return null;
}
//do it by invoking method
protected override bool OnCheck() {
var instance = targetMethod.IsStatic ? null : agent;
if ( checkValue.varType == typeof(float) ) {
return OperationTools.Compare((float)targetMethod.Invoke(instance, null), (float)checkValue.value, comparison, 0.05f);
}
if ( checkValue.varType == typeof(int) ) {
return OperationTools.Compare((int)targetMethod.Invoke(instance, null), (int)checkValue.value, comparison);
}
return ObjectUtils.AnyEquals(targetMethod.Invoke(instance, null), checkValue.value);
}
void SetMethod(MethodInfo method) {
if ( method != null ) {
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
this.method = new SerializedMethodInfo(method);
this.checkValue.SetType(method.ReturnType);
comparison = CompareMethod.EqualTo;
}
}
///----------------------------------------------------------------------------------------------
///---------------------------------------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.HelpBox(XMLDocs.GetMemberSummary(targetMethod), UnityEditor.MessageType.None);
GUILayout.EndVertical();
GUI.enabled = checkValue.varType == typeof(float) || checkValue.varType == typeof(int);
comparison = (CompareMethod)UnityEditor.EditorGUILayout.EnumPopup("Comparison", comparison);
GUI.enabled = true;
NodeCanvas.Editor.BBParameterEditor.ParameterField("Value", checkValue);
}
}
#endif
}
}

View File

@@ -0,0 +1,19 @@
fileFormatVersion: 2
guid: eaff4f1c6d295bc4aa9684e6f323f562
timeCreated: 1430482605
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Tasks/Conditions/ScriptControl/CheckProperty_Multiplatform.cs
uploadId: 704937

View File

@@ -0,0 +1,361 @@
using System.Reflection;
using System.Linq;
using NodeCanvas.Framework;
using ParadoxNotion;
using ParadoxNotion.Design;
using UnityEngine;
using UnityEngine.Events;
using ParadoxNotion.Serialization;
using ParadoxNotion.Serialization.FullSerializer;
namespace NodeCanvas.Tasks.Conditions
{
///----------------------------------------------------------------------------------------------
//previous versions
class CheckUnityEvent_0
{
[SerializeField] public System.Type targetType = null;
[SerializeField] public string eventName = null;
}
class CheckUnityEvent_0<T>
{
[SerializeField] public System.Type targetType = null;
[SerializeField] public string eventName = null;
}
class CheckUnityEventValue_0<T>
{
[SerializeField] public System.Type targetType = null;
[SerializeField] public string eventName = null;
}
///----------------------------------------------------------------------------------------------
[Category("✫ Reflected/Events")]
[Description("Will subscribe to a public UnityEvent and return true when that event is raised.")]
[fsMigrateVersions(typeof(CheckUnityEvent_0))]
public class CheckUnityEvent : ConditionTask, IReflectedWrapper, IMigratable<CheckUnityEvent_0>
{
///----------------------------------------------------------------------------------------------
void IMigratable<CheckUnityEvent_0>.Migrate(CheckUnityEvent_0 model) {
this._eventInfo = new SerializedUnityEventInfo(model.targetType?.RTGetField(model.eventName));
}
///----------------------------------------------------------------------------------------------
[SerializeField] private SerializedUnityEventInfo _eventInfo = null;
private MemberInfo targetMember => _eventInfo != null ? _eventInfo.AsMemberInfo() : null;
private bool isStatic => _eventInfo != null ? _eventInfo.isStatic : false;
private System.Type eventType => _eventInfo != null ? _eventInfo.memberType : null;
private FieldInfo targetEventField => _eventInfo;
private PropertyInfo targetEventProp => _eventInfo;
private UnityEvent unityEvent;
public override System.Type agentType {
get
{
if ( targetMember == null ) { return typeof(Transform); }
return isStatic ? null : targetMember.RTReflectedOrDeclaredType();
}
}
protected override string info {
get
{
if ( _eventInfo == null ) { return "No Event Selected"; }
if ( targetMember == null ) { return _eventInfo.AsString().FormatError(); }
return string.Format("'{0}' Raised", targetMember.Name);
}
}
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return _eventInfo; }
protected override string OnInit() {
if ( _eventInfo == null ) { return "No Event Selected"; }
if ( targetMember == null ) { return _eventInfo.AsString(); }
if ( targetEventField != null ) { unityEvent = (UnityEvent)targetEventField.GetValue(agent); }
if ( targetEventProp != null ) { unityEvent = (UnityEvent)targetEventProp.GetValue(agent); }
return null;
}
protected override void OnEnable() {
if ( unityEvent != null ) { unityEvent.AddListener(Raised); }
}
protected override void OnDisable() {
if ( unityEvent != null ) { unityEvent.RemoveListener(Raised); }
}
public void Raised() { YieldReturn(true); }
protected override bool OnCheck() { return false; }
void SetTargetEvent(MemberInfo newMember) {
if ( newMember != null ) {
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
_eventInfo = new SerializedUnityEventInfo(newMember);
}
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnTaskInspectorGUI() {
if ( !Application.isPlaying && GUILayout.Button("Select Event") ) {
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(UnityEvent), SetTargetEvent, menu);
menu = EditorUtils.GetInstancePropertySelectionMenu(comp.GetType(), typeof(UnityEvent), SetTargetEvent, true, false, menu);
}
menu.AddSeparator("/");
}
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
menu = EditorUtils.GetStaticFieldSelectionMenu(t, typeof(UnityEvent), SetTargetEvent, menu);
menu = EditorUtils.GetStaticPropertySelectionMenu(t, typeof(UnityEvent), SetTargetEvent, true, false, menu);
if ( typeof(Component).IsAssignableFrom(t) ) {
menu = EditorUtils.GetInstanceFieldSelectionMenu(t, typeof(UnityEvent), SetTargetEvent, menu);
menu = EditorUtils.GetInstancePropertySelectionMenu(t, typeof(UnityEvent), SetTargetEvent, true, false, menu);
}
}
menu.ShowAsBrowser("Select Event", this.GetType());
Event.current.Use();
}
if ( targetMember != null ) {
GUILayout.BeginVertical("box");
UnityEditor.EditorGUILayout.LabelField("Type", targetMember.RTReflectedOrDeclaredType().FriendlyName());
UnityEditor.EditorGUILayout.LabelField("Event", targetMember.Name);
UnityEditor.EditorGUILayout.LabelField("Event Type", eventType.FriendlyName());
GUILayout.EndVertical();
}
}
#endif
}
///----------------------------------------------------------------------------------------------
[Category("✫ Reflected/Events")]
[Description("Will subscribe to a public UnityEvent<T> and return true when that event is raised.")]
[fsMigrateVersions(typeof(CheckUnityEvent_0<>))]
public class CheckUnityEvent<T> : ConditionTask, IReflectedWrapper, IMigratable<CheckUnityEvent_0<T>>
{
///----------------------------------------------------------------------------------------------
void IMigratable<CheckUnityEvent_0<T>>.Migrate(CheckUnityEvent_0<T> model) {
this._eventInfo = new SerializedUnityEventInfo(model.targetType?.RTGetField(model.eventName));
}
///----------------------------------------------------------------------------------------------
[SerializeField]
private SerializedUnityEventInfo _eventInfo = null;
[SerializeField, BlackboardOnly]
private BBParameter<T> saveAs = null;
private MemberInfo targetMember => _eventInfo != null ? _eventInfo.AsMemberInfo() : null;
private bool isStatic => _eventInfo != null ? _eventInfo.isStatic : false;
private System.Type eventType => _eventInfo != null ? _eventInfo.memberType : null;
private FieldInfo targetEventField => _eventInfo;
private PropertyInfo targetEventProp => _eventInfo;
private UnityEvent<T> unityEvent;
public override System.Type agentType {
get
{
if ( targetMember == null ) { return typeof(Transform); }
return isStatic ? null : targetMember.RTReflectedOrDeclaredType();
}
}
protected override string info {
get
{
if ( _eventInfo == null ) { return "No Event Selected"; }
if ( targetMember == null ) { return _eventInfo.AsString().FormatError(); }
return string.Format("'{0}' Raised", targetMember.Name);
}
}
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return _eventInfo; }
protected override string OnInit() {
if ( _eventInfo == null ) { return "No Event Selected"; }
if ( targetMember == null ) { return _eventInfo.AsString(); }
if ( targetEventField != null ) { unityEvent = (UnityEvent<T>)targetEventField.GetValue(agent); }
if ( targetEventProp != null ) { unityEvent = (UnityEvent<T>)targetEventProp.GetValue(agent); }
return null;
}
protected override void OnEnable() {
if ( unityEvent != null ) { unityEvent.AddListener(Raised); }
}
protected override void OnDisable() {
if ( unityEvent != null ) { unityEvent.RemoveListener(Raised); }
}
public void Raised(T eventValue) {
saveAs.value = eventValue;
YieldReturn(true);
}
protected override bool OnCheck() { return false; }
void SetTargetEvent(MemberInfo newMember) {
if ( newMember != null ) { _eventInfo = new SerializedUnityEventInfo(newMember); }
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnTaskInspectorGUI() {
if ( !Application.isPlaying && GUILayout.Button("Select Event") ) {
var menu = new UnityEditor.GenericMenu();
if ( agent != null ) {
foreach ( var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags == 0) ) {
menu = EditorUtils.GetInstanceFieldSelectionMenu(comp.GetType(), typeof(UnityEvent<T>), SetTargetEvent, menu);
menu = EditorUtils.GetInstancePropertySelectionMenu(comp.GetType(), typeof(UnityEvent<T>), SetTargetEvent, true, false, menu);
}
menu.AddSeparator("/");
}
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
menu = EditorUtils.GetStaticFieldSelectionMenu(t, typeof(UnityEvent<T>), SetTargetEvent, menu);
menu = EditorUtils.GetStaticPropertySelectionMenu(t, typeof(UnityEvent<T>), SetTargetEvent, true, false, menu);
if ( typeof(Component).IsAssignableFrom(t) ) {
menu = EditorUtils.GetInstanceFieldSelectionMenu(t, typeof(UnityEvent<T>), SetTargetEvent, menu);
menu = EditorUtils.GetInstancePropertySelectionMenu(t, typeof(UnityEvent<T>), SetTargetEvent, true, false, menu);
}
}
menu.ShowAsBrowser("Select Event", this.GetType());
Event.current.Use();
}
if ( targetMember != null ) {
GUILayout.BeginVertical("box");
UnityEditor.EditorGUILayout.LabelField("Type", targetMember.RTReflectedOrDeclaredType().FriendlyName());
UnityEditor.EditorGUILayout.LabelField("Event", targetMember.Name);
UnityEditor.EditorGUILayout.LabelField("Event Type", eventType.FriendlyName());
GUILayout.EndVertical();
NodeCanvas.Editor.BBParameterEditor.ParameterField("Save Value As", saveAs, true);
}
}
#endif
}
///----------------------------------------------------------------------------------------------
[Category("✫ Reflected/Events")]
[Description("Will subscribe to a public UnityEvent<T> and return true when that event is raised and it's value is equal to provided value as well.")]
[fsMigrateVersions(typeof(CheckUnityEventValue_0<>))]
public class CheckUnityEventValue<T> : ConditionTask, IReflectedWrapper, IMigratable<CheckUnityEventValue_0<T>>
{
///----------------------------------------------------------------------------------------------
void IMigratable<CheckUnityEventValue_0<T>>.Migrate(CheckUnityEventValue_0<T> model) {
this._eventInfo = new SerializedUnityEventInfo(model.targetType?.RTGetField(model.eventName));
}
///----------------------------------------------------------------------------------------------
[SerializeField] private SerializedUnityEventInfo _eventInfo = null;
[SerializeField] private BBParameter<T> checkValue = null;
private MemberInfo targetMember => _eventInfo != null ? _eventInfo.AsMemberInfo() : null;
private bool isStatic => _eventInfo != null ? _eventInfo.isStatic : false;
private System.Type eventType => _eventInfo != null ? _eventInfo.memberType : null;
private FieldInfo targetEventField => _eventInfo;
private PropertyInfo targetEventProp => _eventInfo;
private UnityEvent<T> unityEvent;
public override System.Type agentType {
get
{
if ( targetMember == null ) { return typeof(Transform); }
return isStatic ? null : targetMember.RTReflectedOrDeclaredType();
}
}
protected override string info {
get
{
if ( _eventInfo == null ) { return "No Event Selected"; }
if ( targetMember == null ) { return _eventInfo.AsString().FormatError(); }
return string.Format("'{0}' Raised && Value == {1}", targetMember.Name, checkValue);
}
}
ISerializedReflectedInfo IReflectedWrapper.GetSerializedInfo() { return _eventInfo; }
protected override string OnInit() {
if ( _eventInfo == null ) { return "No Event Selected"; }
if ( targetEventField == null ) { return _eventInfo.AsString(); }
if ( targetEventField != null ) { unityEvent = (UnityEvent<T>)targetEventField.GetValue(agent); }
if ( targetEventProp != null ) { unityEvent = (UnityEvent<T>)targetEventProp.GetValue(agent); }
return null;
}
protected override void OnEnable() {
if ( unityEvent != null ) { unityEvent.AddListener(Raised); }
}
protected override void OnDisable() {
if ( unityEvent != null ) { unityEvent.RemoveListener(Raised); }
}
public void Raised(T eventValue) {
if ( ObjectUtils.AnyEquals(checkValue.value, eventValue) ) {
YieldReturn(true);
}
}
protected override bool OnCheck() { return false; }
void SetTargetEvent(MemberInfo newMember) {
if ( newMember != null ) { _eventInfo = new SerializedUnityEventInfo(newMember); }
}
///----------------------------------------------------------------------------------------------
///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
protected override void OnTaskInspectorGUI() {
if ( !Application.isPlaying && GUILayout.Button("Select Event") ) {
var menu = new UnityEditor.GenericMenu();
if ( agent != null ) {
foreach ( var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags == 0) ) {
menu = EditorUtils.GetInstanceFieldSelectionMenu(comp.GetType(), typeof(UnityEvent<T>), SetTargetEvent, menu);
menu = EditorUtils.GetInstancePropertySelectionMenu(comp.GetType(), typeof(UnityEvent<T>), SetTargetEvent, true, false, menu);
}
menu.AddSeparator("/");
}
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
menu = EditorUtils.GetStaticFieldSelectionMenu(t, typeof(UnityEvent<T>), SetTargetEvent, menu);
menu = EditorUtils.GetStaticPropertySelectionMenu(t, typeof(UnityEvent<T>), SetTargetEvent, true, false, menu);
if ( typeof(Component).IsAssignableFrom(t) ) {
menu = EditorUtils.GetInstanceFieldSelectionMenu(t, typeof(UnityEvent<T>), SetTargetEvent, menu);
menu = EditorUtils.GetInstancePropertySelectionMenu(t, typeof(UnityEvent<T>), SetTargetEvent, true, false, menu);
}
}
menu.ShowAsBrowser("Select Event", this.GetType());
Event.current.Use();
}
if ( targetMember != null ) {
GUILayout.BeginVertical("box");
UnityEditor.EditorGUILayout.LabelField("Type", targetMember.RTReflectedOrDeclaredType().FriendlyName());
UnityEditor.EditorGUILayout.LabelField("Event", targetMember.Name);
UnityEditor.EditorGUILayout.LabelField("Event Type", eventType.FriendlyName());
GUILayout.EndVertical();
NodeCanvas.Editor.BBParameterEditor.ParameterField("Check Value", checkValue);
}
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: fe46d20c88d90154b83bcaac3641ad85
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Tasks/Conditions/ScriptControl/CheckUnityEvent.cs
uploadId: 704937

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 0b84dc3952e158249809c4e92b3fbfa6
folderAsset: yes
timeCreated: 1521293700
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,141 @@
using System.Linq;
using System.Reflection;
using NodeCanvas.Framework;
using NodeCanvas.Framework.Internal;
using ParadoxNotion;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.Tasks.Conditions
{
[Name("Check Function (Desktop Only)")]
[Category("✫ Reflected/Faster Versions (Desktop Platforms Only)")]
[Description("This version works in destop/JIT platform only.\n\nCall a function with none or up to 6 parameters on a component and return whether or not the return value is equal to the check value")]
public class CheckFunction : ConditionTask
{
[SerializeField]
protected ReflectedFunctionWrapper functionWrapper;
[SerializeField]
protected BBParameter checkValue;
[SerializeField]
protected CompareMethod comparison;
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 paramInfo = "";
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}", mInfo, targetMethod.Name, paramInfo, OperationTools.GetCompareString(comparison) + checkValue);
}
}
public override void OnValidate(ITaskSystem ownerSystem) {
if ( functionWrapper != null && functionWrapper.HasChanged() ) {
SetMethod(functionWrapper.GetMethod());
}
}
//store the method info on agent set for performance
protected override string OnInit() {
if ( targetMethod == null ) { return "Missing Method"; }
try {
functionWrapper.Init(targetMethod.IsStatic ? null : agent);
return null;
}
catch { return "CheckFunction Error"; }
}
//do it by invoking method
protected override bool OnCheck() {
if ( functionWrapper == null ) {
return true;
}
if ( checkValue.varType == typeof(float) ) {
return OperationTools.Compare((float)functionWrapper.Call(), (float)checkValue.value, comparison, 0.05f);
}
if ( checkValue.varType == typeof(int) ) {
return OperationTools.Compare((int)functionWrapper.Call(), (int)checkValue.value, comparison);
}
return ObjectUtils.AnyEquals(functionWrapper.Call(), checkValue.value);
}
void SetMethod(MethodInfo method) {
if ( method != null ) {
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
functionWrapper = ReflectedFunctionWrapper.Create(method, blackboard);
checkValue = BBParameter.CreateInstance(method.ReturnType, blackboard);
comparison = CompareMethod.EqualTo;
}
}
///----------------------------------------------------------------------------------------------
///---------------------------------------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, true, menu);
}
menu.AddSeparator("/");
}
foreach ( var t in TypePrefs.GetPreferedTypesList(typeof(object)) ) {
menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 6, false, true, menu);
if ( typeof(UnityEngine.Component).IsAssignableFrom(t) ) {
menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 6, false, true, 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);
GUILayout.EndVertical();
var paramNames = targetMethod.GetParameters().Select(p => p.Name.SplitCamelCase()).ToArray();
var variables = functionWrapper.GetVariables();
for ( var i = 0; i < paramNames.Length; i++ ) {
NodeCanvas.Editor.BBParameterEditor.ParameterField(paramNames[i], variables[i + 1]);
}
GUI.enabled = checkValue.varType == typeof(float) || checkValue.varType == typeof(int);
comparison = (CompareMethod)UnityEditor.EditorGUILayout.EnumPopup("Comparison", comparison);
GUI.enabled = true;
NodeCanvas.Editor.BBParameterEditor.ParameterField("Check Value", checkValue);
}
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 7aae3badff3e29842aa5d63e1f7ab85c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Tasks/Conditions/ScriptControl/Standalone/CheckFunction.cs
uploadId: 704937

View File

@@ -0,0 +1,128 @@
using System.Reflection;
using NodeCanvas.Framework;
using NodeCanvas.Framework.Internal;
using ParadoxNotion;
using ParadoxNotion.Design;
using UnityEngine;
using System.Linq;
namespace NodeCanvas.Tasks.Conditions
{
[Name("Check Property (Desktop Only)")]
[Category("✫ Reflected/Faster Versions (Desktop Platforms Only)")]
[Description("This version works in destop/JIT platform only.\n\nCheck a property on a script and return if it's equal or not to the check value")]
public class CheckProperty : ConditionTask
{
[SerializeField]
protected ReflectedFunctionWrapper functionWrapper;
[SerializeField]
protected BBParameter checkValue;
[SerializeField]
protected CompareMethod comparison;
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, OperationTools.GetCompareString(comparison) + checkValue.ToString());
}
}
public override void OnValidate(ITaskSystem ownerSystem) {
if ( functionWrapper != null && functionWrapper.HasChanged() ) {
SetMethod(functionWrapper.GetMethod());
}
}
//store the method info on agent set for performance
protected override string OnInit() {
if ( targetMethod == null ) { return "Missing Property"; }
try {
functionWrapper.Init(targetMethod.IsStatic ? null : agent);
return null;
}
catch { return "CheckProperty Error"; }
}
//do it by invoking method
protected override bool OnCheck() {
if ( functionWrapper == null ) {
return true;
}
if ( checkValue.varType == typeof(float) ) {
return OperationTools.Compare((float)functionWrapper.Call(), (float)checkValue.value, comparison, 0.05f);
}
if ( checkValue.varType == typeof(int) ) {
return OperationTools.Compare((int)functionWrapper.Call(), (int)checkValue.value, comparison);
}
return ObjectUtils.AnyEquals(functionWrapper.Call(), checkValue.value);
}
void SetMethod(MethodInfo method) {
if ( method != null ) {
UndoUtility.RecordObject(ownerSystem.contextObject, "Set Reflection Member");
functionWrapper = ReflectedFunctionWrapper.Create(method, blackboard);
checkValue = BBParameter.CreateInstance(method.ReturnType, blackboard);
comparison = CompareMethod.EqualTo;
}
}
///----------------------------------------------------------------------------------------------
///---------------------------------------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);
GUILayout.EndVertical();
GUI.enabled = checkValue.varType == typeof(float) || checkValue.varType == typeof(int);
comparison = (CompareMethod)UnityEditor.EditorGUILayout.EnumPopup("Comparison", comparison);
GUI.enabled = true;
NodeCanvas.Editor.BBParameterEditor.ParameterField("Value", checkValue);
}
}
#endif
}
}

View File

@@ -0,0 +1,15 @@
fileFormatVersion: 2
guid: 2dcf607e06046ba49a7a3ec644179530
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
AssetOrigin:
serializedVersion: 1
productId: 14914
packageName: NodeCanvas
packageVersion: 3.3.1
assetPath: Assets/ParadoxNotion/NodeCanvas/Tasks/Conditions/ScriptControl/Standalone/CheckProperty.cs
uploadId: 704937