Files
gold_dolphin/unity/Assets/Script/Tools/Pollsysytem/PollBase.cs
2026-06-20 19:35:25 +08:00

73 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PollBase : MonoBehaviour
{
//自动释放时间/秒
protected float m_ReleaseTime;
//上次释放的时间/毫微秒 10……7
protected long m_LastReleaseTime = 0;
//对象池
protected List<PollObject> m_Objects;
public void Start()
{
m_LastReleaseTime = System.DateTime.Now.Ticks;
}
/// <summary>
/// 初始化对象池
/// </summary>
/// <param name="time"></param>
public void Init(float time)
{
m_ReleaseTime = time;
m_Objects = new List<PollObject>();
}
/// <summary>
/// 取出对象
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public virtual Object Spwan(string name)
{
foreach (PollObject po in m_Objects)
{
if (po.Name == name)
{
m_Objects.Remove(po);
return po.Object;
}
}
return null;
}
/// <summary>
/// 回收
/// </summary>
/// <param name="name"></param>
/// <param name="obj"></param>
public virtual void UnSpwan(string name, Object obj)
{
PollObject po = new PollObject(name, obj);
m_Objects.Add(po);
}
/// <summary>
/// 释放
/// </summary>
public virtual void Release()
{
}
private void Update()
{
if (System.DateTime.Now.Ticks - m_LastReleaseTime >= m_ReleaseTime * 10000000)
{
m_LastReleaseTime = System.DateTime.Now.Ticks;
Release();
}
}
}