/// <summary> /// 봇 인스턴스의 메인 Thread를 시작합니다. /// </summary> /// <param name="minimizeWindow">봇 가동 완료 시 채팅창을 최소화할지 여부</param> protected void StartMainTask(bool minimizeWindow = false) { if (!KakaoTalk.IsInitialized()) { KakaoTalk.InitializeManually(); } if (Type == TargetTypeOption.Self) { Window = KakaoTalk.MainWindow.Friends.StartChattingWithMyself(RoomName, minimizeWindow); } else if (Type == TargetTypeOption.Friend) { Window = KakaoTalk.MainWindow.Friends.StartChattingWith(RoomName, minimizeWindow); } else if (Type == TargetTypeOption.Group) { Window = KakaoTalk.MainWindow.Chatting.StartChattingAt(RoomName, minimizeWindow); } KakaoTalk.Message[] messages; while ((messages = Window.GetMessagesUsingClipboard()) == null) { Thread.Sleep(GetMessageInterval); } SendMainTaskStartNotice(); while ((messages = Window.GetMessagesUsingClipboard()) == null) { Thread.Sleep(GetMessageInterval); } LastMessageIndex = messages.Length - 1; MainTaskRunner = new Thread(new ThreadStart(RunMain)); MainTaskRunner.Start(); }
public void Chat(bool isSend, string text, string user, Sprite picture) { if (text.Trim() == "") { return; } bool isBottom = scrollBar.value <= 0.00001f; //보내는 사람은 노랑, 받는 사람은 흰색영역을 크게 만들고 텍스트 대입 KakaoTalk kakaoTalk = Instantiate(isSend ? myKakaoTalk : otherKakaoTalk).GetComponent <KakaoTalk>(); kakaoTalk.transform.SetParent(ContentRect.transform, false); kakaoTalk.messageBoxRect.sizeDelta = new Vector2(600, kakaoTalk.messageBoxRect.sizeDelta.y); kakaoTalk.messageTextRect.GetComponent <Text>().text = text; Fit(kakaoTalk.messageBoxRect); // 두 줄 이상이면 크기를 줄여가면서, 한 줄이 아래로 내려가면 바로 전 크기를 대입 float X = kakaoTalk.messageTextRect.sizeDelta.x + 42; float Y = kakaoTalk.messageTextRect.sizeDelta.y; if (Y > 49) { for (int i = 0; i < 200; i++) { kakaoTalk.messageBoxRect.sizeDelta = new Vector2(X - i * 2, kakaoTalk.messageBoxRect.sizeDelta.y); Fit(kakaoTalk.messageBoxRect); if (Y != kakaoTalk.messageTextRect.sizeDelta.y) { kakaoTalk.messageBoxRect.sizeDelta = new Vector2(X - (i * 2) + 2, Y); break; } } } else { kakaoTalk.messageBoxRect.sizeDelta = new Vector2(X, Y); } // 현재 것에 분까지 나오는 날짜와 유저이름 대입 DateTime t = DateTime.Now; kakaoTalk.Time = t.ToString("yyyy-MM-dd-HH-mm"); kakaoTalk.userNameText.text = user; kakaoTalk.userImage.sprite = picture; if (isItCreated[0] == true && isSend == true) { kakaoTalk.votedImage.SetActive(true); } // 현재 것은 항상 새로운 시간 대입 int hour = t.Hour; if (t.Hour == 0) { hour = 12; } else if (t.Hour > 12) { hour -= 12; } kakaoTalk.timeText.text = (t.Hour > 12 ? "오후 " : "오전 ") + hour + ":" + t.Minute.ToString("D2"); Fit(kakaoTalk.messageBoxRect); Fit(kakaoTalk.katalkRect); Fit(ContentRect); // 스크롤바가 위로 올라간 상태에서 메시지를 받으면 맨 아래로 내리지 않음 if (!isSend && !isBottom) { return; } Invoke("ScrollDelay", 0.03f); }