void SetMethod(MethodInfo method)
        {
            if (method == null)
            {
                return;
            }
            this.method = new SerializedMethodInfo(method);
            this.parameters.Clear();
            this.parameterIsByRef.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);
                parameterIsByRef.Add(pType.IsByRef);
            }

            this.checkValue = new BBObjectParameter(method.ReturnType)
            {
                bb = blackboard
            };
            comparison = CompareMethod.EqualTo;
        }
        ///----------------------------------------------------------------------------------------------
        ///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
        protected override void OnTaskInspectorGUI()
        {
            base.OnTaskInspectorGUI();
            if (signalDefinition.isNoneOrNull)
            {
                return;
            }
            var parameters = signalDefinition.value.parameters;

            EditorUtils.Separator();
            foreach (var parameter in parameters)
            {
                BBObjectParameter bbParam = null;
                if (!argumentsMap.TryGetValue(parameter.ID, out bbParam))
                {
                    bbParam = argumentsMap[parameter.ID] = new BBObjectParameter(parameter.type)
                    {
                        useBlackboard = true, bb = ownerSystemBlackboard
                    };
                }
                NodeCanvas.Editor.BBParameterEditor.ParameterField(parameter.name, bbParam, true);
            }

            foreach (var key in argumentsMap.Keys.ToArray())
            {
                if (!parameters.Select(v => v.ID).Contains(key))
                {
                    argumentsMap.Remove(key);
                }
            }
        }
		////////////////////////////////////////
		///////////GUI AND EDITOR STUFF/////////
		////////////////////////////////////////
		#if UNITY_EDITOR
		
		protected override void OnTaskInspectorGUI(){

			if (!Application.isPlaying && GUILayout.Button("Select Static Method")){

				UnityEditor.GenericMenu.MenuFunction2 MethodSelected = (m) => {
					var newMethod = (MethodInfo)m;
					this.method = new SerializedMethodInfo(newMethod);
					this.parameters.Clear();
					foreach(var p in newMethod.GetParameters()){
						var newParam = new BBObjectParameter{bb = blackboard};
						newParam.SetType(p.ParameterType);
						if (p.IsOptional){
							newParam.value = p.DefaultValue;
						}
						parameters.Add(newParam);
					}

					if (newMethod.ReturnType != typeof(void)){
						this.returnValue = new BBObjectParameter{bb = blackboard};
						this.returnValue.SetType(newMethod.ReturnType);
					}					
				};
				
				var menu = new UnityEditor.GenericMenu();
				foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(object), true)){
					foreach(var m in t.GetMethods(BindingFlags.Static | BindingFlags.Public).OrderBy(m => !m.IsSpecialName) ){
						
						if (m.IsGenericMethod)
							continue;

						var parameters = m.GetParameters();
						if (parameters.Length > 3)
							continue;

						menu.AddItem(new GUIContent(t.FriendlyName() + "/" + m.SignatureName()), false, MethodSelected, m);

					}
				}
				menu.ShowAsContext();
				Event.current.Use();
			}


			if (targetMethod != null){
				GUILayout.BeginVertical("box");
				UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.DeclaringType.FriendlyName());
				UnityEditor.EditorGUILayout.LabelField("Method", targetMethod.Name);
				UnityEditor.EditorGUILayout.LabelField("Returns", targetMethod.ReturnType.FriendlyName());
				GUILayout.EndVertical();

				var paramNames = targetMethod.GetParameters().Select(p => p.Name.SplitCamelCase() ).ToArray();
				for (var i = 0; i < paramNames.Length; i++){
					EditorUtils.BBParameterField(paramNames[i], parameters[i]);
				}

				if (targetMethod.ReturnType != typeof(void)){
					EditorUtils.BBParameterField("Save Return Value", returnValue, true);
				}
			}
		}
        void SetMethod(MethodInfo method)
        {
            if (method != null)
            {
                this.method = new SerializedMethodInfo(method);
                this.parameters.Clear();
                foreach (var p in method.GetParameters())
                {
                    var newParam = new BBObjectParameter(p.ParameterType)
                    {
                        bb = blackboard
                    };
                    if (p.IsOptional)
                    {
                        newParam.value = p.DefaultValue;
                    }
                    parameters.Add(newParam);
                }

                this.checkValue = new BBObjectParameter(method.ReturnType)
                {
                    bb = blackboard
                };
                comparison = CompareMethod.EqualTo;
            }
        }
        void SetMethod(MethodInfo method)
        {
            if (method == null)
            {
                return;
            }

            this.method = new SerializedMethodInfo(method);
            this.parameters.Clear();
            foreach (var p in method.GetParameters())
            {
                var newParam = new BBObjectParameter(p.ParameterType)
                {
                    bb = blackboard
                };
                if (p.IsOptional)
                {
                    newParam.value = p.DefaultValue;
                }
                parameters.Add(newParam);
            }

            if (method.ReturnType != typeof(void))
            {
                this.returnValue = new BBObjectParameter(method.ReturnType)
                {
                    bb = blackboard
                };
            }
            else
            {
                this.returnValue = null;
            }
        }
        ////////////////////////////////////////
        ///////////GUI AND EDITOR STUFF/////////
        ////////////////////////////////////////
        protected override void OnTaskInspectorGUI()
        {
            if (!Application.isPlaying && GUILayout.Button("Select Method")){

                System.Action<MethodInfo> MethodSelected = (method) => {
                    this.method = new SerializedMethodInfo(method);
                    this.parameters.Clear();
                    foreach(var p in method.GetParameters()){
                        var newParam = new BBObjectParameter{bb = blackboard};
                        newParam.SetType(p.ParameterType);
                        if (p.IsOptional){
                            newParam.value = p.DefaultValue;
                        }
                        parameters.Add(newParam);
                    }

                    if (method.ReturnType != typeof(void) && targetMethod.ReturnType != typeof(IEnumerator)){
                        this.returnValue = new BBObjectParameter{bb = blackboard};
                        this.returnValue.SetType(method.ReturnType);
                    }
                };

                if (agent != null){

                    EditorUtils.ShowGameObjectMethodSelectionMenu(agent.gameObject, typeof(object), typeof(object), MethodSelected, 3, false, false);

                } else {
                    var menu = new UnityEditor.GenericMenu();
                    foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component), true))
                        menu = EditorUtils.GetMethodSelectionMenu(t, typeof(object), typeof(object), MethodSelected, 3, false, false, menu);
                    menu.ShowAsContext();
                    Event.current.Use();
                }
            }

            if (targetMethod != null){
                GUILayout.BeginVertical("box");
                UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName());
                UnityEditor.EditorGUILayout.LabelField("Method", targetMethod.Name);
                UnityEditor.EditorGUILayout.LabelField("Returns", targetMethod.ReturnType.FriendlyName());

                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++){
                    EditorUtils.BBParameterField(paramNames[i], parameters[i]);
                }

                if (targetMethod.ReturnType != typeof(void) && targetMethod.ReturnType != typeof(IEnumerator)){
                    EditorUtils.BBParameterField("Save Return Value", returnValue, true);
                }
            }
        }
		////////////////////////////////////////
		///////////GUI AND EDITOR STUFF/////////
		////////////////////////////////////////
		#if UNITY_EDITOR

		protected override void OnTaskInspectorGUI(){

			if (!Application.isPlaying && GUILayout.Button("Select Method")){
				
				System.Action<MethodInfo> MethodSelected = (method)=> {
					this.method = new SerializedMethodInfo(method);
					this.parameters.Clear();
					foreach(var p in method.GetParameters()){
						var newParam = new BBObjectParameter{bb = blackboard};
						newParam.SetType(p.ParameterType);
						if (p.IsOptional){
							newParam.value = p.DefaultValue;
						}
						parameters.Add(newParam);
					}

					this.checkValue = new BBObjectParameter{bb = blackboard};
					this.checkValue.SetType(method.ReturnType);
					comparison = CompareMethod.EqualTo;
				};

				if (agent != null){
					EditorUtils.ShowGameObjectMethodSelectionMenu(agent.gameObject, typeof(object), typeof(object), MethodSelected, 3, false, true);
				} else {
					var menu = new UnityEditor.GenericMenu();
					foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component), true))
						menu = EditorUtils.GetMethodSelectionMenu(t, typeof(object), typeof(object), MethodSelected, 3, false, true, menu);
					menu.ShowAsContext();
					Event.current.Use();
				}
			}

			if (targetMethod != null){
				GUILayout.BeginVertical("box");
				UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName());
				UnityEditor.EditorGUILayout.LabelField("Method", targetMethod.Name);
				GUILayout.EndVertical();

				var paramNames = targetMethod.GetParameters().Select(p => p.Name.SplitCamelCase() ).ToArray();
				for (var i = 0; i < paramNames.Length; i++){
					EditorUtils.BBParameterField(paramNames[i], parameters[i]);
				}

				GUI.enabled = checkValue.varType == typeof(float) || checkValue.varType == typeof(int);
				comparison = (CompareMethod)UnityEditor.EditorGUILayout.EnumPopup("Comparison", comparison);
				GUI.enabled = true;				
				EditorUtils.BBParameterField("Check Value", checkValue);
			}
		}
