static void Main(string[] args) { TestDele testDele = new TestDele(); onClick dm01 = new onClick(testDele.MouseClick); dm01("Left"); // == MouseClick("Left"); // Delegate dm01가 onClick의 MouseClick에 대한 대리권한을 가졌다. // 이는 dm01가 MouseClick에 대한 포인터를 가졌다는 의미로 // dm01을 사용함으로서 MouseClick을 사용할 수 있다. dm01 = new onClick(testDele.KeyBoradClick); // 이렇게 초기화가 가능하다. dm01("Space"); dm01 = testDele.func; // 이렇게 이미 객체가 생성이 되어있는 상태라면 이와 같이 생성이 가능하다. dm01("func (string)"); Console.WriteLine(); onClick dm02 = new onClick(testDele.KeyBoradClick); onClick dm03 = new onClick(testDele.MouseClick); Console.WriteLine("dm01에 dm01, dm02, dm03 권한 부여"); dm01 = dm01 + dm02 + dm03; // 위와 같은 방법으로 dm01는 기존의 func에 대한 권한에 더하여 // KeyBoradClick과 MouseClick의 권한 2가지를 더하여 사용할 수 있다. // 연산자 중복을 통한 overloading 이다. dm01("Combine"); Console.WriteLine("\n dm02 권한 삭제"); dm01 = dm01 - dm02; dm01("Selected"); Console.WriteLine(); onClick ob; ob = delegate(string str) { // 입력 메소드. 즉흥적으로 생성이 가능하다. // 이렇게 함으로서 간단한 함수를 생성이 가능하다. Console.WriteLine("str = {0}", str); }; ob("Creating Method at Delegate"); }
//create symbol represent access to data void Start() { GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); //difine the shape sphere.gameObject.transform.position = new Vector3(0, 0, 0); //location of symbol //should be attach to object //var boxCollider = sphere.gameObject.AddComponent<BoxCollider>(); //boxCollider.isTrigger = true; onClick oc = sphere.gameObject.AddComponent(typeof(onClick)) as onClick; //onclick reaction, should open text mesh onGUI og = sphere.gameObject.AddComponent(typeof(onGUI)) as onGUI; //add other componment to match the change with main component GameObject sphere1 = GameObject.CreatePrimitive(PrimitiveType.Sphere); //difine the shape sphere1.gameObject.transform.position = new Vector3(3, 0, 0); //location of symbol //should be attach to object //var boxCollider = sphere.gameObject.AddComponent<BoxCollider>(); //boxCollider.isTrigger = true; onClick oc1 = sphere1.gameObject.AddComponent(typeof(onClick)) as onClick; //onclick reaction, should open text mesh onGUI og1 = sphere1.gameObject.AddComponent(typeof(onGUI)) as onGUI; //add other componment to match the change with main component GameObject sphere2 = GameObject.CreatePrimitive(PrimitiveType.Sphere); //difine the shape sphere2.gameObject.transform.position = new Vector3(-3, 0, 0); //location of symbol //should be attach to object //var boxCollider = sphere.gameObject.AddComponent<BoxCollider>(); //boxCollider.isTrigger = true; onClick oc2 = sphere2.gameObject.AddComponent(typeof(onClick)) as onClick; //onclick reaction, should open text mesh onGUI og2 = sphere2.gameObject.AddComponent(typeof(onGUI)) as onGUI; //add other componment to match the change with main component }
public void registerOnClickCallBack(onClick callback) { onClickCallbacks.Add(callback); }