1
0
Fork 0
This repository has been archived on 2024-01-06. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
MMORPG_PROJECT/Unity network UDP/Assets/scripts/network/common/Register.cs
2016-06-22 21:45:43 +02:00

36 lines
801 B
C#

using UnityEngine;
using System.Collections;
using System;
public class Register {
public static Type[] registeredClass;
public static void registerClass()
{
registeredClass = new Type[] {
typeof(MessagePacket),
typeof(MainState_Connection_Request_Packet),
typeof(Disconnect_Client_Packet)
};
}
public static Type getClass(int id)
{
return registeredClass[id];
}
public static int getId(Type cl)
{
for (int i = 0; i < registeredClass.Length; i++)
{
if (cl == registeredClass[i]) return i;
}
return -1;
}
public static object instantiate(int id)
{
return getClass(id).GetConstructor(Type.EmptyTypes).Invoke(Type.EmptyTypes);
}
}