公共Mono模块
This commit is contained in:
parent
ae2237a011
commit
3efdf65bdb
8
Assets/Scripts/ProjectBase/Mono.meta
Normal file
8
Assets/Scripts/ProjectBase/Mono.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e30bce2b8dc3a1542ab441145ccbca6a
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
48
Assets/Scripts/ProjectBase/Mono/MonoController.cs
Normal file
48
Assets/Scripts/ProjectBase/Mono/MonoController.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Events;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Mono的管理类
|
||||||
|
/// 1.声明周期函数
|
||||||
|
/// 2.事件
|
||||||
|
/// 3.协程
|
||||||
|
/// </summary>
|
||||||
|
public class MonoController : MonoBehaviour
|
||||||
|
{
|
||||||
|
private event UnityAction updateEvent;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
DontDestroyOnLoad(this.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if (updateEvent != null)
|
||||||
|
{
|
||||||
|
updateEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 给外部提供的添加帧更新事件的函数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fun"></param>
|
||||||
|
public void AddUpdateListener(UnityAction fun)
|
||||||
|
{
|
||||||
|
updateEvent += fun;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 提供给外部 用于移除帧更新事件函数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fun"></param>
|
||||||
|
public void RemoveUpdateListener(UnityAction fun)
|
||||||
|
{
|
||||||
|
updateEvent -= fun;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
Assets/Scripts/ProjectBase/Mono/MonoController.cs.meta
Normal file
11
Assets/Scripts/ProjectBase/Mono/MonoController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 981b118304ab49c45bf5c15ce9853338
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
58
Assets/Scripts/ProjectBase/Mono/MonoMgr.cs
Normal file
58
Assets/Scripts/ProjectBase/Mono/MonoMgr.cs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Events;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 可以提供给外部添加帧更新事件的方法
|
||||||
|
/// 可以给外部添加协程的方法
|
||||||
|
/// </summary>
|
||||||
|
public class MonoMgr : BaseManager<MonoMgr>
|
||||||
|
{
|
||||||
|
private MonoController controller;
|
||||||
|
|
||||||
|
public MonoMgr()
|
||||||
|
{
|
||||||
|
//保证了MonoController的唯一性
|
||||||
|
GameObject obj = new GameObject("MonoController");
|
||||||
|
controller = obj.AddComponent<MonoController>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 给外部提供的添加帧更新事件的函数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fun"></param>
|
||||||
|
public void AddUpdateListener(UnityAction fun)
|
||||||
|
{
|
||||||
|
controller.AddUpdateListener(fun);
|
||||||
|
// controller.StartCoroutine();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 提供给外部 用于移除帧更新事件函数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fun"></param>
|
||||||
|
public void RemoveUpdateListener(UnityAction fun)
|
||||||
|
{
|
||||||
|
controller.RemoveUpdateListener(fun);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 封装一个协程,后续也可以添加方法来封装
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="routine"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Coroutine StartCoroutine(IEnumerator routine)
|
||||||
|
{
|
||||||
|
return controller.StartCoroutine(routine);
|
||||||
|
}
|
||||||
|
|
||||||
|
//这里可以继续封装别的Mono方法
|
||||||
|
/*public Coroutine StartCoroutine(IEnumerator routine)
|
||||||
|
{
|
||||||
|
return controller.StartCoroutine(routine);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
11
Assets/Scripts/ProjectBase/Mono/MonoMgr.cs.meta
Normal file
11
Assets/Scripts/ProjectBase/Mono/MonoMgr.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4de48ca79531e9942b06cabbc98dac8b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -2,12 +2,22 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class TestTest
|
||||||
|
{
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
Debug.Log("TestTest");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class Test : MonoBehaviour
|
public class Test : MonoBehaviour
|
||||||
{
|
{
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
|
TestTest t = new TestTest();
|
||||||
|
MonoMgr.GetInstance().AddUpdateListener(t.Update);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
|
Loading…
x
Reference in New Issue
Block a user