Статья носит ознакомительный характер, и не претендует на истину в последней инстанции.
По мере изучения API я буду пополнять информацию.
И так доступ к игровому миру и ее механике мы получаем через класс MyAPIGateway.
Который в себе содержит следующие интерфейсы:
IMyCubeBuilder CubeBuilder;
IMyEntities Entities;
IMyMultiplayer Multiplayer;
IMyPlayerCollection Players;
IMySession Session;
IMyTerminalActionsHelper TerminalActionsHelper;
IMyUtilities Utilities;
По скольку все они объявлены через модификатор static нам не нужно создавать экземпляр данного класса, мы просто будем обращаться напрямую.
Рассмотрим каждый.
1) CubeBuilder - содержит методы и объекты для управления процессов создания блоков.
public interface IMyCubeBuilder
{
bool BlockCreationIsActivated { get; }
bool CopyPasteIsActivated { get; }
bool FreezeGizmo { get; set; }
bool IsActivated { get; }
bool ShipCreationIsActivated { get; }
bool ShowRemoveGizmo { get; set; }
bool UseSymmetry { get; set; }
bool UseTransparency { get; set; }
void Activate();
void ActivateShipCreationClipboard(MyObjectBuilder_CubeGrid grid, VRageMath.Vector3 centerDeltaDirection, float dragVectorLength);
void ActivateShipCreationClipboard(MyObjectBuilder_CubeGrid[] grids, VRageMath.Vector3 centerDeltaDirection, float dragVectorLength);
bool AddConstruction(IMyEntity buildingEntity);
void Deactivate();
void DeactivateBlockCreation();
void DeactivateCopyPaste();
void DeactivateShipCreationClipboard();
IMyCubeGrid FindClosestGrid();
void StartNewGridPlacement(MyCubeSize cubeSize, bool isStatic);
}
2) Entities - этот интерфейс я думаю будет интересней всего для создателей модов. Он содержит в себе методы для создания и управления всеми подконтрольными нам сущностями игрового мира, сенсоры, двигатели, орудия, кнопки и т.д.
public interface IMyEntities
{
event Action OnCloseAll;
event Action<IMyEntity, string, string> OnEntityNameSet;
event Action<IMyEntity> OnEntityRemove;
void AddEntity(IMyEntity entity, bool insertIntoScene = true);
IMyEntity CreateFromObjectBuilder(MyObjectBuilder_EntityBase objectBuilder);
IMyEntity CreateFromObjectBuilderAndAdd(MyObjectBuilder_EntityBase objectBuilder);
IMyEntity CreateFromObjectBuilderNoinit(MyObjectBuilder_EntityBase objectBuilder);
void EnableEntityBoundingBoxDraw(IMyEntity entity, bool enable, VRageMath.Vector4? color = null, float lineWidth = 0.01f, VRageMath.Vector3? inflateAmount = null);
bool EntityExists(string name);
bool Exist(IMyEntity entity);
bool ExistsById(long entityId);
VRageMath.Vector3? FindFreePlace(VRageMath.Vector3 basePos, float radius, int maxTestCount = 20, int testsPerDistance = 5, float stepSize = 1f);
List<IMyEntity> GetElementsInBox(ref VRageMath.BoundingBox boundingBox);
void GetEntities(HashSet<IMyEntity> entities, Func<IMyEntity, bool> collect = null);
List<IMyEntity> GetEntitiesInAABB(ref VRageMath.BoundingBox boundingBox);
List<IMyEntity> GetEntitiesInSphere(ref VRageMath.BoundingSphere boundingSphere);
IMyEntity GetEntity(Func<IMyEntity, bool> match);
IMyEntity GetEntityById(long entityId);
IMyEntity GetEntityByName(string name);
void GetInflatedPlayerBoundingBox(ref VRageMath.BoundingBox playerBox, float inflation);
IMyEntity GetIntersectionWithSphere(ref VRageMath.BoundingSphere sphere);
IMyEntity GetIntersectionWithSphere(ref VRageMath.BoundingSphere sphere, IMyEntity ignoreEntity0, IMyEntity ignoreEntity1);
List<IMyEntity> GetIntersectionWithSphere(ref VRageMath.BoundingSphere sphere, IMyEntity ignoreEntity0, IMyEntity ignoreEntity1, bool ignoreVoxelMaps, bool volumetricTest);
IMyEntity GetIntersectionWithSphere(ref VRageMath.BoundingSphere sphere, IMyEntity ignoreEntity0, IMyEntity ignoreEntity1, bool ignoreVoxelMaps, bool volumetricTest, bool excludeEntitiesWithDisabledPhysics = false, bool ignoreFloatingObjects = true, bool ignoreHandWeapons = true);
bool IsInsideVoxel(VRageMath.Vector3 pos, VRageMath.Vector3 hintPosition, out VRageMath.Vector3 lastOutsidePos);
bool IsInsideWorld(VRageMath.Vector3 pos);
bool IsNameExists(IMyEntity entity, string name);
bool IsRaycastBlocked(VRageMath.Vector3 pos, VRageMath.Vector3 target);
bool IsSelectable(IMyEntity entity);
bool IsSpherePenetrating(ref VRageMath.BoundingSphere bs);
bool IsTypeHidden(Type type);
bool IsTypeSelectable(Type type);
bool IsVisible(IMyEntity entity);
bool IsWorldLimited();
void MarkForClose(IMyEntity entity);
void RegisterForDraw(IMyEntity entity);
void RegisterForUpdate(IMyEntity entity);
void RemapObjectBuilder(MyObjectBuilder_EntityBase objectBuilder);
void RemapObjectBuilderCollection(IEnumerable<MyObjectBuilder_EntityBase> objectBuilders);
void RemoveEntity(IMyEntity entity);
void RemoveFromClosedEntities(IMyEntity entity);
void RemoveName(IMyEntity entity);
void SetEntityName(IMyEntity IMyEntity, bool possibleRename = true);
void SetTypeHidden(Type type, bool hidden);
void SetTypeSelectable(Type type, bool selectable);
bool TryGetEntityById(long id, out IMyEntity entity);
bool TryGetEntityByName(string name, out IMyEntity entity);
void UnhideAllTypes();
void UnregisterForDraw(IMyEntity entity);
void UnregisterForUpdate(IMyEntity entity, bool immediate = false);
float WorldHalfExtent();
float WorldSafeHalfExtent();
}
3) Multiplayer - данный интерфейс предоставляет нам скудные возможности по получению информации о сетевой игре.
public interface IMyMultiplayer
{
bool IsServer { get; }
bool MultiplayerActive { get; }
ulong MyId { get; }
string MyName { get; }
IMyPlayerCollection Players { get; }
ulong ServerId { get; }
bool IsServerPlayer(IMyPlayer player);
}
4) Players - немаловажный интерфейс, благодаря которому скоро появятся NPC в игре стараниями моддеров. Предоставляет возможность добавлять, убивать, удалять игроков.
public interface IMyPlayerCollection
{
DictionaryReader<long, MyPlayerInfo> AllPlayers { get; }
int Count { get; }
IMyPlayer this[ulong steamUserId] { get; }
void Add(IMyPlayer player);
long AddNewNpc(string npcName);
bool Exists(ulong steamUserId);
void ExtendControl(IMyEntity entityWithControl, IMyEntity entityGettingControl);
IMyPlayer GetPlayerControllingEntity(IMyEntity entity);
void GetPlayers(List<IMyPlayer> players, Func<IMyPlayer, bool> collect = null);
bool HasExtendedControl(IMyEntity firstEntity, IMyEntity secondEntity);
void KillPlayer(long playerId);
void ReduceControl(IMyEntity entityWhichKeepsControl, IMyEntity entityWhichLoosesControl);
void Remove(IMyPlayer player);
void Remove(ulong steamUserId);
void RemoveControlledEntity(IMyEntity entity);
void RevivePlayer(long playerId);
void SendControlledEntities(ulong sendTo);
SerializableDictionary<long, ulong> Serialize();
void SetControlledEntity(ulong steamUserId, IMyEntity entity);
void TryExtendControl(IMyEntity entityWithControl, IMyEntity entityGettingControl);
bool TryGetPlayer(ulong steamUserId, out IMyPlayer player);
bool TryReduceControl(IMyEntity entityWhichKeepsControl, IMyEntity entityWhichLoosesControl);
bool TrySetControlledEntity(ulong steamUserId, IMyEntity entity);
void UpdateFromPlayer(long playerId);
void UpdateFromPlayers();
void UpdateFromSession(List<MyObjectBuilder_Checkpoint.PlayerItem> playersFromSession);
}
5) Session - данный интерфейс позволяет работать с текущей игровой сессией и ее параметрами ( творческий ли режим, максимальное кол-во игроков и т.д.)
public interface IMySession
{
float AssemblerEfficiencyMultiplier { get; }
float AssemblerSpeedMultiplier { get; }
bool AutoHealing { get; }
uint AutoSaveInMinutes { get; }
IMyCameraController CameraController { get; }
bool CargoShipsEnabled { get; }
bool ClientCanSave { get; }
IMyControllableEntity ControlledObject { get; }
bool CreativeMode { get; }
string CurrentPath { get; }
string Description { get; set; }
TimeSpan ElapsedPlayTime { get; }
bool EnableCopyPaste { get; }
MyEnvironmentHostilityEnum EnvironmentHostility { get; }
DateTime GameDateTime { get; set; }
float GrinderSpeedMultiplier { get; }
float HackSpeedMultiplier { get; }
float InventoryMultiplier { get; }
bool IsCameraAwaitingEntity { get; set; }
short MaxFloatingObjects { get; }
short MaxPlayers { get; }
bool MultiplayerAlive { get; set; }
bool MultiplayerDirect { get; set; }
double MultiplayerLastMsg { get; set; }
string Name { get; set; }
float NegativeIntegrityTotal { get; set; }
MyOnlineModeEnum OnlineMode { get; }
string Password { get; set; }
IMyLocalPlayer Player { get; }
float PositiveIntegrityTotal { get; set; }
float RefinerySpeedMultiplier { get; }
bool ShowPlayerNamesOnHud { get; }
bool SurvivalMode { get; }
bool ThrusterDamage { get; }
string ThumbPath { get; }
TimeSpan TimeOnBigShip { get; }
TimeSpan TimeOnFoot { get; }
TimeSpan TimeOnJetpack { get; }
TimeSpan TimeOnSmallShip { get; }
IMyVoxelMaps VoxelMaps { get; }
bool WeaponsEnabled { get; }
float WelderSpeedMultiplier { get; }
ulong? WorkshopId { get; }
string WorldID { get; set; }
void BeforeStartComponents();
void Draw();
void GameOver();
void GameOver(MyTextsWrapperEnum? customMessage);
MyObjectBuilder_Checkpoint GetCheckpoint(string saveName);
MyObjectBuilder_Sector GetSector();
Dictionary<string, byte[]> GetVoxelMapsArray();
MyObjectBuilder_World GetWorld();
bool IsPausable();
void RegisterComponent(MySessionComponentBase component, MyUpdateOrder updateOrder, int priority);
bool Save(string customSaveName = null);
void SetAsNotReady();
void Unload();
void UnloadDataComponents();
void UnloadMultiplayer();
void UnregisterComponent(MySessionComponentBase component);
void Update(float timeInSeconds);
void UpdateComponents();
}
6) TerminalActionsHelper - еще не разобрался, но думаю это как то связано с терминалами в игре..
public interface IMyTerminalActionsHelper
{
void GetActions(Type blockType, List<ITerminalAction> resultList, Func<ITerminalAction, bool> collect = null);
}
7) Utilities - интерфейс утилит, тут мы имеем доступ к чату, уведомлениям, и к неким хранилищам данных, мне еще предстоит разобраться с этим.
public interface IMyUtilities
{
IMyConfigDedicated ConfigDedicated { get; }
event MessageEnteredDel MessageEntered;
string GetTypeName(Type type);
TextReader ReadFileInGlobalStorage(string file);
TextReader ReadFileInLocalStorage(string file, Type callingType);
void SendMessage(string messageText);
void ShowMessage(string sender, string messageText);
void ShowNotification(string message, int disappearTimeMs = 2000, MyFontEnum font = MyFontEnum.White);
TextWriter WriteFileInGlobalStorage(string file);
TextWriter WriteFileInLocalStorage(string file, Type callingType);
}
По мере изучения API я буду пополнять информацию.
И так доступ к игровому миру и ее механике мы получаем через класс MyAPIGateway.
Который в себе содержит следующие интерфейсы:
IMyCubeBuilder CubeBuilder;
IMyEntities Entities;
IMyMultiplayer Multiplayer;
IMyPlayerCollection Players;
IMySession Session;
IMyTerminalActionsHelper TerminalActionsHelper;
IMyUtilities Utilities;
По скольку все они объявлены через модификатор static нам не нужно создавать экземпляр данного класса, мы просто будем обращаться напрямую.
Рассмотрим каждый.
1) CubeBuilder - содержит методы и объекты для управления процессов создания блоков.
public interface IMyCubeBuilder
{
bool BlockCreationIsActivated { get; }
bool CopyPasteIsActivated { get; }
bool FreezeGizmo { get; set; }
bool IsActivated { get; }
bool ShipCreationIsActivated { get; }
bool ShowRemoveGizmo { get; set; }
bool UseSymmetry { get; set; }
bool UseTransparency { get; set; }
void Activate();
void ActivateShipCreationClipboard(MyObjectBuilder_CubeGrid grid, VRageMath.Vector3 centerDeltaDirection, float dragVectorLength);
void ActivateShipCreationClipboard(MyObjectBuilder_CubeGrid[] grids, VRageMath.Vector3 centerDeltaDirection, float dragVectorLength);
bool AddConstruction(IMyEntity buildingEntity);
void Deactivate();
void DeactivateBlockCreation();
void DeactivateCopyPaste();
void DeactivateShipCreationClipboard();
IMyCubeGrid FindClosestGrid();
void StartNewGridPlacement(MyCubeSize cubeSize, bool isStatic);
}
2) Entities - этот интерфейс я думаю будет интересней всего для создателей модов. Он содержит в себе методы для создания и управления всеми подконтрольными нам сущностями игрового мира, сенсоры, двигатели, орудия, кнопки и т.д.
public interface IMyEntities
{
event Action OnCloseAll;
event Action<IMyEntity, string, string> OnEntityNameSet;
event Action<IMyEntity> OnEntityRemove;
void AddEntity(IMyEntity entity, bool insertIntoScene = true);
IMyEntity CreateFromObjectBuilder(MyObjectBuilder_EntityBase objectBuilder);
IMyEntity CreateFromObjectBuilderAndAdd(MyObjectBuilder_EntityBase objectBuilder);
IMyEntity CreateFromObjectBuilderNoinit(MyObjectBuilder_EntityBase objectBuilder);
void EnableEntityBoundingBoxDraw(IMyEntity entity, bool enable, VRageMath.Vector4? color = null, float lineWidth = 0.01f, VRageMath.Vector3? inflateAmount = null);
bool EntityExists(string name);
bool Exist(IMyEntity entity);
bool ExistsById(long entityId);
VRageMath.Vector3? FindFreePlace(VRageMath.Vector3 basePos, float radius, int maxTestCount = 20, int testsPerDistance = 5, float stepSize = 1f);
List<IMyEntity> GetElementsInBox(ref VRageMath.BoundingBox boundingBox);
void GetEntities(HashSet<IMyEntity> entities, Func<IMyEntity, bool> collect = null);
List<IMyEntity> GetEntitiesInAABB(ref VRageMath.BoundingBox boundingBox);
List<IMyEntity> GetEntitiesInSphere(ref VRageMath.BoundingSphere boundingSphere);
IMyEntity GetEntity(Func<IMyEntity, bool> match);
IMyEntity GetEntityById(long entityId);
IMyEntity GetEntityByName(string name);
void GetInflatedPlayerBoundingBox(ref VRageMath.BoundingBox playerBox, float inflation);
IMyEntity GetIntersectionWithSphere(ref VRageMath.BoundingSphere sphere);
IMyEntity GetIntersectionWithSphere(ref VRageMath.BoundingSphere sphere, IMyEntity ignoreEntity0, IMyEntity ignoreEntity1);
List<IMyEntity> GetIntersectionWithSphere(ref VRageMath.BoundingSphere sphere, IMyEntity ignoreEntity0, IMyEntity ignoreEntity1, bool ignoreVoxelMaps, bool volumetricTest);
IMyEntity GetIntersectionWithSphere(ref VRageMath.BoundingSphere sphere, IMyEntity ignoreEntity0, IMyEntity ignoreEntity1, bool ignoreVoxelMaps, bool volumetricTest, bool excludeEntitiesWithDisabledPhysics = false, bool ignoreFloatingObjects = true, bool ignoreHandWeapons = true);
bool IsInsideVoxel(VRageMath.Vector3 pos, VRageMath.Vector3 hintPosition, out VRageMath.Vector3 lastOutsidePos);
bool IsInsideWorld(VRageMath.Vector3 pos);
bool IsNameExists(IMyEntity entity, string name);
bool IsRaycastBlocked(VRageMath.Vector3 pos, VRageMath.Vector3 target);
bool IsSelectable(IMyEntity entity);
bool IsSpherePenetrating(ref VRageMath.BoundingSphere bs);
bool IsTypeHidden(Type type);
bool IsTypeSelectable(Type type);
bool IsVisible(IMyEntity entity);
bool IsWorldLimited();
void MarkForClose(IMyEntity entity);
void RegisterForDraw(IMyEntity entity);
void RegisterForUpdate(IMyEntity entity);
void RemapObjectBuilder(MyObjectBuilder_EntityBase objectBuilder);
void RemapObjectBuilderCollection(IEnumerable<MyObjectBuilder_EntityBase> objectBuilders);
void RemoveEntity(IMyEntity entity);
void RemoveFromClosedEntities(IMyEntity entity);
void RemoveName(IMyEntity entity);
void SetEntityName(IMyEntity IMyEntity, bool possibleRename = true);
void SetTypeHidden(Type type, bool hidden);
void SetTypeSelectable(Type type, bool selectable);
bool TryGetEntityById(long id, out IMyEntity entity);
bool TryGetEntityByName(string name, out IMyEntity entity);
void UnhideAllTypes();
void UnregisterForDraw(IMyEntity entity);
void UnregisterForUpdate(IMyEntity entity, bool immediate = false);
float WorldHalfExtent();
float WorldSafeHalfExtent();
}
3) Multiplayer - данный интерфейс предоставляет нам скудные возможности по получению информации о сетевой игре.
public interface IMyMultiplayer
{
bool IsServer { get; }
bool MultiplayerActive { get; }
ulong MyId { get; }
string MyName { get; }
IMyPlayerCollection Players { get; }
ulong ServerId { get; }
bool IsServerPlayer(IMyPlayer player);
}
4) Players - немаловажный интерфейс, благодаря которому скоро появятся NPC в игре стараниями моддеров. Предоставляет возможность добавлять, убивать, удалять игроков.
public interface IMyPlayerCollection
{
DictionaryReader<long, MyPlayerInfo> AllPlayers { get; }
int Count { get; }
IMyPlayer this[ulong steamUserId] { get; }
void Add(IMyPlayer player);
long AddNewNpc(string npcName);
bool Exists(ulong steamUserId);
void ExtendControl(IMyEntity entityWithControl, IMyEntity entityGettingControl);
IMyPlayer GetPlayerControllingEntity(IMyEntity entity);
void GetPlayers(List<IMyPlayer> players, Func<IMyPlayer, bool> collect = null);
bool HasExtendedControl(IMyEntity firstEntity, IMyEntity secondEntity);
void KillPlayer(long playerId);
void ReduceControl(IMyEntity entityWhichKeepsControl, IMyEntity entityWhichLoosesControl);
void Remove(IMyPlayer player);
void Remove(ulong steamUserId);
void RemoveControlledEntity(IMyEntity entity);
void RevivePlayer(long playerId);
void SendControlledEntities(ulong sendTo);
SerializableDictionary<long, ulong> Serialize();
void SetControlledEntity(ulong steamUserId, IMyEntity entity);
void TryExtendControl(IMyEntity entityWithControl, IMyEntity entityGettingControl);
bool TryGetPlayer(ulong steamUserId, out IMyPlayer player);
bool TryReduceControl(IMyEntity entityWhichKeepsControl, IMyEntity entityWhichLoosesControl);
bool TrySetControlledEntity(ulong steamUserId, IMyEntity entity);
void UpdateFromPlayer(long playerId);
void UpdateFromPlayers();
void UpdateFromSession(List<MyObjectBuilder_Checkpoint.PlayerItem> playersFromSession);
}
5) Session - данный интерфейс позволяет работать с текущей игровой сессией и ее параметрами ( творческий ли режим, максимальное кол-во игроков и т.д.)
public interface IMySession
{
float AssemblerEfficiencyMultiplier { get; }
float AssemblerSpeedMultiplier { get; }
bool AutoHealing { get; }
uint AutoSaveInMinutes { get; }
IMyCameraController CameraController { get; }
bool CargoShipsEnabled { get; }
bool ClientCanSave { get; }
IMyControllableEntity ControlledObject { get; }
bool CreativeMode { get; }
string CurrentPath { get; }
string Description { get; set; }
TimeSpan ElapsedPlayTime { get; }
bool EnableCopyPaste { get; }
MyEnvironmentHostilityEnum EnvironmentHostility { get; }
DateTime GameDateTime { get; set; }
float GrinderSpeedMultiplier { get; }
float HackSpeedMultiplier { get; }
float InventoryMultiplier { get; }
bool IsCameraAwaitingEntity { get; set; }
short MaxFloatingObjects { get; }
short MaxPlayers { get; }
bool MultiplayerAlive { get; set; }
bool MultiplayerDirect { get; set; }
double MultiplayerLastMsg { get; set; }
string Name { get; set; }
float NegativeIntegrityTotal { get; set; }
MyOnlineModeEnum OnlineMode { get; }
string Password { get; set; }
IMyLocalPlayer Player { get; }
float PositiveIntegrityTotal { get; set; }
float RefinerySpeedMultiplier { get; }
bool ShowPlayerNamesOnHud { get; }
bool SurvivalMode { get; }
bool ThrusterDamage { get; }
string ThumbPath { get; }
TimeSpan TimeOnBigShip { get; }
TimeSpan TimeOnFoot { get; }
TimeSpan TimeOnJetpack { get; }
TimeSpan TimeOnSmallShip { get; }
IMyVoxelMaps VoxelMaps { get; }
bool WeaponsEnabled { get; }
float WelderSpeedMultiplier { get; }
ulong? WorkshopId { get; }
string WorldID { get; set; }
void BeforeStartComponents();
void Draw();
void GameOver();
void GameOver(MyTextsWrapperEnum? customMessage);
MyObjectBuilder_Checkpoint GetCheckpoint(string saveName);
MyObjectBuilder_Sector GetSector();
Dictionary<string, byte[]> GetVoxelMapsArray();
MyObjectBuilder_World GetWorld();
bool IsPausable();
void RegisterComponent(MySessionComponentBase component, MyUpdateOrder updateOrder, int priority);
bool Save(string customSaveName = null);
void SetAsNotReady();
void Unload();
void UnloadDataComponents();
void UnloadMultiplayer();
void UnregisterComponent(MySessionComponentBase component);
void Update(float timeInSeconds);
void UpdateComponents();
}
6) TerminalActionsHelper - еще не разобрался, но думаю это как то связано с терминалами в игре..
public interface IMyTerminalActionsHelper
{
void GetActions(Type blockType, List<ITerminalAction> resultList, Func<ITerminalAction, bool> collect = null);
}
7) Utilities - интерфейс утилит, тут мы имеем доступ к чату, уведомлениям, и к неким хранилищам данных, мне еще предстоит разобраться с этим.
public interface IMyUtilities
{
IMyConfigDedicated ConfigDedicated { get; }
event MessageEnteredDel MessageEntered;
string GetTypeName(Type type);
TextReader ReadFileInGlobalStorage(string file);
TextReader ReadFileInLocalStorage(string file, Type callingType);
void SendMessage(string messageText);
void ShowMessage(string sender, string messageText);
void ShowNotification(string message, int disappearTimeMs = 2000, MyFontEnum font = MyFontEnum.White);
TextWriter WriteFileInGlobalStorage(string file);
TextWriter WriteFileInLocalStorage(string file, Type callingType);
}