Update icon mall

This commit is contained in:
HungDK
2025-10-27 09:39:27 +07:00
parent bd34b294f9
commit dd8858b8a5
5 changed files with 80 additions and 457 deletions
@@ -1,229 +0,0 @@
using UnityEngine;
using UnityEngine.UI;
public class ShopIconHandler : MonoBehaviour
{
[Header("Shop Icon")]
public Button shopIconButton;
public Image shopIconImage;
[Header("Shop Manager")]
public ShopUIManager shopManager;
[Header("Visual Feedback")]
public Color normalColor = Color.white;
public Color hoverColor = Color.yellow;
public Color pressedColor = Color.red;
[Header("Animation")]
public bool enableHoverAnimation = true;
public float hoverScale = 1.1f;
public float animationSpeed = 5f;
private Vector3 originalScale;
private bool isHovering = false;
void Start()
{
InitializeShopIcon();
SetupEventListeners();
}
void InitializeShopIcon()
{
// Store original scale for animation
originalScale = transform.localScale;
// Setup button if not already assigned
if (shopIconButton == null)
{
shopIconButton = GetComponent<Button>();
}
// Setup image if not already assigned
if (shopIconImage == null)
{
shopIconImage = GetComponent<Image>();
}
// Set initial color
if (shopIconImage != null)
{
shopIconImage.color = normalColor;
}
}
void SetupEventListeners()
{
if (shopIconButton != null)
{
shopIconButton.onClick.AddListener(OnShopIconClicked);
}
// Setup hover events if we have an EventTrigger component
var eventTrigger = GetComponent<UnityEngine.EventSystems.EventTrigger>();
if (eventTrigger != null)
{
SetupHoverEvents(eventTrigger);
}
}
void SetupHoverEvents(UnityEngine.EventSystems.EventTrigger eventTrigger)
{
// Pointer Enter event
var pointerEnter = new UnityEngine.EventSystems.EventTrigger.Entry();
pointerEnter.eventID = UnityEngine.EventSystems.EventTriggerType.PointerEnter;
pointerEnter.callback.AddListener((data) => OnPointerEnter());
eventTrigger.triggers.Add(pointerEnter);
// Pointer Exit event
var pointerExit = new UnityEngine.EventSystems.EventTrigger.Entry();
pointerExit.eventID = UnityEngine.EventSystems.EventTriggerType.PointerExit;
pointerExit.callback.AddListener((data) => OnPointerExit());
eventTrigger.triggers.Add(pointerExit);
// Pointer Down event
var pointerDown = new UnityEngine.EventSystems.EventTrigger.Entry();
pointerDown.eventID = UnityEngine.EventSystems.EventTriggerType.PointerDown;
pointerDown.callback.AddListener((data) => OnPointerDown());
eventTrigger.triggers.Add(pointerDown);
// Pointer Up event
var pointerUp = new UnityEngine.EventSystems.EventTrigger.Entry();
pointerUp.eventID = UnityEngine.EventSystems.EventTriggerType.PointerUp;
pointerUp.callback.AddListener((data) => OnPointerUp());
eventTrigger.triggers.Add(pointerUp);
}
void OnShopIconClicked()
{
Debug.Log("Shop icon clicked - Opening shop");
if (shopManager != null)
{
shopManager.OpenShop();
}
else
{
Debug.LogWarning("ShopManager not assigned to ShopIconHandler");
}
// Play click animation
PlayClickAnimation();
}
void OnPointerEnter()
{
isHovering = true;
if (shopIconImage != null)
{
shopIconImage.color = hoverColor;
}
if (enableHoverAnimation)
{
StartCoroutine(ScaleAnimation(originalScale * hoverScale));
}
}
void OnPointerExit()
{
isHovering = false;
if (shopIconImage != null)
{
shopIconImage.color = normalColor;
}
if (enableHoverAnimation)
{
StartCoroutine(ScaleAnimation(originalScale));
}
}
void OnPointerDown()
{
if (shopIconImage != null)
{
shopIconImage.color = pressedColor;
}
}
void OnPointerUp()
{
if (shopIconImage != null)
{
shopIconImage.color = isHovering ? hoverColor : normalColor;
}
}
void PlayClickAnimation()
{
if (enableHoverAnimation)
{
StartCoroutine(ClickAnimation());
}
}
System.Collections.IEnumerator ScaleAnimation(Vector3 targetScale)
{
Vector3 startScale = transform.localScale;
float elapsedTime = 0f;
while (elapsedTime < 1f / animationSpeed)
{
elapsedTime += Time.deltaTime;
float progress = elapsedTime * animationSpeed;
transform.localScale = Vector3.Lerp(startScale, targetScale, progress);
yield return null;
}
transform.localScale = targetScale;
}
System.Collections.IEnumerator ClickAnimation()
{
Vector3 clickScale = originalScale * 0.9f;
// Scale down
yield return StartCoroutine(ScaleAnimation(clickScale));
// Scale back up
yield return StartCoroutine(ScaleAnimation(originalScale));
}
public void SetShopManager(ShopUIManager manager)
{
shopManager = manager;
}
public void SetShopIcon(Sprite iconSprite)
{
if (shopIconImage != null)
{
shopIconImage.sprite = iconSprite;
}
}
public void SetInteractable(bool interactable)
{
if (shopIconButton != null)
{
shopIconButton.interactable = interactable;
}
if (shopIconImage != null)
{
shopIconImage.color = interactable ? normalColor : Color.gray;
}
}
void OnDestroy()
{
if (shopIconButton != null)
{
shopIconButton.onClick.RemoveListener(OnShopIconClicked);
}
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: cd13f037c7222a041bb6ab59a7c85e18
@@ -6,8 +6,6 @@ public class ShopSystemSetup : MonoBehaviour
public GShopLoader shopLoader;
public ShopUIManager shopUIManager;
public ShopCategoryManager shopCategoryManager;
public ShopIconHandler shopIconHandler;
[Header("Auto Setup")]
public bool autoFindComponents = true;
@@ -40,12 +38,6 @@ public class ShopSystemSetup : MonoBehaviour
{
shopCategoryManager = FindFirstObjectByType<ShopCategoryManager>();
}
// Find ShopIconHandler
if (shopIconHandler == null)
{
shopIconHandler = FindFirstObjectByType<ShopIconHandler>();
}
}
void ConnectComponents()
@@ -62,12 +54,6 @@ public class ShopSystemSetup : MonoBehaviour
shopCategoryManager.Initialize(shopUIManager);
}
// Connect ShopIconHandler with ShopUIManager
if (shopIconHandler != null && shopUIManager != null)
{
shopIconHandler.SetShopManager(shopUIManager);
}
Debug.Log("Shop system components connected successfully");
}
@@ -108,12 +94,6 @@ public class ShopSystemSetup : MonoBehaviour
isValid = false;
}
if (shopIconHandler == null)
{
Debug.LogError("ShopIconHandler is missing!");
isValid = false;
}
if (isValid)
{
Debug.Log("✓ All shop system components are properly set up!");
@@ -129,7 +129,7 @@ public class ShopUIManager : MonoBehaviour
Debug.Log($"Category switch to {categoryIndex} completed in {switchTime * 1000f:F2}ms");
}
void RefreshShopDisplay()
public void RefreshShopDisplay()
{
// Return all current panels to pool
ReturnAllPanelsToPool();
+79 -205
View File
@@ -81125,17 +81125,11 @@ PrefabInstance:
insertIndex: -1
addedObject: {fileID: 982872367}
m_SourcePrefab: {fileID: 100100000, guid: f2e88ae97c9b2624dbbad1d5fc0c14b8, type: 3}
--- !u!114 &982872359 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 4443224849876948823, guid: f2e88ae97c9b2624dbbad1d5fc0c14b8, type: 3}
--- !u!1 &982872359 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 7404691444252589623, guid: f2e88ae97c9b2624dbbad1d5fc0c14b8, type: 3}
m_PrefabInstance: {fileID: 982872358}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 988a04b7abdde4a44af423870878845a, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!224 &982872360 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 1845571473519222713, guid: f2e88ae97c9b2624dbbad1d5fc0c14b8, type: 3}
@@ -85779,10 +85773,9 @@ GameObject:
- component: {fileID: 1058661534}
- component: {fileID: 1058661538}
- component: {fileID: 1058661537}
- component: {fileID: 1058661536}
- component: {fileID: 1058661535}
- component: {fileID: 1058661539}
m_Layer: 5
m_Name: Button
m_Name: MallBtn
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@@ -85799,16 +85792,15 @@ RectTransform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1.1249999, y: 1.1249999, z: 1.1249999}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1354665858}
m_Children: []
m_Father: {fileID: 77022148}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 941.6249, y: 176.62506}
m_SizeDelta: {x: 160, y: 114.1119}
m_AnchoredPosition: {x: 913.7, y: 169}
m_SizeDelta: {x: 93, y: 95}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1058661535
--- !u!114 &1058661537
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@@ -85817,19 +85809,36 @@ MonoBehaviour:
m_GameObject: {fileID: 1058661533}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cd13f037c7222a041bb6ab59a7c85e18, type: 3}
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
shopIconButton: {fileID: 1058661536}
shopIconImage: {fileID: 1058661537}
shopManager: {fileID: 982872359}
normalColor: {r: 1, g: 1, b: 1, a: 1}
hoverColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1}
pressedColor: {r: 1, g: 0, b: 0, a: 1}
enableHoverAnimation: 1
hoverScale: 1.1
animationSpeed: 5
--- !u!114 &1058661536
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 92771ba86721b394796427b2d71f8d98, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &1058661538
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1058661533}
m_CullTransparentMesh: 1
--- !u!114 &1058661539
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
@@ -85838,7 +85847,7 @@ MonoBehaviour:
m_GameObject: {fileID: 1058661533}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
m_Script: {fileID: 11500000, guid: 9085046f02f69544eb97fd06b6048fe2, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
@@ -85870,47 +85879,37 @@ MonoBehaviour:
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 1058661537}
m_OnClick:
toggleTransition: 1
graphic: {fileID: 0}
m_Group: {fileID: 0}
onValueChanged:
m_PersistentCalls:
m_Calls: []
--- !u!114 &1058661537
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1058661533}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &1058661538
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1058661533}
m_CullTransparentMesh: 1
m_Calls:
- m_Target: {fileID: 982872359}
m_TargetAssemblyTypeName: UnityEngine.GameObject, UnityEngine
m_MethodName: SetActive
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 1123164073}
m_TargetAssemblyTypeName: ShopUIManager, Assembly-CSharp
m_MethodName: RefreshShopDisplay
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_IsOn: 0
--- !u!1 &1059979959
GameObject:
m_ObjectHideFlags: 0
@@ -89715,6 +89714,17 @@ Transform:
- {fileID: 712801087}
m_Father: {fileID: 1548855194}
m_LocalEulerAnglesHint: {x: 2.2721434, y: -40.814484, z: -6.375526}
--- !u!114 &1123164073 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 4443224849876948823, guid: f2e88ae97c9b2624dbbad1d5fc0c14b8, type: 3}
m_PrefabInstance: {fileID: 982872358}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 982872359}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 988a04b7abdde4a44af423870878845a, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1124642183
GameObject:
m_ObjectHideFlags: 0
@@ -108947,142 +108957,6 @@ Transform:
m_Children: []
m_Father: {fileID: 694729138}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1354665857
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1354665858}
- component: {fileID: 1354665860}
- component: {fileID: 1354665859}
m_Layer: 5
m_Name: Text (TMP)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1354665858
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1354665857}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1058661534}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1354665859
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1354665857}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: Button
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4281479730
m_fontColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 24
m_fontSizeBase: 24
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 2
m_VerticalAlignment: 512
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_TextWrappingMode: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 0
m_ActiveFontFeatures: 6e72656b
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_EmojiFallbackSupport: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!222 &1354665860
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1354665857}
m_CullTransparentMesh: 1
--- !u!1 &1355062949
GameObject:
m_ObjectHideFlags: 0