본문 바로가기
728x90

c#30

Unity & C# ~ 시간을 나타내는 법(float to string) float timeValue = 90; // second try { string time1 = string.Format("{0:#0}:{1:00}", Mathf.Floor(timeValue / 60), Mathf.Floor(timeValue) % 60); Debug.Log($"Change time second : {time1}"); } catch(Exception e) { Debug.LogError($"timeValue error {e}"); } try { string time2 = string.Format("{0:00}:{1:00}", Mathf.Floor(timeValue / 60), Mathf.Floor(timeValue) % 60); Debug.Log($"Change time second2 : {.. 2023. 11. 3.
Unity & C# ~ 한/영 전환 하는 클래스 using System; using System.Diagnostics; using System.Runtime.InteropServices; public class ImeChange { #region imm32.dll :: Get_IME_Mode IME가져오기 [DllImport("imm32.dll")] public static extern IntPtr ImmGetContext(IntPtr hWnd); [DllImport("imm32.dll")] public static extern bool ImmSetConversionStatus(IntPtr hIMC, int fdwConversion, int fdwSentence); [DllImport("imm32.dll")] private static extern I.. 2023. 6. 29.
Unity & C# ~ 이미지 파일을 로드하여 스프라이트로 만들기 (Image file Load to Sprite) - 저장된 이미지 경로를 가지고 이미지를 로드하여 스프라이트로 형 변환을 한 후, 유니티 image ui에 넣기 using System.IO; using UnityEngine; using UnityEngine.UI; public Image image;// unity ui image public string filePath;// image file path public Vector2 imageSize;// image size x : width, y : height public void LoadImage() { byte[] byteTexture = File.ReadAllBytes(filePath);// 파일 불러오기 Texture2D texture2d = new Texture2D((int)imageSize... 2023. 3. 14.
Unity & C# ~ JsonConvert 사용법 using System; using System.IO; using UnityEngine; using Newtonsoft.Json; //serializable data [Serializable] public class TestData { public string testStr; public TestData(string _inputString) { testStr = _inputString; } } public class TestJson : MonoBehaviour { // Start is called before the first frame update void Start() { //load string filePath = Application.dataPath + "/TestData.json"; string.. 2023. 2. 24.
Unity & C# ~ Additive Load된 씬의 라이팅 세팅 가져오는 법 유니티 라이팅 세팅은 활성화된 씬의 세팅을 가져오는데 additive load된 씬은 활성화된 씬이 아니기 때문에 additive laod된 씬의 라이팅 정보를 가져오지 않는다. 그래서 additive load할 씬의 라이팅 정보를 가져와 적용할 때는 해당 씬을 활성화 시켜줘야 한다. using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class TestAdditiveSceneManager : MonoBehaviour { [SerializeField] Button button; // Start is called before the first frame update void Start() { button.onC.. 2023. 2. 9.
Unity & C# ~ Regex 사용해보기 c#에서 문자열 패턴을 찾거나 문자열의 잘못된 입력 등을 확인할 때 사용할 수 있음. 메타문자 ^ 첫 글자 $ 마지막 글자 \w 문자(영숫자) \s 공백 \d 숫자 * 0 혹은 그 이상 + 1개 이상 ? 0 또는 1 . 새로운 라인을 제외한 한 문자 [ ] 가능한 문자 [^ ] 가능하지 않은 문자 [ - ] 가능한 문자 범위 {n , m} 최소 n개부터 최대 m개까지 ( ) 그룹 | 논리 OR 예시 // a-z 범위의 문자 string match = @"[a-z]"; // '강'으로 시작하고 '구'로 끝나는 문자 string match = @"^강\w*구$"; // 2자리 숫자 string match = @"\d{2}"; // 핸드폰 번호 ex) 000-0000-0000 string match = @"(.. 2022. 12. 28.
SMALL