Beispiel #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);
        }
Beispiel #2
0
        public virtual void OnOkClick(MyGuiControlButton sender)
        {
            if (HasEntity())
            {
                if (m_idTextbox != null)
                {
                    if (m_entity.EntityId != null)
                    {
                        var newId = new MyEntityIdentifier(Convert.ToUInt32(m_idTextbox.Text));

                        if (newId.NumericValue != m_entity.EntityId.Value.NumericValue && !MyEntityIdentifier.ExistsById(newId))
                        {
                            MyEntityIdentifier.RemoveEntity(m_entity.EntityId.Value);
                            m_entity.EntityId = newId;
                            MyEntityIdentifier.AddEntityWithId(m_entity);
                        }
                    }
                }

                if (IsPositionInput())
                {
                    Vector3 position = GetNewPosition();
                    if (IsValidPositionInput(position))
                    {
                        MyEditorGizmo.MoveAndRotateObject(position, m_entity.GetWorldRotation(), m_entity);
                    }
                }
            }
        }