写了个贼牛逼的ui父类

This commit is contained in:
wulongxiao 2024-11-27 11:49:57 +08:00
parent acd8b40f0f
commit 730f0d33d7
6 changed files with 227 additions and 11 deletions

View File

@ -6,7 +6,7 @@ using DG.Tweening;
//显示动画
public class main_BaseShowPanel : MonoBehaviour
{
{
[Header("父类自动的panel按需要给")]
public GameObject _panel;
public void showPanel(GameObject panel)

View File

@ -1,13 +1,42 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ui_huodong :main_BaseShowPanel
{
[Header("按钮,请和面板一一对应")]
public List<Button> btns = new List<Button>();
[Header("面板,请和按钮一一对应")]
public List<GameObject> panels=new List<GameObject>();
// Start is called before the first frame update
void Start()
{
base.showPanel(base._panel);
// 确保btns和panels列表的大小一致
if (btns.Count != panels.Count)
{
Debug.LogError("按钮列表和面板列表的数量不匹配!");
return; // 防止继续执行
}
// 反向遍历按钮列表
for (int index = 0; index < btns.Count; index++)
{
int currentIndex = index; // 创建一个局部变量来捕获当前的index
btns[currentIndex].onClick.AddListener(() =>
{
if (panels[currentIndex] == null)
{
Debug.LogError("panel is null");
return;
}
GameObject.Instantiate(panels[currentIndex],GameObject.Find("Canvas").GetComponent<Transform>());
});
}
}

View File

@ -2,11 +2,8 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ui_huodongguize :main_BaseShowPanel
public class ui_huodongguize: ui_huodong
{
void Start()
{
base.showPanel(base._panel);
}
}

View File

@ -2,10 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ui_huodongxiangqing :main_BaseShowPanel
public class ui_huodongxiangqing :ui_huodong
{
void Start()
{
base.showPanel(base._panel);
}
}

View File

@ -543,7 +543,16 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c95363cad8b348746bb23e5c2999c90d, type: 3}
m_Name:
m_EditorClassIdentifier:
_canvas: {fileID: 0}
_panel: {fileID: 499058876202855932}
btns:
- {fileID: 589695940868190867}
- {fileID: 7321123989325159614}
- {fileID: 2047883622368478094}
panels:
- {fileID: 499058875926005686, guid: 505b246c7a82d2e4bb24cc057b8bd793, type: 3}
- {fileID: 499058875926005686, guid: 505b246c7a82d2e4bb24cc057b8bd793, type: 3}
- {fileID: 499058875926005686, guid: 505b246c7a82d2e4bb24cc057b8bd793, type: 3}
--- !u!1 &499058876078584823
GameObject:
m_ObjectHideFlags: 0
@ -631,6 +640,7 @@ GameObject:
- component: {fileID: 499058876109961378}
- component: {fileID: 499058876109961376}
- component: {fileID: 499058876109961439}
- component: {fileID: 589695940868190867}
m_Layer: 5
m_Name: t2
m_TagString: Untagged
@ -687,6 +697,50 @@ MonoBehaviour:
m_FlexibleWidth: -1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &589695940868190867
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 499058876109961379}
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: 0}
m_OnClick:
m_PersistentCalls:
m_Calls: []
--- !u!1 &499058876167891745
GameObject:
m_ObjectHideFlags: 0
@ -920,6 +974,7 @@ GameObject:
- component: {fileID: 7887763884358934968}
- component: {fileID: 8879021915959974125}
- component: {fileID: 8044630059487427399}
- component: {fileID: 7321123989325159614}
m_Layer: 5
m_Name: t3
m_TagString: Untagged
@ -976,6 +1031,50 @@ MonoBehaviour:
m_FlexibleWidth: -1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &7321123989325159614
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 737395417232846308}
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: 0}
m_OnClick:
m_PersistentCalls:
m_Calls: []
--- !u!1 &743420519794011153
GameObject:
m_ObjectHideFlags: 0
@ -1063,6 +1162,7 @@ GameObject:
- component: {fileID: 7732135253984477920}
- component: {fileID: 6439638315203938387}
- component: {fileID: 5254693992088958375}
- component: {fileID: 2047883622368478094}
m_Layer: 5
m_Name: t4
m_TagString: Untagged
@ -1119,6 +1219,50 @@ MonoBehaviour:
m_FlexibleWidth: -1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &2047883622368478094
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2454270055691179675}
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: 0}
m_OnClick:
m_PersistentCalls:
m_Calls: []
--- !u!1 &3941312822989608268
GameObject:
m_ObjectHideFlags: 0

View File

@ -544,6 +544,10 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
_panel: {fileID: 499058876202855932}
btns:
- {fileID: 5838319156628403795}
panels:
- {fileID: 499058875926005686, guid: ddafb4e1a6fbede44ad0d183e29fe953, type: 3}
--- !u!1 &499058876078584823
GameObject:
m_ObjectHideFlags: 0
@ -631,6 +635,7 @@ GameObject:
- component: {fileID: 499058876109961378}
- component: {fileID: 499058876109961376}
- component: {fileID: 499058876109961439}
- component: {fileID: 5838319156628403795}
m_Layer: 5
m_Name: t2
m_TagString: Untagged
@ -687,6 +692,50 @@ MonoBehaviour:
m_FlexibleWidth: -1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!114 &5838319156628403795
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 499058876109961379}
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: 0}
m_OnClick:
m_PersistentCalls:
m_Calls: []
--- !u!1 &499058876167891745
GameObject:
m_ObjectHideFlags: 0