Example #1
0
		public override void Initialize (IFormulaParent _parent)
		{
			base.Initialize (_parent);

			ExpressionParser parser = new ExpressionParser ();
			Expression expression = parser.EvaluateExpression (mFormulaText);
			ApplyFormula = expression.ToDelegate(new List<string>(mParameters.Keys).ToArray());
		}
Example #2
0
			public Parameter (Match m, IFormulaParent _parent)
			{
				string key = m.Groups [1].Value;
				if (string.IsNullOrEmpty (key)) {
					beingKey = BEING_KEY.SELF;
				} else {
					try {
						beingKey = (BEING_KEY)Enum.Parse (typeof(BEING_KEY), key.TrimEnd('.').ToUpper ());
					} catch {
						Debug.LogError ("the being key " + key + " is not recognized in formula of object " 
							+ Error.Hierarchy(_parent.GetComponent()));
						beingKey = BEING_KEY.SELF;
					}
				}

				valueName = m.Groups [2].Value;

				alias = Enum.GetName (typeof(BEING_KEY), beingKey).ToLower() + "_" + valueName;
				initialName = m.Groups [0].Value;
			}
Example #3
0
		public virtual void Initialize (IFormulaParent _parent)
		{
			mParent = _parent;
			mFormulaText = mParent.GetFormulaText ();

			Debug.Assert (!string.IsNullOrEmpty (mFormulaText), 
				"Formula is empty for component : " + Error.Hierarchy(mParent.GetComponent()));

			mParameters = new Dictionary<string, Parameter> ();
			MatchCollection matches = ParamRegex.Matches (mFormulaText);


			foreach (Match m in matches) {
				Parameter p = new Parameter (m, _parent);
				mFormulaText = mFormulaText.Replace (p.initialName, p.alias);
				if (!mParameters.ContainsKey(p.alias)) {
					mParameters.Add (p.alias, p);
				}
			}


			mIsInitialized = true;

		}