/// <summary> /// 改变sprite隶属的组 /// </summary> private void ChangeTag(string newTag, SpriteInfo si) { if (newTag == si.tag) { return; } //从旧的组中移除 SpriteInfoGroup oldSpriteInforGroup = spriteAsset.listSpriteGroup.Find(sig => sig.tag == si.tag); if (oldSpriteInforGroup != null && oldSpriteInforGroup.spritegroups.Contains(si)) { oldSpriteInforGroup.spritegroups.Remove(si); } //如果旧的组为空,则删掉旧的组 if (oldSpriteInforGroup.spritegroups.Count <= 0) { spriteAsset.listSpriteGroup.Remove(oldSpriteInforGroup); } si.tag = newTag; //添加到新的组 SpriteInfoGroup newSpriteInforGroup = spriteAsset.listSpriteGroup.Find(sig => sig.tag == newTag); if (newSpriteInforGroup != null) { newSpriteInforGroup.spritegroups.Add(si); } EditorUtility.SetDirty(spriteAsset); }
private void ShowCells() { for (int i = 0; i < spriteAsset.listSpriteGroup.Count; i++) { SpriteInfoGroup group = spriteAsset.listSpriteGroup[i]; GUILayout.BeginHorizontal("HelpBox"); this.AddFoldOutBtn(group.tag, group); group.size = EditorGUILayout.FloatField("size:", group.size); group.width = EditorGUILayout.FloatField("wid:", group.width); group.x = EditorGUILayout.FloatField("x:", group.x); group.y = EditorGUILayout.FloatField("y:", group.y); GUILayout.EndHorizontal(); #region 展开的sprite组,显示所有sprite属性 if (showdata == group) { for (int j = 0; j < group.spritegroups.Count; j++) { SpriteInfo info = group.spritegroups[j]; ShowCell(info); } } #endregion } }
void FillSpriteTag(InlineText text, StringBuilder stringBuilder, Match match, int matchindex, int atlasId, string atlasTag) { if (text.Manager != null && text.Manager.CanRendering(atlasId) && text.Manager.CanRendering(atlasTag)) { SpriteAsset sprAsset; SpriteInfoGroup tagSprites = text.Manager.FindSpriteGroup(atlasTag, out sprAsset); if (tagSprites != null && tagSprites.spritegroups.Count > 0) { if (!text.Manager.isRendering(sprAsset)) { text.Manager.PushRenderAtlas(sprAsset); } if (_SpaceGen == null) { _SpaceGen = new TextGenerator(); } if (cacheframecnt != Time.frameCount || cachetext != text) { cacheframecnt = Time.frameCount; cachetext = text; Vector2 extents = text.rectTransform.rect.size; TextGenerationSettings settings = text.GetGenerationSettings(extents); _SpaceGen.Populate(palceholder, settings); } IList <UIVertex> spaceverts = _SpaceGen.verts; float spacewid = spaceverts[1].position.x - spaceverts[0].position.x; float spaceheight = spaceverts[0].position.y - spaceverts[3].position.y; float autosize = Mathf.Min(tagSprites.size, Mathf.Max(spacewid, spaceheight)); float spacesize = Mathf.Min(spacewid, spaceheight); int fillspacecnt = Mathf.RoundToInt(autosize / spacesize); for (int i = 0; i < fillspacecnt; i++) { stringBuilder.Append(palceholder); } if (fillspacecnt > 0) { SpriteTagInfo tempSpriteTag = new SpriteTagInfo(); tempSpriteTag.ID = atlasId; tempSpriteTag.Tag = atlasTag; tempSpriteTag.Size = new Vector2(autosize, autosize); tempSpriteTag.pos = new Vector3[4]; tempSpriteTag.uv = tagSprites.spritegroups[0].uv; tempSpriteTag.FillIdxAndPlaceHolder(stringBuilder.Length * 4 - 1, matchindex, fillspacecnt); text.AddFillData(tempSpriteTag); } } } }
private void ShowAnimations() { playSpeed = EditorGUILayout.IntSlider("speed", playSpeed, 1, 60); GUILayout.Space(5); EditorGUILayout.BeginVertical("window"); int column = 3; int m = 0; int fixhor = -1; for (int i = 0; i < spriteAsset.listSpriteGroup.Count; i++) { SpriteInfoGroup group = spriteAsset.listSpriteGroup[i]; if (group.spritegroups.Count > 1) { int index; if (!animationframes.TryGetValue(group, out index)) { animationframes[group] = 0; index = 0; } SpriteInfo info = group.spritegroups[index]; int c = m % column; if (c == 0) { EditorGUILayout.BeginHorizontal(); fixhor = 1; ShowAnimationCell(group, info); } else if (c == column - 1) { ShowAnimationCell(group, info); fixhor = 0; EditorGUILayout.EndHorizontal(); } else { ShowAnimationCell(group, info); } m++; } } if (fixhor > 0) { EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); GUILayout.Space(10); }
void MarkDirtyStaticEmoji() { if (alltexts != null && alltexts.Count > 0) { if (listeners == null) { listeners = new Dictionary <InlineText, ListenerData>(); } for (int i = 0; i < alltexts.Count; ++i) { InlineText text = alltexts[i]; List <IFillData> emojidata = text.PopEmojiData(); if (text != null && emojidata != null && emojidata.Count > 0 && allatlas != null && allatlas.Count > 0) { bool isdirty = false; ListenerData data = null; if (listeners.TryGetValue(text, out data)) { isdirty = data.Dirty(text); if (isdirty) { data.Set(text); } } else { data = new ListenerData(); data.Set(text); listeners.Add(text, data); } int staticcnt = 0; for (int j = 0; j < emojidata.Count; ++j) { IFillData taginfo = emojidata[j]; SpriteAsset asset = null; SpriteInfoGroup groupinfo = manager.FindSpriteGroup(taginfo.Tag, out asset); if (groupinfo != null && groupinfo.spritegroups.Count == 1) { staticcnt++; } } if (staticcnt > 0 && isdirty) { this.TryRendering(text); } } } } }
public SpriteInfoGroup FindSpriteGroup(string TagName, out SpriteAsset resultatlas) { EmojiTools.BeginSample("Emoji_FindSpriteGroup"); #if UNITY_EDITOR && !EMOJI_RUNTIME resultatlas = null; SpriteInfoGroup result = null; if (_unityallAtlases != null) { for (int i = 0; i < _unityallAtlases.Count; ++i) { SpriteAsset asset = _unityallAtlases[i]; for (int j = 0; j < asset.listSpriteGroup.Count; ++j) { SpriteInfoGroup group = asset.listSpriteGroup[j]; if (group.tag.Equals(TagName)) { result = group; resultatlas = asset; break; } } } } if (_lostAssets == null) { _lostAssets = new List <string>(); } if (resultatlas != null && !PreparedAtlas.Contains(resultatlas.AssetName)) { if (!_lostAssets.Contains(resultatlas.AssetName)) { _lostAssets.Add(resultatlas.AssetName); } } EmojiTools.EndSample(); return(result); #else resultatlas = null; SpriteInfoGroup result = null; KeyValuePair <SpriteAsset, SpriteInfoGroup> data; if (_spritemap.TryGetValue(TagName, out data)) { result = data.Value; resultatlas = data.Key; } EmojiTools.EndSample(); return(result); #endif }
/// <summary> /// 新增标签 /// </summary> private void AddTagSure() { SpriteInfoGroup sig = new SpriteInfoGroup(); sig.tag = addTagName; spriteAsset.listSpriteGroup.Add(sig); spriteAsset.listSpriteGroup.Sort((l, r) => { return(l.tag.CompareTo(r.tag)); }); Reset(); EditorUtility.SetDirty(spriteAsset); }
bool CanRender(int atlasid, string key, ref TextCotext context, out SpriteInfoGroup group) { bool canrender = false; group = null; for (int i = 0; i < context.Refercens.Count; i++) { var refasset = context.Refercens[i]; if (refasset.ID == atlasid && context.GroupMapper.TryGetValue(key, out group)) { canrender = true; break; } } return(canrender); }
void RebuildTagList() { EmojiTools.BeginSample("Emoji_rebuildTags"); _alltags.Clear(); _spritemap.Clear(); #if UNITY_EDITOR && !EMOJI_RUNTIME if (_unityallAtlases != null) { for (int i = 0; i < _unityallAtlases.Count; ++i) { SpriteAsset asset = _unityallAtlases[i]; for (int j = 0; j < asset.listSpriteGroup.Count; ++j) { SpriteInfoGroup infogroup = asset.listSpriteGroup[j]; SpriteInfoGroup group; if (_alltags.TryGetValue(infogroup.tag, out group)) { Debug.LogErrorFormat("already exist :{0} ", infogroup.tag); } _alltags[infogroup.tag] = infogroup; } } } #else for (int i = 0; i < _sharedAtlases.Count; ++i) { SpriteAsset asset = _sharedAtlases[i]; for (int j = 0; j < asset.listSpriteGroup.Count; ++j) { SpriteInfoGroup infogroup = asset.listSpriteGroup[j]; SpriteInfoGroup group; if (_alltags.TryGetValue(infogroup.tag, out group)) { Debug.LogErrorFormat("already exist :{0} ", infogroup.tag); } _alltags[infogroup.tag] = infogroup; _spritemap[infogroup.tag] = new KeyValuePair <SpriteAsset, SpriteInfoGroup>(asset, infogroup); } } #endif EmojiTools.EndSample(); }
void UpdateFrame() { if (animations.Count > 0) { float current = (float)EditorApplication.timeSinceStartup; var en = animations.GetEnumerator(); while (en.MoveNext()) { SpriteInfoGroup group = en.Current.Key; float start = en.Current.Value; int shouldframe = Mathf.CeilToInt((current - start) * playSpeed); int maxframe = group.spritegroups.Count; int currentframe = shouldframe % maxframe; animationframes[group] = currentframe; } this.Repaint(); } }
private void ClickSurebtn() { if (string.IsNullOrEmpty(addTagName)) { Debug.Log("请输入新建标签的名称!"); } else { SpriteInfoGroup spriteInforGroup = spriteAsset.listSpriteGroup.Find(sig => sig.tag == addTagName); if (spriteInforGroup != null) { Debug.Log("该标签已存在!"); } else { AddTagSure(); } } }
private void ShowAnimationCell(SpriteInfoGroup group, SpriteInfo info) { EditorGUILayout.ObjectField("", info.sprite, typeof(Sprite), false, GUILayout.Width(80)); GUILayout.BeginVertical(); GUI.enabled = false; GUILayout.Label("Name:" + group.tag, GUILayout.Width(200)); GUI.enabled = true; if (GUILayout.Button("Play", GUILayout.Width(80))) { animations[group] = (float)EditorApplication.timeSinceStartup; } if (GUILayout.Button("Stop", GUILayout.Width(80))) { animations.Remove(group); } GUILayout.EndVertical(); }
void Fill(InlineText target, SpriteInfoGroup group, int elementidx, ref float linesize, ref TextElementResult textresult, out int fillsize) { fillsize = 0; float spacesize = Mathf.Max(_placesize.x, _placesize.y); float minsize = Mathf.Min(group.size, Mathf.Min(_placesize.x, _placesize.y)); if (minsize > 0.1f) { float autosize = Mathf.Min(group.size, spacesize); int fillspacecnt = Mathf.CeilToInt(autosize / minsize);; if (target.horizontalOverflow != HorizontalWrapMode.Overflow && fillspacecnt > 0) { float wid = target.rectTransform.rect.width; float fillwidth = fillspacecnt * (minsize + _space); //填充字符之间穿插了换行的情况 进行检测 if (wid - linesize < fillwidth) { fillspacecnt = 1; linesize = 0; textresult.ParseGroup.EmojiResult.GetFixedIndex().Add(elementidx); } else { linesize += fillwidth; } } fillsize = fillspacecnt; textresult.ParseGroup.EmojiResult.GetEmojiSize().Add(autosize); textresult.ParseGroup.EmojiResult.GetGroups().Add(group); } }
void PlayAnimation() { EmojiTools.BeginSample("Emoji_GroupAnimation"); if (alltexts != null) { if (_time == null) { _time = Time.timeSinceLevelLoad; } else { float deltatime = Time.timeSinceLevelLoad - _time.Value; int framecnt = Mathf.RoundToInt(deltatime * Speed); if (framecnt > 0) { List <string> joblist = ListPool <string> .Get(); for (int i = 0; i < alltexts.Count; ++i) { InlineText text = alltexts[i]; List <IFillData> emojidata = text.PopEmojiData(); if (emojidata != null && emojidata.Count > 0 && allatlas != null && allatlas.Count > 0) { for (int j = 0; j < emojidata.Count; ++j) { IFillData taginfo = emojidata[j]; if (taginfo == null || taginfo.ignore) { continue; } SpriteAsset asset = null; SpriteInfoGroup groupinfo = manager.FindSpriteGroup(taginfo.Tag, out asset); if (groupinfo != null && groupinfo.spritegroups.Count > 1) { int index = framecnt % groupinfo.spritegroups.Count; SpriteInfo sprInfo = groupinfo.spritegroups[index]; taginfo.uv = sprInfo.uv; //render next CanvasGraphicGroup group = FindGraphicGroup(text.canvas, asset.ID); if (group != null) { if (tempMesh == null) { tempMesh = UnitMeshInfoPool.Get(); } RefreshSubUIMesh(text, group, asset, taginfo.pos, taginfo.uv, joblist); if (group.isDirty) { group.graphic.SetVerticesDirty(); } joblist.Add(taginfo.Tag); } } } } } ListPool <string> .Release(joblist); } } } EmojiTools.EndSample(); }
void PlayAnimation() { EmojiTools.BeginSample("Emoji_UnitAnimation"); if (alltexts != null) { if (_time == null) { _time = Time.timeSinceLevelLoad; } else { float deltatime = Time.timeSinceLevelLoad - _time.Value; //at least one frame int framecnt = Mathf.RoundToInt(deltatime * Speed); if (framecnt > 0) { for (int i = 0; i < alltexts.Count; ++i) { InlineText text = alltexts[i]; List <IFillData> emojidata = text.PopEmojiData(); if (emojidata != null && emojidata.Count > 0 && allatlas != null && allatlas.Count > 0) { for (int j = 0; j < emojidata.Count; ++j) { IFillData taginfo = emojidata[j]; if (taginfo == null || taginfo.ignore) { continue; } SpriteAsset asset = null; SpriteInfoGroup groupinfo = manager.FindSpriteGroup(taginfo.Tag, out asset); if (groupinfo != null && groupinfo.spritegroups.Count > 1) { int index = framecnt % groupinfo.spritegroups.Count; SpriteInfo sprInfo = groupinfo.spritegroups[index]; taginfo.uv = sprInfo.uv; List <SpriteGraphic> list = null; SpriteGraphic target = FindGraphic(text, asset, out list); if (target) { if (tempMesh == null) { tempMesh = UnitMeshInfoPool.Get(); } if (renderData == null) { renderData = new Dictionary <Graphic, UnitMeshInfo>(emojidata.Count); } RefreshSubUIMesh(text, target, asset, taginfo.pos, taginfo.uv); } } } } } } } } EmojiTools.EndSample(); }
private void ShowBatchTools() { GUILayout.BeginVertical("HelpBox"); spriteAsset.AssetName = EditorGUILayout.TextField("AssetName:", spriteAsset.AssetName); spriteAsset.ID = EditorGUILayout.IntField("ID:", spriteAsset.ID); GUILayout.BeginHorizontal(); addTagName = EditorGUILayout.TextField("add Tag", addTagName); if (GUILayout.Button("Sure")) { ClickSurebtn(); } GUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); this.batchsize = EditorGUILayout.Vector2Field("batch size", this.batchsize); if (GUILayout.Button("Sure")) { for (int i = 0; i < spriteAsset.listSpriteGroup.Count; i++) { SpriteInfoGroup group = spriteAsset.listSpriteGroup[i]; group.size = this.batchsize.x; group.width = this.batchsize.y; } } EditorGUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("RestSize", GUILayout.Width(100))) { for (int i = 0; i < spriteAsset.listSpriteGroup.Count; i++) { SpriteInfoGroup group = spriteAsset.listSpriteGroup[i]; for (int j = 0; j < group.spritegroups.Count; ++j) { SpriteInfo info = group.spritegroups[j]; float value = Mathf.Max(info.sprite.rect.width, info.sprite.rect.height); group.size = Mathf.Max(value, group.size); group.width = 1; } } } if (GUILayout.Button("Clear Tag", GUILayout.Width(100))) { ClearTag(); } if (GUILayout.Button("batch pack Tags", GUILayout.Width(120))) { isPackingAnimation = !isPackingAnimation; this.animations.Clear(); this.animationframes.Clear(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
private void ShowWillPackCells() { EditorGUILayout.BeginHorizontal("HelpBox"); GUILayout.Label("Tag:", GUILayout.Width(50)); if (GUILayout.Button(aniTagName, "MiniPopup", GUILayout.Width(100))) { GenericMenu gm = new GenericMenu(); for (int i = 0; i < spriteAsset.listSpriteGroup.Count; i++) { SpriteInfoGroup group = spriteAsset.listSpriteGroup[i]; gm.AddItem(new GUIContent(group.tag), false, () => { aniTagName = group.tag; }); } gm.ShowAsContext(); } if (GUILayout.Button("Select All", GUILayout.Width(100))) { for (int i = 0; i < spriteAsset.listSpriteGroup.Count; i++) { SpriteInfoGroup group = spriteAsset.listSpriteGroup[i]; selections[group.tag] = group; } } if (GUILayout.Button("DisSelect All", GUILayout.Width(100))) { selections.Clear(); } if (GUILayout.Button("Pack into Animation", GUILayout.Width(150))) { if (!string.IsNullOrEmpty(aniTagName)) { List <SpriteInfoGroup> removelist = new List <SpriteInfoGroup>(); SpriteInfoGroup firstGroup = null; var en = selections.GetEnumerator(); while (en.MoveNext()) { SpriteInfoGroup group = en.Current.Value; if (firstGroup == null) { firstGroup = group; group.tag = aniTagName; } else { firstGroup.size = Mathf.Max(firstGroup.size, group.size); firstGroup.spritegroups.AddRange(group.spritegroups); removelist.Add(group); } } for (int i = 0; i < removelist.Count; ++i) { SpriteInfoGroup group = removelist[i]; this.spriteAsset.listSpriteGroup.Remove(group); } selections.Clear(); } } EditorGUILayout.EndHorizontal(); GUILayout.Space(2); int t = 0; for (int i = 0; i < spriteAsset.listSpriteGroup.Count; i++) { SpriteInfoGroup group = spriteAsset.listSpriteGroup[i]; EditorGUILayout.BeginHorizontal("HelpBox"); bool exist = selections.ContainsKey(group.tag); bool newselect = EditorGUILayout.Toggle(exist, GUILayout.Width(20)); if (newselect != exist) { if (newselect) { selections[group.tag] = group; } else { selections.Remove(group.tag); } } GUILayout.Label(string.Format("[{0}] : {1}", i, group.tag), GUILayout.Width(100)); AddFoldOutBtn("", group); EditorGUILayout.EndHorizontal(); for (int j = 0; j < group.spritegroups.Count; j++) { SpriteInfo info = group.spritegroups[j]; if (ReferenceEquals(showdata, group)) { ShowCell(info); } ++t; } } }