Beispiel #1
0
            /// <summary>
            /// Handles deserializing, displaying, and re-serializing parameter data for the specified RumiaAction
            /// </summary>
            private void DrawParameterField(RumiaAction rumiaAction, ref string choiceParameter)
            {
                // TODO: Might want to use some sort of JSON Serialization if this gets more complicated.
                // http://wiki.unity3d.com/index.php/SimpleJSON
                switch (rumiaAction.type)
                {
                case RumiaAction.RumiaActionType.Vector:
                    choiceParameter = RumiaAction.VectorSubRumiaAction.SerializeParameter(
                        EditorGUILayout.Vector2Field("Parameter:", RumiaAction.VectorSubRumiaAction.DeserializeParameter(choiceParameter)));
                    break;

                case RumiaAction.RumiaActionType.Bool:
                    choiceParameter = RumiaAction.BoolSubRumiaAction.SerializeParameter(
                        EditorGUILayout.Toggle("Parameter:", RumiaAction.BoolSubRumiaAction.DeserializeParameter(choiceParameter)));
                    break;

                case RumiaAction.RumiaActionType.Int:
                    choiceParameter = RumiaAction.IntSubRumiaAction.SerializeParameter(
                        EditorGUILayout.IntField("Parameter:", RumiaAction.IntSubRumiaAction.DeserializeParameter(choiceParameter)));
                    break;

                case RumiaAction.RumiaActionType.Float:
                    choiceParameter = RumiaAction.FloatSubRumiaAction.SerializeParameter(
                        EditorGUILayout.FloatField("Parameter:", RumiaAction.FloatSubRumiaAction.DeserializeParameter(choiceParameter)));
                    break;

                case RumiaAction.RumiaActionType.String:
                    choiceParameter = RumiaAction.StringSubRumiaAction.SerializeParameter(
                        EditorGUILayout.TextField("Parameter:", RumiaAction.StringSubRumiaAction.DeserializeParameter(choiceParameter)));
                    break;

                default:
                    throw new Exception("Did not properly account for rumiaAction of type " + rumiaAction.type);
                }
            }
        /// <summary>
        /// Schedules a collection of <see cref="RumiaMeasure"/>s that each start at the same <see cref="measureNumber"/>
        /// </summary>
        /// <param name="forceOnStartMeasure">If true, then modify the trigger time of each action to be on the first measure
        /// that is played. If false, skip the action if its trigger time is before the start time of the first measure.</param>
        private IEnumerable <SchedulableAction> ScheduleRumiaMeasureList(IEnumerable <RumiaMeasure> measures, int measureNumber, bool forceOnStartMeasure)
        {
            List <SchedulableAction> ret = new List <SchedulableAction>();

            // Iterate through each measure
            foreach (RumiaMeasure measure in measures.Where(measure => measure != null))
            {
                // Iterate through each instant (32nd note) in the measure
                for (int k = 0; k < ACTIONS_PER_MEASURE; k++)
                {
                    RumiaActionList[]     rumiaActionLists     = measure.RumiaActionLists;
                    ChoiceParameterList[] choiceParameterLists = measure.ChoiceParameterLists;
                    if (rumiaActionLists[k] == null)
                    {
                        continue;
                    }

                    // Iterate through each RumiaAction assigned to this instant
                    List <RumiaAction> rumiaActions     = rumiaActionLists[k].RumiaActions;
                    List <string>      choiceParameters = choiceParameterLists[k].ChoiceParameters;
                    for (int l = 0; l < rumiaActions.Count; l++)
                    {
                        RumiaAction rumiaAction = rumiaActions[l];
                        // Get the serialized parameter to pass into the RumiaAction when it comes time to invoke it
                        string parameter = choiceParameters[l];

                        // If the action is "None", ignore it
                        if (rumiaAction.ActionName.Equals(RumiaAction.NoneString))
                        {
                            continue;
                        }

                        // Factor in the start measure, which measure we're currently on, and which part of the measure we're currently on
                        int elapsedThirtySecondNotes =
                            Config.StartMeasure * ACTIONS_PER_MEASURE + measureNumber * ACTIONS_PER_MEASURE + k;
                        float triggerTime = timingController.GetThirtysecondNoteTime() * elapsedThirtySecondNotes;

                        // This could happen if we have set a non-zero start time
                        if (triggerTime < timeElapsed)
                        {
                            if (forceOnStartMeasure)
                            {
                                triggerTime = timeElapsed;
                            }
                            else
                            {
                                continue;
                            }
                        }

                        SchedulableAction schedulableAction =
                            new SchedulableAction(triggerTime, rumiaAction, GetPatternInstance, parameter);
                        ret.Add(schedulableAction);
                    }
                }
            }

            return(ret);
        }
        private static RumiaAction CreateStringRumiaAction()
        {
            RumiaAction act = new RumiaAction {
                type = RumiaActionType.String, String = new StringSubRumiaAction()
            };

            return(act);
        }
        private static RumiaAction CreateFloatRumiaAction()
        {
            RumiaAction act = new RumiaAction {
                type = RumiaActionType.Float, Float = new FloatSubRumiaAction()
            };

            return(act);
        }
        private static RumiaAction CreateIntRumiaAction()
        {
            RumiaAction act = new RumiaAction {
                type = RumiaActionType.Int, Int = new IntSubRumiaAction()
            };

            return(act);
        }
        private static RumiaAction CreateBoolRumiaAction()
        {
            RumiaAction act = new RumiaAction {
                type = RumiaActionType.Bool, Bool = new BoolSubRumiaAction()
            };

            return(act);
        }
        private static RumiaAction CreateVectorRumiaAction()
        {
            RumiaAction act = new RumiaAction {
                type = RumiaActionType.Vector, Vector = new VectorSubRumiaAction()
            };

            return(act);
        }
        private static RumiaAction CreateBasicRumiaAction()
        {
            RumiaAction act = new RumiaAction {
                type = RumiaActionType.Basic, Basic = new BasicSubRumiaAction()
            };

            return(act);
        }
Beispiel #9
0
 public SchedulableAction(float triggerTime, RumiaAction rumiaAction, Func <Pattern> patternInstanceGetter,
                          string serializedParameter)
 {
     TriggerTime                = triggerTime;
     this.rumiaAction           = rumiaAction;
     this.patternInstanceGetter = patternInstanceGetter;
     this.serializedParameter   = serializedParameter;
 }
Beispiel #10
0
        /// <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);
        }
Beispiel #11
0
            /// <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);
                }
            }
Beispiel #12
0
        /// <summary>
        /// Delete whatever data we have in <see cref="RumiaActions"/> and recreate it.
        /// - The first RumiaAction in the list is null
        /// - Additional entries are created and added for each method in this script with a
        ///   <see cref="RumiaActionAttribute"/> tag.
        ///
        /// Also sets the int IDs of each RumiaAction
        /// </summary>
        public void GenerateRumiaActions()
        {
            RumiaActions.Clear();

            // Add the null RumiaAction if it is not present
            RumiaActions.Add(RumiaAction.CreateNullRumiaAction());

            MethodInfo[] methods = GetType()
                                   .GetMethods()
                                   .Where(t => t.GetCustomAttributes(typeof(RumiaActionAttribute), false).Length > 0)
                                   .ToArray();
            foreach (MethodInfo method in methods)
            {
                GenerateRumiaActionForMethod(method);
            }

            // Update the IDs in case any entries were added/removed/reordered
            for (int i = 0; i < RumiaActions.Count; i++)
            {
                RumiaActions[i].ID = i;
            }

            EditorUtility.SetDirty(this);
        }
        public static RumiaAction CreateNullRumiaAction()
        {
            RumiaAction act = new RumiaAction();

            return(act);
        }
Beispiel #14
0
            public override void OnInspectorGUI()
            {
                // Draw the default inspector
                DrawDefaultInspector();
                RumiaMeasure measure = target as RumiaMeasure;

                if (measure == null)
                {
                    return;
                }
                Pattern pattern = measure.Pattern;

                if (!pattern)
                {
                    return;
                }

                List <RumiaAction> choices = pattern.GetAllRumiaActions();

                EditorGUILayout.LabelField("32nd note triggers", EditorStyles.boldLabel);
                EditorGUIUtility.labelWidth = 80;
                EditorGUIUtility.fieldWidth = 150;
                Color defColor = GUI.color;

                // Handle each group of RumiaActions to be scheduled for this instant in time
                for (int i = 0; i < SIZE; i++)
                {
                    if (measure.RumiaActionLists[i] == null)
                    {
                        measure.RumiaActionLists[i] = new RumiaActionList();
                    }

                    EditorGUILayout.BeginHorizontal();
                    List <RumiaAction> rumiaActionList     = measure.RumiaActionLists[i].RumiaActions;
                    List <string>      choiceParameterList = measure.ChoiceParameterLists[i].ChoiceParameters;

                    // Button to add a new RumiaAction
                    GUI.color = Color.green;
                    if (GUILayout.Button("+", GUILayout.Width(30)))
                    {
                        rumiaActionList.Add(new RumiaAction());
                        choiceParameterList.Add(null);
                    }

                    // Button to remove the last RumiaAction in the list
                    GUI.color = Color.red;
                    if (GUILayout.Button("-", GUILayout.Width(30)) && rumiaActionList.Count > 0)
                    {
                        rumiaActionList.RemoveAt(rumiaActionList.Count - 1);
                        choiceParameterList.RemoveAt(choiceParameterList.Count - 1);
                    }

                    GUI.color = defColor;
                    GUILayout.Label(GetLabel(i), GUILayout.Width(50));

                    // Handle each individual RumiaAction
                    for (int j = 0; j < rumiaActionList.Count; j++)
                    {
                        // Formatting
                        if (j > 0)
                        {
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Label("", GUILayout.Width(117));
                        }

                        // Draw the RumiaAction field
                        RumiaAction updatedRumiaAction     = rumiaActionList[j];
                        string      updatedChoiceParameter = choiceParameterList[j];
                        DrawRumiaActionField(choices, ref updatedRumiaAction, ref updatedChoiceParameter);
                        rumiaActionList[j]     = updatedRumiaAction;
                        choiceParameterList[j] = updatedChoiceParameter;
                    }

                    EditorGUILayout.EndHorizontal();

                    if ((i + 1) % ELEMENTS_PER_BEAT == 0 && i < (SIZE - 1))
                    {
                        HorizontalLine();
                    }
                }
                EditorGUIUtility.labelWidth = 0;
                EditorGUIUtility.fieldWidth = 0;

                // Save the changes back to the object
                EditorUtility.SetDirty(target);
            }