Пример #8
0
 void SetMethod(MethodInfo method)
 {
     if (method != null)
     {
         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);
         }
     }
 }
Пример #9
0
        ////////////////////////////////////////
        ///////////GUI AND EDITOR STUFF/////////
        ////////////////////////////////////////
                #if UNITY_EDITOR
        protected override void OnTaskInspectorGUI()
        {
            if (!Application.isPlaying && GUILayout.Button("Select Action Method"))
            {
                System.Action <MethodInfo> MethodSelected = (method) => {
                    this.method = new SerializedMethodInfo(method);
                    this.parameters.Clear();
                    foreach (var p in method.GetParameters())
                    {
                        var newParam = new BBObjectParameter {
                            bb = blackboard
                        };
                        newParam.SetType(p.ParameterType);
                        parameters.Add(newParam);
                    }
                };

                if (agent != null)
                {
                    EditorUtils.ShowGameObjectMethodSelectionMenu(agent.gameObject, typeof(Status), typeof(object), MethodSelected, 1, false, true);
                }
                else
                {
                    var menu = new UnityEditor.GenericMenu();
                    foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component), true))
                    {
                        menu = EditorUtils.GetMethodSelectionMenu(t, typeof(Status), typeof(object), MethodSelected, 1, false, true, menu);
                    }
                    menu.ShowAsContext();
                    Event.current.Use();
                }
            }

            if (targetMethod != null)
            {
                GUILayout.BeginVertical("box");
                UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName());
                UnityEditor.EditorGUILayout.LabelField("Selected Action Method:", targetMethod.Name);
                GUILayout.EndVertical();

                if (targetMethod.GetParameters().Length == 1)
                {
                    var paramName = targetMethod.GetParameters()[0].Name.SplitCamelCase();
                    EditorUtils.BBParameterField(paramName, parameters[0]);
                }
            }
        }
