/// <summary> /// Display the choices and any configurable parameters for this pattern's available RumiaActions, and update /// with any changes we make /// </summary> private void DrawRumiaActionField(List <RumiaAction> choices, ref RumiaAction rumiaAction, ref string choiceParameter) { // Get the name of the currently selected RumiaAction string currentName = rumiaAction.ActionName; Type currentType = rumiaAction.GetSubRumiaAction()?.GetParameterType(); // Get all of the RumiaAction names List <string> choiceNames = choices.Select(e => e.ActionName).ToList(); // If the currently chosen RumiaAction no longer exists, replace it with a NullAction if (!choiceNames.Contains(currentName)) { currentName = RumiaAction.NoneString; } // Get the ID of the currently selected RumiaAction int currentIndex = choices.First(e => e.ActionName.Equals(currentName)).ID; // Present the RumiaActions by a list of names and allow us to select a new one int chosenIndex = EditorGUILayout.Popup(currentIndex, choices.Select(e => e.ActionName).ToArray()); // Update the selected choice rumiaAction = choices[chosenIndex]; // Handle presenting and updating the parameter value for the selected RumiaAction Type parameterType = rumiaAction.GetSubRumiaAction()?.GetParameterType(); if (parameterType != null) { // If we changed the parameter type, then set the choice parameter value back to null to avoid type weirdness if (parameterType != currentType) { choiceParameter = null; } DrawParameterField(rumiaAction, ref choiceParameter); } }
/// <summary> /// Create a pattern action for a single method. This determines what type of <see cref="RumiaAction.ISubRumiaAction"/> to use based on the /// type of the method's parameter. Only accepts methods with a single parameter or no parameters. /// Creates the new RumiaAction and adds it to <see cref="RumiaActions"/>. /// </summary> private void GenerateRumiaActionForMethod(MethodInfo method) { ParameterInfo[] parameters = method.GetParameters(); // Only accept methods with zero or one parameter if (parameters.Length >= 2) { Debug.LogError("Too many parameters for method " + method.Name + ". Methods with the [RumiaActionAttribute] can only have one parameter."); return; } RumiaAction.RumiaActionType actionType; if (parameters.Length == 0) { // No parameters, so use a BasicSubRumiaAction actionType = RumiaAction.RumiaActionType.Basic; } else { // Exactly one parameter. Get its mapped RumiaAction type. Type parameterType = parameters[0].ParameterType; actionType = RumiaAction.GetRumiaActionType(parameterType); if (actionType == RumiaAction.RumiaActionType.Undefined) { Debug.LogError( "No RumiaAction type assigned to typesDict for parameter type: " + parameterType); return; } } // Create the RumiaAction based on the per-SubRumiaAction definition RumiaAction rumiaAction = RumiaAction.CreateRumiaAction(actionType); rumiaAction.ActionName = method.Name; rumiaAction.GetSubRumiaAction()?.GenerateRumiaActionEvent(method, this); RumiaActions.Add(rumiaAction); }