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; }
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); }
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); }
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); }
public static void RemoveAll(EntityBase parent) { NativeEntityMethods.RemoveAllEntityLinks(parent.GetIEntity()); }
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); }
internal EntityLink(IntPtr handle, EntityBase entity) { Handle = handle; Parent = entity; }
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; }