How to use MBObjectManager?

Users who are viewing this thread

Since the stable and beta version of the game use different assemblies for MBObjectManager, I can't just call CreateObject() method.

Therefore i use reflection

C#:
            object objectManager = Game.Current.ObjectManager;
            if (objectManager == null)
            {
                InformationManager.DisplayMessage(new InformationMessage("ERROR: MBObjectManager is null"));
                return;
            }
            Type objectManagerType = objectManager.GetType();
            if (objectManagerType == null)
            {
                InformationManager.DisplayMessage(new InformationMessage("ERROR: objectManagerType is null"));
                return;
            }
            MethodInfo createObjectMethod = objectManagerType.GetMethod("CreateObject", new Type[2] { typeof(Type), typeof(string) });
            if (createObjectMethod == null)
            {
                InformationManager.DisplayMessage(new InformationMessage("ERROR: createObjectMethod is null"));
                return;
            }
            Kingdom kingdom = (Kingdom)createObjectMethod.Invoke(objectManager, new object[2] { typeof(Kingdom), "playerland_kingdom" });
            if (kingdom == null)
            {
                InformationManager.DisplayMessage(new InformationMessage("ERROR: Object kingdom is null"));
                return;
            }

Is it supposed to be like this or there is a simpler way to use MBObjectManager?
 
Back
Top Bottom