コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.anyKeyDown == true)
        {
            //print ("joystickuimanager anykey down");
            Canvas canvas = gameObject.GetComponent <Canvas>();
            if (canvas.enabled == false)
            {
                print("test joystickuimanager canvas enabled == false, this value may control by programmer using show or hide function from script");
                return;
            }
            //20160616 现在不需要通过LB,RB进行tab的操作,
//			if(Input.GetKeyDown(KeyCode.Joystick8Button4)){
//				//L
//				print("press l");
//				undoKeyButton();
//				return;
//			}
//			if(Input.GetKeyDown(KeyCode.JoystickButton4)
//				|| Input.GetKeyDown(KeyCode.LeftArrow)){//即使是leftarrow "Input.inputstring"还是null
//				//L

//				print("press 0l");
//				undoKeyButton();
//				return;
//			}
//			if (Input.GetKeyDown (KeyCode.Joystick8Button5)) {//暂时没有知道Joystick8是什么(JoystickButton5是普通的摇杆)
//				//R
//				print("press r");
//				doKeyButton();
//				return;
//			}
//			if (Input.GetKeyDown (KeyCode.JoystickButton5)
//				|| Input.GetKeyDown(KeyCode.RightArrow)) {//即使是rightarrow "Input.inputstring"还是null
//				//R
//				print("press 0r");
//				doKeyButton();
//				return;
//			}
//			if (Input.GetKeyDown (KeyCode.Tab)) {
//				doKeyButton ();
//				return;
//			}
            if (Input.inputString == "%" || Input.inputString == "~" ||
                Input.inputString == "{" || Input.inputString == "}")
            {
                return;
            }


            //传递到子元素,显示用---------------------------------------------------------
            //~只有能改变的时候才改变~
            for (int i = 0; i < gameObject.transform.childCount; i++)
            {
                Transform      t      = gameObject.transform.GetChild(i);
                JoystickButton script = t.GetComponent <JoystickButton> ();
                //script.keyHandler +=OnCustomerKeySelected;
                if (script != null)
                {
                    string pressedString = this.pressedString;
                    //demo 设置,不能用8,9做按钮
                    if (pressedString == "?|JoystickButton8" || pressedString == "?|JoystickButton9")
                    {
                        pressedString = "";
                    }
                    if (string.IsNullOrEmpty(pressedString) == false)                       //容易出错,要细心处理,只有不等于null的时候才触发
                    {
                        script.OnKeyDown(curr, pressedString.ToUpper());
                    }
                }
                //script.OnKeyDown(curr,Input.inputString.ToUpper());
            }
            //--------------------------------------------------------------------------
            if (isMouseDown() == true)
            {
                return;
            }
            //if (curr == "joystick") {
            //如果manager是摇杆状态,不可用手点击(
            //但实际情况是,这个界面本来就不应该接受touchcount)
            //也就是手点击,无论manager是什么情况,都不应出现,除了debug的时候
            if (Input.touchCount > 0)
            {
                return;
            }

            //}

            print("test joystickuimanager update function");
            //print (Input.inputString);//joystick的时候,会返回null ,print null会出错
            //			if (Input.inputString.ToUpper() == KeyCode.A.ToString()) {
            //				print ("tick a");
            //			}
            //


            if (string.IsNullOrEmpty(curr))
            {
                print("joystick manager, unrecognize curr id'");
                return;
            }
            //			if(string.IsNullOrEmpty(Input.inputString)){
            //				print ("joystick manager, unrecognize inputstring, especially test for joystick");
            //				return;
            //			}


            if (lst.ContainsKey(curr))
            {
                print("contain curr" + curr);
                print("Input string = " + Input.inputString);
                //lst [curr] = Input.inputString.ToUpper ();
                //如果

                lst[curr] = this.pressedString.ToUpper();
            }
            else
            {
                print("contain curr not" + curr);
                print("Input string = " + Input.inputString);
                //lst.Add(curr,Input.inputString.ToUpper());
                lst.Add(curr, this.pressedString.ToUpper());
            }
        }
    }