示例#1
0
        public Optional <RotationMetadata> From(object baseGhost)
        {
            RotationMetadata rotationMetadata = null;

            if (baseGhost is BaseAddCorridorGhost)
            {
                BaseAddCorridorGhost corridorGhost = baseGhost as BaseAddCorridorGhost;
                int rotation = (int)corridorGhost.ReflectionGet("rotation");
                rotationMetadata = new CorridorRotationMetadata(rotation);
            }
            else if (baseGhost is BaseAddMapRoomGhost)
            {
                BaseAddMapRoomGhost mapRoomGhost = baseGhost as BaseAddMapRoomGhost;
                Base.CellType       cellType     = (Base.CellType)mapRoomGhost.ReflectionGet("cellType");
                int connectionMask = (int)mapRoomGhost.ReflectionGet("connectionMask");
                rotationMetadata = new MapRoomRotationMetadata((byte)cellType, connectionMask);
            }
            else if (baseGhost is BaseAddModuleGhost)
            {
                BaseAddModuleGhost module = baseGhost as BaseAddModuleGhost;

                Int3 cell      = module.anchoredFace.Value.cell;
                int  direction = (int)module.anchoredFace.Value.direction;

                rotationMetadata = new BaseModuleRotationMetadata(cell, direction);
            }
            else if (baseGhost is BaseAddFaceGhost)
            {
                BaseAddFaceGhost faceGhost = baseGhost as BaseAddFaceGhost;

                if (faceGhost.anchoredFace.HasValue)
                {
                    Base.Face anchoredFace = faceGhost.anchoredFace.Value;

                    rotationMetadata = new AnchoredFaceRotationMetadata(anchoredFace.cell, (int)anchoredFace.direction, (int)faceGhost.faceType);
                }
            }

            return(Optional.OfNullable(rotationMetadata));
        }
示例#2
0
        private static void ApplyRotationMetadata(GameObject ghostModel, RotationMetadata rotationMetadata)
        {
            BaseGhost component = ghostModel.GetComponent <BaseGhost>();

            if (component == null)
            {
                Log.Error("Was unable to apply rotation metadata - no BaseGhost found");
            }
            else if (component.GetType() != rotationMetadata.GhostType)
            {
                Log.Error("Was unable to apply rotation metadata - " + component.GetType() + " did not match " + rotationMetadata.GhostType);
            }
            else if (component is BaseAddCorridorGhost)
            {
                Log.Info("Placing BaseAddCorridorGhost Rotation Metadata");

                CorridorRotationMetadata corridorRotationMetadata = (rotationMetadata as CorridorRotationMetadata);
                BaseAddCorridorGhost     corridor = (component as BaseAddCorridorGhost);
                corridor.ReflectionSet("rotation", corridorRotationMetadata.Rotation);

                int  corridorType = (int)corridor.ReflectionCall("CalculateCorridorType");
                Base ghostBase    = (Base)corridor.ReflectionGet("ghostBase");
                ghostBase.SetCorridor(Int3.zero, corridorType, corridor.isGlass);
                corridor.ReflectionCall("RebuildGhostGeometry");
            }
            else if (component is BaseAddMapRoomGhost)
            {
                Log.Info("Placing MapRoomRotationMetadata Rotation Metadata");

                MapRoomRotationMetadata mapRoomRotationMetadata = (rotationMetadata as MapRoomRotationMetadata);
                BaseAddMapRoomGhost     mapRoom = (component as BaseAddMapRoomGhost);
                mapRoom.ReflectionSet("cellType", mapRoomRotationMetadata.CellType);
                mapRoom.ReflectionSet("connectionMask", mapRoomRotationMetadata.ConnectionMask);

                Base ghostBase = (Base)mapRoom.ReflectionGet("ghostBase");

                ghostBase.SetCell(Int3.zero, (Base.CellType)mapRoomRotationMetadata.CellType);
                mapRoom.ReflectionCall("RebuildGhostGeometry");
            }
            else if (component is BaseAddModuleGhost)
            {
                BaseModuleRotationMetadata baseModuleRotationMetadata = (rotationMetadata as BaseModuleRotationMetadata);
                BaseAddModuleGhost         module = (component as BaseAddModuleGhost);

                module.anchoredFace = new Base.Face(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction);
                module.ReflectionCall("RebuildGhostGeometry");
            }
            else if (component is BaseAddFaceGhost)
            {
                AnchoredFaceRotationMetadata baseModuleRotationMetadata = (rotationMetadata as AnchoredFaceRotationMetadata);
                BaseAddFaceGhost             faceGhost = (component as BaseAddFaceGhost);
                Log.Info("Applying BaseAddFaceGhost " + baseModuleRotationMetadata);


                Base.Face face = new Base.Face(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction);
                faceGhost.anchoredFace = face;

                Base          ghostBase = (Base)faceGhost.ReflectionGet("ghostBase");
                Base.FaceType faceType  = (Base.FaceType)baseModuleRotationMetadata.FaceType;
                ghostBase.SetFace(face, faceType);

                faceGhost.ReflectionCall("RebuildGhostGeometry");
            }
        }