コード例 #1
0
 private void CopyFloatingObjectInternal(MyFloatingObject toCopy)
 {
     this.m_copiedFloatingObjects.Add((MyObjectBuilder_FloatingObject)toCopy.GetObjectBuilder(true));
     if (this.m_copiedFloatingObjects.Count == 1)
     {
         MatrixD  pasteMatrix = GetPasteMatrix();
         Vector3D translation = toCopy.WorldMatrix.Translation;
         this.m_dragPointToPositionLocal = Vector3D.TransformNormal(toCopy.PositionComp.GetPosition() - translation, toCopy.PositionComp.WorldMatrixNormalizedInv);
         this.m_dragDistance             = (float)(translation - pasteMatrix.Translation).Length();
         this.m_pasteDirUp            = (Vector3)toCopy.WorldMatrix.Up;
         this.m_pasteDirForward       = (Vector3)toCopy.WorldMatrix.Forward;
         this.m_pasteOrientationAngle = 0f;
     }
     this.m_copiedFloatingObjectOffsets.Add(toCopy.WorldMatrix.Translation - this.m_copiedFloatingObjects[0].PositionAndOrientation.Value.Position);
 }
コード例 #2
0
        private void CopyFloatingObjectInternal(MyFloatingObject toCopy)
        {
            m_copiedFloatingObjects.Add((MyObjectBuilder_FloatingObject)toCopy.GetObjectBuilder(true));
            if (m_copiedFloatingObjects.Count == 1)
            {
                MatrixD pasteMatrix = GetPasteMatrix();
                Vector3 dragPointGlobal = toCopy.WorldMatrix.Translation;

                m_dragPointToPositionLocal = Vector3D.TransformNormal(toCopy.PositionComp.GetPosition() - dragPointGlobal, toCopy.PositionComp.WorldMatrixNormalizedInv);
                m_dragDistance = (float)(dragPointGlobal - pasteMatrix.Translation).Length();

                m_pasteDirUp = toCopy.WorldMatrix.Up;
                m_pasteDirForward = toCopy.WorldMatrix.Forward;
                m_pasteOrientationAngle = 0.0f;
            }
            m_copiedFloatingObjectOffsets.Add(toCopy.WorldMatrix.Translation - m_copiedFloatingObjects[0].PositionAndOrientation.Value.Position);
        }
コード例 #3
0
        public bool PasteFloatingObject(MyInventory buildInventory = null)
        {
            if (m_copiedFloatingObjects.Count == 0)
            {
                return(false);
            }

            if ((m_copiedFloatingObjects.Count > 0) && !IsActive)
            {
                if (CheckPastedFloatingObjects())
                {
                    Activate();
                }
                else
                {
                    MyHud.Notifications.Add(MyNotificationSingletons.CopyPasteBlockNotAvailable);
                    MyGuiAudio.PlaySound(MyGuiSounds.HudUnable);
                }
                return(true);
            }

            if (!m_canBePlaced)
            {
                MyGuiAudio.PlaySound(MyGuiSounds.HudUnable);
                return(false);
            }

            MyGuiAudio.PlaySound(MyGuiSounds.HudPlaceBlock);

            MyEntities.RemapObjectBuilderCollection(m_copiedFloatingObjects);

            m_tmpPastedBuilders.Clear();
            m_tmpPastedBuilders.Capacity = m_copiedFloatingObjects.Count;
            MyFloatingObject firstPastedFloatingObject = null;

            int  i      = 0;
            bool retVal = false;

            foreach (var floatingObjectBuilder in m_copiedFloatingObjects)
            {
                floatingObjectBuilder.PersistentFlags = MyPersistentEntityFlags2.InScene | MyPersistentEntityFlags2.Enabled;
                MyFloatingObject pastedFloatingObject = MyEntities.CreateFromObjectBuilderAndAdd(floatingObjectBuilder) as MyFloatingObject;
                if (i == 0)
                {
                    firstPastedFloatingObject = pastedFloatingObject;
                }

                if (pastedFloatingObject == null)
                {
                    retVal = true;
                    continue;
                }

                pastedFloatingObject.PositionComp.SetWorldMatrix(m_previewFloatingObjects[i].WorldMatrix);
                i++;
                pastedFloatingObject.Physics.LinearVelocity = m_objectVelocity;

                if (MySession.ControlledEntity != null && MySession.ControlledEntity.Entity.Physics != null && m_calculateVelocity)
                {
                    pastedFloatingObject.Physics.AngularVelocity = MySession.ControlledEntity.Entity.Physics.AngularVelocity;
                }

                var builder = pastedFloatingObject.GetObjectBuilder();
                m_tmpPastedBuilders.Add(builder);

                retVal = true;
            }

            // CH:TODO: This would probably be safer if it was requested from the server as well
            MySyncCreate.SendEntitiesCreated(m_tmpPastedBuilders);

            Deactivate();
            return(retVal);
        }