コード例 #1
0
        void EntityIDInput(ScreenResult result, string resultText)
        {
            if (result == ScreenResult.Ok)
            {
                uint entityID;
                if (uint.TryParse(resultText, out entityID))
                {
                    var entity = MyEntities.GetEntityByIdOrNull(new MyEntityIdentifier(entityID));
                    if (entity != null)
                    {
                        var position = entity.GetPosition() - entity.WorldVolume.Radius * entity.GetForward();
                        MySpectator.SetViewMatrix(Matrix.CreateLookAt(position, entity.GetPosition(), entity.GetUp()));

                        MyEditorGizmo.AddEntityToSelection(entity);
                    }
                    else
                    {
                        MyGuiScreenMessageBox.Show(MyTextsWrapperEnum.EntityIsNotExist, type: MyMessageBoxType.ERROR);
                    }
                }
                else
                {
                    MyGuiScreenMessageBox.Show(MyTextsWrapperEnum.WrongNumberFormat, type: MyMessageBoxType.ERROR);
                }
            }
        }
コード例 #2
0
        void OnNewEntity(ref MyEventNewEntity msg)
        {
            var entityId = msg.ObjectBuilder.EntityId.ToEntityId();

            if (entityId.HasValue && MyEntities.GetEntityByIdOrNull(entityId.Value) != null)
            {
                return;
            }

            var entity = MyEntities.CreateFromObjectBuilderAndAdd(null, msg.ObjectBuilder, msg.Position.GetMatrix());

            HookEntity(entity);
        }
コード例 #3
0
        public MyConnectEntityOperation ConnectEntity(uint entityId)
        {
            MyConnectEntityOperation result;

            MyEntity entityById = MyEntities.GetEntityByIdOrNull(new MyEntityIdentifier(entityId));

            if (entityById == null)
            {
                result = MyConnectEntityOperation.NotExists;
            }
            else
            {
                IMyUseableEntity connectableEntity = entityById as IMyUseableEntity;
                if (connectableEntity == null || (connectableEntity.UseProperties.UseType & MyUseType.FromHUB) == 0 || !(connectableEntity is IMyHasGuiControl))
                {
                    result = MyConnectEntityOperation.NotSupported;
                }
                else
                {
                    if (m_connectedEntities.Contains(connectableEntity))
                    {
                        result = MyConnectEntityOperation.AlreadyConnected;
                    }
                    else
                    {
                        entityById.OnClosing += m_onEntityClosingHandler;
                        m_connectedEntities.Add(connectableEntity);
                        result = MyConnectEntityOperation.Success;

                        if (OnEntityConnected != null)
                        {
                            OnEntityConnected(connectableEntity);
                        }
                    }
                }
            }

            return(result);
        }
コード例 #4
0
        public MyConnectEntityOperation DisconnetEntity(uint entityId)
        {
            MyEntity entity = MyEntities.GetEntityByIdOrNull(new MyEntityIdentifier(entityId));

            Debug.Assert(entity != null);
            IMyUseableEntity useableEntity = entity as IMyUseableEntity;

            Debug.Assert(useableEntity != null);
            if (entity != null)
            {
                entity.OnClosing -= m_onEntityClosingHandler;
            }
            bool removed = m_connectedEntities.Remove(useableEntity);

            if (removed && OnEntityDisconnected != null)
            {
                OnEntityDisconnected(useableEntity);
            }

            var result = removed ? MyConnectEntityOperation.Success : MyConnectEntityOperation.NotExists;

            return(result);
        }
コード例 #5
0
        // Resolve EntityId links.
        public void ResolveLinks()
        {
            // parent entities (prefabs)
            if (objectBuilder.ParentEntityId != null && MyEntities.GetEntities().Contains(this))
            {
                var parent = MyEntities.GetEntityByIdOrNull(new MyEntityIdentifier((uint)objectBuilder.ParentEntityId.Value));
                if (parent != null)
                {
                    var worldMatrix = WorldMatrix;
                    MyEntities.Remove(this);
                    //parent.Children.Add(this);  // remove it and add back through the parent
                    parent.AddChild(this);
                    this.Activate(true, false);
                    SetWorldMatrix(worldMatrix);
                }
            }

            // neighbors
            foreach (var neighborId in objectBuilder.NeighborEntityIds)
            {
                var neighbor = MyEntities.GetEntityByIdOrNull(new MyEntityIdentifier((uint)neighborId));
                if (neighbor != null && neighbor is MyWayPoint)
                {
                    Connect(this, (MyWayPoint)neighbor);
                }
            }

            // path placing
            for (int i = 0; i < objectBuilder.GroupPlacings.Count; i++)
            {
                var name    = objectBuilder.GroupNames[i];
                var placing = objectBuilder.GroupPlacings[i];

                // resolve path by name: create it if it didn't exist
                MyWayPointPath path = MyWayPointGraph.GetPath(name);
                if (path == null)
                {
                    path = new MyWayPointPath(name);
                }

                // make enough empty waypoints to make it fit
                while (placing >= path.WayPoints.Count)
                {
                    path.WayPoints.Add(null);
                }

                path.WayPoints[placing] = this;
            }

            // can't delete object builder
            // This function is reentrant and sometimes we need both runs.
            //objectBuilder = null;

            // but we can delete neighbor and path info
            if (MyGuiScreenGamePlay.Static.IsGameActive())
            {
                objectBuilder.GroupNames.Clear();
                objectBuilder.GroupPlacings.Clear();
                objectBuilder.NeighborEntityIds.Clear();
            }
        }