Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit 7f1dba0

Browse files
committed
整理了代码
1 parent 1a1cf70 commit 7f1dba0

File tree

93 files changed

+1899
-1796
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1899
-1796
lines changed

Assets/Hidden.meta renamed to Assets/EmojiText.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Hidden/Editor.meta renamed to Assets/EmojiText/Editor.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
using UnityEditor;
4+
using System.IO;
5+
using System.Collections.Generic;
6+
7+
namespace EmojiText.Taurus
8+
{
9+
public static class CreateSpriteAsset
10+
{
11+
[MenuItem("Assets/Create/Sprite Asset", false, 10)]
12+
static void main()
13+
{
14+
Object target = Selection.activeObject;
15+
if (target == null || target.GetType() != typeof(Texture2D))
16+
return;
17+
18+
Texture2D sourceTex = target as Texture2D;
19+
//整体路径
20+
string filePathWithName = AssetDatabase.GetAssetPath(sourceTex);
21+
//带后缀的文件名
22+
string fileNameWithExtension = Path.GetFileName(filePathWithName);
23+
//不带后缀的文件名
24+
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePathWithName);
25+
//不带文件名的路径
26+
string filePath = filePathWithName.Replace(fileNameWithExtension, "");
27+
28+
SpriteAsset spriteAsset = AssetDatabase.LoadAssetAtPath(filePath + fileNameWithoutExtension + ".asset", typeof(SpriteAsset)) as SpriteAsset;
29+
bool isNewAsset = spriteAsset == null ? true : false;
30+
if (isNewAsset)
31+
{
32+
spriteAsset = ScriptableObject.CreateInstance<SpriteAsset>();
33+
spriteAsset.TexSource = sourceTex;
34+
spriteAsset.ListSpriteGroup = GetAssetSpriteInfor(sourceTex);
35+
AssetDatabase.CreateAsset(spriteAsset, filePath + fileNameWithoutExtension + ".asset");
36+
}
37+
}
38+
39+
public static List<SpriteInforGroup> GetAssetSpriteInfor(Texture2D tex)
40+
{
41+
List<SpriteInforGroup> _listGroup = new List<SpriteInforGroup>();
42+
string filePath = UnityEditor.AssetDatabase.GetAssetPath(tex);
43+
44+
Object[] objects = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(filePath);
45+
46+
List<SpriteInfor> _tempSprite = new List<SpriteInfor>();
47+
48+
Vector2 _texSize = new Vector2(tex.width, tex.height);
49+
for (int i = 0; i < objects.Length; i++)
50+
{
51+
if (objects[i].GetType() != typeof(Sprite))
52+
continue;
53+
SpriteInfor temp = new SpriteInfor();
54+
Sprite sprite = objects[i] as Sprite;
55+
temp.Id = i;
56+
temp.Name = sprite.name;
57+
temp.Pivot = sprite.pivot;
58+
temp.Rect = sprite.rect;
59+
temp.Sprite = sprite;
60+
temp.Tag = sprite.name;
61+
temp.Uv = GetSpriteUV(_texSize, sprite.rect);
62+
_tempSprite.Add(temp);
63+
}
64+
65+
for (int i = 0; i < _tempSprite.Count; i++)
66+
{
67+
SpriteInforGroup _tempGroup = new SpriteInforGroup();
68+
_tempGroup.Tag = _tempSprite[i].Tag;
69+
//_tempGroup.Size = 24.0f;
70+
//_tempGroup.Width = 1.0f;
71+
_tempGroup.ListSpriteInfor = new List<SpriteInfor>();
72+
_tempGroup.ListSpriteInfor.Add(_tempSprite[i]);
73+
for (int j = i + 1; j < _tempSprite.Count; j++)
74+
{
75+
if (_tempGroup.Tag == _tempSprite[j].Tag)
76+
{
77+
_tempGroup.ListSpriteInfor.Add(_tempSprite[j]);
78+
_tempSprite.RemoveAt(j);
79+
j--;
80+
}
81+
}
82+
_listGroup.Add(_tempGroup);
83+
_tempSprite.RemoveAt(i);
84+
i--;
85+
}
86+
87+
return _listGroup;
88+
}
89+
90+
private static Vector2[] GetSpriteUV(Vector2 texSize, Rect _sprRect)
91+
{
92+
Vector2[] uv = new Vector2[4];
93+
uv[0] = new Vector2(_sprRect.x / texSize.x, (_sprRect.y + _sprRect.height) / texSize.y);
94+
uv[1] = new Vector2((_sprRect.x + _sprRect.width) / texSize.x, (_sprRect.y + _sprRect.height) / texSize.y);
95+
uv[2] = new Vector2((_sprRect.x + _sprRect.width) / texSize.x, _sprRect.y / texSize.y);
96+
uv[3] = new Vector2(_sprRect.x / texSize.x, _sprRect.y / texSize.y);
97+
return uv;
98+
}
99+
100+
}
101+
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using UnityEditor;
5+
using System;
6+
7+
namespace EmojiText.Taurus
8+
{
9+
public class EmojiShaderGUI : ShaderGUI
10+
{
11+
12+
public override void OnGUI(UnityEditor.MaterialEditor materialEditor, UnityEditor.MaterialProperty[] properties)
13+
{
14+
// base.OnGUI(materialEditor, properties);
15+
16+
Material targetMat = materialEditor.target as Material;
17+
18+
// see if redify is set, and show a checkbox
19+
bool redify = Array.IndexOf(targetMat.shaderKeywords, "EMOJI_ANIMATION") != -1;
20+
EditorGUI.BeginChangeCheck();
21+
redify = EditorGUILayout.Toggle("Emoji Animation", redify);
22+
if (EditorGUI.EndChangeCheck())
23+
{
24+
// enable or disable the keyword based on checkbox
25+
if (redify)
26+
targetMat.EnableKeyword("EMOJI_ANIMATION");
27+
else
28+
targetMat.DisableKeyword("EMOJI_ANIMATION");
29+
}
30+
}
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEditor;
4+
using UnityEditor.UI;
5+
using UnityEngine;
6+
7+
namespace EmojiText.Taurus
8+
{
9+
[CustomEditor(typeof(InlineText), true)]
10+
[CanEditMultipleObjects]
11+
public class TextEditor : GraphicEditor
12+
{
13+
#region 属性
14+
private InlineText _inlineText;
15+
private string _lastText;
16+
SerializedProperty _text;
17+
SerializedProperty m_Text;
18+
SerializedProperty m_FontData;
19+
GUIContent _inputGUIContent;
20+
GUIContent _outputGUIContent;
21+
#endregion
22+
protected override void OnEnable()
23+
{
24+
base.OnEnable();
25+
_lastText = "";
26+
_inputGUIContent = new GUIContent("Input Text");
27+
_outputGUIContent = new GUIContent("Output Text");
28+
29+
_text = serializedObject.FindProperty("_text");
30+
m_Text = serializedObject.FindProperty("m_Text");
31+
m_FontData = serializedObject.FindProperty("m_FontData");
32+
33+
_inlineText = target as InlineText;
34+
}
35+
36+
public override void OnInspectorGUI()
37+
{
38+
serializedObject.Update();
39+
EditorGUILayout.PropertyField(_text, _inputGUIContent);
40+
EditorGUILayout.PropertyField(m_Text, _outputGUIContent);
41+
EditorGUILayout.PropertyField(m_FontData);
42+
AppearanceControlsGUI();
43+
RaycastControlsGUI();
44+
serializedObject.ApplyModifiedProperties();
45+
//更新字符
46+
if (_inlineText != null && _lastText != _text.stringValue)
47+
{
48+
_inlineText.text = _text.stringValue;
49+
_lastText = _text.stringValue;
50+
}
51+
}
52+
}
53+
54+
}

0 commit comments

Comments
 (0)