Commit 2d6afbcd authored by Ever's avatar Ever

添加一些新的创建组列表代码

parent 70230318
...@@ -12,13 +12,6 @@ public class GameMgr : MonoBehaviour ...@@ -12,13 +12,6 @@ public class GameMgr : MonoBehaviour
get { return ins; } get { return ins; }
} }
private void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
FileUtility.Instance.SavePng(md.png);
}
}
private void Start() private void Start()
{ {
ins = this; ins = this;
......
This diff is collapsed.
...@@ -2,126 +2,30 @@ ...@@ -2,126 +2,30 @@
using UnityEngine; using UnityEngine;
using System; using System;
public class ParamedEventDispatcher<T> public static class EventDispatcher
{ {
private Dictionary<string, Action<T>> mEventList = new Dictionary<string, Action<T>>(); public delegate void DispatchDelegate(params object[] values);
public void RegisterEvent(string name, Action<T> callback, bool register)
{
if (register)
{
if (!mEventList.ContainsKey(name))
mEventList.Add(name, callback);
else
mEventList[name] += callback;
}
else
mEventList[name] -= callback;
}
public void Dispatch(string name, T value)
{
if (mEventList.TryGetValue(name, out var _callbackList))
{
_callbackList?.Invoke(value);
}
}
}
public class EventDispatcher
{
static Dictionary<string, Action> mEventList = new Dictionary<string, Action>();
static ParamedEventDispatcher<string> mStringEventDispatcher = new ParamedEventDispatcher<string>();
static ParamedEventDispatcher<float> mFloatEventDispatcher = new ParamedEventDispatcher<float>();
static ParamedEventDispatcher<Vector3> mVector3EventDispatcher = new ParamedEventDispatcher<Vector3>();
static ParamedEventDispatcher<bool> mBoolEventDispatcher = new ParamedEventDispatcher<bool>();
static ParamedEventDispatcher<long> mLongEventDispatcher = new ParamedEventDispatcher<long>();
/// <summary> private static Dictionary<string, DispatchDelegate> eVentList = new Dictionary<string, DispatchDelegate>();
/// 注册事件 public static void RegisterEvent(string name, DispatchDelegate callback, bool register)
/// </summary>
/// <param name="name"></param>
/// <param name="callback"></param>
/// <param name="register"></param>
public static void RegisterEvent(string name, Action callback, bool register)
{ {
if (register) if (register)
{ {
if (!mEventList.ContainsKey(name)) if (!eVentList.ContainsKey(name))
mEventList.Add(name, callback); eVentList.Add(name, callback);
else else
mEventList[name] += callback; eVentList[name] += callback;
} }
else else
if (mEventList.ContainsKey(name)) eVentList[name] -= callback;
mEventList[name] -= callback;
} }
/// <summary> public static void Dispatch(string name, params object[] value)
/// 发送事件
/// </summary>
/// <param name="name"></param>
public static void Dispatch(string name)
{ {
if (mEventList.TryGetValue(name, out var _callbackList)) if (eVentList.TryGetValue(name, out var _callbackList))
{ {
_callbackList?.Invoke(); _callbackList?.Invoke(value);
} }
} }
/// <summary>
/// 注册事件、register true为注册 false为释放
/// </summary>
/// <param name="name"></param>
/// <param name="callback"></param>
/// <param name="register"></param>
public static void RegisterEvent(string name, Action<string> callback, bool register)
{
mStringEventDispatcher.RegisterEvent(name, callback, register);
}
public static void Dispatch(string name, string value)
{
mStringEventDispatcher.Dispatch(name, value);
Dispatch(name);
}
public static void RegisterEvent(string name, Action<Vector3> callback, bool register)
{
mVector3EventDispatcher.RegisterEvent(name, callback, register);
}
public static void Dispatch(string name, Vector3 value)
{
mVector3EventDispatcher.Dispatch(name, value);
Dispatch(name);
}
public static void RegisterEvent(string name, Action<bool> callback, bool register)
{
mBoolEventDispatcher.RegisterEvent(name, callback, register);
}
public static void Dispatch(string name, bool value)
{
mBoolEventDispatcher.Dispatch(name, value);
Dispatch(name);
}
public static void RegisterEvent(string name, Action<float> callback, bool register)
{
mFloatEventDispatcher.RegisterEvent(name, callback, register);
}
public static void Dispatch(string name, float value)
{
mFloatEventDispatcher.Dispatch(name, value);
Dispatch(name);
}
public static void RegisterEvent(string name, Action<long> callback, bool register)
{
mLongEventDispatcher.RegisterEvent(name, callback, register);
}
public static void Dispatch(string name, long value)
{
mLongEventDispatcher.Dispatch(name, value);
Dispatch(name);
}
} }
\ No newline at end of file
...@@ -25,6 +25,15 @@ public static class EventName ...@@ -25,6 +25,15 @@ public static class EventName
public const string Event_showImagePageData = "showImagePageData"; public const string Event_showImagePageData = "showImagePageData";
public const string Event_switchPage = "switchPage"; public const string Event_switchPage = "switchPage";
public const string Event_setImageViewLable = "setImageViewLable"; public const string Event_setImageViewLable = "setImageViewLable";
public const string Event_LoadingPanelCLose = "LoadingPanelCLose";//加载进度界面关闭
public const string Event_LoadingChange = "Event_LoadingChange"; //加载界面进度改变
public const string Event_GroupListCreate = "Event_GroupListCreate";//加载组的数量
public const string Event_GropuItemChange = "Event_GropuItemChange";//某个组的进度改变
public const string Event_GroupItemClick = "Event_GroupItemClick";//点击某一个组
public const string Event_AllGroupOver = "Event_AllGroupOver";//游戏结束,全部组都涂完了
} }
public class DataName public class DataName
......
fileFormatVersion: 2
guid: d969c7038afe56e488abfa374e53f34b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LoadingPanel : MonoBehaviour
{
public Slider JIndu;
// Start is called before the first frame update
void Start()
{
RegisterEvent(true);
}
private void OnDestroy()
{
RegisterEvent(false);
}
private void RegisterEvent(bool flag)
{
EventDispatcher.RegisterEvent(EventName.Event.Event_LoadingChange, ChangeSlider, flag);
EventDispatcher.RegisterEvent(EventName.Event.Event_LoadingPanelCLose, ClosePanel, flag);
}
private void ClosePanel(object[] values)
{
gameObject.SetActive(false);
}
private void ChangeSlider(object[] values)
{
//JIndu.value = value;
}
}
fileFormatVersion: 2
guid: 3410719131608854fb387489813f7421
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 804bd96816d3e4644a15363efb564de6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameEndPanel : MonoBehaviour
{
public GameObject BG;
public Button SaveVideo_Btn;
public Button RePlayVideo_Btn;
public Button Share_Btn;
public Button Continue_Btn;
public Transform PicParent;
public ScrollRect scrollRect;
public HorizontalLayoutGroup ItemParent;
public GameObject item_obj;
private void Start()
{
ResiterEvent(true);
BG.SetActive(false);
SaveVideo_Btn.onClick.AddListener(SaveVideo_Btn_Click);
RePlayVideo_Btn.onClick.AddListener(RePlayVideo_Btn_Click);
Share_Btn.onClick.AddListener(Share_Btn_Click);
Continue_Btn.onClick.AddListener(Continue_Btn_Click);
}
private void CreateItem() //创建列表item
{
int childNum = 10;
for (int i = 0; i < childNum; i++)
{
var child = Instantiate(item_obj).transform;
child.SetParent(ItemParent.transform);
child.gameObject.SetActive(true);
child.localEulerAngles = Vector3.zero;
child.localScale = Vector3.one;
child.localPosition= Vector3.zero;
}
}
private void Continue_Btn_Click()
{
Debug.Log("点击继续按钮");
}
private void Share_Btn_Click()
{
Debug.Log("点击分享按钮");
}
private void RePlayVideo_Btn_Click()
{
Debug.Log("点击回放动画");
}
private void SaveVideo_Btn_Click()
{
Debug.Log("点击保存视频");
}
private void ResiterEvent(bool flag)
{
EventDispatcher.RegisterEvent(EventName.Event.Event_AllGroupOver, GameEnd, flag);
}
private void GameEnd(object[] values)
{
BG.SetActive(true);
CreateItem();
}
}
fileFormatVersion: 2
guid: 06843c444db04674a8142dd5e251e42d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -57,8 +57,8 @@ public class gameInLoading : MonoBehaviour,IEventHandler ...@@ -57,8 +57,8 @@ public class gameInLoading : MonoBehaviour,IEventHandler
slider.value = 0; slider.value = 0;
slider.maxValue = maxvalue; slider.maxValue = maxvalue;
slider.minValue = 0; slider.minValue = 0;
utilsTools.onEvent(this, EventName.Event.Event_inGameLoadingValue); //utilsTools.onEvent(this, EventName.Event.Event_inGameLoadingValue);
utilsTools.onEvent(this, EventName.Event.Event_initViewShowData); //utilsTools.onEvent(this, EventName.Event.Event_initViewShowData);
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
......
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
public class GroupListManager : MonoBehaviour
{
public ScrollRect scrollview; //列表
public GameObject GroupItem_Obj; //要实例化的预制体
public GridLayoutGroup Content;
private List<colorItem> AllItem = new List<colorItem>();
// Start is called before the first frame update
void Start()
{
ResiterEvent(true);
}
private void ResiterEvent(bool flag)
{
EventDispatcher.RegisterEvent(EventName.Event.Event_GroupListCreate, CreateGroup, flag);
EventDispatcher.RegisterEvent(EventName.Event.Event_GropuItemChange, GroupItemChange, flag);
}
private void GroupItemChange(object[] values)
{
RoomGroupsData data = (RoomGroupsData)values[0];
float Jindu = 0.4f;
var item = AllItem.FirstOrDefault((a) => { return a.GID == data.id; });
if (item != null)
{
item.ChangeProgress(Jindu);
}
}
private void CreateGroup(object[] values)
{
List<RoomGroupsData> roomGroupsData = (List<RoomGroupsData>)values[0];
int AllGroupNum = roomGroupsData.Count; //总的组个数
float NowJindu = 0.4f; //现在的进度
Transform tran;
foreach (var item in roomGroupsData)
{
tran = GameObject.Instantiate(GroupItem_Obj).transform;
tran.SetParent(Content.transform);
tran.localPosition = Vector3.zero;
tran.localRotation = Quaternion.Euler(0, 0, 0);
tran.localScale = Vector3.one;
var coloritem = tran.GetComponent<colorItem>();
coloritem.Init(new Color(item.R, item.G, item.B), NowJindu,item.id);
AllItem.Add(coloritem);
}
}
}
fileFormatVersion: 2
guid: 188c7a4252da17a499888b798e1639de
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -7,6 +7,7 @@ using Unity.VisualScripting; ...@@ -7,6 +7,7 @@ using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
using static UnityEngine.InputManagerEntry;
public class colorItem : MonoBehaviour, IPointerDownHandler, IPointerUpHandler public class colorItem : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{ {
...@@ -68,6 +69,23 @@ public class colorItem : MonoBehaviour, IPointerDownHandler, IPointerUpHandler ...@@ -68,6 +69,23 @@ public class colorItem : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
return isSelect; return isSelect;
} }
} }
public void Init(Color color,float Jindu,int groupid)
{
IsSelect = false;
if (mat == null)
{
CreateMat();
}
NowProgress = Jindu;
UseColor = color;
GID = groupid;
}
public void ChangeProgress(float jindu)
{
NowProgress = jindu;
}
public void PlayInitAni() public void PlayInitAni()
{ {
transform.DOScale(Vector3.one * SelectAniScale, 0.3f).onComplete=()=> { transform.DOScale(Vector3.one * NotSelectScale, 0.2f); }; transform.DOScale(Vector3.one * SelectAniScale, 0.3f).onComplete=()=> { transform.DOScale(Vector3.one * NotSelectScale, 0.2f); };
...@@ -144,10 +162,6 @@ public class colorItem : MonoBehaviour, IPointerDownHandler, IPointerUpHandler ...@@ -144,10 +162,6 @@ public class colorItem : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
//effectImg.Height = 1.0f - nowProgress; //effectImg.Height = 1.0f - nowProgress;
//effectImg.Height = nowProgress; //effectImg.Height = nowProgress;
if (mat == null)
{
CreateMat();
}
Image_Jindu.material.SetFloat("progress", nowProgress); Image_Jindu.material.SetFloat("progress", nowProgress);
transform.Find("idname").gameObject.SetActive(!isend); transform.Find("idname").gameObject.SetActive(!isend);
...@@ -200,10 +214,6 @@ public class colorItem : MonoBehaviour, IPointerDownHandler, IPointerUpHandler ...@@ -200,10 +214,6 @@ public class colorItem : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
Image_DI.color = color1; Image_DI.color = color1;
if (mat == null)
{
CreateMat();
}
Image_Jindu.material.SetColor("color1", UseColor); Image_Jindu.material.SetColor("color1", UseColor);
Image_Jindu.material.SetColor("color2", new Color(color1.r, color1.g - 0.1f, color1.b - 0.1f, color1.a)); Image_Jindu.material.SetColor("color2", new Color(color1.r, color1.g - 0.1f, color1.b - 0.1f, color1.a));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment