본문 바로가기
728x90

Unity3D53

Unity & C# ~ TMPRO에서 텍스트 길이 아는 법 TMPRO에서는 UI의 길이뿐 아니라, 현재 사용한 텍스트의 길이를 확인할 수 있는 명령어가 있다. using TMPro; TMP_Text a; void Start() { float b = a.preferredWidth; //b => a의 계산된 텍스트 폭 } 2022. 7. 1.
Unity & C# ~ Text 말 줄임표 표기 '나랏말씀이....'과 같이 ... 말 줄임표를 쓰는 법 string a = "abcdefg"; int textLength = 3; void TextLengthFunc() { if(a.length > textLength) { var b = a.Substring(0, textLength) + "..."; } } //출력 abc... string.Substring(시작할 글자 index, 글자수 value) = 시작할 글자 index부터 글자수만큼 잘라냄 2022. 7. 1.
Unity & C# ~ multipart 코드 분석 참고 블로그 : https://spirit32.tistory.com/21 [C#] multipart/form-data 파일 업로드 C# 에서 multipart/form-data로 파일 업로드하는 예제. 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51.. spirit32.tistory.com //object형식으로 만들 클래스 //파일을 전송할 때 object형식으로 보내지 않으면 형식에러가 발생함 public class FormFile { public string Name { get; set; } .. 2022. 6. 28.
Unity & C# ~ List<Class> 형식 위의 이미지와 같은 List 형식을 만드는 방법 using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class ExampleList : MonoBehaviour { public ListExample listExample = new ListExample(); } [Serializable] public class ListExample { public List id; public ListExample() { id = new List(); } } [Serializable] public class ExampleGuide { public int id; public string name; p.. 2022. 6. 16.
Unity & C# ~ 음성 녹음 세팅 using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Start() { AudioSource aud = GetComponent(); aud.clip = Microphone.Start("Built-in Microphone", true, 10, 44100); aud.Play(); } } /* Microphone.Start(deviceName, loop, lengthSec, frequency); deviceName = string형, null값 사용 가능 loop = bool형, lengthSec에 도달하면 레코딩을 계속하거나 AudioClip을 처음부터 레코딩하는지 여부를 표시 lengthSec.. 2022. 6. 8.
Unity & C# ~ Anchor에 따른 Position 값 설정 앵커 위치가 바뀐 상태에서 position을 세팅할 때, local 또는 world 좌표로 세팅을 했는데 원하는 위치에 가지 않을 때가 있음. 이건 앵커 좌표와 local, world 좌표가 다른 것 때문에 발생함. 이럴때는 코드로 position값을 설정할 때, local이나 world좌표가 아닌 anchored 좌표로 설정하면 해결됨. anchor 좌표를 설정하기 위해서는 RectTransform 컴포넌트를 찾아야함. //anchoredRect의 x좌표를 anchoredObj의 anchoredPosition x 좌표로 설정하기 var AnchoredX = anchoredObj.GetComponent().anchoredPosition.x; anchoredRect.anchoredPosition = new.. 2022. 6. 7.
SMALL