Пример #10
0
        //Shows blackboard variables mapping
        void ShowVariablesMapping()
        {
            EditorUtils.TitledSeparator("SubTree Local Variables Mapping");
            UnityEditor.EditorGUILayout.HelpBox("You can set the SubDialogueTree's variables if any, by mapping them to the variables of this Dialogue Tree.\nIf set to 'NONE', the variable will not be affected.", UnityEditor.MessageType.Info);

            var subTreeVariables = subTree.blackboard.variables.Values.ToList();

            if (subTreeVariables.Count == 0)
            {
                return;
            }

            foreach (var variable in subTreeVariables)
            {
                if (variable is Variable <VariableSeperator> )
                {
                    continue;
                }

                if (variable.isProtected)
                {
                    UnityEditor.EditorGUILayout.LabelField(variable.name, "(Variable is Protected)");
                    continue;
                }

                BBObjectParameter bbParam = null;
                if (!variablesMap.TryGetValue(variable.ID, out bbParam))
                {
                    bbParam = variablesMap[variable.ID] = new BBObjectParameter(variable.varType)
                    {
                        useBlackboard = true
                    };
                    bbParam.bb = DLGTree.blackboard;
                }
                EditorUtils.BBParameterField(variable.name, bbParam);
            }

            foreach (var key in variablesMap.Keys.ToList())
            {
                if (!subTreeVariables.Select(v => v.ID).Contains(key))
                {
                    variablesMap.Remove(key);
                }
            }
        }
