继续搞点新机制
This commit is contained in:
35
Assets/Scripts/MainGame/Base/GameElement.cs
Normal file
35
Assets/Scripts/MainGame/Base/GameElement.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Continentis.MainGame
|
||||
{
|
||||
public interface IGameElement
|
||||
{
|
||||
public static readonly Dictionary<Guid, IGameElement> Instances = new Dictionary<Guid, IGameElement>();
|
||||
|
||||
public Guid elementID { get; set; }
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
elementID = Guid.NewGuid();
|
||||
|
||||
if (!Instances.ContainsKey(this.elementID))
|
||||
{
|
||||
Instances.Add(this.elementID, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"GameElement with ID {this.elementID} is already registered.");
|
||||
}
|
||||
}
|
||||
|
||||
public void Unregister()
|
||||
{
|
||||
if (Instances.ContainsKey(this.elementID))
|
||||
{
|
||||
Instances.Remove(this.elementID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user