void setLoadedMouse() { for (int i = 0; i < changedMouseList.Count; i++) { if (changedMouseList [i] != null) { //se ho passato il tempo if (changedMouseList [i].changingTime < Time.time) { //mousePosition = changedMouseList[i].newMousePosition; InputMousePosition mousePos = changedMouseList[i].newMousePosition; Vector3 tempMouseWorldPos = new Vector3(mousePos.inputX, mousePos.inputY, mousePos.inputZ); Vector3 tempMouseScreenPos = Camera.main.WorldToScreenPoint(tempMouseWorldPos); InputMousePosition mousePosScreen = new InputMousePosition(); mousePosScreen.inputX = tempMouseScreenPos.x; mousePosScreen.inputY = tempMouseScreenPos.y; mousePosScreen.inputZ = tempMouseScreenPos.z; //mousePosition = new InputMousePosition(tempMouseScreenPos.x, tempMouseScreenPos.y, tempMouseScreenPos.z); mousePosition = mousePosScreen; changedMouseList.RemoveAt(i); } else { return; } } } }
// Update is called once per frame void Update() { //creo il bool per vedere se un bottone ha cambiato il suo stato bool[] changedButtonsBool = new bool[inputButtons.Length]; //creo il bool per vedere se un asse ha cambiato il suo stato bool[] changedAxisBool = new bool[inputAxis.Length]; //creo il bool per vedere se un asse ha cambiato il suo stato bool changedMouseBool = false; if (loadSaveState == LoadSaveState.Save) { //se un bottone cambia il suo stato, metto il relativo bool a true for (int i = 0; i < inputButtons.Length; i++) { changedButtonsBool [i] = verifyIfButtonChanged(inputButtons [i].name); } //se un asse cambia il suo stato, metto il relativo bool a true for (int i = 0; i < inputAxis.Length; i++) { changedAxisBool [i] = verifyIfAxisChanged(inputAxis [i].name); } //Debug.Log (verifyIfMouseChanged()); if (Input.mousePresent) { changedMouseBool = verifyIfMouseChanged(); } } if (loadSaveState != LoadSaveState.Load) { //funzioni per gestire l'input effettivo dell'utente, non quello caricato setButtons(); setAxis(); if (Input.mousePresent) { setMouse(); } } //se un bottone risulta aver cambiato il suo stato, dal proprio bool, lo salvo nella lista di bottoni cambiati, insieme al tempo di cambiamento if (loadSaveState == LoadSaveState.Save) { for (int i = 0; i < changedButtonsBool.Length; i++) { if (changedButtonsBool[i] == true) { InputButton tempInputButton = new InputButton(); tempInputButton.name = inputButtons[i].name; tempInputButton.buttonDown = inputButtons[i].buttonDown; tempInputButton.buttonUp = inputButtons[i].buttonUp; tempInputButton.buttonStay = inputButtons[i].buttonStay; ChangedButtons tempChanged = new ChangedButtons(Time.time, tempInputButton); changedButtonsList.Add(tempChanged); } } for (int i = 0; i < changedAxisBool.Length; i++) { if (changedAxisBool[i] == true) { InputAxis tempInputAxis = new InputAxis(); tempInputAxis.name = inputAxis[i].name; tempInputAxis.getAxisNormal = inputAxis[i].getAxisNormal; tempInputAxis.getAxisRaw = inputAxis[i].getAxisRaw; ChangedAxis tempChanged = new ChangedAxis(Time.time, tempInputAxis); changedAxisList.Add(tempChanged); } } if (Input.mousePresent && changedMouseBool) { Vector3 tempInputMouse = Input.mousePosition; //sarebbe meglio salvare le posizioni nel worldSpace, altrimenti sono in pixel, perciò relative alla risoluzione InputMousePosition tempInputMousePosition = new InputMousePosition(); /* * tempInputMousePosition.inputX = Input.mousePosition.x; * tempInputMousePosition.inputY = Input.mousePosition.y; * tempInputMousePosition.inputZ = Input.mousePosition.z; */ tempInputMousePosition.inputX = Camera.main.ScreenToWorldPoint(tempInputMouse).x; tempInputMousePosition.inputY = Camera.main.ScreenToWorldPoint(tempInputMouse).y; tempInputMousePosition.inputZ = Camera.main.ScreenToWorldPoint(tempInputMouse).z; ChangedMouse tempChanged = new ChangedMouse(Time.time, tempInputMousePosition); changedMouseList.Add(tempChanged); } /* * //salvataggio delle variabili del component transform degli oggetti da "correggere" * if ((Mathf.Abs (Time.time - lastCorrectionTime)) > correctionTime) * { * lastCorrectionTime = Time.time; * for (int i = 0; i<gameObjectsToControl.Count; i++) * { * if (gameObjectsToControl[i] != null && gameObjectsToControl[i].tag != "") * { * GameObjectToControl tempGOTC = new GameObjectToControl(); * * GameObject tempGO = GameObject.FindGameObjectWithTag(gameObjectsToControl[i].tag); * * tempGOTC.tag = gameObjectsToControl[i].tag; * //tempGOTC.gameObject = gameObjectsToControl[i].gameObject; * Vector3 tempPos = tempGO.transform.position; * tempGOTC.position = new Vect3(tempPos.x, tempPos.y, tempPos.z); * Vector3 tempScale = tempGO.transform.localScale; * tempGOTC.scale = new Vect3(tempScale.x, tempScale.y, tempScale.z); * Quaternion tempQuaternion = tempGO.transform.rotation; * tempGOTC.rotation = new Quat(tempQuaternion.x, tempQuaternion.y, tempQuaternion.z, tempQuaternion.w); * * ChangedObjects tempChanged = new ChangedObjects(Time.time, tempGOTC); * changedObjectsList.Add(tempChanged); * } * } * } */ } //se carico l'input da file, allora setto le relative variabili in modo che sembri input effettivo if (loadSaveState == LoadSaveState.Load) { setLoadedButtons(); setLoadedAxis(); setLoadedMouse(); } }
public ChangedMouse(float inputTime, InputMousePosition inputMousePosition) { this.changingTime = inputTime; this.newMousePosition = inputMousePosition; }