private void OnValidate() { iconHolder = GetComponent <MapIconHolder>(); if (iconHolder) { iconHolder.textToDisplay = GetMapIconName(); iconHolder.iconEvents.onFingerClick.AddListener(ShowNameAtMousePosition); iconHolder.iconEvents.onMouseEnter.AddListener(ShowNameAtMousePosition); iconHolder.iconEvents.onMouseExit.AddListener(HideNameImmediately); } }
protected override void OnAwake() { if (!interactive) { interactive = transform.FindOrCreate("Interactive"); } var collider = interactive.GetOrAddComponent <CircleCollider2D>(); collider.isTrigger = true; collider.radius = 1.0f; iconHolder = GetComponentInChildren <MapIconHolder>(); }
private void Awake() { iconHolder = GetComponent <MapIconHolder>(); if (iconHolder) { iconHolder.textToDisplay = GetMapIconName(); iconHolder.iconEvents.RemoveAllListner(); iconHolder.iconEvents.onFingerClick.AddListener(ShowNameAtMousePosition); iconHolder.iconEvents.onMouseEnter.AddListener(ShowNameAtMousePosition); iconHolder.iconEvents.onMouseExit.AddListener(HideNameImmediately); } transform = base.transform; }
private void DrawMapIcons() { if (!UI || !UI.gameObject) { return; } if (!Camera.orthographic) { Camera.orthographic = true; } if (!Camera.CompareTag("MapCamera")) { Camera.tag = "MapCamera"; } if (Camera.cullingMask != mapRenderMask) { Camera.cullingMask = mapRenderMask; } foreach (var iconKvp in iconsWithHolder) { MapIconHolder holder = iconKvp.Key; float sqrDistance = Vector3.SqrMagnitude(holder.transform.position - player.position); if (iconKvp.Key.isActiveAndEnabled && !iconKvp.Value.ForceHided && (isViewingWorldMap && holder.drawOnWorldMap || !isViewingWorldMap && (!holder.AutoHide || holder.AutoHide && holder.DistanceSqr >= sqrDistance))) { if (holder.showRange && !iconKvp.Value.iconRange) { iconKvp.Value.iconRange = ObjectPool.Get(UI.rangePrefab.gameObject, UI.rangesParent).GetComponent <MapIconRange>(); } holder.ShowIcon(CameraZoom); DrawMapIcon(holder.transform.position + new Vector3(holder.offset.x, use2D ? holder.offset.y : 0, use2D ? 0 : holder.offset.y), iconKvp.Value, holder.keepOnMap); if (!IsViewingWorldMap && sqrDistance > holder.DistanceSqr * 0.81f && sqrDistance < holder.DistanceSqr) { iconKvp.Value.ImageCanvas.alpha = (holder.DistanceSqr - sqrDistance) / (holder.DistanceSqr * 0.19f); } else { iconKvp.Value.ImageCanvas.alpha = 1; } } else { holder.HideIcon(); } } foreach (var icon in IconsWithoutHolder.Values) { DrawMapIcon(icon.worldPosition, icon.mapIcon, icon.keepOnMap); } }
public void Recycle() { if (holder) { holder.iconInstance = null; holder = null; } iconImage.raycastTarget = true; removeAble = true; if (!string.IsNullOrEmpty(TextToDisplay) && tips && tips.openBy is MapIcon icon && icon == this) { tips.Close(); } textToDisplay = string.Empty; ObjectPool.Put(gameObject); }
public void Init(MapIconHolder holder) { rectTransform.pivot = new Vector2(0.5f, 0.5f); rectTransform.sizeDelta = holder.iconSize; iconImage.overrideSprite = holder.icon; iconType = holder.iconType; holder.iconInstance = this; this.holder = holder; if (holder.showRange) { ZetanUtility.SetActive(iconRange, true); } else { ZetanUtility.SetActive(iconRange, false); } }
public void RemoveMapIcon(MapIconHolder holder, bool force = false) { if (!holder || !holder.removeAble && !force) { Debug.Log("return1"); return; } //Debug.Log("remove"); iconsWithHolder.TryGetValue(holder, out MapIcon iconFound); if (!iconFound && holder.iconInstance) { iconFound = holder.iconInstance; } if (iconFound) { iconFound.Recycle(); } iconsWithHolder.Remove(holder); }
private void DrawMapIcons() { if (!UI || !UI.gameObject) { return; } if (!MapCamera.orthographic) { MapCamera.orthographic = true; } if (MapCamera.cullingMask != mapRenderMask) { MapCamera.cullingMask = mapRenderMask; } foreach (var iconKvp in iconsWithHolder) { MapIconHolder holder = iconKvp.Key; float distance = Vector3.Magnitude(holder.transform.position - player.position); if (iconKvp.Key.isActiveAndEnabled && !iconKvp.Value.ForceHided && (isViewingWorldMap && holder.drawOnWorldMap || !isViewingWorldMap && (!holder.AutoHide || holder.AutoHide && holder.maxValidDistance >= distance))) { holder.ShowIcon(CameraZoom); DrawMapIcon(holder.transform.position + new Vector3(holder.offset.x, use2D ? holder.offset.y : 0, use2D ? 0 : holder.offset.y), iconKvp.Value, holder.keepOnMap); if (!IsViewingWorldMap && distance > holder.maxValidDistance * 0.9f && distance < holder.maxValidDistance) { iconKvp.Value.ImageCanvas.alpha = (holder.maxValidDistance - distance) / (holder.maxValidDistance * 0.1f); } else { iconKvp.Value.ImageCanvas.alpha = 1; } } else { holder.HideIcon(); } } foreach (var icon in NormalIcons) { DrawMapIcon(icon.Position, icon, icon.KeepOnMap); } }
public void Recycle() { if (holder) { holder.iconInstance = null; holder = null; } iconImage.raycastTarget = true; RemoveAble = true; if (!string.IsNullOrEmpty(TextToDisplay)) { TipsManager.Instance.Hide(); } TextToDisplay = string.Empty; if (iconRange) { ObjectPool.Put(iconRange.gameObject); } iconRange = null; ObjectPool.Put(gameObject); }
public void CreateMapIcon(MapIconHolder holder) { if (!UI || !UI.gameObject || !holder.icon) { return; } MapIcon icon = ObjectPool.Get(UI.iconPrefab.gameObject, SelectParent(holder.iconType)).GetComponent <MapIcon>(); icon.Init(holder); iconsWithHolder.TryGetValue(holder, out MapIcon iconFound); //Icons.Add(icon); if (iconFound != null) { holder.iconInstance = icon; iconsWithHolder[holder] = icon; } else { iconsWithHolder.Add(holder, icon); } return; }
private void OnEnable() { holder = target as MapIconHolder; icon = serializedObject.FindProperty("icon"); iconSize = serializedObject.FindProperty("iconSize"); iconType = serializedObject.FindProperty("iconType"); drawOnWorldMap = serializedObject.FindProperty("drawOnWorldMap"); keepOnMap = serializedObject.FindProperty("keepOnMap"); maxValidDistance = serializedObject.FindProperty("maxValidDistance"); forceHided = serializedObject.FindProperty("forceHided"); removeAble = serializedObject.FindProperty("removeAble"); showRange = serializedObject.FindProperty("showRange"); rangeColor = serializedObject.FindProperty("rangeColor"); rangeSize = serializedObject.FindProperty("rangeSize"); textToDisplay = serializedObject.FindProperty("textToDisplay"); iconEvents = serializedObject.FindProperty("iconEvents"); onFingerClick = iconEvents.FindPropertyRelative("onFingerClick"); onMouseClick = iconEvents.FindPropertyRelative("onMouseClick"); onMouseEnter = iconEvents.FindPropertyRelative("onMouseEnter"); onMouseExit = iconEvents.FindPropertyRelative("onMouseExit"); gizmos = serializedObject.FindProperty("gizmos"); }
public void CreateMapIcon(MapIconHolder holder) { if (!UI || !UI.gameObject || !holder.icon) { return; } MapIcon icon = ObjectPool.Get(UI.iconPrefab.gameObject, SelectParent(holder.iconType)).GetComponent <MapIcon>(); InitIcon(); iconsWithHolder.TryGetValue(holder, out MapIcon iconFound); if (iconFound != null) { holder.iconInstance = icon; iconsWithHolder[holder] = icon; } else { iconsWithHolder.Add(holder, icon); } return; void InitIcon() { icon.iconImage.rectTransform.pivot = new Vector2(0.5f, 0.5f); icon.iconImage.overrideSprite = holder.icon; icon.iconImage.rectTransform.sizeDelta = holder.iconSize; icon.iconType = holder.iconType; icon.RemoveAble = holder.removeAble; holder.iconInstance = icon; icon.holder = holder; if (holder.showRange) { icon.iconRange = ObjectPool.Get(UI.rangePrefab.gameObject, UI.rangesParent).GetComponent <MapIconRange>(); } } }