public virtual void Parse(Dictionary<string,object> dict)
{
//base.Parse(dict);
//GameObject gameObject = new GameObject();
//this.gameObject = gameObject;
//and set the id
//this.gameObject.name = dict["id"].ToString();
// Debug.Log("<color=yellow>UIText gameObject:</color> " + this.gameObject);
// foreach(KeyValuePair<string,object> entry in dict)
// {
// Debug.Log(entry.Key + ": " + entry.Value.ToString());
// }
// GameObject text46 = new GameObject();
// text46.name = objId;
//gameObject.transform.parent = GameObject.Find("Canvas").transform;
uiText = gameObject.GetComponent<UnityEngine.UI.Text>();
if (uiText == null)
{
uiText = gameObject.AddComponent<UnityEngine.UI.Text>();
}
I18nManager i18n = I18nManager.Instance;
Debug.Log("uiText:" + uiText);
uiText.text = i18n.Get(dict["id"].ToString());
//Debug.Log("GetPixelAdjustedRect: " + t.GetPixelAdjustedRect());
if(dict.ContainsKey("position"))
{
string pos = dict["position"].ToString();
float px = System.Convert.ToSingle(pos.Split(',')[0]);
float py = System.Convert.ToSingle(pos.Split(',')[1]);
Log.Debug("Position:"+px+","+py);
// this.gameObject.transform.position = new Vector3(px, py, 0);
uiText.rectTransform.anchoredPosition = new Vector2(px * 100, py * 100);
//this.gameObject.name = dict["position"].ToString();
}
if(dict.ContainsKey("rotation"))
{
string rot = dict["rotation"].ToString();
float rx = System.Convert.ToSingle(rot.Split(',')[0]);
float ry = System.Convert.ToSingle(rot.Split(',')[1]);
//Log.Debug("Rotation:"+rot+":"+rx+","+ry);
this.gameObject.transform.localRotation = Quaternion.Euler(new Vector3(rx, ry, 0));
//this.gameObject.name = dict["position"].ToString();
}
if(dict.ContainsKey("scale"))
{
string sc = dict["scale"].ToString();
float sx = System.Convert.ToSingle(sc.Split(',')[0]);
float sy = System.Convert.ToSingle(sc.Split(',')[1]);
this.gameObject.transform.localScale = new Vector3(sx * 10, sy * 10, 0); //TODO
}
if(dict.ContainsKey("order"))
{
SortingOrder = System.Convert.ToInt32(dict["order"].ToString());
}
if(dict.ContainsKey("layer"))
{
string layer = dict["layer"].ToString();
this.gameObject.layer = LayerMask.NameToLayer(layer);
}
if(dict.ContainsKey("fontSize"))
{
FontSize = System.Convert.ToInt32(dict["fontSize"].ToString());
}
if(dict.ContainsKey("spacing"))
{
string value = dict["spacing"].ToString();
LineSpacing = float.Parse(value);
}
if(dict.ContainsKey("fontStyle"))
{
//TODO implement possibility to disply UIText in Bold or Italic
string fontStyleDef = dict["fontStyle"].ToString();
if(fontStyleDef == "bold")
FontStyleDef = FontStyle.Bold;
else if(fontStyleDef == "italic")
FontStyleDef = FontStyle.Italic;
else if(fontStyleDef == "bold and italic")
FontStyleDef = FontStyle.BoldAndItalic;
}
if(dict.ContainsKey("color"))
{
string color = dict["color"].ToString();
byte red = System.Convert.ToByte(color.Split(',')[0]);
byte green = System.Convert.ToByte(color.Split(',')[1]);
byte blue = System.Convert.ToByte(color.Split(',')[2]);
byte alpha = System.Convert.ToByte(color.Split(',')[3]);
Debug.Log(string.Format("<color=yellow>{0}: {1},{2},{3},{4}</color>", name, red, green, blue, alpha));
FontColor = new Color32(red, green, blue, alpha);
}
else
{
FontColor = color;
}
if(dict.ContainsKey("localized"))
{
string value = dict["localized"].ToString();
isLocalized = (value == "true" ) ? true : false;
textId = dict["id"].ToString();
}
if(dict.ContainsKey("font"))
{
uiText.font = Resources.Load<Font>(dict["font"].ToString());
Log.Debug("font:"+font);
}
if(dict.ContainsKey("anchor"))
{
string value = dict["anchor"].ToString();
if(value == "middle center")
uiText.alignment = TextAnchor.MiddleCenter;
else if(value == "middle left")
uiText.alignment = TextAnchor.MiddleLeft;
else if(value == "middle right")
uiText.alignment = TextAnchor.MiddleRight;
else if(value == "upper left")
uiText.alignment = TextAnchor.UpperLeft;
else if(value == "upper center")
uiText.alignment = TextAnchor.UpperCenter;
else if(value == "upper right")
uiText.alignment = TextAnchor.UpperRight;
else if(value == "lower left")
uiText.alignment = TextAnchor.UpperLeft;
else if(value == "lower center")
uiText.alignment = TextAnchor.UpperCenter;
else if(value == "lower right")
uiText.alignment = TextAnchor.UpperRight;
}
// if(dict.ContainsKey("alignment"))
// {
// string value = dict["alignment"].ToString();
// if(value == "left")
// Alignment = TextAlignment.Left;
// else if(value == "center")
// Alignment = TextAlignment.Center;
// else if(value == "right")
// Alignment = TextAlignment.Right;
// }
if(dict.ContainsKey("wrapsize"))
{
string value = dict["wrapsize"].ToString();
this.wrapSize = Convert.ToInt32(value);
}
if(dict.ContainsKey("maxlength"))
{
string value = dict["maxlength"].ToString();
this.maxLength = Convert.ToInt32(value);
}
if(dict.ContainsKey("format"))
{
string value = dict["format"].ToString();
this.format = value;
}
if(dict.ContainsKey("numeric"))
{
string value = dict["numeric"].ToString();
this.isNumeric = (value == "true" ) ? true : false;
}
if(dict.ContainsKey("text"))
{
Text = dict["text"].ToString();
}
// uiText.rectTransform.sizeDelta = new Vector2(uiText.preferredWidth, uiText.preferredHeight);
// Debug.Log(string.Format("<color=yellow>UIText: {0} : ({1}, {2})</color>", name, uiText.rectTransform.sizeDelta.x, uiText.rectTransform.sizeDelta.y));
}//Parse()