Esempio n. 1
0
        /// <summary>
        /// Gets object builder from object.
        /// </summary>
        /// <returns></returns>
        public virtual MyObjectBuilder_EntityBase GetObjectBuilder(bool copy = false)
        {
            var objBuilder = MyEntityFactory.CreateObjectBuilder(this);

            if (objBuilder != null)
            {
                objBuilder.PositionAndOrientation = new MyPositionAndOrientation()
                {
                    Position = this.PositionComp.GetPosition(),
                    Up       = (Vector3)this.WorldMatrix.Up,
                    Forward  = (Vector3)this.WorldMatrix.Forward
                };

                objBuilder.EntityId = this.EntityId;
                Debug.Assert(objBuilder.EntityId != 0);

                objBuilder.Name            = this.Name;
                objBuilder.PersistentFlags = Render.PersistentFlags;

                if (MyPerGameSettings.ComponentSaving)
                {
                    objBuilder.ComponentContainer = Components.Serialize();
                }
            }
            return(objBuilder);
        }
Esempio n. 2
0
 public static MyObjectBuilder_EntityBase EntityFactoryCreateObjectBuilder(this MyEntity thisEntity)
 {
     return(MyEntityFactory.CreateObjectBuilder(thisEntity));
 }
Esempio n. 3
0
        private void PlaceAreaMarker()
        {
            Vector3D cameraPos, cameraDir;

            if (MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.ThirdPersonSpectator || MySession.Static.GetCameraControllerEnum() == MyCameraControllerEnum.Entity)
            {
                var headMatrix = MySession.Static.ControlledEntity.GetHeadMatrix(true, true);
                cameraPos = headMatrix.Translation;
                cameraDir = headMatrix.Forward;
            }
            else
            {
                cameraPos = MySector.MainCamera.Position;
                cameraDir = MySector.MainCamera.WorldMatrix.Forward;
            }

            List <MyPhysics.HitInfo> hitInfos = new List <MyPhysics.HitInfo>();

            MyPhysics.CastRay(cameraPos, cameraPos + cameraDir * 100, hitInfos, MyPhysics.CollisionLayers.ObjectDetectionCollisionLayer);
            if (hitInfos.Count == 0)
            {
                return;
            }

            MyPhysics.HitInfo?closestValidHit = null;
            foreach (var hitInfo in hitInfos)
            {
                var ent = hitInfo.HkHitInfo.GetHitEntity();
                if (ent is MyCubeGrid)
                {
                    closestValidHit = hitInfo;
                    break;
                }
                else if (ent is MyVoxelMap)
                {
                    closestValidHit = hitInfo;
                    break;
                }
            }

            if (closestValidHit.HasValue)
            {
                MyAreaMarkerDefinition definition = AreaMarkerDefinition;
                Debug.Assert(definition != null, "Area marker definition cannot be null!");
                if (definition == null)
                {
                    return;
                }

                Vector3D position = closestValidHit.Value.Position;

                var forward = Vector3D.Reject(cameraDir, Vector3D.Up);

                if (Vector3D.IsZero(forward))
                {
                    forward = Vector3D.Forward;
                }

                var positionAndOrientation = new MyPositionAndOrientation(position, Vector3D.Normalize(forward), Vector3D.Up);

                MyObjectBuilder_AreaMarker objectBuilder = (MyObjectBuilder_AreaMarker)MyObjectBuilderSerializer.CreateNewObject(definition.Id);
                objectBuilder.PersistentFlags        = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene;
                objectBuilder.PositionAndOrientation = positionAndOrientation;

                if (objectBuilder.IsSynced)
                {
                    SerializableDefinitionId id = definition.Id;
                    MyMultiplayer.RaiseStaticEvent(x => CreateNewPlaceArea, id, positionAndOrientation);
                }
                else
                {
                    MyAreaMarker flag = MyEntityFactory.CreateEntity <MyAreaMarker>(objectBuilder);
                    flag.Init(objectBuilder);

                    MyEntities.Add(flag);
                }
            }
        }
Esempio n. 4
0
 public static MyObjectBuilder_EntityBase EntityFactoryCreateObjectBuilder(this MyEntity thisEntity) =>
 MyEntityFactory.CreateObjectBuilder(thisEntity);