Add task icon, correct show logic, dlg ui feature
This commit is contained in:
@@ -4635,6 +4635,7 @@ RectTransform:
|
||||
- {fileID: 1687288316189840478}
|
||||
- {fileID: 3413131598704007284}
|
||||
- {fileID: 1802319080125745111}
|
||||
- {fileID: 8560871508586000967}
|
||||
m_Father: {fileID: 9127077926286418868}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0.5, y: 0.5}
|
||||
@@ -4997,6 +4998,138 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
m_HorizontalFit: 0
|
||||
m_VerticalFit: 2
|
||||
--- !u!1 &5079467856058945530
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 8560871508586000967}
|
||||
- component: {fileID: 4358218663584653282}
|
||||
- component: {fileID: 2639378489502838745}
|
||||
- component: {fileID: 7962930401627561727}
|
||||
m_Layer: 5
|
||||
m_Name: Button
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!224 &8560871508586000967
|
||||
RectTransform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5079467856058945530}
|
||||
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: 945666739613519770}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 1, y: 1}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
m_AnchoredPosition: {x: -62, y: -72}
|
||||
m_SizeDelta: {x: 58, y: 58}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!222 &4358218663584653282
|
||||
CanvasRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5079467856058945530}
|
||||
m_CullTransparentMesh: 1
|
||||
--- !u!114 &2639378489502838745
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5079467856058945530}
|
||||
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: 21300000, guid: fb2f2f58be45f6e4890e85cc00b0bcc9, 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!114 &7962930401627561727
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5079467856058945530}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Navigation:
|
||||
m_Mode: 3
|
||||
m_WrapAround: 0
|
||||
m_SelectOnUp: {fileID: 0}
|
||||
m_SelectOnDown: {fileID: 0}
|
||||
m_SelectOnLeft: {fileID: 0}
|
||||
m_SelectOnRight: {fileID: 0}
|
||||
m_Transition: 1
|
||||
m_Colors:
|
||||
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
|
||||
m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
|
||||
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
|
||||
m_ColorMultiplier: 1
|
||||
m_FadeDuration: 0.1
|
||||
m_SpriteState:
|
||||
m_HighlightedSprite: {fileID: 0}
|
||||
m_PressedSprite: {fileID: 0}
|
||||
m_SelectedSprite: {fileID: 0}
|
||||
m_DisabledSprite: {fileID: 0}
|
||||
m_AnimationTriggers:
|
||||
m_NormalTrigger: Normal
|
||||
m_HighlightedTrigger: Highlighted
|
||||
m_PressedTrigger: Pressed
|
||||
m_SelectedTrigger: Selected
|
||||
m_DisabledTrigger: Disabled
|
||||
m_Interactable: 1
|
||||
m_TargetGraphic: {fileID: 2639378489502838745}
|
||||
m_OnClick:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 6999114045547682248}
|
||||
m_TargetAssemblyTypeName: UnityEngine.GameObject, UnityEngine
|
||||
m_MethodName: SetActive
|
||||
m_Mode: 6
|
||||
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
|
||||
--- !u!1 &5087525444877170506
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -6483,8 +6616,8 @@ MonoBehaviour:
|
||||
m_TargetGraphic: {fileID: 7392889747821849613}
|
||||
m_HandleRect: {fileID: 2343337405992641122}
|
||||
m_Direction: 2
|
||||
m_Value: 0
|
||||
m_Size: 0.9999435
|
||||
m_Value: 1
|
||||
m_Size: 1
|
||||
m_NumberOfSteps: 0
|
||||
m_OnValueChanged:
|
||||
m_PersistentCalls:
|
||||
@@ -8731,7 +8864,7 @@ PrefabInstance:
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8395333742829132721, guid: 9456de25596014039bd4d0d3927b709a, type: 3}
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 336.93
|
||||
value: 336.93002
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8395333742829132721, guid: 9456de25596014039bd4d0d3927b709a, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.x
|
||||
|
||||
@@ -15,6 +15,7 @@ using PerfectWorld.Scripts.Task;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
|
||||
namespace BrewMonster.Scripts.Task.UI
|
||||
{
|
||||
@@ -150,6 +151,7 @@ namespace BrewMonster.Scripts.Task.UI
|
||||
private new void OnEnable()
|
||||
{
|
||||
OnShowDialog();
|
||||
OnCommand_havequest();
|
||||
}
|
||||
|
||||
private new void Awake()
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:49dbfd3874bae260b9c7fd5cf05128cc19c395f788f891042d55cebf488bb41f
|
||||
size 200520845
|
||||
oid sha256:397ac9cbccc4da94dc85eb3c9f08ebde4a37f97ef96ae1b8046b17e0f036c775
|
||||
size 200529103
|
||||
|
||||
+100
-22
@@ -63,36 +63,114 @@ public class CECUIManager : MonoSingleton<CECUIManager>
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lấy hoặc spawn UI mới nếu chưa có
|
||||
/// Show UI by name of component ("DlgTask", "EC_InventoryUI")
|
||||
/// </summary>
|
||||
public T ShowUI<T>() where T : Component
|
||||
/// <param name="componentName">name of component ("DlgTask", "EC_InventoryUI")</param>
|
||||
public void ShowUI(string componentName)
|
||||
{
|
||||
var type = typeof(T);
|
||||
if (string.IsNullOrEmpty(componentName) || canvasDlg == null)
|
||||
{
|
||||
if (canvasDlg == null) Debug.LogError("canvasDlg chưa được gán");
|
||||
return;
|
||||
}
|
||||
|
||||
// Nếu đã spawn rồi thì bật lại
|
||||
if (_spawnedUIs.TryGetValue(type, out var uiGo))
|
||||
var type = FindTypeByName(componentName);
|
||||
|
||||
if (TryShowCachedUI(type)) return;
|
||||
if (FindUIByName(componentName, type)) return;
|
||||
if (FindUIByType(type)) return;
|
||||
|
||||
Debug.LogWarning($"Không tìm thấy UI {componentName} đã spawn trong canvasDlg. Type found: {(type != null ? type.FullName : "null")}");
|
||||
}
|
||||
|
||||
private System.Type FindTypeByName(string componentName)
|
||||
{
|
||||
string[] namespacePrefixes = {
|
||||
"", // No namespace
|
||||
"BrewMonster.Scripts.Task.UI.",
|
||||
"BrewMonster.UI.",
|
||||
"BrewMonster.Scripts.UI.",
|
||||
"BrewMonster."
|
||||
};
|
||||
|
||||
// Try with common namespace prefixes
|
||||
foreach (var prefix in namespacePrefixes)
|
||||
{
|
||||
string fullTypeName = string.IsNullOrEmpty(prefix) ? componentName : prefix + componentName;
|
||||
var type = System.Type.GetType(fullTypeName);
|
||||
if (type != null) return type;
|
||||
}
|
||||
|
||||
// Search in all assemblies
|
||||
foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
var type = assembly.GetType(componentName);
|
||||
if (type != null) return type;
|
||||
|
||||
foreach (var prefix in namespacePrefixes)
|
||||
{
|
||||
if (string.IsNullOrEmpty(prefix)) continue;
|
||||
type = assembly.GetType(prefix + componentName);
|
||||
if (type != null) return type;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool TryShowCachedUI(System.Type type)
|
||||
{
|
||||
if (type != null && _spawnedUIs.TryGetValue(type, out var uiGo))
|
||||
{
|
||||
uiGo.SetActive(true);
|
||||
return uiGo.GetComponent<T>();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Tìm prefab phù hợp
|
||||
var prefab = uiPrefabs.Find(p => p.GetComponent<T>() != null);
|
||||
if (prefab == null)
|
||||
{
|
||||
Debug.LogError($"Không tìm thấy prefab chứa component {type.Name}");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Spawn mới
|
||||
var instance = Instantiate(prefab, uiRoot ? uiRoot : transform);
|
||||
instance.name = $"{type.Name}_UI";
|
||||
_spawnedUIs[type] = instance;
|
||||
instance.SetActive(true);
|
||||
|
||||
return instance.GetComponent<T>();
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool FindUIByName(string componentName, System.Type type)
|
||||
{
|
||||
for (int i = 0; i < canvasDlg.transform.childCount; i++)
|
||||
{
|
||||
var child = canvasDlg.transform.GetChild(i);
|
||||
if (!child.name.Contains(componentName) && child.name != componentName) continue;
|
||||
|
||||
if (type != null)
|
||||
{
|
||||
var foundComponent = child.GetComponentInChildren(type, true);
|
||||
if (foundComponent != null)
|
||||
{
|
||||
ActivateAndCacheUI(foundComponent.gameObject, type);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
ActivateAndCacheUI(child.gameObject, type);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool FindUIByType(System.Type type)
|
||||
{
|
||||
if (type == null) return false;
|
||||
|
||||
var foundComponent = canvasDlg.GetComponentInChildren(type, true);
|
||||
if (foundComponent != null)
|
||||
{
|
||||
ActivateAndCacheUI(foundComponent.gameObject, type);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void ActivateAndCacheUI(GameObject uiGameObject, System.Type type)
|
||||
{
|
||||
uiGameObject.SetActive(true);
|
||||
if (type != null) _spawnedUIs[type] = uiGameObject;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Ẩn UI (disable thay vì destroy)
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user