/// <summary> /// Helper function that returns the selected root object. /// </summary> static public GameObject SelectedRoot(bool createIfMissing) { GameObject go = Selection.activeGameObject; // Only use active objects if (go != null && !NJGTools.GetActive(go)) { go = null; } return(go); }
/// <summary> /// Update the icon icon for the specified unit, assuming it's visible. /// </summary> protected override void UpdateIcon(NJGMapItem item, float x, float y) { // If the unit is not visible, don't consider it bool isVisible = false; if (map.fow.enabled) { isVisible = (((x - mapBorderRadius) >= -mapHalfScale.x) && ((x + mapBorderRadius) <= mapHalfScale.x)) && (((y - mapBorderRadius) >= -mapHalfScale.y) && ((y + mapBorderRadius) <= mapHalfScale.y)); if (!item.isRevealed) { isVisible = false; } } else { isVisible = (((x - mapBorderRadius) >= -mapHalfScale.x) && ((x + mapBorderRadius) <= mapHalfScale.x)) && (((y - mapBorderRadius) >= -mapHalfScale.y) && ((y + mapBorderRadius) <= mapHalfScale.y)); } if (!isPanning) { if (!isVisible && item.haveArrow) { if (item.arrow == null) { item.arrow = (UIMapArrowBase)GetArrow(item); } if (item.arrow != null) { if (!NJGTools.GetActive(item.arrow.gameObject)) { NJGTools.SetActive(item.arrow.gameObject, true); } item.arrow.UpdateRotation(target.position); } } else if (isVisible && item.haveArrow) { if (item.arrow != null) { if (NJGTools.GetActive(item.arrow.gameObject)) { NJGTools.SetActive(item.arrow.gameObject, false); } } } } if (!isVisible) { return; } UIMapIconBase icon = GetEntry(item); if (icon != null && !icon.isValid) { icon.isMapIcon = false; icon.isValid = true; Transform t = icon.cachedTransform; Vector3 newPos = new Vector3(x, y, 0f); if (item.updatePosition) { if (t.localPosition != newPos) { t.localPosition = newPos; } } if (item.rotate) { float angle = ((Vector3.Dot(item.cachedTransform.forward, Vector3.Cross(Vector3.up, Vector3.forward)) <= 0f) ? 1f : -1f) * Vector3.Angle(item.cachedTransform.forward, Vector3.forward); t.localEulerAngles = new Vector3(t.localEulerAngles.x, t.localEulerAngles.y, angle); } else if (!item.rotate && rotateWithPlayer) { Vector3 eu = new Vector3(0, 0, -iconRoot.localEulerAngles.z); if (!t.localEulerAngles.Equals(eu)) { t.localEulerAngles = eu; } } else if (!t.localEulerAngles.Equals(Vector3.zero)) { t.localEulerAngles = Vector3.zero; } } }