Пример #11
0
        void SetMethod(MethodInfo method)
        {
            if (method == null)
            {
                return;
            }
            this.method = new SerializedMethodInfo(method);
            this.parameters.Clear();
            this.parameterIsByRef.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);
                parameterIsByRef.Add(pType.IsByRef);
            }

            if (method.ReturnType != typeof(void) && targetMethod.ReturnType != typeof(IEnumerator))
            {
                this.returnValue = new BBObjectParameter(method.ReturnType)
                {
                    bb = blackboard
                };
            }
            else
            {
                this.returnValue = null;
            }
        }
Пример #12
0
 protected override void OnNodeInspectorGUI()
 {
     selectionMode = (CaseSelectionMode)UnityEditor.EditorGUILayout.EnumPopup("Selection Mode", selectionMode);
     if (selectionMode == CaseSelectionMode.IndexBased)
     {
         intCase        = (BBParameter <int>)EditorUtils.BBParameterField("Int", intCase);
         outOfRangeMode = (OutOfRangeMode)UnityEditor.EditorGUILayout.EnumPopup("When Out Of Range", outOfRangeMode);
     }
     else
     {
         enumCase = (BBObjectParameter)EditorUtils.BBParameterField("Enum", enumCase, true);
         if (enumCase.value != null)
         {
             GUILayout.BeginVertical("box");
             foreach (var s in System.Enum.GetNames(enumCase.value.GetType()))
             {
                 GUILayout.Label(s);
             }
             GUILayout.EndVertical();
         }
     }
 }
Пример #13
0
        ////////////////////////////////////////
        ///////////GUI AND EDITOR STUFF/////////
        ////////////////////////////////////////
                #if UNITY_EDITOR
        protected override void OnTaskInspectorGUI()
        {
            if (!Application.isPlaying && GUILayout.Button("Select Method"))
            {
                System.Action <MethodInfo> MethodSelected = (method) => {
                    this.method = new SerializedMethodInfo(method);
                    this.parameters.Clear();
                    foreach (var p in method.GetParameters())
                    {
                        var newParam = new BBObjectParameter {
                            bb = blackboard
                        };
                        newParam.SetType(p.ParameterType);
                        if (p.IsOptional)
                        {
                            newParam.value = p.DefaultValue;
                        }
                        parameters.Add(newParam);
                    }

                    this.checkValue = new BBObjectParameter {
                        bb = blackboard
                    };
                    this.checkValue.SetType(method.ReturnType);
                    comparison = CompareMethod.EqualTo;
                };

                if (agent != null)
                {
                    EditorUtils.ShowGameObjectMethodSelectionMenu(agent.gameObject, typeof(object), typeof(object), MethodSelected, 3, false, true);
                }
                else
                {
                    var menu = new UnityEditor.GenericMenu();
                    foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component), true))
                    {
                        menu = EditorUtils.GetMethodSelectionMenu(t, typeof(object), typeof(object), MethodSelected, 3, false, true, menu);
                    }
                    menu.ShowAsContext();
                    Event.current.Use();
                }
            }

            if (targetMethod != null)
            {
                GUILayout.BeginVertical("box");
                UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName());
                UnityEditor.EditorGUILayout.LabelField("Method", targetMethod.Name);
                GUILayout.EndVertical();

                var paramNames = targetMethod.GetParameters().Select(p => p.Name.SplitCamelCase()).ToArray();
                for (var i = 0; i < paramNames.Length; i++)
                {
                    EditorUtils.BBParameterField(paramNames[i], parameters[i]);
                }

                GUI.enabled = checkValue.varType == typeof(float) || checkValue.varType == typeof(int);
                comparison  = (CompareMethod)UnityEditor.EditorGUILayout.EnumPopup("Comparison", comparison);
                GUI.enabled = true;
                EditorUtils.BBParameterField("Check Value", checkValue);
            }
        }
        void SetMethod(MethodInfo method)
        {
            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 newParam = new BBObjectParameter(p.ParameterType){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;
            }
        }
        ////////////////////////////////////////
        ///////////GUI AND EDITOR STUFF/////////
        ////////////////////////////////////////
        protected override void OnTaskInspectorGUI()
        {
            if (!Application.isPlaying && GUILayout.Button("Select Action Method")){

                System.Action<MethodInfo> MethodSelected = (method)=>{
                    this.method = new SerializedMethodInfo(method);
                    this.parameters.Clear();
                    foreach(var p in method.GetParameters()){
                        var newParam = new BBObjectParameter{bb = blackboard};
                        newParam.SetType(p.ParameterType);
                        parameters.Add(newParam);
                    }
                };

                if (agent != null){
                    EditorUtils.ShowGameObjectMethodSelectionMenu(agent.gameObject, typeof(Status), typeof(object), MethodSelected, 1, false, true);
                } else {
                    var menu = new UnityEditor.GenericMenu();
                    foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component), true))
                        menu = EditorUtils.GetMethodSelectionMenu(t, typeof(Status), typeof(object), MethodSelected, 1, false, true, menu);
                    menu.ShowAsContext();
                    Event.current.Use();
                }
            }

            if (targetMethod != null){
                GUILayout.BeginVertical("box");
                UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName());
                UnityEditor.EditorGUILayout.LabelField("Selected Action Method:", targetMethod.Name);
                GUILayout.EndVertical();

                if (targetMethod.GetParameters().Length == 1){
                    var paramName = targetMethod.GetParameters()[0].Name.SplitCamelCase();
                    EditorUtils.BBParameterField(paramName, parameters[0]);
                }
            }
        }
