Beispiel #1
0
        /// <summary>
        /// Check if there has been a click. Ifso then raycast and check if there has been clicked on a specific game object. Ifso fire an event with the click object as a parameter.
        /// </summary>
        private void CheckObjectsClick()
        {
            // Gives errors
            // if (Input.GetMouseButtonDown(0) && !_manager.SwipeController.IsSwipeHappening)
            if (Input.GetMouseButtonDown(0))
            {
                var unitClick      = new OnUnitClick();
                var buildingClick  = new OnBuildingClick();
                var highlightClick = new OnHighlightClick();

                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    foreach (Unit unit in lm.CurrentLevel.CurrentPlayer.OwnedUnits)
                    {
                        if (unit.UnitGameObject.collider == hit.collider)
                        {
                            unitClick.unit = unit.UnitGameObject;
                            break;
                        }
                    }
                    foreach (Building building in lm.CurrentLevel.CurrentPlayer.OwnedBuildings)
                    {
                        if (building.BuildingGameObject.collider == hit.collider)
                        {
                            buildingClick.building = building.BuildingGameObject;
                            break;
                        }
                    }
                    foreach (HighlightObject highlightObj in highlight.HighlightObjects)
                    {
                        if (highlightObj.collider == hit.collider)
                        {
                            highlightClick.highlight = highlightObj;
                            break;
                        }
                    }
                }

                if (unitClick.unit == null && highlightClick.highlight == null && !movement.NeedsMoving ||
                    (highlight.IsHighlightOn && unitClick.unit != null))
                {
                    highlight.ClearHighlights();
                }
                EventHandler.dispatch(unitClick);
                EventHandler.dispatch(buildingClick);
                EventHandler.dispatch(highlightClick);
            }
        }
Beispiel #2
0
        /// <summary>
        /// This method is executed when an clicked on building event is fired.
        /// </summary>
        /// <param Name="evt"></param>
        private void OnBuildingClick(OnBuildingClick evt)
        {
            if (evt.building != null)
            {
                if (!IsProductionOverlayActive && evt.building.BuildingGame.CanProduce)
                {
                    BuildingClickedProduction         = evt.building;
                    CurrentOverlay                    = CreatorFactoryProductionOverlay.CreateProductionOverlay(BuildingClickedProduction.type);
                    CurrentOverlay.transform.position = GetBelowScreenPosition();
                    CurrentOverlay.transform.parent   = Camera.main.transform;

                    CurrentOverlay.GetComponentsInChildren <ProductionScript>().ToList().ForEach(x => x.ParentProduction = this);
                    InitiateMoving(false);
                    IsProductionOverlayActive = true;
                }
            }
        }
 public void OnPointerClick(BuildingObject target, PointerEventData eventData)
 {
     CurrentMode.OnPointerClick(target, eventData);
     OnBuildingClick?.Invoke(target);
 }