본문 바로가기

프로그래밍12

C# XML 읽어오기 string _path = @"C:/Test.xml"; XmlDocument Document = new XmlDocument(); Document.Load(_path); XmlNodeList xmlNodeList = Document.SelectNodes("TestList"); 2020. 12. 1.
C# DateTime 포맷 // create date time 2008-03-09 16:05:07.123 DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123); String.Format("{0:y yy yyy yyyy}", dt); // "8 08 008 2008" year String.Format("{0:M MM MMM MMMM}", dt); // "3 03 Mar March" month String.Format("{0:d dd ddd dddd}", dt); // "9 09 Sun Sunday" day String.Format("{0:h hh H HH}", dt); // "4 04 16 16" hour 12/24 String.Format("{0:m mm}", dt); // "5 05" .. 2020. 9. 2.
유니티 Microphone 녹음 시작-종료 지점 잘라서 녹음. AudioClip recordClip; void StartRecordMicrophone() { recordClip = Microphone.Start("Built-in Microphone", true, 100, 44100); } void StopRecordMicrophone() { int lastTime = Microphone.GetPosition(null); if (lastTime == 0) return; else { Microphone.End(Microphone.devices[0]); float[] samples = new float[recordClip.samples]; recordClip.GetData(samples, 0); float[] cutSamples = new float[lastTime]; .. 2020. 8. 28.
C# 문자열로 변수이름 가져오기 public class MyClass { public string _datafile; public MyClass() { _datafile = "Hello"; } public void PrintField() { var result = this.GetType().GetField("_datafile").GetValue(this); Console.WriteLine(result); // will print Hello } } 2020. 4. 19.
C# 문자열을 int 리스트 / int 배열로 변환하기 // 문자열 -> int 리스트 string sNumbers = "1,2,3,4,5"; List numbers = new List(); umbers = sNumbers.Split(',').Select(Int32.Parse).ToList(); // 문자열 -> int 배열 string sNumbers = "1,2,3,4,5"; int[] numbers = sNumbers.Split(',').Select(n => Convert.ToInt32(n)).ToArray(); 출처: https://stackoverflow.com/questions/911717/split-string-convert-tolistint-in-one-line 2020. 2. 28.
유니티 UI 클릭했을 때, 클릭된 위치 값 가져오기 300x300 크기의 이미지에서 정중앙에 클릭하면 150,150의 좌표를 가져옴(피벗이 0,0 기준) 왼쪽 최하단을 클릭하면 0,0의 좌표를 가져옴. public void OnPointerClick(PointerEventData eventData) { if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(GetComponent(), eventData.position, eventData.pressEventCamera, out Vector2 localCursor)) return; Debug.Log("LocalCursor:" + localCursor); } 출처: https://answers.unity.com/questions/892333/find-xy-.. 2019. 11. 7.