Example #1
0
 public SubactionVarData(string _name, SubactionSource _source, SubactionVarType _type, string _data, string desc = "", bool _editable = true)
 {
     name        = _name;
     source      = _source;
     type        = _type;
     data        = _data;
     editable    = _editable;
     description = desc;
 }
Example #2
0
 public void SetTypeString(string typeString)
 {
     if (typeString == "string")
     {
         type = SubactionVarType.STRING;
     }
     if (typeString == "int")
     {
         type = SubactionVarType.INT;
     }
     if (typeString == "float")
     {
         type = SubactionVarType.FLOAT;
     }
     if (typeString == "bool")
     {
         type = SubactionVarType.BOOL;
     }
     else
     {
         Debug.LogError("Invalid type passed to SubactionVarData: " + typeString);
     }
 }
Example #3
0
    /// <summary>
    /// Given a line containing the definition of a SubactionData, return that SubactionData as an object.
    /// This uses reflection to get the Subactions, so the spelling of the SubName is key.
    /// </summary>
    /// <param name="line">The line being parsed</param>
    /// <returns>A proper SubactionData object, ready for injecting into a Dynamic Action</returns>
    private static SubactionData processSubactionLine(string line, int lineNumber)
    {
        string[] startParenSplit = line.Split('(');

        //This string should contain EXACTLY one parenthesis pair. Any more or less and you f****d up your script, dawg
        if (startParenSplit.Length != 2 || !line.EndsWith(")"))
        {
            //Debug.Log(startParenSplit.Length);
            //Debug.Log(line.EndsWith(")"));
            throwException("Incorrect parenthesis in subDataLine: " + line, lineNumber);
            return(null);
        }
        string subDataName = startParenSplit[0];
        string argList     = startParenSplit[1].Substring(0, startParenSplit[1].Length - 1);
        //Debug.Log(string.Format("PARSING SUBACTION {0}\n\tArguments: {1}",subDataName,argList));


        SubactionDataDefault subDataDef = Resources.Load <SubactionDataDefault>("SubactionData/" + subDataName);

        if (subDataDef != null)
        {
            SubactionData subData   = subDataDef.CreateSubactionData();
            string[]      splitArgs = new string[0];
            if (argList.Length > 0)
            {
                splitArgs = argList.Split(',');
            }
            if (subDataDef.scriptArgNames.Count != splitArgs.Length)
            {
                throwException(string.Format("Subaction {0} has {1} arguments, expecting {2}", subDataName, splitArgs.Length, subDataDef.scriptArgNames.Count), lineNumber);
                return(null);
            }
            for (int i = 0; i < splitArgs.Length; i++)
            {
                string argumentName = subDataDef.scriptArgNames[i];

                SubactionSource source = SubactionSource.CONSTANT;
                if (splitArgs[i].StartsWith("owner."))
                {
                    source       = SubactionSource.OWNER;
                    splitArgs[i] = splitArgs[i].Substring("owner.".Length);
                }
                else if (splitArgs[i].StartsWith("action."))
                {
                    source       = SubactionSource.ACTION;
                    splitArgs[i] = splitArgs[i].Substring("action.".Length);
                }

                SubactionVarType varType = subDataDef.arguments[argumentName].type;

                SubactionVarData argVarData = new SubactionVarData(argumentName, source, varType, splitArgs[i]);
                subData.arguments[argumentName] = argVarData;
            }
            return(subData);
        }
        else
        {
            throwException("No Subaction found with name " + subDataName, lineNumber);
        }
        return(null);
    }