// return true if PointerOver is removed private bool removePointerOver() { // We ask to remove PointerOver if we have at least a PointerOver already included inside gameObject OR a PointerOver will be added during next FYFY update if (this.gameObject.GetComponent <PointerOver>() != null || GameObjectManager.containActionFor(typeof(AddComponent <PointerOver>), new Transform [] { this.gameObject.transform })) { // We check if there is an UnbindGameObject action on my gameobject or on my parents. // If not, we have to use FYFY to remove PointerOver in order to keep families synchronized. // If so, we can't use FYFY because "remove" action will be queued after unbind and will not be able to proceed (unknown game object). Then we have to remove PointerOver component thanks to classic Unity function. Transform[] parents = this.gameObject.GetComponentsInParent <Transform>(true); // this.gameobject.transform is include if (GameObjectManager.containActionFor(typeof(UnbindGameObject), parents)) { // We find an unbind action, then we remove PointerOver component with classic Unity function PointerOver component = GetComponent <PointerOver>(); if (component != null) { Object.Destroy(component); } } else { // We don't find an unbind action then we remove PointerOver component with FYFY // This action will be added and treated in the current preprocess operation. // See MainLoop.preprocess for details. GameObjectManager.removeComponent <PointerOver>(this.gameObject, true); } return(true); } return(false); }
// Use to process your families. protected override void onProcess(int familiesUpdateCount) { PointerOver po = GameObject.FindGameObjectWithTag("HUD").GetComponent <PointerOver> (); if (po) { gameInfo.First().GetComponent <GameInfo> ().mouseOverHUD = true; } else { gameInfo.First().GetComponent <GameInfo> ().mouseOverHUD = false; } }
private void Awake() { _userIDPointerOver = _inputUserID.GetComponent <PointerOver>(); _addressPointerOver = _inputAddress.GetComponent <PointerOver>(); _portPointerOver = _inputPort.GetComponent <PointerOver>(); _numberPadPointerOver = _numberPad.GetComponent <PointerOver>(); AirVRClientInputField[] inputFields = GetComponentsInChildren <AirVRClientInputField>(true); foreach (AirVRClientInputField inputField in inputFields) { inputField.owner = this; } _numberPad.KeyClicked += onNumberPadKeyClicked; }
// Use to process your families. protected override void onProcess(int familiesUpdateCount) { GameInfo gi = gameInfo.First().GetComponent <GameInfo> (); //count the number of go selected gi.selectedGO = 0; foreach (GameObject go in clickableGO) { if (go.GetComponent <Clickable> ().isSelected) { gi.selectedGO++; } } //mouse over an object? gi.mouseNotOverObject = true; if (movingGO.First().GetComponent <Move>().directionGO.GetComponentInChildren <PointerOver>()) { gi.mouseNotOverObject = false; } else { foreach (GameObject go in clickableGO) { if (go.GetComponent <PointerOver>()) { gi.mouseNotOverObject = false; break; } } } if (gi.selectedGO != 0 && Input.GetMouseButtonDown(0) && !gi.mouseOverHUD && gi.mouseNotOverObject) //if there are selected objects and the left click is pressed over nothing { foreach (GameObject g in clickableGO) { //unselect all objects if (g.GetComponent <Clickable> ().isSelected) { g.GetComponent <Clickable> ().isSelected = false; } } } foreach (GameObject go in clickableGO) { PointerOver po = go.GetComponent <PointerOver> (); //select/unselect objects if (po && !gi.mouseOverHUD && Input.GetMouseButtonDown(0)) //if mouse over go and left mouse button clicked { bool s = go.GetComponent <Clickable>().isSelected; if (gi.selectedGO == gi.nbSelectableGO && !go.GetComponent <Clickable> ().isSelected) //if there is a selected go and the clicked go was not selected before click { foreach (GameObject g in clickableGO) { //unselect the selected go if (g.GetComponent <Clickable> ().isSelected) { g.GetComponent <Clickable> ().isSelected = false; } } } gi.selectedChanged = true; //true when the selected object just changed gi.selectedChangedEM = true; //same as selectedChanged but in editor mode go.GetComponent <Clickable> ().isSelected = !s; //select the clicked go or unselect it if it was already selected } bool selected = go.GetComponent <Clickable> ().isSelected; //Enable the good overlay if (selected) { foreach (Transform child in go.transform) { GameObject g = child.gameObject; if (g.name != "Direction") { if (g.tag == "SelectedOverlay") //visible when the go is selected { g.GetComponent <Renderer> ().enabled = true; } else { g.GetComponent <Renderer> ().enabled = false; } } } } else { if (po && !gi.mouseOverHUD) //if mouse over { foreach (Transform child in go.transform) { GameObject g = child.gameObject; if (g.name != "Direction") { if (g.tag == "MouseOverOverlay") //visible when the mouse is over the go { g.GetComponent <Renderer> ().enabled = true; } else { g.GetComponent <Renderer> ().enabled = false; } } } } else //hide both overlay { foreach (Transform child in go.transform) { GameObject g = child.gameObject; if ((g.tag == "MouseOverOverlay" || g.tag == "SelectedOverlay") && g.name != "Direction") { g.GetComponent <Renderer> ().enabled = false; } } } } } //count the number of selected go gi.selectedGO = 0; foreach (GameObject go in clickableGO) { if (go.GetComponent <Clickable> ().isSelected) { gi.selectedGO++; } } }
// Use to process your families. protected override void onProcess(int familiesUpdateCount) { if (!gameInfo.First().GetComponent <GameInfo>().playing) { bool mouseOverHUD = gameInfo.First().GetComponent <GameInfo>().mouseOverHUD; foreach (GameObject go in draggable) { PointerOver po = go.GetComponent <PointerOver>(); if (po && !mouseOverHUD) { //if mouse over the object and not over ui if (Input.GetMouseButtonDown(0)) { //if mouse's left button just got pressed //set the go as "dragged" go.GetComponent <Draggable>().dragged = true; //the go is currently dragged gameInfo.First().GetComponent <GameInfo>().objectDragged = true; //an object is dragged go.GetComponent <Draggable>().positionBeforeDrag = go.transform.position; //store the current go position as position before drag go.GetComponent <Draggable>().fromMouseToCenter = go.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y - 0.5f)); //vector from mouse position to screen center before drag (positions in the world) } } } if (!Input.GetMouseButton(0) && gameInfo.First().GetComponent <GameInfo>().objectDragged) {//if the left click is released and an object is dragged foreach (GameObject go in draggable) { if (go.GetComponent <Draggable>().dragged) {//find the dragged object //set go to not dragged go.GetComponent <Draggable>().dragged = false; gameInfo.First().GetComponent <GameInfo>().objectDragged = false; gameInfo.First().gameObject.GetComponent <GameInfo>().selectedChanged = true; go.GetComponent <Draggable>().canBeMoved = false; Color uipColor = gameInfo.First().GetComponent <GameInfo>().uiParameters.GetComponent <Image>().color; Color uipdColor = gameInfo.First().GetComponent <GameInfo>().uipDelete.GetComponent <Image>().color; Color bpColor = gameInfo.First().GetComponent <GameInfo>().ballParameters.GetComponent <Image>().color; Color urColor = gameInfo.First().GetComponent <GameInfo>().uniformRotator.GetComponent <Image>().color; gameInfo.First().GetComponent <GameInfo>().uiParameters.GetComponent <Image>().color = new Color(uipColor.r, uipColor.g, uipColor.b, 1); //show uiP gameInfo.First().GetComponent <GameInfo>().uipDelete.GetComponent <Image>().color = new Color(uipdColor.r, uipdColor.g, uipdColor.b, 1); //show uiP delete button gameInfo.First().GetComponent <GameInfo>().ballParameters.GetComponent <Image>().color = new Color(bpColor.r, bpColor.g, bpColor.b, 1); //show bP gameInfo.First().GetComponent <GameInfo>().uniformRotator.GetComponent <Image>().color = new Color(urColor.r, urColor.g, urColor.b, 1); //show ur } } } if (gameInfo.First().GetComponent <GameInfo>().objectDragged) {//if an object is dragged foreach (GameObject go in draggable) { Draggable d = go.GetComponent <Draggable>(); if (d.isDraggable && d.dragged) { Color uipColor = gameInfo.First().GetComponent <GameInfo>().uiParameters.GetComponent <Image>().color; Color uipdColor = gameInfo.First().GetComponent <GameInfo>().uipDelete.GetComponent <Image>().color; Color bpColor = gameInfo.First().GetComponent <GameInfo>().ballParameters.GetComponent <Image>().color; Color urColor = gameInfo.First().GetComponent <GameInfo>().uniformRotator.GetComponent <Image>().color; gameInfo.First().GetComponent <GameInfo>().uiParameters.GetComponent <Image>().color = new Color(uipColor.r, uipColor.g, uipColor.b, 75f / 255); //hide uiP gameInfo.First().GetComponent <GameInfo>().uipDelete.GetComponent <Image>().color = new Color(uipdColor.r, uipdColor.g, uipdColor.b, 75f / 255); //hide uiP delete button gameInfo.First().GetComponent <GameInfo>().ballParameters.GetComponent <Image>().color = new Color(bpColor.r, bpColor.g, bpColor.b, 75f / 255); //hide bP gameInfo.First().GetComponent <GameInfo>().uniformRotator.GetComponent <Image>().color = new Color(urColor.r, urColor.g, urColor.b, 75f / 255); //hide ur Vector3 newPos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y - 0.5f)) + d.fromMouseToCenter; //new position of the object if (!d.canBeMoved) { if ((newPos - d.positionBeforeDrag).magnitude > 1) { /* the object can be moved only if the distance between the position before * the drag and the current position of the mouse is bigger than a certain value * this way the object won't be dragged with a miss click */ d.canBeMoved = true; if (undoredo.First().GetComponent <UndoRedoValues>().draggedAtCreation) { undoredo.First().GetComponent <UndoRedoValues>().draggedAtCreation = false; } else { if (gameInfo.First().GetComponent <GameInfo>().levelEditorMode) { undoredo.First().GetComponent <UndoRedoValues>().editorUndoActionTypes.Push(1); undoredo.First().GetComponent <UndoRedoValues>().editorUndoDraggedGO.Push(go.GetComponent <IDUndoRedo>().id); undoredo.First().GetComponent <UndoRedoValues>().editorUndoDraggedPositions.Push(go.transform.position); } else { undoredo.First().GetComponent <UndoRedoValues>().undoActionTypes.Push(1); undoredo.First().GetComponent <UndoRedoValues>().undoDraggedGO.Push(go.GetComponent <IDUndoRedo>().id); undoredo.First().GetComponent <UndoRedoValues>().undoDraggedPositions.Push(go.transform.position); } } } } if (d.canBeMoved) { go.transform.position = newPos;//move the object to the new position if (gameInfo.First().GetComponent <GameInfo>().selectedGO > gameInfo.First().GetComponent <GameInfo>().nbSelectableGO) { foreach (GameObject g in clickableGO) { //unselect all objects if (g.GetComponent <Clickable>().isSelected) { g.GetComponent <Clickable>().isSelected = false; } } } go.GetComponent <Clickable>().isSelected = true;//select the moved object } } } } } }