private void CheckObjects() { foreach (ManageableObjet obj in _objectGenerator.ObjectFactory) { if (!FocusedObjects.Contains(obj)) { _radialPanel.SetButtonsActiveState(false, obj.Type); } } foreach (ManageableObjet obj in FocusedObjects) { if (obj is Twippie) { Twippie t = (Twippie)obj; if (t.LineRenderer != null) { t.LineRenderer.enabled = true; } } _radialPanel.SetButtonsActiveState(true, obj.Type, true); if (!_mainPanel.SetStatPanelActiveState(true, obj.Type)) { Debug.Log("global stat not found"); } else { Debug.Log("global stat " + obj.GetType().ToString() + " a été updaté !"); } } _uiManager.InfoGUI = true; CurrentContolMode = ControlMode.CheckingMultiple; }
private void OnGUI() { if (CurrentContolMode == ControlMode.Selecting) { Vector3 currPos = Input.mousePosition; Vector2 invertedCurrent = new Vector2(currPos.x, Screen.height - currPos.y); Vector2 invertedOrigin = new Vector2(OriginClic.x, Screen.height - OriginClic.y); Vector2 mixX = new Vector2(invertedCurrent.x, invertedOrigin.y); Vector2 mixY = new Vector2(invertedOrigin.x, invertedCurrent.y); Rect rect = new Rect(); if (invertedCurrent.x > invertedOrigin.x && invertedCurrent.y > invertedOrigin.y) { rect = new Rect(invertedOrigin, invertedCurrent - invertedOrigin); } else if (invertedCurrent.x > invertedOrigin.x) { rect = new Rect(mixY, mixX - mixY); } else if (invertedCurrent.y > invertedOrigin.y) { rect = new Rect(mixX, mixY - mixX); } else { rect = new Rect(invertedCurrent, invertedOrigin - invertedCurrent); } if (!FocusedObjects.Exists(x => x is Twippie)) { DrawScreenRect(rect, new Color(1, 1, 1, .4f)); DrawScreenRectBorder(rect, 2f, Color.white); } else { DrawScreenRect(rect, new Color(1, .7f, .5f, .4f)); DrawScreenRectBorder(rect, 2f, new Color(1, .7f, .5f)); } } }
private void Update() { //if (FocusedUI == null) //{ // if (_uiManager.InfoGUI) // { // //if (_autoZoom != ZoomMode.Intermediate) // //{ // // _autoZoom = ZoomMode.Intermediate; // // StartCoroutine(AutoZoom(10)); // //} // } // else // { // //if (_autoZoom != ZoomMode.Initial) // //{ // // StartCoroutine(AutoZoom(-1, true)); // //} // //else // //{ // //_wheelSpeed = Input.GetAxis("Mouse ScrollWheel") * _zoomSensitivity; // //} // } //} //else //{ // //if (_autoZoom != ZoomMode.Focused) // //{ // // StartCoroutine(AutoZoom(20)); // // _autoZoom = ZoomMode.Focused; // //} //} _wheelSpeed = Input.GetAxis("Mouse ScrollWheel") * _zoomSensitivity; if (_wheelSpeed != 0) { if (_zoomTask != null) { StopCoroutine(_zoomTask); } _zoomTask = StartCoroutine(ZoomTo(_camera.fieldOfView - _wheelSpeed * _zoomSpeed * _camera.fieldOfView, .2f)); } if (AnyClic() && MousePosVoid()) { _uiManager.DisablePreviewCam(); _uiManager.InfoGUI = false; FocusedUI = null; StartCoroutine(_radialPanel.SetAllButtonsActiveStateWithDelay(false, 1)); _mainPanel.SetAllStatPanelsActiveState(false); _radialPanel.Close(); foreach (var obj in FocusedObjects) { if (obj is Twippie twippie) { twippie.LineRenderer.enabled = false; } obj.SetSelectionActive(false); } FocusedObjects.Clear(); if (FocusedObject != null) { if (FocusedObject is Twippie twippie) { twippie.LineRenderer.enabled = false; } FocusedObject.SetSelectionActive(false); FocusedObject = null; } MainPanel.Instance.SetActive(false); CurrentContolMode = ControlMode.Waiting; } else if (AnyClic()) { DefineOriginClick(); } switch (CurrentContolMode) { case ControlMode.Waiting: if (Input.GetButton("Fire1")) { CurrentClicMode = ClicMode.LeftClic; DefineOriginClick(); } else if (Input.GetButton("Fire2")) { CurrentClicMode = ClicMode.RightClic; DefineOriginClick(); } else if (Input.GetButton("Fire3")) { CurrentClicMode = ClicMode.CentralClic; DefineOriginClick(); } break; case ControlMode.Clicking: if ((Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1)) && FocusedObject != null) { CheckObject(); } if (Vector2.Distance(OriginClic, Input.mousePosition) > DIST_TO_DRAG) { if (FocusedObject != null && (CurrentClicMode != ClicMode.CentralClic) && AnyClicHold()) { FocusedLayer = FocusedObject.gameObject.layer; CurrentContolMode = ControlMode.Dragging; } else if (CurrentClicMode == ClicMode.CentralClic) { CurrentContolMode = ControlMode.Selecting; FocusedObject = null; } } break; case ControlMode.Dragging: if (NewObject && !_planeCollider.activeSelf) { _planeCollider.SetActive(true); if (!(FocusedObject is AerialObjet)) { foreach (var zone in _zoneManager.Zones) { zone.SetDisplayMode(DisplayMode.Accessible); } } } if (FocusedObject is DraggableObjet draggable) { if (!(FocusedObject is Twippie)) { if (draggable.Zone != null) { draggable.Zone.Accessible = true; } } } if (Input.GetButton("Fire1")) // Clic gauche { if (!_dragCollider.activeSelf) { _dragCollider.SetActive(true); } if (FocusedObject != null) { if (FocusedObject is AerialObjet) { _aerialDragCollider.SetActive(true); } if (FocusedObject is DraggableObjet d) { if (d.Coll.enabled) { d.Coll.enabled = false; } if (Input.mousePosition.x < Screen.width * 4 / 10 || Input.mousePosition.x > Screen.width * 6 / 10 || Input.mousePosition.y < Screen.height * 3 / 8 || Input.mousePosition.y > Screen.height * 5 / 8) { if (d.Planet != null) { d.Planet.AbsRotateObjet(); } } } } } else if (Input.GetButton("Fire2") && FocusedObject is DraggableObjet) // Clic droit sur un objet draggable { if (!_planeCollider.activeSelf) { FocusedObject.gameObject.layer = 15; foreach (Transform child in FocusedObject.transform) { child.gameObject.layer = 15; } if (!_uiResources.Selected) { _uiResources.PlayMouthOpen(); _uiResources.Selected = true; } _planeCollider.SetActive(true); } if (FocusedObject != null) { if (FocusedObject is DraggableObjet d2) { if (d2.Coll.enabled) { d2.Coll.enabled = false; } } } } else // Clic laché { if (CurrentClicMode == ClicMode.RightClic) { if (_uiResources != null && _uiResources.MouseOver && FocusedObject is DraggableObjet) { Debug.Log("Resources added: " + FocusedObject.WoodCost + " Wood, " + FocusedObject.WaterCost + " Water, " + FocusedObject.StoneCost + " Stone"); _uiResources.AddResources(FocusedObject.WoodCost, FocusedObject.WaterCost, FocusedObject.StoneCost); _objectManager.RemoveObject(FocusedObject); Destroy(FocusedObject.gameObject); } } CurrentClicMode = ClicMode.None; if (_planeCollider.activeSelf) { FocusedObject.gameObject.layer = FocusedLayer; foreach (Transform child in FocusedObject.transform) { child.gameObject.layer = FocusedLayer; } _planeCollider.SetActive(false); } _aerialDragCollider.SetActive(false); _dragCollider.SetActive(false); if (FocusedObject) { if (FocusedObject is DraggableObjet) { DraggableObjet d = (DraggableObjet)FocusedObject; if (!d.Coll.enabled) { d.Coll.enabled = true; } } } if (FocusedObject != null) { if (FocusedObject is DraggableObjet) { if (FocusedObject is AerialObjet) { AerialObjet aerialObjet = (AerialObjet)FocusedObject; aerialObjet.Zone = _zoneManager.GetAerialZone(aerialObjet.transform); } else { DraggableObjet draggableObjet = (DraggableObjet)FocusedObject; draggableObjet.ZoneId = _zoneManager.GetZone(false, draggableObjet.Zone.Id, draggableObjet.transform.position); if (draggableObjet is IConsumable) { draggableObjet.Zone.Resources.Add(new Resource(ResourceType.Food, draggableObjet.GetComponent <IConsumable>(), 0)); } } } } if (NewObject) { if (FocusedObject is DraggableObjet) { if ((FocusedObject is AerialObjet) == false) { DraggableObjet draggableObjet = (DraggableObjet)FocusedObject; if (!draggableObjet.Zone.Accessible) { _objectManager.RemoveObject(FocusedObject); Destroy(FocusedObject.gameObject); FocusedObject = null; NewObject = false; CurrentContolMode = ControlMode.Waiting; } } } } if (FocusedObject != null) { if (!(FocusedObject is AerialObjet) && !(FocusedObject is Twippie) && FocusedObject is DraggableObjet d3) { d3.ZoneId = _zoneManager.GetZone(true, d3.Zone.Id, d3.transform.position); } } FocusedObject = null; NewObject = false; CurrentContolMode = ControlMode.Waiting; } break; case ControlMode.Selecting: if (!Input.GetButton("Fire3")) { CurrentClicMode = ClicMode.None; if (FocusedObjects.Count > 0) { if (FocusedObjects.Count == 1) { FocusedObject = FocusedObjects[0]; FocusedObjects.Clear(); CheckObject(); } else { CheckObjects(); } } else { CurrentContolMode = ControlMode.Waiting; } } break; case ControlMode.Checking: if (FocusedObject is Planet planet) { if (planet.Shaping) { return; } } break; case ControlMode.CheckingMultiple: break; } }