示例#1
0
        MyEntity LoadDisplay()
        {
            if (m_block == null)
            {
                return(null);
            }

            string model = "Display_" + m_block.BlockDefinition.SubtypeId + ".mwm";

            MyEntity entity;

            entity = new MyEntity();
            entity.Init(null, GetModelsFolder() + model, (MyEntity)m_block, null, null);
            entity.Render.EnableColorMaskHsv = true;
            entity.Render.ColorMaskHsv       = m_block.Render.ColorMaskHsv;
            entity.Render.PersistentFlags    = MyPersistentEntityFlags2.CastShadows;

            entity.PositionComp.LocalMatrix =
                Matrix.CreateFromTransformScale(
                    Quaternion.Identity,
                    Vector3.Zero,
                    Vector3.One);

            entity.Flags = EntityFlags.NeedsWorldMatrix | EntityFlags.Visible | EntityFlags.NeedsDraw | EntityFlags.NeedsDrawFromParent | EntityFlags.InvalidateOnMove;
            entity.OnAddedToScene(m_block);

            return(entity);
        }
示例#2
0
 //Shell Entities
 public IMyEntity EmptyEntity(string displayName, string model)
 {
     try
     {
         var ent = new MyEntity();
         ent.Init(new StringBuilder(displayName), model, null, null, null);
         MyAPIGateway.Entities.AddEntity(ent);
         return(ent);
     }
     catch (Exception ex) { Log.Line($"Exception in EmptyEntity: {ex}"); return(null); }
 }
示例#3
0
        IMyEntity CreateBubble(float radius)
        {
            MyEntity ent = new MyEntity();

            ent.Init(null, WarpConstants.warpBubble, null, radius * 0.004f, null);
            ent.Render.CastShadows = false;
            ent.IsPreview          = true;
            ent.Save             = false;
            ent.SyncFlag         = false;
            ent.NeedsWorldMatrix = true;
            ent.Flags           |= EntityFlags.IsNotGamePrunningStructureObject;
            MyEntities.Add(ent);
            return(ent);
        }
示例#4
0
        private MyEntity PrimeEntityActivator()
        {
            var ent = new MyEntity();

            ent.Init(null, ModelPath, null, null, null);
            ent.Render.CastShadows = false;
            ent.IsPreview          = true;
            ent.Save             = false;
            ent.SyncFlag         = false;
            ent.NeedsWorldMatrix = false;
            ent.Flags           |= EntityFlags.IsNotGamePrunningStructureObject;
            MyEntities.Add(ent, false);
            return(ent);
        }
示例#5
0
 public static MyEntity EmptyEntity(string displayName, string model, MyEntity parent, bool parented = false)
 {
     try
     {
         var myParent = parented ? parent : null;
         var ent = new MyEntity { NeedsWorldMatrix = true, Physics = !parented ? new MyHandToolBase.MyBlockingBody(new MyHandToolBase(), parent) { IsPhantom = true } : null };
         ent.Init(new StringBuilder(displayName), model, myParent, null, null);
         ent.Name = $"{parent.EntityId}";
         ent.DefinitionId = new MyDefinitionId(MyObjectBuilderType.Invalid, MyStringHash.GetOrCompute("DefenseShield"));
         ent.Hierarchy.ChildId = parent.EntityId;
         MyEntities.Add(ent);
         return ent;
     }
     catch (Exception ex) { Log.Line($"Exception in EmptyEntity: {ex}"); return null; }
 }
示例#6
0
 public static MyEntity EmptyEntity(string displayName, string model, MyEntity parent, bool parented = false)
 {
     try
     {
         var myParent = parented ? parent : null;
         var ent      = new MyEntity {
             NeedsWorldMatrix = true
         };
         ent.Init(new StringBuilder(displayName), model, myParent, null);
         ent.Name = $"{parent.EntityId}";
         MyAPIGateway.Entities.AddEntity(ent);
         return(ent);
     }
     catch (Exception ex) { Log.Line($"Exception in EmptyEntity: {ex}"); return(null); }
 }
示例#7
0
文件: Spawn.cs 项目: CultOfClang/sero
 public static MyEntity EmptyEntity(string displayName, string model, MyEntity parent, bool parented = false)
 {
     try
     {
         var ent = new MyEntity();
         ent.Init(null, model, null, null, null);
         ent.Render.CastShadows = false;
         ent.IsPreview          = true;
         ent.Render.Visible     = true;
         ent.Save             = false;
         ent.SyncFlag         = false;
         ent.NeedsWorldMatrix = false;
         ent.Flags           |= EntityFlags.IsNotGamePrunningStructureObject;
         MyEntities.Add(ent);
         return(ent);
     }
     catch (Exception ex) { Log.Line($"Exception in EmptyEntity: {ex}"); return(null); }
 }
示例#8
0
        internal MyEntity TriggerEntityActivator()
        {
            var ent = new MyEntity();

            ent.Init(null, TriggerEntityModel, null, null, null);
            ent.Render.CastShadows = false;
            ent.IsPreview          = true;
            ent.Save             = false;
            ent.SyncFlag         = false;
            ent.NeedsWorldMatrix = false;
            ent.Flags           |= EntityFlags.IsNotGamePrunningStructureObject;
            MyEntities.Add(ent);

            ent.PositionComp.SetWorldMatrix(ref MatrixD.Identity, null, false, false, false);
            ent.InScene = false;
            ent.Render.RemoveRenderObjects();
            return(ent);
        }
