예제 #1
0
        protected override MyEntity CreateEntity(string hudLabelText, MyMwcObjectBuilder_Base objectBuilder, Matrix matrix, Vector2?screenPosition)
        {
            MyEntity entity = base.CreateEntity(hudLabelText, objectBuilder, matrix, screenPosition);

            // add waypoints
            if (entity is MyPrefabBase)
            {
                (entity as MyPrefabBase).InitWaypoints();
            }
            else if (entity is MyPrefabContainer)
            {
                foreach (var prefab in (entity as MyPrefabContainer).GetPrefabs())
                {
                    (prefab as MyPrefabBase).InitWaypoints();
                }
            }

            float distanceFromCamera = entity.WorldVolume.Radius * (entity is MyPrefabBase ? 4 : 2);

            Vector3 newPosition;

            if (screenPosition.HasValue)
            {
                Ray ray = MyUtils.ConvertMouseToRay(MyGuiManager.GetScreenCoordinateFromNormalizedCoordinate(screenPosition.Value));
                newPosition = ray.Position + ray.Direction * distanceFromCamera;
            }
            else
            {
                newPosition = MySpectator.Position + distanceFromCamera * MySpectator.Orientation;
            }

            entity.MoveAndRotate(newPosition, entity.GetWorldRotation());

            return(entity);
        }