11using UnityEngine ;
22using UnityEngine . UI ;
3- using System . Threading . Tasks ;
43using System . Collections . Generic ;
54
65namespace OpenAI
@@ -9,17 +8,16 @@ public class TextCompletionChat : MonoBehaviour
98 {
109 [ SerializeField ] private InputField inputField ;
1110 [ SerializeField ] private Button button ;
12- [ SerializeField ] private RectTransform context ;
11+ [ SerializeField ] private ScrollRect scroll ;
1312
1413 [ SerializeField ] private RectTransform sent ;
1514 [ SerializeField ] private RectTransform received ;
1615
1716 private float height ;
1817 private OpenAIApi openai = new OpenAIApi ( ) ;
1918
20- private List < ChatMessage > messages = new List < ChatMessage > ( ) ;
21- private string prompt = "Act as a random stranger in a chat room and reply to the questions.\n Q: " ;
2219 private string userInput ;
20+ private string prompt = "Act as a random stranger in a chat room and reply to the questions.\n Q: " ;
2321
2422 private void Start ( )
2523 {
@@ -28,14 +26,15 @@ private void Start()
2826
2927 private void AppendMessage ( string message , bool isUser = true )
3028 {
31- context . SetSizeWithCurrentAnchors ( RectTransform . Axis . Vertical , 0 ) ;
29+ scroll . content . SetSizeWithCurrentAnchors ( RectTransform . Axis . Vertical , 0 ) ;
3230
33- var item = Instantiate ( isUser ? sent : received , context ) ;
34- LayoutRebuilder . ForceRebuildLayoutImmediate ( item ) ;
31+ var item = Instantiate ( isUser ? sent : received , scroll . content ) ;
3532 item . GetChild ( 0 ) . GetChild ( 0 ) . GetComponent < Text > ( ) . text = message ;
3633 item . anchoredPosition = new Vector2 ( 0 , - height ) ;
34+ LayoutRebuilder . ForceRebuildLayoutImmediate ( item ) ;
3735 height += item . sizeDelta . y ;
38- context . SetSizeWithCurrentAnchors ( RectTransform . Axis . Vertical , height ) ;
36+ scroll . content . SetSizeWithCurrentAnchors ( RectTransform . Axis . Vertical , height ) ;
37+ scroll . verticalNormalizedPosition = 0 ;
3938 }
4039
4140 private async void SendReply ( )
0 commit comments