전체 글 527

형식 매개 변수 T

using System.Collections; using System.Collections.Generic; using UnityEngine; public class NewBehaviourScript : MonoBehaviour { void Print(T value) where T : class{//class타입만 허용합니다. 가령 float타입 같은 경우는 struct이기 때문에 오류가 뜹니다. print(value); } // Start is called before the first frame update void Start() { // Print('a'); // string이기 때문에 void Print(string value)에 들어간다. Print("abc"); Print(4.3f); } // ..

인터페이스

using System.Collections; using System.Collections.Generic; using UnityEngine; abstract public class A: MonoBehaviour { abstract public void Abc(); } abstract public class B: MonoBehaviour { abstract public void Bbc(); } public interface iTest { // 다중 상속 void Bbc(); // 인터페이스에는 변수가 올 수 없다. // 함수, 프로퍼티, 인덱서, 이벤트만 올 수 있다. // 뼈대만 만들어야한다. } public class NewBehaviourScript : A, iTest { public override..

인덱서

using System.Collections; using System.Collections.Generic; using UnityEngine; public class Record { public int[] temp = new int[5]; // 인덱서 this는 해당 클래스를 지칭하는 예약어 // this는 인덱서의 이름 // int index로 매개변수를 받아줍니다. public int this[int index] { get { if(index >= temp.length) { Debug.Log("인덱스가 너무 큽니다."); return 0; }else { return temp[index]; } } // Record 클래스가 monoBehaviour를 상속받지 못하였기 때문에 print를 사용할 수 없습니..

상속

using System.Collections; using System.Collections.Generic; using UnityEngine; abstract public class Human : MonoBehaviour { public string humanName; public int humanAge; protected virtual void info(){ //virtual은 자식 클래스에서 재정의 할 수 있게 해주는 녀석 print("나는 인간입니다."); } // 추상함수 // 자식 클래스에서 기능을 완성시켜야 하는 함수 // 이걸 쓰게 되면 클래스 자체도 미완성이 되기 때문에 class에도 abstract를 써야한다. abstract protected void Name(); } using Syst..

델리게이트

using System.Collections; using System.Collections.Generic; using UnityEngine; public class test : MonoBehaviour { // 함수들을 관리해주는 녀석들 public delegate void ChainFunction(int value); public static event ChainFunction onStart; // ChainFunction chain; 이벤트를 선언하지 않을 경우 해줘야합니다. int power; int defence; public void SetPower(int value) { power += value; print("power의 값이" + value + "만큼 증가했습니다. 총 power의 값 = ..

구조체

using System.Collections; using System.Collections.Generic; using UnityEngine; // struct는 값타입 // class는 주소 타입 public enum Item{ Weapon, Sheild, Potion, } public struct MyStruct //상속이 불가 { public int a; //class와는 다르게 직접적인 값을 대입할 수 없다. public MyStruct(int _a, int _b, int _c, int _d){ //생성자 javaScript의 constructor와 같다 a = _a; b = _b; c = _c; d = _d; } public void GetA(int value){ a = 1; } } public ..

네임스페이스

using System.Collections; using System.Collections.Generic; using UnityEngine; using Keidy.Studio; using Keidy; // namespace 사용이유: 협업과 대형 프로젝트, 외부 라이브러리 클래스의 중복을 막기 위해 namespace Keidy { public class Youtube { } namespace Studio { public class Youtube { int like; public void SetLike(int value) { like = value; } public bool isLike(){ return like !=0; } } } } public class test : MonoBehaviour { You..