public UtilityAI(List <UtilityAction> acts, UtilityBehaviourAI target) { this.actions = acts; this.selected = new List <UtilityAction>(); this.Initialize(target); }
public void Initialize(UtilityBehaviourAI target) { if (this.isCondition) { this.condition = System.Func <MovementController, bool> .CreateDelegate(typeof(System.Func <MovementController, bool>), target, target.GetType().GetMethod(method)) as System.Func <MovementController, bool>; } else { this.mapper = System.Func <MovementController, float> .CreateDelegate(typeof(System.Func <MovementController, float>), target, target.GetType().GetMethod(method)) as System.Func <MovementController, float>; } this.initialized = true; }
private void Initialize(UtilityBehaviourAI target) { if (this.actions == null) { // Debug.LogError("ERROR: Could not initialize AI, maybe the initialization was called in an Awake function instead of a Start function."); return; } foreach (UtilityAction action in this.actions) { action.Initialize(action.method, target); } this.Check(target); }
private void Check(string a, UtilityBehaviourAI target) { UtilityScorer scorer; string[] methods = new string[this.scorers.Count]; for (int i = 0; i < this.scorers.Count; i++) { scorer = this.scorers[i]; if (Array.IndexOf(methods, scorer.method) >= 0) { // Debug.LogWarning($"WARNING : The scorer '{scorer.method}' is defined multiples times for the same action '{a}' !", target.transform); } else { methods[i] = scorer.method; } } }
private void Check(UtilityBehaviourAI target) { UtilityAction action; string[] methods = new string[this.actions.Count]; for (int i = 0; i < this.actions.Count; i++) { action = this.actions[i]; if (Array.IndexOf(methods, action.method) >= 0) { // Debug.LogWarning($"WARNING : The action '{action.method}' is defined multiples times in inspector !", target.transform); } else { methods[i] = action.method; } } }
/* --------------------------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------------------------*/ /* -------------------------------------- UTIL FUNCTION ---------------------------------------*/ /* --------------------------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------------------------*/ /* --------------------------------------------------------------------------------------------*/ public void Initialize(string a, UtilityBehaviourAI target) { MethodInfo methodInfo; methodInfo = target.GetType().GetMethod(method); if (methodInfo.ReturnType == typeof(void)) { this.action = System.Action <MovementController> .CreateDelegate(typeof(System.Action <MovementController>), target, methodInfo) as System.Action <MovementController>; } else { this.coroutineFactory = System.Func <MovementController, UtilityAction, IEnumerator> .CreateDelegate(typeof(System.Func <MovementController, UtilityAction, IEnumerator>), target, methodInfo) as System.Func <MovementController, UtilityAction, IEnumerator>; } foreach (UtilityScorer scorer in this.scorers) { scorer.Initialize(target); } this.Check(a, target); }
public sealed override void OnInspectorGUI() { UtilityBehaviourAI script = target as UtilityBehaviourAI; baserect = EditorGUILayout.GetControlRect(true, 0); /*Rect n = new Rect(); * n.x = baserect.x; * n.y += 500; * n.width = 200; * n.height = 16; * val = EditorGUI.FloatField(n, "Val", val);*/ baserect.height += 17; GUI.enabled = false; EditorGUI.ObjectField(baserect, "Script", MonoScript.FromMonoBehaviour(script), typeof(UtilityBehaviourAI), false); GUI.enabled = true; baserect.y += 20; EditorGUI.LabelField(baserect, "Update Interval", EditorStyles.miniLabel); baserect.x += 90; baserect.width += -95; script.updateRate = EditorGUI.Slider(baserect, script.updateRate, 0.02f, 1f); // reset baserect.y += 10; baserect.x += -90; baserect.width += 95; baserect.height += -17; for (int act = 0; act < actions.arraySize; act++) { actionRef = actions.GetArrayElementAtIndex(act); scorers = actionRef.FindPropertyRelative("scorers"); baserect.x += -5; baserect.y += 11; baserect.height += 50; EditorGUI.DrawRect(baserect, actionColor); baserect.x += 8; baserect.y += 7; baserect.width += -15; baserect.height += -38; this.ActionMethodField(baserect, actionRef); baserect.x += 12; baserect.y += 19; cacherect = baserect; cacherect.width = 60; script.displayScorers[act] = EditorGUI.Foldout(cacherect, script.displayScorers[act], "Scorers"); cacherect = baserect; cacherect.x = baserect.width + -91; cacherect.y += -2; cacherect.width = 108; cacherect.height = 17; if (GUI.Button(cacherect, "REMOVE")) { script.displayScorers.RemoveAt(act); script.RemoveActionAt(act); serializedObject.Update(); return; } // reset baserect.x += 108; baserect.y += -2; baserect.width += -120; baserect.height += 5; if (script.displayScorers[act]) { baserect.x += -128; baserect.y += 26; cacherect = baserect; cacherect.width += 135; cacherect.height = (scorers.arraySize > 0) ? 68 * scorers.arraySize + 25 : 20; EditorGUI.DrawRect(cacherect, actionColor); for (int sco = 0; sco < scorers.arraySize; sco++) { baserect.x += 11; baserect.y += -4; cacherect = baserect; cacherect.width += 118; cacherect.height = 65; EditorGUI.DrawRect(cacherect, scorerColor); baserect.x += 6; baserect.y += 6; baserect.width += 106; baserect.height += -2; cacherect = baserect; cacherect.y += 20; cacherect.height = 16; scoreRef = scorers.GetArrayElementAtIndex(sco); if (script.actions[act].scorers[sco].isCondition) { this.ScorerConditionMethodField(baserect, scoreRef); script.actions[act].scorers[sco].score = EditorGUI.IntField(cacherect, "Score", script.actions[act].scorers[sco].score); cacherect.x += 82; cacherect.y += -21; cacherect.width = 39; cacherect.height = 15; script.actions[act].scorers[sco].not = GUI.Toggle(cacherect, script.actions[act].scorers[sco].not, "Not"); } else { this.ScorerCurveMethodField(baserect, scoreRef); script.actions[act].scorers[sco].curve = EditorGUI.CurveField(cacherect, "Curve", script.actions[act].scorers[sco].curve); } baserect.x += 2; baserect.y += 37; cacherect = baserect; cacherect.width = 59; cacherect.height = 15; if (GUI.Button(cacherect, "REMOVE")) { script.actions[act].RemoveScorerAt(sco); serializedObject.Update(); return; } baserect.x += -19; baserect.y += 29; baserect.width += -106; baserect.height += 2; } if (scorers.arraySize > 0) { baserect.y += 5; } cacherect = baserect; cacherect.x = baserect.width + 14; cacherect.y += -7; cacherect.width = 61; cacherect.height = 20; if (GUI.Button(cacherect, "BOOL")) { if ((scorerConditionMethodNames.Length + scorerConditionMethodNames.Length) == script.actions[act].scorers.Count) { // Debug.Log("No need to add another scorer, there is enough !"); } else { script.actions[act].AddCondition(); serializedObject.Update(); } } cacherect.x = baserect.width + 76; if (GUI.Button(cacherect, "FLOAT")) { if ((scorerConditionMethodNames.Length + scorerConditionMethodNames.Length) == script.actions[act].scorers.Count) { // Debug.Log("No need to add another scorer, there is enough !"); } else { script.actions[act].AddCurve(); serializedObject.Update(); } } baserect.x += 10; baserect.y += -7; // reset baserect.x += -5; baserect.y += 20; baserect.width += 135; baserect.height += -17; } else { // loop reset baserect.x += -123; baserect.y += 19; baserect.width += 135; baserect.height += -17; } } baserect.x += -5; baserect.y += 14; baserect.width += 1; baserect.height = 23; if (GUI.Button(baserect, "ADD NEW ACTION")) { if (actionMethodNames.Length == script.actions.Count) { // Debug.Log($"No need to add another action, there is enough ! (Number of action found: {actionMethodNames.Length})"); } else { script.displayScorers.Add(false); script.AddAction(); serializedObject.Update(); } } GUILayout.Space(baserect.y + 25); serializedObject.ApplyModifiedProperties(); }