Example #1
0
        public override MyObjectBuilder_EntityBase GetObjectBuilder(bool copy = false)
        {
            MyObjectBuilder_AreaMarker objectBuilder = base.GetObjectBuilder(copy) as MyObjectBuilder_AreaMarker;

            objectBuilder.SubtypeName = this.m_definition.Id.SubtypeName;
            return(objectBuilder);
        }
Example #2
0
        static void CreateNewPlaceArea(SerializableDefinitionId id, MyPositionAndOrientation positionAndOrientation)
        {
            MyObjectBuilder_AreaMarker objectBuilder = (MyObjectBuilder_AreaMarker)MyObjectBuilderSerializer.CreateNewObject(id);

            objectBuilder.PersistentFlags        = MyPersistentEntityFlags2.Enabled | MyPersistentEntityFlags2.InScene;
            objectBuilder.PositionAndOrientation = positionAndOrientation;

            MyEntities.CreateFromObjectBuilderAndAdd(objectBuilder);
        }
Example #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);
                }
            }
        }