示例#9
0
        private void CreateCenterSphere(MyEntity block)
        {
            if (block == null)
            {
                return;
            }

            m_centerSphere = new MyEntity();
            m_centerSphere.Init(null, m_modelsFolder + "sphere.mwm", block, null, null);
            m_centerSphere.Render.EnableColorMaskHsv = true;
            m_centerSphere.Render.ColorMaskHsv       = block.Render.ColorMaskHsv;
            m_centerSphere.Render.PersistentFlags    = MyPersistentEntityFlags2.CastShadows;
            m_centerSphere.PositionComp.LocalMatrix  = Matrix.CreateFromTransformScale(Quaternion.Identity, new Vector3(0f, -1.0f, 0f), Vector3.One);
            m_centerSphere.Flags = EntityFlags.Visible | EntityFlags.NeedsDraw | EntityFlags.NeedsDrawFromParent | EntityFlags.InvalidateOnMove;
            m_centerSphere.OnAddedToScene(block);

            MyCubeBlockEmissive.SetEmissiveParts(m_centerSphere, 0.0f, Color.FromNonPremultiplied(new Vector4(0.35f, 0.05f, 0.35f, 0.75f)), Color.White);
        }
示例#10
0
 public static MyEntity EmptyEntity(string displayName, string model, MyEntity parent, bool parented = false)
 {
     try
     {
         var myParent = parented ? parent : null;
         var ent      = new MyEntity {
             NeedsWorldMatrix = true, Physics = !parented ? new MyHandToolBase.MyBlockingBody(new MyHandToolBase(), parent)
             {
                 IsPhantom = true
             } : null
         };
         ent.Init(new StringBuilder(displayName), model, myParent, null, null);
         ent.Name = $"{parent.EntityId}";
         MyEntities.Add(ent);
         return(ent);
     }
     catch (Exception ex) { Log.Line($"Exception in EmptyEntity: {ex}"); return(null); }
 }
示例#11
0
        protected void InternalAddEntity( )
        {
            try
            {
                if (AddEntityQueue.Count == 0)
                {
                    return;
                }

                BaseEntity entityToAdd = AddEntityQueue.Dequeue( );

                if (ExtenderOptions.IsDebugging)
                {
                    ApplicationLog.BaseLog.Debug(entityToAdd.GetType( ).Name + " '" + entityToAdd.GetType( ).Name + "': Adding to scene ...");
                }

                //Create the backing object
                Type entityType   = entityToAdd.GetType( );
                Type internalType = (Type)BaseEntity.InvokeStaticMethod(entityType, "get_InternalType");
                if (internalType == null)
                {
                    throw new Exception("Could not get internal type of entity");
                }
                entityToAdd.BackingObject = Activator.CreateInstance(internalType);

                //Add the backing object to the main game object manager
                MyEntity backingObject = (MyEntity)entityToAdd.BackingObject;
                backingObject.Init(entityToAdd.ObjectBuilder);
                MyEntities.Add(backingObject);

                if (entityToAdd is FloatingObject)
                {
                    try
                    {
                        //Broadcast the new entity to the clients
                        MyObjectBuilder_EntityBase baseEntity = backingObject.GetObjectBuilder( );
                        //TODO - Do stuff

                        entityToAdd.ObjectBuilder = baseEntity;
                    }
                    catch (Exception ex)
                    {
                        ApplicationLog.BaseLog.Error("Failed to broadcast new floating object");
                        ApplicationLog.BaseLog.Error(ex);
                    }
                }
                else
                {
                    try
                    {
                        //Broadcast the new entity to the clients
                        MyObjectBuilder_EntityBase baseEntity = backingObject.GetObjectBuilder( );
                        MySyncCreate.SendEntityCreated(baseEntity);

                        entityToAdd.ObjectBuilder = baseEntity;
                    }
                    catch (Exception ex)
                    {
                        ApplicationLog.BaseLog.Error("Failed to broadcast new entity");
                        ApplicationLog.BaseLog.Error(ex);
                    }
                }

                if (ExtenderOptions.IsDebugging)
                {
                    Type type = entityToAdd.GetType( );
                    ApplicationLog.BaseLog.Debug(type.Name + " '" + entityToAdd.Name + "': Finished adding to scene");
                }
            }
            catch (Exception ex)
            {
                ApplicationLog.BaseLog.Error(ex);
            }
        }
示例#12
0
        /// <summary>
        /// Add anima part for animation, parent will be one of root's subpart.
        /// </summary>
        /// <param name="subpartName">root subpart name.</param>
        /// <param name="modelFile">>Model file name inside Models folder, excluding extension.</param>
        /// <param name="smoothAnim">smooth animation, linear lerp between keyframes.</param>
        /// <param name="visible">initialize it visible?</param>
        /// <returns>part or null for failure.</returns>
        public AnimaPart AddPartToSubpart(string subpartName, string modelFile, bool smoothAnim = false, bool visible = true)
        {
            if (m_entity == null) return null;
            if (!m_entity.Subparts.ContainsKey(subpartName)) return null;

            // Create part
            MyEntity parentEntity = m_entity.Subparts[subpartName];
            MyEntity part_entity = new MyEntity();
            part_entity.Init(null, m_modelsFolder + modelFile + ".mwm", parentEntity, null, null);
            part_entity.Render.EnableColorMaskHsv = true;
            part_entity.Render.ColorMaskHsv = m_entity.Render.ColorMaskHsv;
            part_entity.Render.PersistentFlags = MyPersistentEntityFlags2.CastShadows;
            part_entity.PositionComp.LocalMatrix = Matrix.Identity;
            part_entity.Flags = EntityFlags.Visible | EntityFlags.NeedsDraw | EntityFlags.NeedsDrawFromParent | EntityFlags.InvalidateOnMove;
            part_entity.OnAddedToScene(parentEntity);

            AnimaPart part = new AnimaPart(this, null, part_entity);
            if (!visible) part.Visible = false;
            m_partList.Add(part);
            return part;
        }