public void setTextInEditor(bool ignoreSame = true) { if (ignoreSame && _lastStr == contentStr) { return; } Vector2 lastPivot = pivot; pivot = new Vector2(0, 1); isCreating = true; _lastStr = contentStr; PrefabSetting settings = GlobalController.instance.prefabSetting; GameObject obj; SpriteRenderer spr; FontData d; float x = 0; chars = contentStr.ToCharArray(); for (int i = 0; i < chars.Length; i++) { if (analyse.fontDatas.TryGetValue(System.Convert.ToInt32(chars[i]), out d)) { if (i >= _character.Count) { obj = new GameObject(); spr = obj.AddComponent <SpriteRenderer>(); _character.Add(obj); } else { obj = _character[i]; obj.SetActive(true); spr = obj.GetComponent <SpriteRenderer>(); } obj.tag = Config.TAG_CHAR; obj.gameObject.layer = transform.gameObject.layer; spr = obj.GetComponent <SpriteRenderer>(); spr.color = color; spr.sortingOrder = 1; obj.transform.SetParent(transform, false); obj.name = chars[i].ToString(); obj.transform.localPosition = new Vector2(x, -d._actualOffsetY); x += d.actualAdvance; spr.sprite = d.spr; } } for (int i = chars.Length; i < _character.Count; i++) { _character[i].SetActive(false); } _textWidth = x; pivot = lastPivot; isCreating = false; }
public void setTextInEditor(bool ignoreSame = true) { if (ignoreSame && _lastStr == contentStr) { return; } Vector2 lastPivot = pivot; pivot = new Vector2(0, 1); isCreating = true; _lastStr = contentStr; PrefabSetting settings = GlobalController.instance.prefabSetting; Transform obj; SpriteRenderer spr; FontData d; CharacterCell cell; BoxCollider2D col; float x = 0; BoxCollider2D prefabCol; List <CharacterCell> _lastList = new List <CharacterCell>(); for (int i = 0; i < _character.Count; i++) { _lastList.Add(_character[i]); } _character.Clear(); chars = contentStr.ToCharArray(); for (int i = 0; i < chars.Length; i++) { if (analyse.fontDatas.TryGetValue(System.Convert.ToInt32(chars[i]), out d)) { if (!_createColliderForChar || d.colList == null || d.colList.Length == 0) { obj = GameObject.Instantiate(settings.charPrefab0).transform; cell = obj.GetComponent <CharacterCell>(); } else { if (d.colList.Length == 1) { obj = GameObject.Instantiate(settings.charPrefab1).transform; } else { obj = GameObject.Instantiate(settings.charPrefab2).transform; } cell = obj.GetComponent <CharacterCell>(); for (int j = 0; j < cell.colList.Length; j++) { col = cell.colList[j]; prefabCol = d.colList[j]; col.size = new Vector2(prefabCol.size.x, prefabCol.size.y); col.offset = new Vector2(prefabCol.offset.x, prefabCol.offset.y); } } obj.tag = Config.TAG_CHAR; obj.gameObject.layer = transform.gameObject.layer; spr = obj.GetComponent <SpriteRenderer>(); CharacterColorData colorData; if (CharacterColor.instance.colorDic.TryGetValue(d.id, out colorData)) { spr.color = colorData.color; } else { spr.color = color; } spr.sortingOrder = 1; obj.transform.SetParent(transform, false); obj.name = chars[i].ToString(); obj.transform.localPosition = new Vector2(x, -d._actualOffsetY); if (i < _lastList.Count) { copy(_lastList[i].gameObject, obj.gameObject); } x += d.actualAdvance; spr.sprite = d.spr; cell.tf = obj.transform; cell.fontData = d; _character.Add(cell); } } for (int i = 0; i < _lastList.Count; i++) { DestroyImmediate(_lastList[i].gameObject); } _textWidth = x; pivot = lastPivot; isCreating = false; }