示例#1
0
        /// <summary>
        /// Advances the disposal traversal by one tile.
        /// </summary>
        public void Traverse()
        {
            ReadyToTraverse = false;

            // Check if just started so we don't end the traversal at the disposal machine we started from.
            if (!justStarted && currentPipe.PipeType == DisposalPipeType.Terminal)
            {
                EjectViaDisposalPipeTerminal();
                return;
            }

            // Advance to next pipe
            justStarted = false;
            OrientationEnum nextPipeRequiredSide = GetConnectedSide(currentPipeOutputSide).AsEnum();
            DisposalPipe    nextPipe             = GetPipeAt(NextPipeLocalPosition, requiredSide: nextPipeRequiredSide);

            if (nextPipe == null)
            {
                EjectViaPipeEnd();
                return;
            }

            TransferContainerToVector(NextPipeVector);
            currentPipeLocalPos   = NextPipeLocalPosition;
            currentPipeOutputSide = Orientation.FromEnum(GetPipeLeavingSide(nextPipe, nextPipeRequiredSide));
            currentPipe           = nextPipe;

            ReadyToTraverse = true;
        }
        void DeconstructPipe()
        {
            DisposalPipe pipe = deconstructInteraction.BasicTile as DisposalPipe;

            // Despawn pipe tile
            var matrix = MatrixManager.AtPoint(deconstructInteraction.WorldPositionTarget.NormalizeTo3Int(), true).Matrix;

            matrix.RemoveUnderFloorTile(deconstructInteraction.TargetCellPos, pipe);

            // Spawn pipe GameObject
            if (deconstructInteraction.BasicTile.SpawnOnDeconstruct == null)
            {
                return;
            }

            var spawn = Spawn.ServerPrefab(deconstructInteraction.BasicTile.SpawnOnDeconstruct, deconstructInteraction.WorldPositionTarget);

            if (!spawn.Successful)
            {
                return;
            }

            if (!spawn.GameObject.TryGetComponent(out Directional directional))
            {
                return;
            }
            directional.FaceDirection(Orientation.FromEnum(pipe.DisposalPipeObjectOrientation));

            if (!spawn.GameObject.TryGetComponent(out ObjectBehaviour behaviour))
            {
                return;
            }
            behaviour.ServerSetPushable(false);
        }
        void ChangePipeObjectToTile()
        {
            Orientation orientation = GetComponent <Directional>().CurrentDirection;

            // Spawn the correct disposal pipe tile, based on current orientation.
            DisposalPipe pipeTileToSpawn = GetPipeTileByOrientation(orientation);

            if (pipeTileToSpawn != null)
            {
                var   matrixTransform = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one);
                Color pipeColor       = GetComponentInChildren <SpriteRenderer>().color;
                registerTile.Matrix.AddUnderFloorTile(registerTile.LocalPositionServer, pipeTileToSpawn, matrixTransform, pipeColor);
                tileChangeManager.UpdateTile(registerTile.LocalPositionServer, pipeTileToSpawn);
                Despawn.ServerSingle(gameObject);
            }
            else
            {
                Logger.LogError($"Failed to spawn disposal pipe tile! Is {name} missing reference to tile asset for {orientation}?");
            }
        }
示例#4
0
        /// <summary>
        /// Create a new disposal instance.
        /// Note: start a disposal instance by using DisposalsManager.Instance.NewDisposal(),
        /// as it will handle instance updates.
        /// </summary>
        /// <param name="container">The virtual container holding the entities to be disposed of.</param>
        public DisposalTraversal(DisposalVirtualContainer container)
        {
            RegisterTile registerTile = container.GetComponent <RegisterTile>();

            matrix = registerTile.Matrix;
            currentPipeLocalPos = registerTile.LocalPositionServer;
            virtualContainer    = container;
            containerTransform  = container.GetComponent <CustomNetTransform>();

            currentPipe = GetPipeAt(currentPipeLocalPos, DisposalPipeType.Terminal);
            if (currentPipe == null)
            {
                virtualContainer.EjectContents();
                DespawnContainerAndFinish();
                return;
            }
            // First() assumes initial pipe is of type: Terminal (as it has just one connectable side)
            // Not an issue unless new traversals do not start from disposal machines.
            // Consider refactoring and using GetPipeLeavingSide(currentPipe, someSide); if this becomes an issue.
            currentPipeOutputSide = Orientation.FromEnum(currentPipe.ConnectablePoints.First().Key);

            justStarted     = true;
            ReadyToTraverse = true;
        }