public bool commit() { for (int i = 0; i < gameObject.transform.childCount; i++) { Transform child = gameObject.transform.GetChild(i); JoystickButton btn = child.GetComponent <JoystickButton> (); if (btn != null) { if (isContain(availableKeys, btn.keySrc)) { PlayerPrefs.SetString(btn.keySrc, btn.keyDefine); } } JoystickRadio radio = child.GetComponent <JoystickRadio> (); if (radio != null) { if (isContain(availableKeys, radio.keySrc)) { PlayerPrefs.SetString(radio.keySrc, radio.isSelect.ToString()); } } } return(true); //PlayerPrefs pref = new PlayerPrefs (); }
private Transform getChildByKey(string key) { //if (this.gameObject == null) { if (this._isNew == true) { return(null); } for (int i = 0; i < gameObject.transform.childCount; i++) { Transform t = gameObject.transform.GetChild(i); JoystickButton script = t.GetComponent <JoystickButton> (); if (script != null && script.keySrc == key) { return(t); } JoystickRadio radio = t.GetComponent <JoystickRadio> (); if (radio != null && radio.keySrc == key) { return(t); } } return(null); }
private int getKeyButtonIndex(string key) { // if (key == null) { // return -1; // } for (int i = 0; i < gameObject.transform.childCount; i++) { Transform t = gameObject.transform.GetChild(i); JoystickButton script = t.GetComponent <JoystickButton> (); //script.keyHandler +=OnCustomerKeySelected; JoystickRadio radio = t.GetComponent <JoystickRadio>(); if (script != null || radio != null) { if (script != null && script.keySrc == key) { return(i); } if (radio != null && t.name == key) { return(i); } //return -1; } else { return(-1); } } return(-1); }
private bool initByPlayerPrefs() { //Debug.Log ("JoystickUImanager init"); for (int i = 0; i < gameObject.transform.childCount; i++) { Transform t = gameObject.transform.GetChild(i); JoystickButton btn = t.GetComponent <JoystickButton> (); if (btn != null) { string value = PlayerPrefs.GetString(btn.keySrc); // if (string.IsNullOrEmpty(value) == false) { // btn.keyDefine = value; // } if (value != null) { // Debug.Log ("src=" + btn.keySrc + " & defin=" + value); btn.keyDefine = value; btn.updateText(); } } //在manager初始化的时候,radio还没初始化,貌似radio.selected没事 JoystickRadio radio = t.GetComponent <JoystickRadio> (); if (radio != null) { string value = PlayerPrefs.GetString(radio.keySrc); if (string.IsNullOrEmpty(value)) { if (value.ToLower() == "true" || value.ToLower() == "false") { if (bool.Parse(value) == true) { //radio.selected (); radio.isPressed = true; //only ui update, may not update the other ui, //but it's ok when this function call on the begining of class } else { } } } } } return(true); }
public void OnRadioSelected(object sender, JoystickRadio.RadioEventArgs e) { _model = e.Key; //JoystickRadio有disselected,在这里处理 for (int i = 0; i < gameObject.transform.childCount; i++) { Transform tran = gameObject.transform.GetChild(i); JoystickRadio radio = tran.GetComponent <JoystickRadio> (); if (radio != null) { if (tran.name == e.Key) { radio.setPressed(true); } else { radio.setPressed(false); } } } }
public void selected(Transform tran) { //触发unselected其他 //并且设置curr for (int i = 0; i < gameObject.transform.childCount; i++) { Transform child = gameObject.transform.GetChild(i); if (child.name == tran.name) { JoystickButton btn = child.GetComponent <JoystickButton> (); if (btn != null) { curr = btn.keySrc; btn.selected(); } JoystickRadio radio = child.GetComponent <JoystickRadio> (); if (radio != null) { curr = tran.name; radio.selected(); } } else { JoystickButton btn = child.GetComponent <JoystickButton> (); if (btn != null) { btn.unSelected(); } JoystickRadio radio = child.GetComponent <JoystickRadio> (); if (radio != null) { radio.unSelected(); } } } }
// Use this for initialization void Start() { for (int i = 0; i < gameObject.transform.childCount; i++) { Transform t = gameObject.transform.GetChild(i); JoystickButton script = t.GetComponent <JoystickButton> (); if (script != null) { script.keyHandler += OnCustomerKeySelected; } JoystickRadio radio = t.GetComponent <JoystickRadio> (); if (radio != null) { radio.keyHandler += OnRadioSelected; } } _instance = this; Hide(); //20160609 hide or show function is for customrize only //the code convert function is on a different channel(parse function) Button btn = gameObject.GetComponentInChildren <Button>(); EventTriggerListener.Get(btn.gameObject).onUp = onPointerUp; //depends on joystick is connected to current ios STouch touch = new STouch(); if (touch.isTouchPlatForm == false) { for (int i = 0; i < gameObject.transform.childCount; i++) { Transform t = gameObject.transform.GetChild(i); JoystickRadio radio = t.GetComponent <JoystickRadio> (); if (radio != null && radio.keySrc == "JS") { //print ("manager js select"); radio.isPressed = true; } } } else { for (int i = 0; i < gameObject.transform.childCount; i++) { Transform t = gameObject.transform.GetChild(i); JoystickRadio radio = t.GetComponent <JoystickRadio> (); if (radio != null && radio.keySrc == "NOR") { //print ("manager nor select"); //radio.selected ();//这里select不能 radio.isPressed = true; } } } this.initByPlayerPrefs(); this.initKeycodeMapping(); Debug.Log("jsm start event"); StartCoroutine(CheckForControllers()); //如果判断到蓝牙手柄,上下左右,将不可被修改 if (Input.GetJoystickNames().Length > 0) { for (int i = 0; i < gameObject.transform.childCount; i++) { Transform t = gameObject.transform.GetChild(i); JoystickButton script = t.GetComponent <JoystickButton> (); if (script != null) { if (script.keySrc == "A" || script.keySrc == "W" || script.keySrc == "D" || script.keySrc == "S") { script.enabled = false; } if (script.keySrc == "A") { script.Text = "<"; script.keyDefine = "<xnfleft"; } else if (script.keySrc == "W") { script.Text = "^"; script.keyDefine = "^xnfup"; } else if (script.keySrc == "D") { script.Text = ">"; script.keyDefine = ">xnfright"; } else if (script.keySrc == "S") { script.Text = ","; script.keySrc = ",xnfdown"; } ; } } } }