protected void CheckTouch() { //if( GameManager.GetCurrentMode() != enabledMode ) return; TouchPhase aInputPhase = TouchPhase.Stationary; //int aTouchCount = Input.touchCount; // Touch Detection if(Input.touchCount > 0){ // Touch aInputPosition = Input.GetTouch(0).position; aInputPhase = Input.GetTouch(0).phase; }else{ // Mouse if( Input.GetMouseButtonDown(0) ){ aInputPhase = TouchPhase.Began; mPrevInputPosition = Input.mousePosition; } if( mPrevInputPosition != Input.mousePosition ){ aInputPhase = TouchPhase.Moved; } if( Input.GetMouseButtonUp(0) ){ aInputPhase = TouchPhase.Ended; //aTouchCount = 0; } aInputPosition = Input.mousePosition; } // Touch Phase Handling if( aInputPhase == TouchPhase.Began ){ // Add code if you want mBeginInputPosition = aInputPosition; mBeginInputButton = ""; Ray aRay = GUICamera.ScreenPointToRay( aInputPosition ); RaycastHit aHit; if( Physics.Raycast(aRay,out aHit, 1000.0f, GUILayerMask.value) ){ EX2D_Button button = aHit.collider.gameObject.GetComponent<EX2D_Button>(); if( button != null ){ mBeginInputButton = button.name; mPressedButton = button; Vector3 scale = mPressedButton.gameObject.transform.localScale; mPressedButton.gameObject.transform.localScale = new Vector3( scale.x * mPressedScale.x, scale.y * mPressedScale.y, scale.z * mPressedScale.z ); //OnTouched if (mPressedButton.CallBackClass!=null){ if (mPressedButton.CallBackClass.name == gameObject.name) { mPressedButton.OnTouchBeganCallBack(); } } } } OnTouchBegan(); // Call Override Method } else if( aInputPhase == TouchPhase.Moved ){ // Add code if you want mPrevInputPosition = aInputPosition; OnTouchMoved(); // Call Override Method } else if( aInputPhase == TouchPhase.Ended ){ bool unprocess = OnTouchEnded(); if( unprocess ){ Ray aRay = GUICamera.ScreenPointToRay( aInputPosition ); RaycastHit aHit; if( Physics.Raycast(aRay,out aHit, 1000.0f, GUILayerMask.value) ){ EX2D_Button button = aHit.collider.gameObject.GetComponent<EX2D_Button>(); if( button != null && button.name == mBeginInputButton ){ if( button.CallBackClass != null ){ if( !IsMoving() && button.enabled && button.CallBackClass.name == gameObject.name ){ button.InvokeCallBack(); } } } } } if( mPressedButton ){ //Vector3 scale = mPressedButton.gameObject.transform.localScale; mPressedButton.gameObject.transform.localScale = new Vector3( 1.0f, 1.0f, 1.0f ); } mPressedButton = null; } #if UNITY_ANDROID || UNITY_EDITOR if ( Input.GetKeyUp(KeyCode.Escape) ) { OnEscape(); } #endif }
// Button Event public virtual void OnButtonPressed( EX2D_Button iButton ) { }
//Use Alchemy public virtual void OnButtonTouched(EX2D_Button iButton) { }