Пример #16
0
 protected override void OnNodeInspectorGUI()
 {
     selectionMode = (CaseSelectionMode)UnityEditor.EditorGUILayout.EnumPopup("Selection Mode", selectionMode);
     if (selectionMode == CaseSelectionMode.IndexBased)
     {
         intCase = (BBParameter<int>)EditorUtils.BBParameterField("Int", intCase);
         outOfRangeMode = (OutOfRangeMode)UnityEditor.EditorGUILayout.EnumPopup("When Out Of Range", outOfRangeMode);
     }
     else
     {
         enumCase = (BBObjectParameter)EditorUtils.BBParameterField("Enum", enumCase, true);
         if (enumCase.value != null){
             GUILayout.BeginVertical("box");
             foreach (var s in System.Enum.GetNames(enumCase.value.GetType()) )
                 GUILayout.Label(s);
             GUILayout.EndVertical();
         }
     }
 }
 void SetMethod(MethodInfo method)
 {
     if (method != null){
         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);
         }
     }
 }
        void SetMethod(MethodInfo method)
        {
            if (method == null){
                return;
            }

            this.method = new SerializedMethodInfo(method);
            this.parameters.Clear();
            foreach(var p in method.GetParameters()){
                var newParam = new BBObjectParameter(p.ParameterType){bb = blackboard};
                if (p.IsOptional){
                    newParam.value = p.DefaultValue;
                }
                parameters.Add(newParam);
            }

            if (method.ReturnType != typeof(void)){
                this.returnValue = new BBObjectParameter(method.ReturnType){bb = blackboard};
            } else {
                this.returnValue = null;
            }
        }
        void SetMethod(MethodInfo method)
        {
            this.method = new SerializedMethodInfo(method);
            this.parameters.Clear();
            foreach(var p in method.GetParameters()){
                var newParam = new BBObjectParameter(p.ParameterType){bb = blackboard};
                if (p.IsOptional){
                    newParam.value = p.DefaultValue;
                }
                parameters.Add(newParam);
            }

            this.checkValue = new BBObjectParameter(method.ReturnType){bb = blackboard};
            comparison = CompareMethod.EqualTo;
        }
        ////////////////////////////////////////
        ///////////GUI AND EDITOR STUFF/////////
        ////////////////////////////////////////
        protected override void OnTaskInspectorGUI()
        {
            if (!Application.isPlaying && GUILayout.Button("Select Method")){

                System.Action<MethodInfo> MethodSelected = (method) => {
                    this.method = new SerializedMethodInfo(method);
                    this.parameters.Clear();
                    foreach(var p in method.GetParameters()){
                        var newParam = new BBObjectParameter{bb = blackboard};
                        newParam.SetType(p.ParameterType);
                        if (p.IsOptional){
                            newParam.value = p.DefaultValue;
                        }
                        parameters.Add(newParam);
                    }

                    if (method.ReturnType != typeof(void) && targetMethod.ReturnType != typeof(IEnumerator)){
                        this.returnValue = new BBObjectParameter{bb = blackboard};
                        this.returnValue.SetType(method.ReturnType);
                    }
                };

                if (agent != null){

                    EditorUtils.ShowGameObjectMethodSelectionMenu(agent.gameObject, typeof(object), typeof(object), MethodSelected, 3, false, false);

                } else {
                    var menu = new UnityEditor.GenericMenu();
                    foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(Component), true))
                        menu = EditorUtils.GetMethodSelectionMenu(t, typeof(object), typeof(object), MethodSelected, 3, false, false, menu);
                    menu.ShowAsContext();
                    Event.current.Use();
                }
            }

            if (targetMethod != null){
                GUILayout.BeginVertical("box");
                UnityEditor.EditorGUILayout.LabelField("Type", agentType.FriendlyName());
                UnityEditor.EditorGUILayout.LabelField("Method", targetMethod.Name);
                UnityEditor.EditorGUILayout.LabelField("Returns", targetMethod.ReturnType.FriendlyName());

                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++){
                    EditorUtils.BBParameterField(paramNames[i], parameters[i]);
                }

                if (targetMethod.ReturnType != typeof(void) && targetMethod.ReturnType != typeof(IEnumerator)){
                    EditorUtils.BBParameterField("Save Return Value", returnValue, true);
                }
            }
        }
