private static string evaluateString(string evalListString, object o, float multiplier, Func <decimal, decimal> appOverride = null) { var parts = Regex.Split(evalListString, ",(?![^(]*\\))"); RectTransform rectTransform = null; mathParser.LocalVariables ["dpi"] = Convert.ToDecimal(PlanetUnityOverride.screenDPI()); mathParser.LocalVariables ["screenW"] = Convert.ToDecimal(Screen.width / multiplier); mathParser.LocalVariables ["screenH"] = Convert.ToDecimal(Screen.height / multiplier); #if UNITY_IOS mathParser.LocalVariables ["statusBarHeight"] = Convert.ToDecimal((0.13f * PlanetUnityOverride.screenDPI()) / multiplier); #else mathParser.LocalVariables ["statusBarHeight"] = 0; #endif GameObject parentAsGameObject = o as GameObject; PUGameObject parentAsPUGameObject = o as PUGameObject; if (parentAsGameObject != null) { rectTransform = parentAsGameObject.GetComponent <RectTransform> (); } else if (parentAsPUGameObject != null) { rectTransform = parentAsPUGameObject.gameObject.GetComponent <RectTransform> (); } if (rectTransform) { // Work around for unity stretching canvas bug if (o is PUCanvas && (int)rectTransform.rect.width == 100 && (int)rectTransform.rect.height == 100) { mathParser.LocalVariables ["w"] = Convert.ToDecimal(Screen.width / multiplier); mathParser.LocalVariables ["h"] = Convert.ToDecimal(Screen.height / multiplier); } else { mathParser.LocalVariables ["w"] = Convert.ToDecimal(rectTransform.rect.width / multiplier); mathParser.LocalVariables ["h"] = Convert.ToDecimal(rectTransform.rect.height / multiplier); } } evalStringBuilder.Length = 0; foreach (string part in parts) { decimal result = (mathParser.Parse(part) * (decimal)multiplier); if (appOverride != null) { result = appOverride(result); } evalStringBuilder.AppendFormat("{0},", result); } evalStringBuilder.Length = evalStringBuilder.Length - 1; return(evalStringBuilder.ToString()); }
public static string processString(object cur, object o, string s) { if (s == null) { return(null); } #if USE_LAURETTE s = s.Replace("@LANGUAGE", Localizations.GetLanguageCode()); #endif s = s.Replace("\\n", "\n"); if (s.Equals("nan")) { return("0"); } if (s.StartsWith("@localization(")) { #if USE_LAURETTE string evalListString = s.Substring(14, s.Length - 15); s = Localizations.TranslateKey(evalListString); #endif } else if (s.StartsWith("@eval(")) { string evalListString = s.Substring(6, s.Length - 7); s = evaluateString(evalListString, o, 1.0f); PUGameObject current = cur as PUGameObject; if (current != null) { foreach (var token in mathParser.usedTokens) { current.Canvas.GetVariable(token).AddListener(current); } } } else if (s.StartsWith("@dpi(")) { string evalListString = s.Substring(5, s.Length - 6); s = evaluateString(evalListString, o, PlanetUnityOverride.screenDPI()); } else if (s.StartsWith("@app1(")) { string evalListString = s.Substring(6, s.Length - 7); s = evaluateString(evalListString, o, PlanetUnityOverride.screenDPI(), PlanetUnityOverride.app1); } return(PlanetUnityOverride.appProcessString(s)); }
public static string processString(object o, string s) { if (s == null) { return(null); } #if USE_LAURETTE s = s.Replace("@LANGUAGE", Localizations.GetLanguageCode()); #endif s = s.Replace("\\n", "\n"); if (s.Equals("nan")) { return("0"); } if (s.StartsWith("@localization(")) { #if USE_LAURETTE string evalListString = s.Substring(14, s.Length - 15); s = Localizations.TranslateKey(evalListString); #endif } else if (s.StartsWith("@eval(")) { string evalListString = s.Substring(6, s.Length - 7); s = evaluateString(evalListString, o, 1.0f); } else if (s.StartsWith("@dpi(")) { string evalListString = s.Substring(5, s.Length - 6); s = evaluateString(evalListString, o, PlanetUnityOverride.screenDPI()); } else if (s.StartsWith("@app1(")) { string evalListString = s.Substring(6, s.Length - 7); s = evaluateString(evalListString, o, PlanetUnityOverride.screenDPI(), PlanetUnityOverride.app1); } return(PlanetUnityOverride.appProcessString(s)); }
public void CheckForEventSystem() { GameObject eventSystem = GameObject.Find("EventSystem"); if (eventSystem == null) { // We need to create this manually... eventSystem = new GameObject("EventSystem"); eventSystem.AddComponent <EventSystem> (); eventSystem.AddComponent <StandaloneInputModule> (); eventSystem.AddComponent <TouchInputModule> (); GameObject.DontDestroyOnLoad(eventSystem); } EventSystem system = eventSystem.GetComponent <EventSystem> (); system.pixelDragThreshold = (int)(PlanetUnityOverride.screenDPI() * 0.1f); }
public static string processString(object o, string s) { if (s == null) { return(null); } s = s.Replace("@LANGUAGE", PlanetUnityLanguage.LanguageCode()); s = s.Replace("\\n", "\n"); if (s.Equals("nan")) { return("0"); } if (s.StartsWith("@eval(")) { string evalListString = s.Substring(6, s.Length - 7); s = evaluateString(evalListString, o, 1.0f); } else if (s.StartsWith("@dpi(")) { string evalListString = s.Substring(5, s.Length - 6); s = evaluateString(evalListString, o, PlanetUnityOverride.screenDPI()); } else if (s.StartsWith("@app1(")) { string evalListString = s.Substring(6, s.Length - 7); s = evaluateString(evalListString, o, PlanetUnityOverride.screenDPI(), PlanetUnityOverride.app1); } else if (s.StartsWith("@")) { string localizedString = PlanetUnityLanguage.Translate(s); if (localizedString.Equals(s) == false) { return(PlanetUnityOverride.appProcessString(localizedString)); } } return(PlanetUnityOverride.appProcessString(s)); }