/// <summary> /// makes the tween ready to run again /// </summary> /// <param name="cmder3d"></param> /// <param name="destSpot"></param> public void ResetData(Transform transf, ZoneSpot destSpot, bool cmderAdjusted = false) { movingTrans = transf; this.destSpot = destSpot; this.cmderAdjusted = cmderAdjusted; elapsedTweenTime = 0; }
void Update() { if (EventSystem.current.IsPointerOverGameObject() || GameInterface.openedPanelsOverlayLevel != 0) { return; } //zones' colliders are in the "zone" layer (num. 8) //hovered zones should grow a little if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit, 100, 1 << 8)) { if (zoneWhitelist != null) { ZoneSpot hitSpotScript = hit.transform.GetComponent <ZoneSpot>(); if (!zoneWhitelist.Contains(hitSpotScript)) { return; } } if (!curHoveredZone) { curHoveredZone = hit.transform; curHoveredZone.localScale = Vector3.one * 1.25f; } } else { if (curHoveredZone) { curHoveredZone.localScale = Vector3.one; curHoveredZone = null; } } }
public void MoveCommander(Commander movingCmder, ZoneSpot destinationSpot, bool runHasActed = true) { Zone ourOldZone = GameController.GetZoneByID(movingCmder.zoneIAmIn); int targetZoneID = (destinationSpot.data as Zone).ID; if (isMultiOrdering && runHasActed) { List <Commander> actedCmders = new List <Commander>(); foreach (Commander cmd in GameController.GetCommandersOfFactionInZone (ourOldZone, GameModeHandler.instance.curPlayingFaction, commandableCommanders)) { cmd.OrderMoveToZone(targetZoneID); actedCmders.Add(cmd); } //World.TidyZone(ourOldZone); not sure if this is still needed CmderBatchHasActed(actedCmders); } else { movingCmder.OrderMoveToZone(targetZoneID); if (runHasActed) { CmderHasActed(movingCmder); } } }
/// <summary> /// starts a tween to the target spot, optionally setting the destination position to a "GoodSpotForCmder" /// </summary> /// <param name="trans"></param> /// <param name="destSpot"></param> /// <param name="cmderAdjusted"></param> public void StartTween(Transform trans, ZoneSpot destSpot, bool cmderAdjusted) { TransformTween newTween = GetATween(); newTween.ResetData(trans, destSpot, cmderAdjusted); activeTweens.Add(newTween); StartCoroutine(TweenRoutine(newTween)); }
private void OnDisable() { if (curSelectedSpot) { curSelectedSpot.Highlighted = false; } curSelectedSpot = null; actionOnDoneLinking = null; }
/// <summary> /// place a zone using its saved coordinates /// </summary> /// <param name="targetZone"></param> public static void PlaceZone(Zone targetZone) { GameObject newSpot = Instantiate(instance.zonePrefab, targetZone.CoordsForWorld, Quaternion.identity); newSpot.transform.parent = instance.zonesContainer; ZoneSpot zsScript = newSpot.GetComponent <ZoneSpot>(); zsScript.data = targetZone; zsScript.RefreshDataDisplay(); }
void Update() { if (GameInterface.openedPanelsOverlayLevel != 0) { return; } foreach (Cmder3d cmd3d in allowedCmders3d) { //commanders which haven't taken an action this turn will keep spinning cmd3d.transform.Rotate(Vector3.up * 100 * Time.deltaTime); } //we still want the spinning commanders if no overlay panel is open if (EventSystem.current.IsPointerOverGameObject()) { return; } if (curSelectedCmder != null) { if (Input.GetButtonDown("Select")) { if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit, 100)) { ZoneSpot hitSpotScript = hit.transform.GetComponent <ZoneSpot>(); if (hitSpotScript) { if (allowedMoveSpots.Contains(hitSpotScript)) { //move commander to target zone spot cmdPhaseMan.MoveCommander(curSelectedCmder, hitSpotScript); } } } } } else { if (Input.GetButtonDown("Select")) { if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit, 100, 1 << 9)) { Cmder3d hitCmder = hit.transform.GetComponent <Cmder3d>(); if (hitCmder) { if (allowedCmders3d.Contains(hitCmder)) { SelectCmder(hitCmder); } } } } } }
public static void PlaceZoneLink(ZoneSpot zs1, ZoneSpot zs2, bool alsoUpdateTheirLinkedList = false) { LinkLine theLink = LinkLineRecycler.GetALine(); Zone z1 = zs1.data as Zone, z2 = zs2.data as Zone; theLink.SetLink(zs1, zs2); instance.linkLines.Add(theLink); if (alsoUpdateTheirLinkedList) { z1.linkedZones.Add(z2.ID); z2.linkedZones.Add(z1.ID); } }
void Update() { if (EventSystem.current.IsPointerOverGameObject()) { return; } if (Input.GetButtonDown("Select")) { if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit, 100, 1 << 8)) { ZoneSpot hitSpotScript = hit.transform.GetComponent <ZoneSpot>(); if (!curSelectedSpot) { //select zone if no zone was already selected curSelectedSpot = hitSpotScript; hitSpotScript.Highlighted = true; } else { //link/unlink to selected if one was already selected //...or deselect, if it's the selected zone if (curSelectedSpot == hitSpotScript) { curSelectedSpot = null; hitSpotScript.Highlighted = false; } else { if (World.GetLinkLineBetween(curSelectedSpot.data, hitSpotScript.data)) { World.RemoveZoneLink(curSelectedSpot.data as Zone, hitSpotScript.data as Zone, true); } else { World.PlaceZoneLink(curSelectedSpot, hitSpotScript, true); } } } } else { //deselect if (curSelectedSpot) { curSelectedSpot.Highlighted = false; } curSelectedSpot = null; } } }
public List <TransformTween> GetAllTweensTargetingZone(ZoneSpot targetSpot) { List <TransformTween> returnedList = new List <TransformTween>(); foreach (TransformTween tween in activeTweens) { if (tween.destSpot == targetSpot) { returnedList.Add(tween); } } return(returnedList); }
public static void CreateNewZoneAtPoint(Vector3 point, bool autoOpenEditMenu = true) { Zone newZone = new Zone("New Zone", point); GameObject newSpot = Instantiate(instance.zonePrefab, point, Quaternion.identity); newSpot.transform.parent = instance.zonesContainer; ZoneSpot spotScript = newSpot.GetComponent <ZoneSpot>(); spotScript.data = newZone; spotScript.RefreshDataDisplay(); if (autoOpenEditMenu) { GameInterface.instance.EditZone(newZone, true); } }
void Update() { if (GameInterface.openedPanelsOverlayLevel != 0 || EventSystem.current.IsPointerOverGameObject()) { if (LayoutToolTip.Instance.gameObject.activeSelf) { LayoutToolTip.Instance.HideTooltip(); } return; } if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit, 100, (1 << 8) | (1 << 9))) { if (!curHoveredObj || curHoveredObj != hit.transform) { LayoutToolTip.Instance.HideTooltip(); curHoveredObj = hit.transform; ZoneSpot spotScript = curHoveredObj.GetComponent <ZoneSpot>(); if (spotScript) { LayoutToolTip.Instance.ShowTooltipForZone (spotScript.data as Zone, Input.mousePosition, GameInterface.instance.curInterfaceMode == GameInterface.InterfaceMode.game); } else { Cmder3d cmderScript = curHoveredObj.GetComponent <Cmder3d>(); if (cmderScript) { LayoutToolTip.Instance.ShowTooltipForCmder(cmderScript.data as Commander, Input.mousePosition); } } } } else { if (curHoveredObj) { curHoveredObj = null; LayoutToolTip.Instance.HideTooltip(); } } }
/// <summary> /// If a commander leaves a zone while another is tweening towards it, /// the one tweening will have a "wrong" destination and might /// overlap with another commander, so we adjust the moving commanders' /// destinations. (This is only for cmder-adjusted tweens) /// </summary> /// <param name="spotWithChanges"></param> public void AdjustTweensThatTargetZone(ZoneSpot spotWithChanges) { int adjustmentCount = 1; int cmdersInSpot = GameController.GetCommandersInZone(spotWithChanges.data as Zone).Count; foreach (TransformTween tween in activeTweens) { if (!tween.cmderAdjusted) { continue; } if (tween.destSpot == spotWithChanges) { tween.destPos = spotWithChanges.GetGoodSpotForCommander( cmdersInSpot - adjustmentCount); adjustmentCount++; } } }
void Update() { if (EventSystem.current.IsPointerOverGameObject() || GameInterface.openedPanelsOverlayLevel > 0) { return; } if (Input.GetButtonDown("Select")) { if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit, 100, 1 << 8)) { ZoneSpot hitSpotScript = hit.transform.GetComponent <ZoneSpot>(); if (hitSpotScript) { GameInterface.instance.EditZone(hitSpotScript.data as Zone, false); } } } }
public void CloseAndSaveChanges() { if (!DataIsValid()) { return; } CheckIfNameIsAlreadyInUse(); ZoneSpot mySpot = dataBeingEdited.MyZoneSpot; //we must get it before applying the new name (we get the spot by name if it's not cached) dataBeingEdited.name = nameInput.text; dataBeingEdited.extraInfo = eInfoInput.text; dataBeingEdited.multTrainingPoints = float.Parse(multTrainingInput.text, CultureInfo.InvariantCulture); dataBeingEdited.multRecruitmentPoints = float.Parse(multRecruitInput.text, CultureInfo.InvariantCulture); dataBeingEdited.multMaxUnitsInGarrison = float.Parse(multMaxGarrInput.text, CultureInfo.InvariantCulture); dataBeingEdited.pointsGivenAtGameStart = int.Parse(startPointsInput.text); dataBeingEdited.ownerFaction = GameController.GetFactionIDByName(ownerFactionDropdown.captionText.text); dataBeingEdited.UpdateCoordsAccordingToSpotPosition(); mySpot.RefreshDataDisplay(); gameObject.SetActive(false); OnWindowIsClosing(); }
void Update() { if (GameInterface.openedPanelsOverlayLevel != 0) { return; } if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit, 100, 1 << 8)) { ZoneSpot hitSpotScript = hit.transform.GetComponent <ZoneSpot>(); if (allowedSpots.Contains(hitSpotScript)) { //select zone if no zone was already selected curHoveredValidZone = hitSpotScript; cmderBlueprint.gameObject.SetActive(true); cmderBlueprint.position = hitSpotScript.GetGoodSpotForCommander(); cmderBlueprint.Rotate(Vector3.up * Time.deltaTime * 100); //just a little rotation to make it prettier haha } else { curHoveredValidZone = null; cmderBlueprint.gameObject.SetActive(false); } } else { curHoveredValidZone = null; cmderBlueprint.gameObject.SetActive(false); } if (Input.GetButtonDown("Select")) { if (curHoveredValidZone != null) { NewCmderPhaseMan.OrderPlaceNewCmder((curHoveredValidZone.data as Zone).ID, GameModeHandler.instance.curPlayingFaction); actionOnSpotSelect(); enabled = false; } } }
/// <summary> /// this loop should only run while no zones are in the zoneSpotsBeingMoved list /// </summary> void SelectionModeLoop() { groundedMousePos = Input.mousePosition; groundedMousePos.z = CameraPanner.DIST_TO_GROUND; canvasScaledMousePos = groundedMousePos / boxSelectorCanvas.scaleFactor; if (Input.GetButtonDown("Select") && !EventSystem.current.IsPointerOverGameObject()) { singleSelectionSpot = null; draggingAction = true; dragActionStartPos = cam.ScreenToWorldPoint(groundedMousePos); boxSelectorRect.pivot = Vector2.zero; boxSelectorRect.anchoredPosition = canvasScaledMousePos; boxSelectorRect.gameObject.SetActive(true); //also let the player pick only one zone by clicking it if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit, 100, 1 << 8)) { ZoneSpot hitSpotScript = hit.transform.GetComponent <ZoneSpot>(); singleSelectionSpot = hitSpotScript; } } if (draggingAction) { reconvertedDragStartPos = cam.WorldToScreenPoint(dragActionStartPos) / boxSelectorCanvas.scaleFactor; //flip pivots in x and y if we go the other way with the mouse boxSelectorPivot.x = reconvertedDragStartPos.x > canvasScaledMousePos.x ? 1.0f : 0.0f; boxSelectorPivot.y = reconvertedDragStartPos.y > canvasScaledMousePos.y ? 1.0f : 0.0f; boxSelectorRect.pivot = boxSelectorPivot; //keep the selector rect's origin from following the camera boxSelectorRect.anchoredPosition = reconvertedDragStartPos; //do a "Vector2 abs" to always get positive width and height //(pivot changes make sure the box grows in the right direction) selectorRectDelta.x = Mathf.Abs(canvasScaledMousePos.x - boxSelectorRect.anchoredPosition.x); selectorRectDelta.y = Mathf.Abs(canvasScaledMousePos.y - boxSelectorRect.anchoredPosition.y); boxSelectorRect.sizeDelta = selectorRectDelta; //highlight zones that would be selected if the player stopped dragging right now CheckZonesToSelectWithBox(false); } if (Input.GetButtonUp("Select") && draggingAction) { draggingAction = false; CheckZonesToSelectWithBox(true); boxSelectorRect.sizeDelta = Vector2.zero; boxSelectorRect.gameObject.SetActive(false); //single zone click end if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit, 100, 1 << 8)) { ZoneSpot hitSpotScript = hit.transform.GetComponent <ZoneSpot>(); //if click started and ended with this zone, we suppose the player wants to move this one only if (singleSelectionSpot == hitSpotScript) { zoneSpotsBeingMoved.Add(singleSelectionSpot); singleSelectionSpot.Highlighted = true; StartMovingProcedure(zoneSpotsBeingMoved); } } singleSelectionSpot = null; } }