protected override void OnPopulateMesh(VertexHelper toFill) { toFill.Clear(); if (_Models == null || _Models.Count <= 0) { return; } Color32 color32 = color; //TODO lizhixiong //在计算定点的时候需要知道Unity的一些默认规则,否则容易陷入泥潭.. //1.在生成三角片的时候坐标原点是左下角,不是常用的屏幕坐标系(左上角),UV也一样。 //2.Unity ugui 默认的三角形的定点绘制顺序如下 // 0 1 // 3 2 // 索引 -> 012 230 for (int i = 0; i < _Models.Count; i++) { GTextEmotionModel model = _Models[i]; GEmotionAsset asset = model.GetEmotionAsset(); if (asset != null) { Vector4 outerUV = asset.GetOuterUV(); uvMin.Set(outerUV.x, outerUV.w); uvMax.Set(outerUV.z, outerUV.y); AddQuad(toFill, model.PosMin, model.PosMax, color32, uvMin, uvMax); } } }
public void Export() { string textPath = Application.dataPath + "/../emoji.txt"; StreamWriter sw = null; try { sw = new StreamWriter(textPath, false, new System.Text.UTF8Encoding(false)); sw.WriteLine("--所有Emoji对应ID "); string s_fileContent = ""; for (int i = 0; i < asset.Count; i++) { GEmotionAsset emotionAsset = asset.GetEmotionAssetAt(i); s_fileContent += asset.Index2Id(i).ToString() + ", " + emotionAsset.Name + "\n"; } sw.Write(s_fileContent); } catch (Exception e) { Debug.LogException(e); } finally { if (sw != null) { sw.Close(); } } Debug.Log(textPath); }
public override void OnInspectorGUI() { if (asset == null) { return; } if (GUILayout.Button("导出txt")) { Export(); } ve2ScorllView = GUILayout.BeginScrollView(ve2ScorllView); GUILayout.Label("表情信息列表"); for (int i = 0; i < asset.Count; i++) { GEmotionAsset emotionAsset = asset.GetEmotionAssetAt(i); //EditorGUILayout.ObjectField(emotionAsset.Name, emotionAsset.IconSprite, typeof(Sprite), false); GUILayout.Space(5); EditorGUILayout.LabelField("Id:" + asset.Index2Id(i).ToString() + " Name:" + emotionAsset.Name); //EditorGUILayout.LabelField("Povit:" + emotionAsset.Pivot.ToString() + " Rect:" + emotionAsset.Rect.ToString()); } GUILayout.EndScrollView(); }
public static List <GEmotionAsset> GetSpritesInfor(Texture2D tex, out int sysIconCount) { List <GEmotionAsset> emotionAssets = new List <GEmotionAsset>(); string filePath = UnityEditor.AssetDatabase.GetAssetPath(tex); Object[] objects = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(filePath); sysIconCount = 0; for (int i = 0; i < objects.Length; i++) { if (objects[i].GetType() == typeof(Sprite)) { GEmotionAsset temp = new GEmotionAsset(); Sprite sprite = objects[i] as Sprite; //temp.Id = i; temp.IconSprite = sprite; #if UNITY_EDITOR temp.Id = GetIDFromName(sprite.name); if (temp.Id < GTextEmotionAssets.EMOJI_ICON_START) { sysIconCount += 1; } #endif //UNITY_EDITOR emotionAssets.Add(temp); } } #if UNITY_EDITOR emotionAssets.Sort(CompareAsset); //sort by name #endif //UNITY_EDITOR if (sysIconCount >= GTextEmotionAssets.EMOJI_ICON_START) { Debug.LogError("sysIconCount > " + (GTextEmotionAssets.EMOJI_ICON_START - 1)); } for (int i = 1; i < sysIconCount; i++) { if (emotionAssets[i].Id - emotionAssets[i - 1].Id != 1) { Debug.LogError("CBT_SysEmoji 数字不连续 At" + emotionAssets[i - 1].Id); } } for (int i = sysIconCount + 1; i < emotionAssets.Count; i++) { if (emotionAssets[i].Id - emotionAssets[i - 1].Id != 1) { Debug.LogError("CBT_Emoji 数字不连续 At" + emotionAssets[i - 1].Id); } } return(emotionAssets); }
public GEmotionAsset GetEmotionAssetByName(string emotionName) { GEmotionAsset ast = this._EmotionAssets.Find(item => item.Name == emotionName); if (ast != null) { return(ast); } return(null); }
static int CompareAsset(GEmotionAsset x, GEmotionAsset y) { if (x.Id > y.Id) { return(1); } else if (x.Id == y.Id) { return(0); } else { return(-1); } }