// Update is called once per frame void Update() { if (controller == null) { return; } // to switch node type, press all buttons while holding trigger // to turn an attacker on/off, press all buttons without trigger if ((controller.GetButton(PSMoveButton.Square) && controller.GetButton(PSMoveButton.Circle) && controller.GetButton(PSMoveButton.Cross) && controller.GetButton(PSMoveButton.Square)) && (controller.GetButtonDown(PSMoveButton.Square) || controller.GetButtonDown(PSMoveButton.Circle) || controller.GetButtonDown(PSMoveButton.Cross) || controller.GetButtonDown(PSMoveButton.Square)) ) { if (controller.Trigger > 0.5f) { if (type == 1) { type = 2; PlayerPrefs.SetInt(controller.Serial + "Type", 2); } else { type = 1; PlayerPrefs.SetInt(controller.Serial + "Type", 1); } } else { active = !active; } ResetLEDAndRumble(); } // if ( calibrationAllowed ) { // // Button presses // if ( controller.GetButtonDown(PSMoveButton.Circle) ) { // if ( !calibrating ) { // calibrating = true; // calibratingXMax = -2048; // calibratingXMin = 2048; // calibratingYMax = -2048; // calibratingYMin = 2048; // calibratingZMax = -2048; // calibratingZMin = 2048; // } // else { // calibrating = false; // PlayerPrefs.SetInt(controller.Serial + "Calibrated", 1); // PlayerPrefs.SetFloat(controller.Serial + "XMax", calibratingXMax); // PlayerPrefs.SetFloat(controller.Serial + "XMin", calibratingXMin); // PlayerPrefs.SetFloat(controller.Serial + "YMax", calibratingYMax); // PlayerPrefs.SetFloat(controller.Serial + "YMin", calibratingYMin); // PlayerPrefs.SetFloat(controller.Serial + "ZMax", calibratingZMax); // PlayerPrefs.SetFloat(controller.Serial + "ZMin", calibratingZMin); // LoadCalibration(); // ResetLEDAndRumble(); // } // } // accelerometer test // if ( !calibrating && (controller.Acceleration-lastAccel).magnitude > Game.Instance.attackAccelThreshold ) { // SetLED(Color.cyan); // SetLED(Color.black, 1f); // } // } mx = controller.Magnetometer.x; my = controller.Magnetometer.y; mz = controller.Magnetometer.z; // Debug.Log (mx.ToString() + " " + my.ToString() + " " + mz.ToString()); if (inGame) { float d = type == 1 ? Game.Instance.magnetThresholdTarget : Game.Instance.magnetThresholdAttacker; if ((mx != 0 || my != 0 || mz != 0) && (mx < mxMin - d || mx > mxMax + d || my < myMin - d || my > myMax + d || mz < mzMin - d || mz > mzMax + d)) { // alive = false; // SetLED(DEADCOLOR); // SetRumble(0); HitEvent(this); } } // if ( calibrating ) { // if ( mx > calibratingXMax ) calibratingXMax = mx; // if ( mx < calibratingXMin ) calibratingXMin = mx; // if ( my > calibratingYMax ) calibratingYMax = my; // if ( my < calibratingYMin ) calibratingYMin = my; // if ( mz > calibratingZMax ) calibratingZMax = mz; // if ( mz < calibratingZMin ) calibratingZMin = mz; // float target = 360; // float px = Math.Min(1, ( calibratingXMax - calibratingXMin ) / target); // float py = Math.Min(1, ( calibratingYMax - calibratingYMin ) / target); // float pz = Math.Min(1, ( calibratingZMax - calibratingZMin ) / target); // Debug.Log(px.ToString() + " " + py.ToString() + " " + pz.ToString()); // float p = Mathf.Min(px, Mathf.Min(py, pz)); // p = Mathf.Pow(p, 4f); // skew color curve // SetLED(new Color(1-p, p, 0)); // } if (mx == 0 && my == 0 && mz == 0) { ResetLEDAndRumble(); SetLED(Color.red); lostConnection = true; } else if (lostConnection) { lostConnection = false; ResetLEDAndRumble(); } // lastAccel = controller.Acceleration; // DEBUG // if ( hasBall ) { // Debug.Log(controller.Orientation.eulerAngles); // Debug.Log((controller.Orientation.eulerAngles - startOrientation)); // Debug.Log((controller.Orientation.eulerAngles - startOrientation).magnitude); // } // if ( Game.Instance.HoldingPlayer != null && Game.Instance.HoldingPlayer != this ) { // Debug.Log (Game.Instance.HoldingPlayer.GetOrientationDifference(this)); // } // float D = Game.Instance.magnetThreshold; // Debug.Log(mx.ToString() + " " + my.ToString() + " " + mz.ToString() + " / " + mxMin.ToString()+"-"+mxMax.ToString() + " " + myMin.ToString()+"-"+myMax.ToString() + " " + mzMin.ToString()+"-"+mzMax.ToString()); // if ( (mx!=0 || my!=0 || mz!=0 ) && ( mx < mxMin-D || mx > mxMax+D || my < myMin-D || my > myMax+D || mz < mzMin-D || mz > mzMax+D ) ) { // SetLED(Color.red); // GameObject.FindObjectOfType<AudioSource>().PlayOneShot(GameObject.FindObjectOfType<Game>().nodeHitSound); // } else { // SetLED(Color.green); // } }