일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
- Cell Shader
- Virtual Byte
- 게임 수학
- ColorGradingLutPass
- 작업 집합
- Windows Build
- Toon Shader
- 개인 바이트
- Rim Light
- 3d
- C언어
- Three(Two) Tone Shading
- 메모리 누수
- Cell Look
- AppSW
- OculusMotionVectorPass
- working set
- 벡터
- VR
- URP
- URP로 변경
- Specular
- Cartoon Rendering
- 프로그래밍 기초
- Private Bytes
- ASW(Application SpaceWarp)
- 가상 바이트
- Today
- Total
WinCNT
Unity에서 Slack으로 파일 업로드 해보기 본문
서론
퍼포먼스 체크한 것을 Slack으로 보내서 저장하는 일에 착수했다
아무것도 모르는 필자에게 사수가 “해줘”를 시전했지만, 레퍼런스가 없으면 너무 빡센 일이 될 게 분명해서 꼬치꼬치 캐물으니 다른 프로젝트에서 비슷한 처리를 하는 파일을 소개시켜줬다
왜 처음부터 알려주지 않는거지?
Slack에서 토큰 취득하기
우선은 Slack API에서 APP을 만들고 토큰을 받아야 한다는 것 같다
Slack API: Applications | Slack
Your Apps Don't see an app you're looking for? Sign in to another workspace.
api.slack.com
일단 기능은 봇을 선택
OAuth & Permissions의 Scopes에서 봇에 대한 파일 업로드에 관한 스코프를 설정해주자
그럼 Install to Workspace가 활성화되니 클릭하고 권한을 허가해주자
그럼 슬랙의 App부분에 지금 만든 앱이 추가된다
그럼 토큰을 획득할 수 있다!
(유저 토큰도 설정해서 취득되었다)
다음으로는 파일을 업로드할 채널에 지금 만든 앱을 추가하자
이러면 Slack에서 할 준비는 끝난다(아마…)
WWWForm과 UnityWebRequest
다음은 유니티의 WWWForm과 UnityWebRequest을 이용해서 슬랙의 채널에 파일을 업로드하자
필드에 대한 설정은 Slack API에서 확인할 수 있다
files.upload API method
Uploads or creates a file.
api.slack.com
필자는 다음과 같은 코드로 테스트 해봤다
처음에는 initial_comment까지만 있어도 되겠지…하고 해봤는데 안 되서 삽집을 좀 했다
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
public sealed class PerformanceChecker : MonoBehaviour
{
void Update()
{
if (Input.GetKeyUp(KeyCode.Return))
{
StartCoroutine(PostToSlack());
}
}
private IEnumerator PostToSlack()
{
yield return new WaitForEndOfFrame();
// 업로드할 파일(.txt) 내용
var sb = new StringBuilder();
sb.AppendLine("File Upload Test");
sb.AppendLine("...");
var form = new WWWForm();
form.AddField("token", "여기에는 Slack의 Bot 토큰을 입력한다");
form.AddField("channels", "여기에는 업로드할 채널의 이름이나 ID를 입력한다");
form.AddField("initial_comment", sb.ToString());
// 문자를 바이너리로 변환
byte[] data = System.Text.Encoding.ASCII.GetBytes(sb.ToString());
form.AddBinaryData("file", data);
form.AddField("filetype", "txt");
form.AddField("filename", "Test.txt");
var req = UnityWebRequest.Post("<https://slack.com/api/files.upload>", form);
yield return req.SendWebRequest();
if (req.result != UnityWebRequest.Result.Success)
Debug.LogError(req.error);
else
Debug.Log("Finished Uploading");
}
}
결과
성공!
마무리
샘플 코드가 있어서 삽질을 덜 하고 끝낼 수 있었다
다행!
참고 사이트
UnityからSlackにメッセージを送る【Unity】【Slack】 - (:3[kanのメモ帳]
UnityからSlackにメッセージを送る【Unity】【Slack】 - (:3[kanのメモ帳]
この記事でのバージョン Unity 2017.2.0f3 はじめに 今回はタイトル通り、UnityからSlackにメッセージを送ってみよう!という記事です。Unityで作ったゲームに組み込むというよりは、エディタ拡張
kan-kikuchi.hatenablog.com
Unity - Scripting API: WWWForm
Unity - Scripting API: WWWForm
Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close
docs.unity3d.com
'Unity > Unity 관련' 카테고리의 다른 글
유니티 간단 팁) 빌드 리포트(Build Report) 보는 법! (0) | 2023.08.08 |
---|---|
유니티 프로퍼티의 할당 체크를 == null외의 방법으로 해보기 (0) | 2023.08.03 |
유니티의 UI 시스템(uGUI)에 대해 조금 알아보기 (0) | 2023.07.24 |
유니티의 Bakery(라이트 맵 생성 에셋) 적용기 (0) | 2023.06.20 |
유니티 스크립트 게임 오브젝트의 레이어와 카메라의 컬링 마스크를 설정하기 (0) | 2023.05.19 |