분류 전체보기 (45) 썸네일형 리스트형 코루틴, using System.Collections; using System.Collections.Generic; using UnityEngine; public class CoroutineTest : MonoBehaviour { //Co routine 협력하는 루틴 IEnumerator timeCo; // Start is called before the first frame update void Start() { //1번 미리 인스턴스를 빼서 넣어두는 방식// timeCo = DelayTimeCo(0.2f); StartCoroutine(timeCo); //IEnumerator 리턴타입을 가진 함수를 매개변수로 쓸때, //2번 그냥 함수를 넣는 방식// //StartCoroutine(DelayTimeCo(0.2f.. 프리팹 원래 상태로 리로드하기 using System.Collections.Generic; using UnityEngine; public class RestoreTransforms : MonoBehaviour { private List _transforms = new List(); private List _positions = new List(); private List _rotations = new List(); private void Awake() { var allTransforms = GetComponentsInChildren(); foreach(var t in allTransforms) { _transforms.Add(t); _positions.Add(t.position); _rotations.Add(t.localRotatio.. type type: 클래스의 데이터 타입에 대한 정보를 가져옴 Type type = slimeA.GetType(); FieldInfo[] fields = type.GetFields(); for(int i = -; i 게임 일시정지 void Update () { if (Input.GetKeyDown(KeyCode.T)) { if (IsPause == false) { Time.timeScale = 0; IsPause = true; return; } /*일시정지 비활성화*/ if (IsPause == true) { Time.timeScale = 1; IsPause = false; return; } } } Deep Copy 밑에 적어놓은 건 교수님 코드 예외 사항 많아서 그대로 쓰진 못하고 코드 연구할 때에만 쓰기! public static T DeepCopy(this T obj) where T : new() { Type type = obj.GetType(); if(type.IsClass) { T.clone = new T(); FieldInfo[] fields = type.GetFields(); foreach(FieldInfo field in fields) { field.SetValue(clone, (field.GetValue(obj)).DeepCopy()); } return (T)clone; } return (T)obj; } } 단점: 클래스가 멤버를 자기 자신으로 갖고 있을 때 무한반복해버림 Parameter / Arguments 차이 void Test(int a, int b) // Parameter { } void Start() { Test(50,40) //Argument } 게임 종료 버튼 public void ExitGame() { #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); // 어플리케이션 종료 #endif } 리플렉션 런타임 시점에 처리 가능. 컴파일 시점에 처리되는 것들 런타임 시점엔 모르니까.. 런타임 시점에서 리플렉션 써서 어거지로 갖고 오는거 나중에 이런게 생길거니까 미리 세팅 해놓으라고 위임하는 느낌인듯 using System.Reflection 추가 필수 type.GetFields 멤버 변수 가져오기 type.GetPropertys 멤버 프로퍼티 가져오기 MethodInfo[] methods = type.GetMethods(); //멤버 함수 가져옴 GetComponent("이름") 문자열은 바꾸기 쉬우니까.. ex) Debug.Log(type.GetField("tempValue"), GetValue(tempA)); 누구한테서 어떤 값을 가져올 것이냐. Type type = tempA.GetType(); t.. 이전 1 2 3 4 5 6 다음