本文整理汇总了C#中IEntity.TryGet方法的典型用法代码示例。如果您正苦于以下问题:C# IEntity.TryGet方法的具体用法?C# IEntity.TryGet怎么用?C# IEntity.TryGet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEntity
的用法示例。
在下文中一共展示了IEntity.TryGet方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UnRender
// ==========================================================================
public void UnRender(IEntity ent)
{
lock (ent) {
// if a parent, the children go too
IEntityCollection coll = null;
if (ent.TryGet<IEntityCollection>(out coll)) {
coll.ForEach(delegate(IEntity entt) { this.UnRender(entt); });
}
if (RendererOgre.GetSceneNodeName(ent) != null) {
string sNodeName = RendererOgre.GetSceneNodeName(ent);
Ogr.RemoveSceneNodeBF(0, sNodeName);
}
}
return;
}
示例2: DecorateRenderEntity
/// <summary>
/// The entity has classes hung off it depending on its type. These classes
/// will be used to differentiate and render the entity.
/// Here we check to see if the decorating classes are on the entity and
/// add them if they are not present.
/// </summary>
/// <param name="ent"></param>
private void DecorateRenderEntity(IEntity ent)
{
// do we have a format converted for this entity?
IWorldRenderConv conver;
lock (ent) {
if (!ent.TryGet<IWorldRenderConv>(out conver)) {
// for the moment, we only know about LL stuff
// TODO: Figure out how to make this dynamic, extendable and runtime
ent.RegisterInterface<IWorldRenderConv>(RendererOgreLL.Instance);
}
// Depending on type, add a creation/management interface
// If it doesn't have a rendering entity, see about adding one
IRenderEntity re;
if (!ent.TryGet<IRenderEntity>(out re)) {
IEntityAvatar av;
if (ent.TryGet<IEntityAvatar>(out av)) {
// if it is an avatar, add the management routines
ent.RegisterInterface<IRenderEntity>(new RenderAvatar(this, ent));
}
else {
IAttachment atch;
if (ent.TryGet<IAttachment>(out atch)) {
ent.RegisterInterface<IRenderEntity>(new RenderAttach(this, ent));
}
else {
ISpecialRender sprend;
if (ent.TryGet<ISpecialRender>(out sprend)) {
if (sprend.Type == SpecialRenderTypes.Foliage) {
ent.RegisterInterface<IRenderEntity>(new RenderFoliage(this, ent));
}
else {
// ent.RegisterInterface<IRenderEntity>(new RenderParticles(this, ent));
}
}
else {
// It's just a prim. Add it's management routines
RenderPrim rprim;
if (!ent.TryGet<RenderPrim>(out rprim)) {
ent.RegisterInterface<IRenderEntity>(new RenderPrim(this, ent));
}
}
}
}
}
}
}
示例3: World_OnEntityUpdate
private void World_OnEntityUpdate(IEntity ent, World.UpdateCodes what)
{
IEntityAvatar av = null;
if (ent.TryGet<IEntityAvatar>(out av)) {
m_log.Log(LogLevel.DUPDATEDETAIL|LogLevel.DVIEWDETAIL, "OnEntityUpdate: Avatar: {0}", ent.Name.Name);
this.Renderer.RenderUpdate(ent, what);
}
else {
m_log.Log(LogLevel.DUPDATEDETAIL|LogLevel.DVIEWDETAIL, "OnEntityUpdate: Other. w={0}", what);
this.Renderer.RenderUpdate(ent, what);
}
return;
}
示例4: RenderUpdate
// ==========================================================================
/// <summary>
/// An entity has been updated. Make the call into the renderer to move or rotate the entity.
/// </summary>
/// <param name="ent"></param>
/// <param name="what"></param>
public void RenderUpdate(IEntity ent, UpdateCodes what)
{
// make sure entity has all the rendering information attached to it
DecorateRenderEntity(ent);
IRenderEntity rent;
// if the entity has a type specific renderer, pass the update there
// (note: terrain comes through here but there is no IRenderEntity for terrain)
if (ent.TryGet<IRenderEntity>(out rent)) {
rent.Update(what);
}
return;
}
示例5: ProcessEntityAnimation
// For the moment, create only one animation for an entity and that is the angular rotation.
private void ProcessEntityAnimation(IEntity ent, ref UpdateCodes updateFlags, OMV.Vector3 angularVelocity)
{
try {
// if there is an angular velocity and this is not an avatar, pass the information
// along as an animation (llTargetOmega)
// we convert the information into a standard form
IEntityAvatar av;
if (angularVelocity != OMV.Vector3.Zero) {
if (!ent.TryGet<IEntityAvatar>(out av)) {
float rotPerSec = angularVelocity.Length() / Constants.TWOPI;
OMV.Vector3 axis = angularVelocity;
axis.Normalize();
IAnimation anim;
if (!ent.TryGet<IAnimation>(out anim)) {
anim = new LLAnimation();
ent.RegisterInterface<IAnimation>(anim);
m_log.Log(LogLevel.DUPDATEDETAIL, "Created prim animation on {0}", ent.Name);
}
if (rotPerSec != anim.StaticRotationRotPerSec || axis != anim.StaticRotationAxis) {
anim.AngularVelocity = angularVelocity; // legacy. Remove when other part plumbed
anim.StaticRotationAxis = axis;
anim.StaticRotationRotPerSec = rotPerSec;
anim.DoStaticRotation = true;
updateFlags |= UpdateCodes.Animation;
m_log.Log(LogLevel.DUPDATEDETAIL, "Updating prim animation on {0}", ent.Name);
}
}
}
}
catch (Exception e) {
m_log.Log(LogLevel.DBADERROR, "FAILED ProcessEntityAnimation: " + e.ToString());
}
}
示例6: CreateAvatarTextures
/// <summary>
/// Create the textures for the avatar. If this is an LLEntityAvatar, extract the
/// texture info from the avatar description and blindly create textures for the
/// parts of the body in the order of the faces that were generated above.
/// </summary>
/// <param name="ent">The entity of the avatar being decorated</param>
/// <param name="forceUpdateFlag">'true' if to force a redraw. If doing the initial
/// creation, a redraw update is not necessary.</param>
public bool CreateAvatarTextures(IEntity ent, bool forceUpdateFlag)
{
IEntityAvatar ientav;
LLEntityAvatar entav;
if (ent.TryGet<IEntityAvatar>(out ientav)) {
if (ientav is LLEntityAvatar) {
entav = (LLEntityAvatar)ientav;
OMV.Avatar av = entav.Avatar;
if (av != null && av.Textures != null) {
OMV.Primitive.TextureEntry texEnt = av.Textures;
OMV.Primitive.TextureEntryFace[] texFaces = texEnt.FaceTextures;
const int genCount = 7;
float[] textureParams = new float[1 + ((int)Ogr.CreateMaterialParam.maxParam) * genCount];
string[] materialNames = new string[genCount];
string[] textureOgreNames = new string[genCount];
textureParams[0] = (float)Ogr.CreateMaterialParam.maxParam;
int[] texIndexes = {
(int)OMV.AvatarTextureIndex.HeadBaked,
(int)OMV.AvatarTextureIndex.UpperBaked,
(int)OMV.AvatarTextureIndex.LowerBaked,
(int)OMV.AvatarTextureIndex.EyesBaked,
(int)OMV.AvatarTextureIndex.HairBaked,
// (int)OMV.AvatarTextureIndex.SkirtBaked
};
int pBase = 1;
int jj = 0;
string textureOgreName;
foreach (int baker in texIndexes) {
CreateMaterialParameters(texFaces[baker],
ent, null, pBase, ref textureParams, jj, out textureOgreName);
materialNames[jj] = EntityNameOgre.ConvertToOgreMaterialNameX(ent.Name, jj);
textureOgreNames[jj] = textureOgreName;
// m_log.Log(LogLevel.DRENDERDETAIL, "CreateAvatarTextures: mat={0}, tex={1}",
// materialNames[jj], textureOgreName);
/*
// The textures for the baked avatar textures are processed specially
// Here we request they be loaded (if not already available) so we can specify their type
EntityNameOgre textureEnt = EntityNameOgre.ConvertOgreResourceToEntityName(textureOgreName);
System.Drawing.Bitmap textureBitmap = ent.AssetContext.GetTexture(textureEnt);
if (textureBitmap == null) {
// texture is not immediately available. Ask for it in a special way
ent.AssetContext.DoTextureLoad(textureEnt, AssetContextBase.AssetType.BakedTexture,
delegate(string name, bool trans) { return; });
}
*/
pBase += (int)textureParams[0];
jj++;
}
m_log.Log(LogLevel.DRENDERDETAIL, "CreateAvatarTextures: materials for {0}", ent.Name);
Ogr.CreateMaterialResource7BF(0f, materialNames[0],
materialNames[0], materialNames[1], materialNames[2], materialNames[3],
materialNames[4], materialNames[5], materialNames[6],
textureOgreNames[0], textureOgreNames[1], textureOgreNames[2], textureOgreNames[3],
textureOgreNames[4], textureOgreNames[5], textureOgreNames[6],
textureParams
);
}
else {
// the avatar is not initialized yet. Try again later.
return false;
}
}
else {
m_log.Log(LogLevel.DBADERROR, "CreateAvatarTexture: REQUEST BUT NOT LLAVATAR");
}
}
else {
string modNames = "";
foreach (string mod in ent.ModuleInterfaceTypeNames()) modNames += " " + mod;
m_log.Log(LogLevel.DBADERROR, "CreateAvatarTexture: REQUEST FOR TEXTURES FOR NON LL ENTITY. Mod={0}", modNames);
}
return true;
}
示例7: World_OnWorldEntityUpdate
void World_OnWorldEntityUpdate(IEntity ent, UpdateCodes what)
{
IEntityAvatar av;
if (ent.TryGet<IEntityAvatar>(out av)) {
// this new entity is an avatar. If we don't know it already, remember same
lock (m_avatars) {
if (!m_avatars.ContainsKey(av.Name.Name)) {
LogManager.Log.Log(LogLevel.DUPDATEDETAIL, "AvatarTracker. Update Tracking avatar {0}", av.Name.Name );
m_avatars.Add(av.Name.Name, av);
}
}
}
return;
}
示例8: World_OnWorldEntityRemoved
void World_OnWorldEntityRemoved(IEntity ent)
{
IEntityAvatar av;
if (ent.TryGet<IEntityAvatar>(out av)) {
// this entity is an avatar. If we're tracking it, stop that
lock (m_avatars) {
if (m_avatars.ContainsKey(av.Name.Name)) {
m_avatars.Remove(av.Name.Name);
}
}
}
return;
}
示例9: RenderUpdate
public void RenderUpdate(IEntity ent, UpdateCodes what)
{
m_log.Log(LogLevel.DRENDERDETAIL, "RenderUpdate: {0} for {1}", ent.Name.Name, what);
bool fullUpdate = false;
lock (ent) {
if (ent is LLEntityBase && ((what & UpdateCodes.New) != 0)) {
CreateNewPrim((LLEntityBase)ent);
fullUpdate = true;
}
if ((what & UpdateCodes.Animation) != 0) {
// the prim has changed its rotation animation
IAnimation anim;
if (ent.TryGet<IAnimation>(out anim)) {
m_log.Log(LogLevel.DRENDERDETAIL, "RenderUpdate: animation ");
RegionRenderInfo rri;
if (ent.RegionContext.TryGet<RegionRenderInfo>(out rri)) {
lock (rri) {
rri.animations.Add(AnimatBase.CreateAnimation(anim, ((LLEntityBase)ent).Prim.LocalID));
}
}
}
}
if ((what & UpdateCodes.Text) != 0) {
// text associated with the prim changed
m_log.Log(LogLevel.DRENDERDETAIL, "RenderUpdate: text changed");
}
if ((what & UpdateCodes.Particles) != 0) {
// particles associated with the prim changed
m_log.Log(LogLevel.DRENDERDETAIL, "RenderUpdate: particles changed");
}
if (!fullUpdate && (what & (UpdateCodes.Scale | UpdateCodes.Position | UpdateCodes.Rotation)) != 0) {
// world position has changed. Tell Ogre they have changed
try {
m_log.Log(LogLevel.DRENDERDETAIL, "RenderUpdate: Updating position/rotation for {0}", ent.Name.Name);
RegionRenderInfo rri;
if (ent.RegionContext.TryGet<RegionRenderInfo>(out rri)) {
lock (rri.renderPrimList) {
// exception if the casting does not work
if (((LLEntityBase)ent).Prim != null) {
uint localID = ((LLEntityBase)ent).Prim.LocalID;
if (rri.renderPrimList.ContainsKey(localID)) {
RenderablePrim rp = rri.renderPrimList[localID];
rp.Position = new OMV.Vector3(ent.RegionPosition.X, ent.RegionPosition.Y, ent.RegionPosition.Z);
rp.Rotation = new OMV.Quaternion(ent.Heading.X, ent.Heading.Y, ent.Heading.Z, ent.Heading.W);
}
}
}
}
}
catch (Exception e) {
m_log.Log(LogLevel.DBADERROR, "RenderUpdate: FAIL updating pos/rot: {0}", e);
}
}
}
return;
}