XmdsSceneFactory.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using CommonAI.Data;
  2. using CommonAI.Zone;
  3. using CommonAI.Zone.ZoneEditor;
  4. using CommonAI.ZoneServer.JSGModule;
  5. using CommonLang;
  6. using CommonLang.Property;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. namespace XmdsCommonServer.Plugin.Scene
  12. {
  13. public class XmdsSceneFactory
  14. {
  15. private static bool m_FinishInit = false;
  16. private static HashMap<int, Type> m_ExtensionTypes = new HashMap<int, Type>();
  17. public static void Init()
  18. {
  19. if (m_FinishInit) { return; }
  20. foreach (Type stype in ReflectionUtil.GetNoneVirtualSubTypes(typeof(XmdsServerScene)))
  21. {
  22. var ext = PropertyUtil.GetAttribute<XmdsExtensionZoneAttribute>(stype);
  23. if (ext != null)
  24. {
  25. m_ExtensionTypes.Put(ext.TemplateID, stype);
  26. }
  27. }
  28. m_FinishInit = true;
  29. }
  30. public static XmdsServerScene CreateScene(TemplateManager templates, InstanceZoneListener listener, SceneData data, GSCreateAreaData gsData, string bindGameSrvId)
  31. {
  32. Type stype;
  33. if (m_ExtensionTypes.TryGetValue(data.TemplateID, out stype))
  34. {
  35. return ReflectionUtil.CreateInstance(stype, templates, listener, data, gsData, bindGameSrvId) as XmdsServerScene;
  36. }
  37. return new XmdsServerScene(templates, listener, data, gsData, bindGameSrvId, JSGModule.GetSpaceDiveSize(data.sceneType));
  38. }
  39. }
  40. }