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

Commit 0f3ee31

Browse files
committed
完成一个聊天的demo,但是好像特别卡,再看看
1 parent b4762f3 commit 0f3ee31

File tree

13 files changed

+107
-22
lines changed

13 files changed

+107
-22
lines changed

Diff for: Assets/TextInlineSprite/Examples/Prefabs.meta

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
15 KB
Binary file not shown.

Diff for: Assets/TextInlineSprite/Examples/Prefabs/ChatItem.prefab.meta

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

Diff for: Assets/TextInlineSprite/Examples/Scene/Chat.unity

62 KB
Binary file not shown.

Diff for: Assets/TextInlineSprite/Examples/Scene/Chat.unity.meta

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

Diff for: Assets/TextInlineSprite/Examples/Scene/Text.unity

808 Bytes
Binary file not shown.

Diff for: Assets/TextInlineSprite/Examples/Scripts/ChatTest.cs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/// ========================================================
2+
/// file:ChatTest.cs
3+
/// brief:
4+
/// author: coding2233
5+
/// date:
6+
/// version:v1.0
7+
/// ========================================================
8+
9+
using System.Collections;
10+
using System.Collections.Generic;
11+
using UnityEngine;
12+
using UnityEngine.UI;
13+
14+
public class ChatTest : MonoBehaviour {
15+
16+
[SerializeField]
17+
private GameObject _PreChatItem;
18+
[SerializeField]
19+
private RectTransform _ChatParent;
20+
[SerializeField]
21+
private RectTransform _ViewContent;
22+
[SerializeField]
23+
private InputField _InputText;
24+
25+
Vector2 _ChatTextSize = new Vector2(330.0f, 26.0f);
26+
float _ViewHight = 0.0f;
27+
28+
#region 点击发送
29+
public void OnClickSend()
30+
{
31+
string _chatString = _InputText.text;
32+
if (string.IsNullOrEmpty(_chatString))
33+
return;
34+
35+
GameObject _chatClone = Instantiate(_PreChatItem);
36+
_chatClone.transform.parent = _ChatParent;
37+
InlineText _chatText = _chatClone.transform.FindChild("Text").GetComponent<InlineText>();
38+
Image _chatImage= _chatClone.transform.FindChild("BG").GetComponent<Image>();
39+
_chatText.text = _chatString;
40+
Vector2 _imagSize = _ChatTextSize;
41+
if (_chatText.preferredWidth < _ChatTextSize.x)
42+
_imagSize.x = _chatText.preferredWidth+2.0f;
43+
if(_chatText.preferredHeight> _ChatTextSize.y)
44+
_imagSize.y = _chatText.preferredHeight;
45+
_chatImage.rectTransform.sizeDelta = _imagSize;
46+
47+
Vector2 _pos = new Vector2(0.0f, _ViewHight);
48+
_chatClone.GetComponent<RectTransform>().anchoredPosition= _pos;
49+
_chatText.ActiveText();
50+
_ViewHight += -_imagSize.y - 20.0f;
51+
_ViewContent.sizeDelta = new Vector2(_ViewContent.sizeDelta.x,Mathf.Abs( _ViewHight));
52+
}
53+
#endregion
54+
}

Diff for: Assets/TextInlineSprite/Examples/Scripts/ChatTest.cs.meta

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

Diff for: Assets/TextInlineSprite/Prefabs/TextInline.prefab

-2.73 KB
Binary file not shown.

Diff for: Assets/TextInlineSprite/Scripts/InlineManager.cs

+8-19
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,19 @@ public class InlineManager : MonoBehaviour {
2626
[Range(1,10)]
2727
private float _AnimationSpeed = 5.0f;
2828

29-
//// Use this for initialization
30-
//void Awake () {
31-
// Initialize();
32-
// }
33-
34-
// Update is called once per frame
35-
void Update () {
36-
//动态表情
37-
if(!_IsStatic)
38-
DrawSpriteAnimation();
39-
}
40-
41-
private void OnEnable()
29+
// Use this for initialization
30+
void Start()
4231
{
4332
Initialize();
4433
}
4534

46-
#if UNITY_EDITOR
47-
public void OnValidate()
48-
{
49-
Initialize();
35+
// Update is called once per frame
36+
void Update () {
37+
//动态表情
38+
if(!_IsStatic)
39+
DrawSpriteAnimation();
5040
}
51-
#endif
52-
41+
5342
#region 初始化
5443
void Initialize()
5544
{

Diff for: Assets/TextInlineSprite/Scripts/InlineText.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,19 @@ protected override void OnEnable()
5656
SetVerticesDirty();
5757
}
5858

59+
public void ActiveText()
60+
{
61+
OnEnable();
62+
}
63+
5964
public override void SetVerticesDirty()
6065
{
6166
base.SetVerticesDirty();
6267
if (!_InlineManager)
68+
{
69+
_OutputText = m_Text;
6370
return;
71+
}
6472

6573
//设置新文本
6674
_OutputText = GetOutputText();
@@ -148,7 +156,6 @@ public override float preferredHeight
148156

149157

150158
#region 计算Quad占位信息
151-
152159
void CalcQuadInfo(IList<UIVertex> verts)
153160
{
154161
foreach (var item in _SpriteInfo)
@@ -373,8 +380,6 @@ public void OnPointerClick(PointerEventData eventData)
373380
}
374381
}
375382
}
376-
377-
378383
#endregion
379384

380385
}

Diff for: ShotScreens/Thumbs.db

-149 KB
Binary file not shown.

Diff for: ShotScreens/text02.jpg

171 KB
Loading

0 commit comments

Comments
 (0)