This commit is contained in:
JA
2026-06-20 19:34:23 +08:00
parent e5031c0068
commit d442805c3f
4136 changed files with 514641 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace Managers
{
public class BagManager
{
PlayerInfo Owner;
public BagManager(PlayerInfo owner)
{
this.Owner = owner;
}
public void AddItem(int key, int value)
{
if (Owner == null) return;
if (Owner.info.BagInfo.ContainsKey(key))
{
Owner.info.BagInfo[key] = Owner.info.BagInfo[key] + value;
}
else
{
Owner.info.BagInfo.Add(key, value);
}
Owner.OnUpdateBagInfo?.Invoke();
Owner.OnUpdateMainUI?.Invoke();
}
public void UserItem(int id, int num)
{
if (Owner == null) return;
if (Owner.info.BagInfo.ContainsKey(id))
{
foreach (var item in Date.Instance.ItemDate)//测试使用道具
{
if (item.Id == id && item.type == ItemClass.User)
{
if(Remove(item,num))
{
Debug.Log("使用道具");
item.UseItem(item);
}
}
if(item.Id == id && item.type == ItemClass.Up)
{
Remove(item, num);
}
}
}
else
{
Debug.LogError("道具缺失");
return;
}
}
private bool Remove(Item item,int num)
{
if (Owner.info.BagInfo[item.Id] < num)
{
Debug.LogFormat("UserItem [{0}] count Insufficient", item.ItemName);
return false;
}
Owner.info.BagInfo[item.Id] = Owner.info.BagInfo[item.Id] - num;//背包减少
if (Owner.info.BagInfo[item.Id] <= 0)
{
Owner.info.BagInfo.Remove(item.Id);
}
Owner.OnUpdateBagInfo?.Invoke();
Owner.OnUpdateMainUI?.Invoke();
Owner.WriteBagInfo();
//保存数据
//Debug.Log(Owner.info.BagValue[item.Id]);
SaveSystem.SaveDate(Owner.info.DatePath, Owner.info);
return true;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 20a184ad6c4412540a4cd3c66711e074
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ManagersMode : MonoBehaviour
{
private static PollManager _pool;
public static PollManager Poll
{
get { return _pool; }
}
private void Awake()
{
_pool = this.gameObject.AddComponent<PollManager>();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: afea4f43157c8f541a7fcde752e70440
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PollManager : MonoBehaviour
{
Transform m_PollParent;
//对象池字典
Dictionary<string, PollBase> m_Polls = new Dictionary<string, PollBase>();
private void Awake()
{
m_PollParent = this.transform.parent.Find("Poll");
}
/// <summary>
/// 创建对象池
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="pollName"></param>
/// <param name="releaseTime"></param>
private void CreatePoll<T>(string pollName, float releaseTime)
where T : PollBase
{
if (!m_Polls.TryGetValue(pollName, out PollBase poll))
{
GameObject go = new GameObject();
go.name = pollName;
go.transform.SetParent(m_PollParent);
poll = go.AddComponent<T>();
poll.Init(releaseTime);
m_Polls.Add(pollName, poll);
}
}
/// <summary>
/// 创建物体对象池
/// </summary>
/// <param name="pollName"></param>
/// <param name="releaseTime"></param>
public void CreateGameObjectPoll(string pollName, float releaseTime)
{
CreatePoll<GameObjectPoll>(pollName, releaseTime);
}
/// <summary>
/// 取出对象
/// </summary>
/// <param name="pollName"></param>
/// <param name="asseteName"></param>
/// <returns></returns>
public Object Spwan(string pollName, string asseteName)
{
if (m_Polls.TryGetValue(pollName, out PollBase poll))
{
return poll.Spwan(asseteName);
}
return null;
}
/// <summary>
/// 回收对象
/// </summary>
/// <param name="pollName"></param>
/// <param name="asseteName"></param>
/// <returns></returns>
public void UnSpwan(string pollName, string asseteName, Object assete)
{
if (m_Polls.TryGetValue(pollName, out PollBase poll))
{
poll.UnSpwan(asseteName, assete);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ea449011b5381b246bcdfef0efa1523c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
public class SceneMonsterManager : MonoBehaviour
{
[SerializeField, Header("怪物列表")] private List<GameObject> monsters = new List<GameObject>();
[SerializeField, Header("怪物生成速率")] private float timer;
public Transform teleporte;
public bool isTeleport = false;
public GameObject box;
private int count = 0;
private float t = 0;
private void Awake()
{
foreach (var item in monsters)
{
item.SetActive(false);
}
}
private void Update()
{
t += Time.deltaTime;
if (t >= timer)
{
Debug.Log(isTeleport);
ABC();
ProtectedMonster();
}
}
void ProtectedMonster()
{
if (count >= monsters.Count)
{
return;
}
monsters[count].SetActive(true);
count += 1;
t = 0;
}
void ABC()
{
if(transform.childCount==0&&!isTeleport)
{
//UIManager.Instance.Show<UILottery>();
Instantiate(box);
isTeleport = true;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3c6d37fb46cffe1408e982d6d1b9a190
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,49 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Events;
namespace Manager
{
class SenceManager:MonoSingleton<SenceManager>
{
UnityAction<float> onProgress = null;
public void LoadScene(int name)
{
StartCoroutine(LoadLevel(name));
}
IEnumerator LoadLevel( int id)
{
Debug.LogFormat("LoadLevel: {0}", name);
AsyncOperation async = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(id);
async.allowSceneActivation = true;
async.completed += LevelLoadCompleted;
//保存数据
PlayerInfo.Instance.info.currentMap=id;
SaveSystem.SaveDate(PlayerInfo.Instance.info.DatePath, PlayerInfo.Instance.info);
while (!async.isDone)
{
if (onProgress != null)
onProgress(async.progress);
yield return null;
}
}
private void LevelLoadCompleted(AsyncOperation obj)
{
if (onProgress != null)
onProgress(1f);
Debug.Log("LevelLoadCompleted:" + obj.progress);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 36641df8733b77f4fb770f6bcfcc598f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,119 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
namespace Manager
{
public class SoundManager : MonoSingleton<SoundManager>
{
public AudioMixer audioMixer;//»ìÒôÆ÷
public AudioSource MusicSource;
public AudioSource SoundSource;
const string MusicPath = "Music/";
const string SoundPath = "Sound/";
private bool musicOn;
public bool MusicOn
{
get { return musicOn; }
set
{
musicOn = value;
this.MusicMute(!musicOn);
}
}
private bool soundOn;
public bool SoundOn
{
get { return soundOn; }
set
{
soundOn = value;
this.SoundMute(!soundOn);
}
}
private int musicVolume;
public int MusicVolume
{
get { return musicVolume; }
set
{
musicVolume = value;
if (musicOn) this.SetVolume("MusicVolume", musicVolume);
}
}
private int soundVolume;
public int SoundVolume
{
get { return soundVolume; }
set
{
soundVolume = value;
if (soundOn) this.SetVolume("SoundVolume", soundVolume);
}
}
public void SoundMute(bool mute)
{
this.SetVolume("SoundVolume", mute ? 0 : soundVolume);
}
public void MusicMute(bool mute)
{
this.SetVolume("MusicVolume", mute ? 0 : musicVolume);
}
void SetVolume(string name, int value)
{
float volume = value * 0.5f - 50f;
this.audioMixer.SetFloat(name, volume);
}
void Start()
{
this.MusicVolume = SystemConfig.MusicVolume;
this.SoundVolume = SystemConfig.SoundVolume;
this.MusicOn = SystemConfig.MusicOn;
this.soundOn = SystemConfig.SoundOn;
}
public void PlayMusic(string name)
{
AudioClip clip = Resloader.Load<AudioClip>(MusicPath + name);
if (clip == null)
{
Debug.LogWarningFormat("PlayMusic:{0} not existed", name);
return;
}
if (MusicSource.isPlaying)
{
MusicSource.Stop();
}
MusicSource.clip = clip;
MusicSource.Play();
}
public void PlaySound(string name)
{
AudioClip clip = Resloader.Load<AudioClip>(SoundPath + name);
if (clip == null)
{
Debug.LogWarningFormat("PlaySound:{0} not existed", name);
return;
}
SoundSource.PlayOneShot(clip);
}
public void PlayEffect(AudioSource audio,AudioClip clip)
{
if (clip == null)
{
Debug.LogWarningFormat("PlaySound:{0} not existed", name);
return;
}
audio.PlayOneShot(clip);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1e3d9918daf58924b994f65a2ebd4d19
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,90 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIManager : Singleton<UIManager>
{
class UIElement
{
public string Resources; //资源路径
public bool Cache; //是否启用
public GameObject Instance; //资源预制体
}
private Dictionary<Type, UIElement> UIResources = new Dictionary<Type, UIElement>(); //存放
public UIManager()
{
this.UIResources.Add(typeof(UILoad), new UIElement() { Resources = "UI/UILoad", Cache = false });
this.UIResources.Add(typeof(UISetting), new UIElement() { Resources = "UI/UISetting", Cache = false });
this.UIResources.Add(typeof(UIGameOver), new UIElement() { Resources = "UI/GameOver", Cache = false });
this.UIResources.Add(typeof(UILottery), new UIElement() { Resources = "UI/LotterySystem", Cache = false });
this.UIResources.Add(typeof(UIEnterScene), new UIElement() { Resources = "UI/EnterScene", Cache = false });
this.UIResources.Add(typeof(UIOpen), new UIElement() { Resources = "UI/UIOpen", Cache = false });
this.UIResources.Add(typeof(EndUI), new UIElement() { Resources = "UI/EndUI", Cache = false });
this.UIResources.Add(typeof(UIBagInfo), new UIElement() { Resources = "UI/BagUI", Cache = false });
this.UIResources.Add(typeof(UILevelUp), new UIElement() { Resources = "UI/UILevelUp", Cache = false });
this.UIResources.Add(typeof(MessageBox), new UIElement() { Resources = "UI/MessageBox", Cache = false });
this.UIResources.Add(typeof(UISaveDate), new UIElement() { Resources = "UI/UISave", Cache = false });
}
~UIManager()
{
}
/// <summary>
/// 加载UI
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public T Show<T>()
{
Type type=typeof(T);
if(this.UIResources.ContainsKey(type))
{
UIElement info = UIResources[type];
if(info.Instance!=null)
{
info.Instance.SetActive(true);
}
else
{
UnityEngine.Object prefab = Resources.Load(info.Resources);
if (prefab == null)
{
return default(T);
}
info.Instance = (GameObject)GameObject.Instantiate(prefab);
}
return info.Instance.GetComponent<T>();
}
return default(T);
}
/// <summary>
/// 关闭UI
/// </summary>
/// <param name="type"></param>
public void Close(Type type)
{
if (this.UIResources.ContainsKey(type))
{
UIElement info = this.UIResources[type];
if (info.Cache)
{
info.Instance.SetActive(false);
}
else
{
GameObject.Destroy(info.Instance);
info.Instance = null;
}
}
}
public void Close<T>()
{
this.Close(typeof(T));
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d821662459e6c244fb644e067145f977
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class UIWindow : MonoBehaviour
{
public delegate void CloseHandler(UIWindow sender, WindowResult result);
public event CloseHandler OnClose;
public GameObject Root;
public virtual System.Type Type { get { return this.GetType(); } }
public enum WindowResult
{
None = 0,
Yes,
NO,
}
public void Close(WindowResult result = WindowResult.None)
{
UIManager.Instance.Close(this.Type);
if (this.OnClose != null)
this.OnClose(this, result);
this.OnClose = null;
}
public virtual void OnCloseClick()
{
this.Close();
}
public virtual void OnYesClick()
{
this.Close(WindowResult.Yes);
}
public virtual void OnNoClick()
{
this.Close(WindowResult.NO);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eac807a7fb4a9ed47ba6b0209ab646d3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: