Exemplo n.º 1
0
        /// <summary>
        /// Create a drop-down list of methods in the action field.
        /// </summary>
        /// <param name="data">Current data for this action field.</param>
        /// <param name="items">A list of methods.</param>
        /// <returns>The data for this action field.</returns>
        private static MethodFieldData BuildItemFieldList(MethodFieldData data, List <MethodInfo> items)
        {
            // hero object does not exist on game object or int list is empty
            if (items.Count == 0)
            {
                data.fieldID   = 0;
                data.fieldName = null;
            }
            // everything looks okay. draw int list.
            else
            {
                // if we are referencing a field that no longer exists in int list, reset condition int field
                if (items.Count < data.fieldID)
                {
                    data.fieldID   = 0;
                    data.fieldName = null;
                }

                // draw the list
                data.fieldID = HeroField.MethodListField.SetValues(items, data.fieldID, 0);

                // populate the fieldName
                if (data.fieldID > 0)
                {
                    data.fieldName = new SerializableMethodInfo(items[data.fieldID - 1]);
                }
            }

            return(data);
        }
Exemplo n.º 2
0
        // --------------------------------------------------------------
        // Initialize Action Field
        // --------------------------------------------------------------

        /// <summary>
        /// Create the subfields that we need for this action field.
        /// </summary>
        /// <param name="title">The title of the action.</param>
        /// <param name="actionField">The action field.</param>
        /// <param name="heroObject">The hero object that contains this action field.</param>
        /// <returns>The data for this action field.</returns>
        private static MethodFieldData CreateFieldData(string title, HeroActionField actionField, HeroObject heroObject)
        {
            MethodFieldData data = new MethodFieldData();

            data.Init(ref actionField);
            data.title           = title;
            data.fieldID         = actionField.ints[0];
            data.fieldNameString = actionField.strings[0];
            data.fieldName       = null;
            return(data);
        }
Exemplo n.º 3
0
        // --------------------------------------------------------------
        // Action Fields
        // --------------------------------------------------------------

        /// <summary>
        /// Get a method from a script.
        /// </summary>
        /// <param name="script">The script that contains the method.</param>
        /// <param name="title">Title for action field.</param>
        /// <param name="actionParams">Action field parameters.</param>
        /// <param name="actionField">Action field.</param>
        /// <param name="actionField"></param>
        /// <returns>The method from the script.</returns>
        public static MethodInfo BuildFieldA(MonoScript script, string title, HeroActionParams actionParams, HeroActionField actionField)
        {
            // create the fields
            MethodFieldData data = CreateFieldData(title, actionField, actionParams.heroObject);

            //-----------------------------------------
            // Display this title above the field
            //-----------------------------------------
            if (data.title != "")
            {
                SimpleLayout.Label(data.title);
            }

            //-----------------------------------------
            // Get the list you want to work with.
            //-----------------------------------------
            List <MethodInfo> items = AddMethodsToList(script);

            data = BuildItemFieldList(data, items);

            // exit early if there is no field name
            if (data.fieldName == null)
            {
                return(null);
            }

            //-----------------------------------------
            // assign values back to hero object fields
            //-----------------------------------------
            actionField.ints[0]    = data.fieldID;
            actionField.strings[0] = data.fieldName.methodInfo.Name;
            actionField.method     = data.fieldName;

            // return a value
            return(data.fieldName.methodInfo);
        }