Пример #21
0
        ////////////////////////////////////////
        ///////////GUI AND EDITOR STUFF/////////
        ////////////////////////////////////////
                #if UNITY_EDITOR
        protected override void OnTaskInspectorGUI()
        {
            if (!Application.isPlaying && GUILayout.Button("Select Static Method"))
            {
                UnityEditor.GenericMenu.MenuFunction2 MethodSelected = (m) => {
                    var newMethod = (MethodInfo)m;
                    this.method = new SerializedMethodInfo(newMethod);
                    this.parameters.Clear();
                    foreach (var p in newMethod.GetParameters())
                    {
                        var newParam = new BBObjectParameter {
                            bb = blackboard
                        };
                        newParam.SetType(p.ParameterType);
                        if (p.IsOptional)
                        {
                            newParam.value = p.DefaultValue;
                        }
                        parameters.Add(newParam);
                    }

                    if (newMethod.ReturnType != typeof(void))
                    {
                        this.returnValue = new BBObjectParameter {
                            bb = blackboard
                        };
                        this.returnValue.SetType(newMethod.ReturnType);
                    }
                };

                var menu = new UnityEditor.GenericMenu();
                foreach (var t in UserTypePrefs.GetPreferedTypesList(typeof(object), true))
                {
                    foreach (var m in t.GetMethods(BindingFlags.Static | BindingFlags.Public).OrderBy(m => !m.IsSpecialName))
                    {
                        if (m.IsGenericMethod)
                        {
                            continue;
                        }

                        var parameters = m.GetParameters();
                        if (parameters.Length > 3)
                        {
                            continue;
                        }

                        menu.AddItem(new GUIContent(t.FriendlyName() + "/" + m.SignatureName()), false, MethodSelected, m);
                    }
                }
                menu.ShowAsContext();
                Event.current.Use();
            }


            if (targetMethod != null)
            {
                GUILayout.BeginVertical("box");
                UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.DeclaringType.FriendlyName());
                UnityEditor.EditorGUILayout.LabelField("Method", targetMethod.Name);
                UnityEditor.EditorGUILayout.LabelField("Returns", targetMethod.ReturnType.FriendlyName());
                GUILayout.EndVertical();

                var paramNames = targetMethod.GetParameters().Select(p => p.Name.SplitCamelCase()).ToArray();
                for (var i = 0; i < paramNames.Length; i++)
                {
                    EditorUtils.BBParameterField(paramNames[i], parameters[i]);
                }

                if (targetMethod.ReturnType != typeof(void))
                {
                    EditorUtils.BBParameterField("Save Return Value", returnValue, true);
                }
            }
        }