private static void CreateNewSet(string aSetName) { if (mRuleSets.ContainsKey(aSetName) == true) { Debug.LogError("RuleSet \"" + aSetName + "\" already defined."); return; } mCurrentSet = new PMesh.RuleSet(); mCurrentSet.mName = aSetName; mCurrentSet.mRules = new List <PMesh.BaseRule>(); mRuleSets.Add(aSetName, mCurrentSet); }
public static void ParseInput(string aInput, string aVariables) { mRuleSets.Clear(); mCurrentSet = null; mVariables.Clear(); string[] variableBlocks = Split(aVariables, OPERATOR_COMMAND_END); for (int variableIndex = 0; variableIndex < variableBlocks.Length; ++variableIndex) { string[] variable = Split(variableBlocks[variableIndex], OPERATOR_ASSIGN); if (variable.Length == 2) { float variableValue = 0.0f; if (float.TryParse(variable[1].Trim(), out variableValue) == true) { mVariables.Add(variable[0].Trim(), variableValue); } } } string[] shapeBlocks = Split(aInput, OPERATOR_SHAPE_END); for (int shapeBlockIndex = 0; shapeBlockIndex < shapeBlocks.Length; ++shapeBlockIndex) { string[] shapeCommands = Split(shapeBlocks[shapeBlockIndex], OPERATOR_SHAPE_START); if (shapeCommands.Length != 2) { continue; } CreateNewSet(shapeCommands[0].Trim()); string[] commands = Split(shapeCommands[1], OPERATOR_COMMAND_END); for (int commandIndex = 0; commandIndex < commands.Length; ++commandIndex) { string commandLine = commands[commandIndex].Trim(); ProcessCommand(commandLine); } } FindObjectOfType <PMesh.ShapeBuilder>().BuildShape(mRuleSets, mVariables); }