Tooltip - template
This commit is contained in:
parent
815c5de830
commit
2db82701a4
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be0bbc86b6144804a8277039b5fe9a16
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
class ItemTooltip : MonoBehaviour
|
||||
{
|
||||
// Card elements
|
||||
// like text fields etc
|
||||
|
||||
// function to overwrite tooltip position to follow the mouse
|
||||
public void Update()
|
||||
{
|
||||
// if tooltip is created then update its position
|
||||
|
||||
Vector2 localPoint;
|
||||
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(
|
||||
transform.parent.GetComponent<RectTransform>(),
|
||||
Input.mousePosition,
|
||||
GameObject.FindObjectOfType<Camera>(),
|
||||
out localPoint
|
||||
);
|
||||
|
||||
transform.localPosition = localPoint;
|
||||
|
||||
Vector2 anchoredPosition = transform.GetComponent<RectTransform>().anchoredPosition;
|
||||
|
||||
//if(anchoredPosition.x + back)
|
||||
transform.GetComponent<RectTransform>().anchoredPosition = anchoredPosition;
|
||||
}
|
||||
|
||||
public void BuildContent(Item item)
|
||||
{
|
||||
// 1. detect type
|
||||
var equippableItem = item as EquippableItem;
|
||||
|
||||
// 2. todo - build tooltip content
|
||||
if (equippableItem == null)
|
||||
BuildBasedOnItem(item);
|
||||
else
|
||||
BuildBasedOnEquippableItem(equippableItem);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void BuildBasedOnItem(Item item)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void BuildBasedOnEquippableItem(EquippableItem item)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea432c2f9c08bc348a24bc7659a46d80
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa6860085c4248c4ab493d42340da014
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
class ItemTooltipController : MonoBehaviour
|
||||
{
|
||||
public static ItemTooltipController Instance { get; private set; }
|
||||
|
||||
[Header("Tooltip template")]
|
||||
[SerializeField] protected GameObject TooltipTemplate;
|
||||
|
||||
[Space]
|
||||
[Header("Tooltip panel")]
|
||||
[SerializeField] protected GameObject _tooltip;
|
||||
|
||||
// canvast react transform - canvast from scene
|
||||
// background rect transform - current slot rect transform
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateTooltip(Item item)
|
||||
{
|
||||
// detect if passed equippable or base item
|
||||
_tooltip = Instantiate(_tooltip, GameObject.FindGameObjectWithTag("GUI").transform);
|
||||
|
||||
// build content based on passed item info
|
||||
_tooltip.GetComponent<ItemTooltip>().BuildContent(item);
|
||||
}
|
||||
|
||||
public void DestroyTooltip()
|
||||
{
|
||||
DestroyImmediate(_tooltip);
|
||||
}
|
||||
|
||||
public void UpdateTooltipPosition()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb8913178367b0745a545a9feb8cfb35
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -109,13 +109,14 @@ public class InventoryPanelController : WarehousePanelController
|
||||
// check if there is item on slot else retrun null breaking function
|
||||
base.MouseEnter(itemSlot, eventData);
|
||||
|
||||
// todo open tooltip panel with item data
|
||||
// Tooltip.OpenPanel(itemSlot. Item); - instantiate tooltip panel object
|
||||
// Tooltip.OpenPanel(itemSlot.Item); - instantiate tooltip panel object
|
||||
ItemTooltipController.Instance.CreateTooltip(itemSlot.Item);
|
||||
}
|
||||
|
||||
public override void MouseExit(ItemSlot itemSlot, PointerEventData eventData)
|
||||
{
|
||||
// Tooltip.CloePanel(); - destroy gameobject if panel is opened
|
||||
ItemTooltipController.Instance.DestroyTooltip();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
Loading…
Reference in New Issue
Block a user