Represents an CryENGINE entity
Inheritance: CryScriptInstance
Exemplo n.º 1
0
        public bool TrySpawn(EntityBase entity)
        {
            if(entity == null)
                throw new System.ArgumentNullException("entity");

            var frameStartTime = Time.FrameStartTime;
            if((frameStartTime - LastSpawned) > SpawnDelay * 1000 || LastSpawned == -1)
            {
                LastSpawned = frameStartTime;

                var pos = Position;
                var rot = Rotation;

                entity.Position = pos;
                entity.Rotation = rot;

                if (entity is Tank && Team != null)
                {
                    var tank = entity as Tank;
                    tank.Team = Team;

                    tank.OnRevive();

                    Network.RemoteInvocation(NetSpawn, NetworkTarget.ToAllClients | NetworkTarget.NoLocalCalls, tank.Id, pos);
                }

                return true;
            }

            return false;
        }
Exemplo n.º 2
0
        internal Attachment(IntPtr ptr, EntityBase owner)
        {
            Owner = owner;
            Owner.OnDestroyed += (instance) => { NativeEntityMethods.RemoveEntity(Id, false); };

            this.SetAttachmentHandle(ptr);

            string attachmentObject = NativeEntityMethods.GetAttachmentObject(this.GetAttachmentHandle());

            var tempEntity = Entity.Spawn("AttachmentEntity", typeof(NativeEntity).Name);

            Id = tempEntity.Id;
            this.SetEntityHandle(tempEntity.GetEntityHandle());

            ScriptManager.Instance.ReplaceScriptInstance(this, tempEntity.ScriptId, ScriptType.Entity);

            this.SetEntityAttachmentHandle(NativeEntityMethods.LinkEntityToAttachment(this.GetAttachmentHandle(), Id));

            if (!String.IsNullOrEmpty(attachmentObject)) // Just in case it had a model loaded by default
                LoadObject(attachmentObject);
        }
Exemplo n.º 3
0
        public static void Set(EntityBase entity, Material mat, int slot = 0)
        {
            #if !(RELEASE && RELEASE_DISABLE_CHECKS)
            if (entity == null)
                throw new ArgumentNullException("entity");
            if (mat == null)
                throw new ArgumentNullException("mat");
            #endif

            NativeMaterialMethods.SetMaterial(entity.GetEntityHandle(), mat.Handle, slot);
        }
Exemplo n.º 4
0
        public static Material Get(EntityBase entity, int slot = 0)
        {
            #if !(RELEASE && RELEASE_DISABLE_CHECKS)
            if (entity == null)
                throw new ArgumentNullException("entity");
            #endif

            var ptr = NativeMaterialMethods.GetMaterial(entity.GetEntityHandle(), slot);
            return TryAdd(ptr);
        }
Exemplo n.º 5
0
 public static void RemoveAll(EntityBase parent)
 {
     NativeEntityMethods.RemoveAllEntityLinks(parent.GetIEntity());
 }
Exemplo n.º 6
0
 public static EntityLink Create(EntityBase parent, EntityBase slave, string linkName, Vec3? relativePos = null, Quat? relativeRot = null)
 {
     return new EntityLink(NativeEntityMethods.AddEntityLink(parent.GetIEntity(), linkName, slave.Id, relativeRot ?? Quat.Identity, relativePos ?? Vec3.Zero), parent);
 }
Exemplo n.º 7
0
 internal EntityLink(IntPtr handle, EntityBase entity)
 {
     Handle = handle;
     Parent = entity;
 }
Exemplo n.º 8
0
        internal static Attachment TryAdd(IntPtr ptr, EntityBase owner)
        {
            if (ptr == IntPtr.Zero)
                return null;

            var attachment = ScriptManager.Instance.Find<Attachment>(ScriptType.Entity, x => x.AttachmentHandle == ptr);
            if (attachment != null)
                return attachment;

            attachment = new Attachment(ptr, owner);

            return attachment;
        }