/// <summary> /// Removes the entity with the specified id. /// </summary> /// <param name="id"> </param> /// <param name="forceRemoveNow"> </param> public static void Remove(EntityId id, bool forceRemoveNow = false) { #if !(RELEASE && RELEASE_DISABLE_CHECKS) if (id == 0) { throw new ArgumentException("entityId cannot be 0!"); } #endif EntityInterop.RemoveEntity(id, forceRemoveNow); }
private void RemoteInvocation(EntityBase target, MethodInfo method, NetworkTarget netTarget, int channelId, params object[] args) { if (!method.ContainsAttribute <RemoteInvocationAttribute>()) { #if RELEASE return; #else throw new AttributeUsageException("Method did not contain RemoteInvocation attribute"); #endif } #if !(RELEASE && RELEASE_DISABLE_CHECKS) if (target == null) { throw new RemoteInvocationException("Non-static method owner does not derive from EntityBase."); } #endif EntityInterop.RemoteInvocation(this.Id, target.Id, method.Name, args, netTarget, channelId); }
/// <summary> /// Loads a mesh for this entity. Can optionally load multiple meshes using entity /// slots. /// </summary> /// <param name="name">Path to the object (Relative to the game directory)</param> /// <param name="slot"></param> /// <returns>true if successful, otherwise false.</returns> public bool LoadObject(string name, int slot = 0) { if (name == null) { throw new ArgumentNullException("name"); } if (name.EndsWith("cgf")) { EntityInterop.LoadObject(this.EntityHandle, name, slot); } else if (name.EndsWith("cdf") || name.EndsWith("cga") || name.EndsWith("chr")) { EntityInterop.LoadCharacter(this.EntityHandle, name, slot); } else { return(false); } return(true); }
/// <summary> /// Get an entity by its unique ID. /// </summary> /// <param name="entityId"> The ID as an unsigned integer. </param> /// <returns> A reference to the entity. </returns> /// <remarks> /// If the entity does not exist in the managed space, this function will attempt to find a /// C++ entity with the specified ID> /// </remarks> public static EntityBase Get(EntityId entityId) { #if !(RELEASE && RELEASE_DISABLE_CHECKS) if (entityId == 0) { throw new ArgumentException("entityId cannot be 0!"); } #endif var ent = Get <EntityBase>(entityId); if (ent != null) { return(ent); } // Couldn't find a CryMono entity, check if a non-managed one exists. var entPointer = EntityInterop.GetEntity(entityId); if (entPointer != IntPtr.Zero) { return(CreateNativeEntity(entityId, entPointer)); } return(null); }
private void RegisterInternalTypes() { CryScript script; if (CryScript.TryCreate(typeof(NativeActor), out script)) { Scripts.Add(script); } if (CryScript.TryCreate(typeof(NativeEntity), out script)) { var entityRegistrationParams = new EntityRegistrationParams { name = script.ScriptName, flags = EntityClassFlags.Default | EntityClassFlags.Invisible }; #if !UNIT_TESTING EntityInterop.RegisterEntityClass(entityRegistrationParams); #endif Scripts.Add(script); } }
/// <summary> /// Unbinds whatever was bound to this attachment from it. /// </summary> public void ClearBinding() { EntityInterop.ClearAttachmentBinding(this.Handle); }
/// <summary> /// Frees the specified slot of all objects. /// </summary> /// <param name="slot">Zero-based index of the slot to free.</param> public void FreeSlot(int slot) { EntityInterop.FreeSlot(this.EntityHandle, slot); }
/// <summary> /// Binds a light source to this attachment. /// </summary> /// <param name="lightParams">A set of parameters that describe a light source.</param> public void SwitchToLightObject(ref LightParams lightParams) { EntityInterop.BindAttachmentToLight(this.Handle, ref lightParams); }
/// <summary> /// Binds a particle effect to this attachment. /// </summary> /// <param name="effect"><see cref="ParticleEffect"/> to bind to this attachment.</param> /// <param name="offset">Position of the particle effect relative to the attachment.</param> /// <param name="dir"> Direction of the particle effect spray.</param> /// <param name="scale"> Scale to assign to the particle effect.</param> public void SwitchToParticleEffectObject(ParticleEffect effect, Vector3 offset, Vector3 dir, float scale) { EntityInterop.BindAttachmentToParticleEffect(this.Handle, effect.Handle, offset, dir, scale); }
/// <summary> /// Invalidate the TriggerBounds, so it gets recalculated and catches things which are /// already inside when it gets enabled. /// </summary> public void InvalidateTrigger() { EntityInterop.InvalidateTrigger(this.EntityHandle); }
/// <summary> /// Binds entity to this attachment. /// </summary> /// <param name="entityId">Identifier of the entity to bind this attachment to.</param> public void SwitchToEntityObject(EntityId entityId) { EntityInterop.BindAttachmentToEntity(this.Handle, entityId); }
private void ProcessWaitingScripts(bool initialLoad) { bool hasDefaultGameRules = false; foreach (var pluginPair in PluginTypes) { ICryMonoPlugin plugin = pluginPair.Key; foreach (Type type in pluginPair.Value) { Type type1 = type; var script = FindScript(ScriptType.Any, x => x.Type == type1); if (script == null) { if (!CryScript.TryCreate(type, out script)) { continue; } } script.RegistrationParams = plugin.GetRegistrationParams(script.ScriptType, type); if (script.Registered) { continue; } if (script.RegistrationParams == null) { continue; } // Contain types that can only be registered at startup here. if (initialLoad) { if (script.RegistrationParams is ActorRegistrationParams) { var registrationParams = (ActorRegistrationParams)script.RegistrationParams; ActorInterop.RegisterActorClass(script.ScriptName, script.Type.Implements(typeof(NativeActor)), registrationParams.isAI); } else if (script.RegistrationParams is EntityRegistrationParams) { var registrationParams = (EntityRegistrationParams)script.RegistrationParams; if (registrationParams.name == null) { registrationParams.name = script.ScriptName; } if (registrationParams.category == null) { registrationParams.category = "Default"; } EntityInterop.RegisterEntityClass(registrationParams); script.RegistrationParams = registrationParams; } } if (script.RegistrationParams is GameRulesRegistrationParams) { var registrationParams = (GameRulesRegistrationParams)script.RegistrationParams; if (registrationParams.name == null) { registrationParams.name = script.ScriptName; } GameRulesInterop.RegisterGameMode(registrationParams.name); if (registrationParams.defaultGamemode || !hasDefaultGameRules) { GameRulesInterop.SetDefaultGameMode(registrationParams.name); hasDefaultGameRules = true; } script.RegistrationParams = registrationParams; } else if (script.RegistrationParams is FlowNodeRegistrationParams) { var registrationParams = (FlowNodeRegistrationParams)script.RegistrationParams; if (registrationParams.name == null) { registrationParams.name = script.ScriptName; } if (registrationParams.category == null) { registrationParams.category = script.Type.Namespace; } if (registrationParams.filter == 0) { registrationParams.filter = FlowNodeFilter.Approved; } script.RegistrationParams = registrationParams; script.ScriptName = registrationParams.category + ":" + registrationParams.name; } else if (script.RegistrationParams is EntityFlowNodeRegistrationParams) { var registrationParams = (EntityFlowNodeRegistrationParams)script.RegistrationParams; script.ScriptName = "entity" + ":" + registrationParams.entityName; } script.Registered = true; this.Scripts.Add(script); } } }
/// <summary> /// </summary> /// <param name="id"> </param> /// <param name="pos"> </param> /// <param name="maxResults"> </param> /// <param name="forceCalculation"> </param> /// <returns> </returns> public static IEnumerable <AreaQueryResult> QueryAreas(EntityId id, Vector3 pos, int maxResults, bool forceCalculation) { var objAreas = EntityInterop.QueryAreas(id, pos, maxResults, forceCalculation); return(objAreas.Cast <AreaQueryResult>()); }
/// <summary> /// Requests movement at the specified slot, providing an animated character is /// currently loaded. /// </summary> /// <param name="request">Object that describes the movement.</param> public void AddMovement(ref EntityMovementRequest request) { EntityInterop.AddMovement(this.AnimatedCharacterHandle, ref request); }
public void Break(BreakageParameters breakageParams) { EntityInterop.BreakIntoPieces(Owner.EntityHandle, 0, 0, breakageParams); }
public static IEnumerable <T> QueryProximity <T>(BoundingBox bbox, EntityFlags flags = 0) where T : EntityBase { return(GetEntitiesCommon <T>(EntityInterop.QueryProximity(bbox, typeof(T).Name, flags))); }
public static IEnumerable <EntityBase> QueryProximity(BoundingBox bbox, string className, EntityFlags flags = 0) { return(GetEntitiesCommon <EntityBase>(EntityInterop.QueryProximity(bbox, className, flags))); }
/// <summary> /// Gets a list of entities within the specified area. /// </summary> /// <param name="bbox"> </param> /// <param name="flags"> </param> /// <returns> </returns> public static IEnumerable <T> GetInBox <T>(BoundingBox bbox, EntityQueryFlags flags = EntityQueryFlags.All) where T : EntityBase { return(GetEntitiesCommon <T>(EntityInterop.GetEntitiesInBox(bbox, flags))); }
public static IEnumerable <EntityBase> GetByClasses(string[] classNames) { return(GetEntitiesCommon <Entity>(EntityInterop.GetEntitiesByClasses(classNames.Cast <object>().ToArray()))); }
/// <summary> /// Gets an array of entities that are of a given class. /// </summary> /// <typeparam name="T"> The entity class to search for. </typeparam> /// <returns> An array of entities of type T. </returns> public static IEnumerable <T> GetByClass <T>() where T : EntityBase { return(GetEntitiesCommon <T>(EntityInterop.GetEntitiesByClass(typeof(T).Name))); }
/// <summary> /// Loads a light source to the specified slot, or to the next available slot. /// </summary> /// <param name="parameters"> /// New params of the light source we wish to load /// </param> /// <param name="slot"> /// Slot we want to load the light into, if -1 chooses the next available slot. /// </param> /// <returns> /// The slot where the light source was loaded, or -1 if loading failed. /// </returns> public int LoadLight(LightParams parameters, int slot = 1) { return(EntityInterop.LoadLight(this.EntityHandle, slot, parameters)); }
public EntityId GetEntityIdByIndex(int index) { return(EntityInterop.GetAreaEntityByIdx(this.Handle, index)); }
/// <summary> /// Gets the path to the currently loaded object. /// </summary> /// <param name="slot"> /// Slot containing the object we want to know the path of. /// </param> /// <returns>Path to the currently loaded object at the specified slot.</returns> public string GetObjectFilePath(int slot = 0) { return(EntityInterop.GetStaticObjectFilePath(this.EntityHandle, slot)); }
/// <summary> /// Gets wrapper for IArea object that is identified by given number. /// </summary> /// <param name="areaId"> <see cref="Int32" /> number that identifies a requested area. </param> /// <returns> Wrapper for IArea object that is identified by given number. </returns> public static Area GetArea(int areaId) { return(TryGet(EntityInterop.GetArea(areaId))); }