public static RoomData BuildFromResource(string roomPath)
        {
            var      texture  = ResourceExtractor.GetTextureFromResource(roomPath);
            RoomData roomData = ExtractRoomDataFromResource(roomPath);

            roomData.room = Build(texture, roomData);
            return(roomData);
        }
        // Token: 0x0600003C RID: 60 RVA: 0x00003AD8 File Offset: 0x00001CD8
        public static RoomFactory.RoomData BuildFromResource(string roomPath)
        {
            Texture2D textureFromResource = ResourceExtractor.GetTextureFromResource(roomPath);

            RoomFactory.RoomData roomData = RoomFactory.ExtractRoomDataFromResource(roomPath);
            roomData.room = RoomFactory.Build(textureFromResource, roomData);
            return(roomData);
        }
Exemple #3
0
        // private static string [] m_AssetBundleNames = new string[] { "shared_auto_001", "shared_auto_002", "brave_resources_001" };
        public static PrototypeDungeonRoom BuildFromResource2(string roomPath, bool setRoomCategory = false, bool autoAssignToFloor = false, bool defineFullPath = false, bool assignDecorationSettings = false)
        {
            string RoomPath = (roomPath);

            if (defineFullPath)
            {
                RoomPath = roomPath;
            }
            Texture2D texture  = ResourceExtractor.GetTextureFromResource(RoomPath);
            RoomData  roomData = ExtractRoomDataFromResource(RoomPath);

            return(Build(texture, roomData, setRoomCategory, autoAssignToFloor, assignDecorationSettings, roomData.weight));
        }
        /// <summary>
        /// Adds a sprite (from a resource) to a collection
        /// </summary>
        /// <returns>The spriteID of the defintion in the collection</returns>
        public static int AddSpriteToCollection(string resourcePath, tk2dSpriteCollectionData collection)
        {
            string extension = !resourcePath.EndsWith(".png") ? ".png" : "";

            resourcePath += extension;
            var texture = ResourceExtractor.GetTextureFromResource(resourcePath); //Get Texture

            var definition = ConstructDefinition(texture);                        //Generate definition

            definition.name = texture.name;                                       //naming the definition is actually extremely important

            return(AddSpriteToCollection(definition, collection));
        }
        /// <summary>
        /// Returns an object with a tk2dSprite component with the
        /// texture of an embedded resource
        /// </summary>
        public static GameObject SpriteFromResource(string spriteName, GameObject obj = null, bool copyFromExisting = true)
        {
            string extension    = !spriteName.EndsWith(".png") ? ".png" : "";
            string resourcePath = spriteName + extension;

            var texture = ResourceExtractor.GetTextureFromResource(resourcePath);

            if (texture == null)
            {
                return(null);
            }

            return(SpriteFromTexture(texture, resourcePath, obj, copyFromExisting));
        }
        // Token: 0x06000017 RID: 23 RVA: 0x00003680 File Offset: 0x00001880
        public GameObject Build()
        {
            GameObject result;

            try
            {
                Texture2D  textureFromResource = ResourceExtractor.GetTextureFromResource(this.spritePath);
                GameObject gameObject          = SpriteBuilder.SpriteFromResource(this.spritePath, null);
                string     text = (this.modID + ":" + this.name).ToLower().Replace(" ", "_");
                //string roomPath = this.roomPath;
                gameObject.name = text;
                tk2dSprite component = gameObject.GetComponent <tk2dSprite>();
                component.IsPerpendicular = true;
                component.PlaceAtPositionByAnchor(this.offset, tk2dBaseSprite.Anchor.LowerCenter);
                Transform transform = new GameObject("talkpoint").transform;
                transform.position = gameObject.transform.position + this.talkPointOffset;
                transform.SetParent(gameObject.transform);
                bool flag  = !this.usesCustomColliderOffsetAndSize;
                bool flag2 = flag;
                if (flag2)
                {
                    IntVector2 intVector = new IntVector2(textureFromResource.width, textureFromResource.height);
                    this.colliderOffset = new IntVector2(0, 0);
                    this.colliderSize   = new IntVector2(intVector.x, intVector.y / 2);
                }
                SpeculativeRigidbody speculativeRigidbody = component.SetUpSpeculativeRigidbody(this.colliderOffset, this.colliderSize);

                speculativeRigidbody.PixelColliders.Add(new PixelCollider
                {
                    ColliderGenerationMode = PixelCollider.PixelColliderGeneration.Manual,
                    CollisionLayer         = CollisionLayer.PlayerBlocker,
                    IsTrigger = false,
                    BagleUseFirstFrameOnly = false,
                    SpecifyBagelFrame      = string.Empty,
                    BagelColliderNumber    = 0,
                    ManualOffsetX          = this.colliderOffset.x,
                    ManualOffsetY          = this.colliderOffset.y,
                    ManualWidth            = this.colliderSize.x,
                    ManualHeight           = this.colliderSize.y,
                    ManualDiameter         = 0,
                    ManualLeftX            = 0,
                    ManualLeftY            = 0,
                    ManualRightX           = 0,
                    ManualRightY           = 0,
                });
                speculativeRigidbody.PixelColliders.Add(new PixelCollider
                {
                    ColliderGenerationMode = PixelCollider.PixelColliderGeneration.Manual,
                    CollisionLayer         = CollisionLayer.EnemyBlocker,
                    IsTrigger = false,
                    BagleUseFirstFrameOnly = false,
                    SpecifyBagelFrame      = string.Empty,
                    BagelColliderNumber    = 0,
                    ManualOffsetX          = this.colliderOffset.x,
                    ManualOffsetY          = this.colliderOffset.y,
                    ManualWidth            = this.colliderSize.x,
                    ManualHeight           = this.colliderSize.y,
                    ManualDiameter         = 0,
                    ManualLeftX            = 0,
                    ManualLeftY            = 0,
                    ManualRightX           = 0,
                    ManualRightY           = 0,
                });
                speculativeRigidbody.PixelColliders.Add(new PixelCollider
                {
                    ColliderGenerationMode = PixelCollider.PixelColliderGeneration.Manual,
                    CollisionLayer         = CollisionLayer.BulletBlocker,
                    IsTrigger = false,
                    BagleUseFirstFrameOnly = false,
                    SpecifyBagelFrame      = string.Empty,
                    BagelColliderNumber    = 0,
                    ManualOffsetX          = this.colliderOffset.x,
                    ManualOffsetY          = this.colliderOffset.y,
                    ManualWidth            = this.colliderSize.x,
                    ManualHeight           = this.colliderSize.y,
                    ManualDiameter         = 0,
                    ManualLeftX            = 0,
                    ManualLeftY            = 0,
                    ManualRightX           = 0,
                    ManualRightY           = 0,
                });
                speculativeRigidbody.PixelColliders.Add(new PixelCollider
                {
                    ColliderGenerationMode = PixelCollider.PixelColliderGeneration.Manual,
                    CollisionLayer         = CollisionLayer.EnemyBulletBlocker,
                    IsTrigger = false,
                    BagleUseFirstFrameOnly = false,
                    SpecifyBagelFrame      = string.Empty,
                    BagelColliderNumber    = 0,
                    ManualOffsetX          = this.colliderOffset.x,
                    ManualOffsetY          = this.colliderOffset.y,
                    ManualWidth            = this.colliderSize.x,
                    ManualHeight           = this.colliderSize.y,
                    ManualDiameter         = 0,
                    ManualLeftX            = 0,
                    ManualLeftY            = 0,
                    ManualRightX           = 0,
                    ManualRightY           = 0,
                });
                speculativeRigidbody.PixelColliders.Add(new PixelCollider
                {
                    ColliderGenerationMode = PixelCollider.PixelColliderGeneration.Manual,
                    CollisionLayer         = CollisionLayer.BeamBlocker,
                    IsTrigger = false,
                    BagleUseFirstFrameOnly = false,
                    SpecifyBagelFrame      = string.Empty,
                    BagelColliderNumber    = 0,
                    ManualOffsetX          = this.colliderOffset.x,
                    ManualOffsetY          = this.colliderOffset.y,
                    ManualWidth            = this.colliderSize.x,
                    ManualHeight           = this.colliderSize.y,
                    ManualDiameter         = 0,
                    ManualLeftX            = 0,
                    ManualLeftY            = 0,
                    ManualRightX           = 0,
                    ManualRightY           = 0,
                });

                OldShrineFactory.CustomShrineController customShrineController = gameObject.AddComponent <OldShrineFactory.CustomShrineController>();
                customShrineController.ID             = text;
                customShrineController.roomStyles     = this.roomStyles;
                customShrineController.isBreachShrine = true;
                customShrineController.offset         = this.offset;
                customShrineController.pixelColliders = speculativeRigidbody.specRigidbody.PixelColliders;
                customShrineController.factory        = this;
                customShrineController.OnAccept       = this.OnAccept;
                customShrineController.OnDecline      = this.OnDecline;
                customShrineController.CanUse         = this.CanUse;
                bool flag3 = this.interactableComponent != null;
                bool flag4 = flag3;
                IPlayerInteractable item;
                if (flag4)
                {
                    item = (gameObject.AddComponent(this.interactableComponent) as IPlayerInteractable);
                }
                else
                {
                    SimpleShrine simpleShrine = gameObject.AddComponent <SimpleShrine>();
                    simpleShrine.isToggle    = this.isToggle;
                    simpleShrine.OnAccept    = this.OnAccept;
                    simpleShrine.OnDecline   = this.OnDecline;
                    simpleShrine.CanUse      = this.CanUse;
                    simpleShrine.text        = this.text;
                    simpleShrine.acceptText  = this.acceptText;
                    simpleShrine.declineText = this.declineText;
                    simpleShrine.talkPoint   = transform;
                    item = simpleShrine;
                }
                GameObject gameObject2 = ShrineFakePrefab.Clone(gameObject);
                gameObject2.GetComponent <OldShrineFactory.CustomShrineController>().Copy(customShrineController);
                gameObject2.name = text;
                bool flag5 = this.isBreachShrine;
                bool flag6 = flag5;
                if (flag6)
                {
                    bool flag7 = !RoomHandler.unassignedInteractableObjects.Contains(item);
                    bool flag8 = flag7;
                    if (flag8)
                    {
                        RoomHandler.unassignedInteractableObjects.Add(item);
                    }
                }
                else
                {
                    bool flag9  = !this.room;
                    bool flag10 = flag9;
                    if (flag10)
                    {
                        this.room = RoomFactory.CreateEmptyRoom(12, 12);
                    }
                    OldShrineFactory.RegisterShrineRoom(gameObject2, this.room, text, this.offset, this.RoomWeight);
                }
                OldShrineFactory.builtShrines.Add(text, gameObject2);
                result = gameObject;
            }
            catch (Exception e)
            {
                Tools.PrintException(e, "FF0000");
                result = null;
            }
            return(result);
        }
Exemple #7
0
        ///maybe add some value proofing here (name != null, collider != IntVector2.Zero)
        public GameObject Build()
        {
            try
            {
                //Get texture and create sprite
                Texture2D tex    = ResourceExtractor.GetTextureFromResource(spritePath);
                var       shrine = GungeonAPI.SpriteBuilder.SpriteFromResource(spritePath, null, false);

                //Add (hopefully) unique ID to shrine for tracking
                string ID = $"{modID}:{name}".ToLower().Replace(" ", "_");
                shrine.name = ID;

                //Position sprite
                var shrineSprite = shrine.GetComponent <tk2dSprite>();
                shrineSprite.IsPerpendicular = true;
                shrineSprite.PlaceAtPositionByAnchor(offset, tk2dBaseSprite.Anchor.LowerCenter);

                //Add speech bubble origin
                var talkPoint = new GameObject("talkpoint").transform;
                talkPoint.position = shrine.transform.position + talkPointOffset;
                talkPoint.SetParent(shrine.transform);

                //Set up collider
                if (!usesCustomColliderOffsetAndSize)
                {
                    IntVector2 spriteDimensions = new IntVector2(tex.width, tex.height);
                    colliderOffset = new IntVector2(0, 0);
                    colliderSize   = new IntVector2(spriteDimensions.x, spriteDimensions.y / 2);
                }
                var body = ItemAPI.SpriteBuilder.SetUpSpeculativeRigidbody(shrineSprite, colliderOffset, colliderSize);

                //if (!string.IsNullOrEmpty(shadowSpritePath))
                //{
                //    var shadow = ((GameObject)UnityEngine.Object.Instantiate(ResourceCache.Acquire("DefaultShadowSprite"))).GetComponent<tk2dSprite>();
                //    var shadowSprite = ItemAPI.SpriteBuilder.SpriteFromResource(shadowSpritePath, null, false).GetComponent<tk2dSprite>();
                //    Tools.Print($"Shadow material: {shadow.renderer.material.name}");
                //    Tools.Print($"\tShadow color: {shadow.color}");
                //    Tools.Print($"\tShadow material: {shadowSprite.renderer.material.name}");
                //    Tools.Print($"\tShadow color: {shadowSprite.color}");
                //    Tools.ExportTexture(shadow.renderer.material.mainTexture.GetReadable());
                //    //Tools.ExportTexture(shadowSprite.renderer.material.mainTexture.GetReadable());

                //    shrineSprite.AttachRenderer(shadow);
                //    shadow.PlaceAtPositionByAnchor(shrineSprite.WorldBottomCenter, tk2dBaseSprite.Anchor.UpperCenter);
                //    //shadow.color = new Color(1, 1, 1, .5f);
                //    //shadow.HeightOffGround = -0.1f;
                //    //shadow.renderer.material = defaultSprite.renderer.material;
                //    DepthLookupManager.ProcessRenderer(shadow.GetComponent<Renderer>(), DepthLookupManager.GungeonSortingLayer.BACKGROUND);

                //    //Tools.LogPropertiesAndFields(defaultSprite);

                //}

                var data = shrine.AddComponent <CustomShrineController>();
                data.ID             = ID;
                data.roomStyles     = roomStyles;
                data.isBreachShrine = true;
                data.offset         = offset;
                data.pixelColliders = body.specRigidbody.PixelColliders;
                data.factory        = this;
                data.OnAccept       = OnAccept;
                data.OnDecline      = OnDecline;
                data.CanUse         = CanUse;
                data.text           = text;
                data.acceptText     = acceptText;
                data.declineText    = declineText;

                if (interactableComponent == null)
                {
                    var simpInt = shrine.AddComponent <SimpleShrine>();
                    simpInt.isToggle    = this.isToggle;
                    simpInt.OnAccept    = this.OnAccept;
                    simpInt.OnDecline   = this.OnDecline;
                    simpInt.CanUse      = CanUse;
                    simpInt.text        = this.text;
                    simpInt.acceptText  = this.acceptText;
                    simpInt.declineText = this.declineText;
                    simpInt.talkPoint   = talkPoint;
                }
                else
                {
                    shrine.AddComponent(interactableComponent);
                }


                shrine.name = ID;
                if (!isBreachShrine)
                {
                    if (!room)
                    {
                        room = RoomFactory.CreateEmptyRoom();
                    }
                    RegisterShrineRoom(shrine, room, ID, offset);
                }
                registeredShrines.Add(ID, shrine);
                FakePrefab.MarkAsFakePrefab(shrine);
                Tools.Print("Added shrine: " + ID);
                return(shrine);
            }
            catch (Exception e)
            {
                Tools.PrintException(e);
                return(null);
            }
        }
Exemple #8
0
        public static void GenerateRoomLayoutFromPNG(PrototypeDungeonRoom room, string filePath, PrototypeRoomPitEntry.PitBorderType PitBorderType = PrototypeRoomPitEntry.PitBorderType.FLAT, CoreDamageTypes DamageCellsType = CoreDamageTypes.None)
        {
            Texture2D m_TextureFromResource = ResourceExtractor.GetTextureFromResource(filePath);

            float DamageToPlayersPerTick = 0;
            float DamageToEnemiesPerTick = 0;
            float TickFrequency          = 0;
            bool  RespectsFlying         = true;
            bool  DamageCellsArePoison   = false;

            if (DamageCellsType == CoreDamageTypes.Fire)
            {
                DamageToPlayersPerTick = 0.5f;
                TickFrequency          = 1;
            }
            else if (DamageCellsType == CoreDamageTypes.Poison)
            {
                DamageCellsArePoison   = true;
                DamageToPlayersPerTick = 0.5f;
                TickFrequency          = 1;
            }

            if (m_TextureFromResource == null)
            {
                ETGModConsole.Log("GenerateRoomFromImage: Error! Requested Texture Resource is Null!");
                return;
            }

            Color WhitePixel      = new Color32(255, 255, 255, 255);    // Wall Cell
            Color PinkPixel       = new Color32(255, 0, 255, 255);      // Diagonal Wall Cell (North East)
            Color YellowPixel     = new Color32(255, 255, 0, 255);      // Diagonal Wall Cell (North West)
            Color HalfPinkPixel   = new Color32(127, 0, 127, 255);      // Diagonal Wall Cell (South East)
            Color HalfYellowPixel = new Color32(127, 127, 0, 255);      // Diagonal Wall Cell (South West)

            Color BluePixel = new Color32(0, 0, 255, 255);              // Floor Cell

            Color BlueHalfGreenPixel = new Color32(0, 127, 255, 255);   // Floor Cell (Ice Override)
            Color HalfBluePixel      = new Color32(0, 0, 127, 255);     // Floor Cell (Water Override)
            Color HalfRedPixel       = new Color32(0, 0, 127, 255);     // Floor Cell (Carpet Override)
            Color GreenHalfRBPixel   = new Color32(127, 255, 127, 255); // Floor Cell (Grass Override)
            Color HalfWhitePixel     = new Color32(127, 127, 127, 255); // Floor Cell (Bone Override)
            Color OrangePixel        = new Color32(255, 127, 0, 255);   // Floor Cell (Flesh Override)
            Color RedHalfGBPixel     = new Color32(255, 127, 127, 255); // Floor Cell (ThickGoop Override)

            Color GreenPixel = new Color32(0, 255, 0, 255);             // Damage Floor Cell

            Color RedPixel = new Color32(255, 0, 0, 255);               // Pit Cell

            int width       = room.Width;
            int height      = room.Height;
            int ArrayLength = (width * height);

            if (m_TextureFromResource.GetPixels32().Length != ArrayLength)
            {
                ETGModConsole.Log("GenerateRoomFromImage: Error! Image resolution doesn't match size of room!");
                return;
            }

            room.FullCellData = new PrototypeDungeonRoomCellData[ArrayLength];
            List <Vector2> m_Pits = new List <Vector2>();

            for (int X = 0; X < width; X++)
            {
                for (int Y = 0; Y < height; Y++)
                {
                    int                          ArrayPosition     = (Y * width + X);
                    Color?                       m_Pixel           = m_TextureFromResource.GetPixel(X, Y);
                    CellType                     cellType          = CellType.FLOOR;
                    DiagonalWallType             diagonalWallType  = DiagonalWallType.NONE;
                    CellVisualData.CellFloorType OverrideFloorType = CellVisualData.CellFloorType.Stone;
                    bool                         isDamageCell      = false;
                    bool                         cellDamagesPlayer = false;
                    if (m_Pixel.HasValue)
                    {
                        if (m_Pixel.Value == WhitePixel | m_Pixel.Value == PinkPixel |
                            m_Pixel.Value == YellowPixel | m_Pixel.Value == HalfPinkPixel |
                            m_Pixel.Value == HalfYellowPixel)
                        {
                            cellType = CellType.WALL;
                            if (m_Pixel.Value == PinkPixel)
                            {
                                diagonalWallType = DiagonalWallType.NORTHEAST;
                            }
                            else if (m_Pixel.Value == YellowPixel)
                            {
                                diagonalWallType = DiagonalWallType.NORTHWEST;
                            }
                            else if (m_Pixel.Value == HalfPinkPixel)
                            {
                                diagonalWallType = DiagonalWallType.SOUTHEAST;
                            }
                            else if (m_Pixel.Value == HalfYellowPixel)
                            {
                                diagonalWallType = DiagonalWallType.SOUTHWEST;
                            }
                        }
                        else if (m_Pixel.Value == RedPixel)
                        {
                            cellType = CellType.PIT;
                            m_Pits.Add(new Vector2(X, Y));
                        }
                        else if (m_Pixel.Value == BluePixel | m_Pixel.Value == GreenPixel |
                                 m_Pixel.Value == BlueHalfGreenPixel | m_Pixel.Value == HalfBluePixel |
                                 m_Pixel.Value == HalfRedPixel | m_Pixel.Value == GreenHalfRBPixel |
                                 m_Pixel.Value == HalfWhitePixel | m_Pixel.Value == OrangePixel |
                                 m_Pixel.Value == RedHalfGBPixel)
                        {
                            cellType = CellType.FLOOR;
                            if (m_Pixel.Value == GreenPixel)
                            {
                                isDamageCell = true;
                                if (DamageCellsType == CoreDamageTypes.Ice)
                                {
                                    cellDamagesPlayer = false;
                                }
                                else
                                {
                                    cellDamagesPlayer = true;
                                }
                            }
                            else if (m_Pixel.Value == BlueHalfGreenPixel)
                            {
                                OverrideFloorType = CellVisualData.CellFloorType.Ice;
                            }
                            else if (m_Pixel.Value == HalfBluePixel)
                            {
                                OverrideFloorType = CellVisualData.CellFloorType.Water;
                            }
                            else if (m_Pixel.Value == HalfRedPixel)
                            {
                                OverrideFloorType = CellVisualData.CellFloorType.Carpet;
                            }
                            else if (m_Pixel.Value == GreenHalfRBPixel)
                            {
                                OverrideFloorType = CellVisualData.CellFloorType.Grass;
                            }
                            else if (m_Pixel.Value == HalfWhitePixel)
                            {
                                OverrideFloorType = CellVisualData.CellFloorType.Bone;
                            }
                            else if (m_Pixel.Value == OrangePixel)
                            {
                                OverrideFloorType = CellVisualData.CellFloorType.Flesh;
                            }
                            else if (m_Pixel.Value == RedHalfGBPixel)
                            {
                                OverrideFloorType = CellVisualData.CellFloorType.ThickGoop;
                            }
                        }
                        else
                        {
                            cellType = CellType.FLOOR;
                        }
                    }
                    else
                    {
                        cellType = CellType.FLOOR;
                    }
                    if (DamageCellsType != CoreDamageTypes.None && isDamageCell)
                    {
                        room.FullCellData[ArrayPosition] = GenerateCellData(cellType, diagonalWallType, cellDamagesPlayer, DamageCellsArePoison, DamageCellsType, DamageToPlayersPerTick, DamageToEnemiesPerTick, TickFrequency, RespectsFlying);
                    }
                    else
                    {
                        room.FullCellData[ArrayPosition] = GenerateCellData(cellType, diagonalWallType, OverrideFloorType: OverrideFloorType);
                    }
                }
            }

            if (m_Pits.Count > 0)
            {
                room.pits = new List <PrototypeRoomPitEntry>()
                {
                    new PrototypeRoomPitEntry(m_Pits)
                    {
                        containedCells = m_Pits,
                        borderType     = PitBorderType
                    }
                };
            }
            room.OnBeforeSerialize();
            room.OnAfterDeserialize();
            room.UpdatePrecalculatedData();
        }
Exemple #9
0
        // Token: 0x0600009A RID: 154 RVA: 0x00008084 File Offset: 0x00006284
        public GameObject Build()
        {
            GameObject result;

            try
            {
                Texture2D  textureFromResource = ResourceExtractor.GetTextureFromResource(this.spritePath);
                GameObject gameObject          = SpriteBuilder.SpriteFromResource(this.spritePath, null);
                string     text = (this.modID + ":" + this.name).ToLower().Replace(" ", "_");
                gameObject.name = text;
                tk2dSprite component = gameObject.GetComponent <tk2dSprite>();
                component.IsPerpendicular = true;
                component.PlaceAtPositionByAnchor(this.offset, tk2dBaseSprite.Anchor.LowerCenter);
                Transform transform = new GameObject("talkpoint").transform;
                transform.position = gameObject.transform.position + this.talkPointOffset;
                transform.SetParent(gameObject.transform);
                bool flag  = !this.usesCustomColliderOffsetAndSize;
                bool flag2 = flag;
                bool flag3 = flag2;
                if (flag3)
                {
                    IntVector2 intVector = new IntVector2(textureFromResource.width, textureFromResource.height);
                    this.colliderOffset = new IntVector2(0, 0);
                    this.colliderSize   = new IntVector2(intVector.x, intVector.y / 2);
                }
                SpeculativeRigidbody speculativeRigidbody = component.SetUpSpeculativeRigidbody(this.colliderOffset, this.colliderSize);
                ShrineFactory.CustomShrineController customShrineController = gameObject.AddComponent <ShrineFactory.CustomShrineController>();
                customShrineController.ID             = text;
                customShrineController.roomStyles     = this.roomStyles;
                customShrineController.isBreachShrine = true;
                customShrineController.offset         = this.offset;
                customShrineController.pixelColliders = speculativeRigidbody.specRigidbody.PixelColliders;
                customShrineController.factory        = this;
                customShrineController.OnAccept       = this.OnAccept;
                customShrineController.OnDecline      = this.OnDecline;
                customShrineController.CanUse         = this.CanUse;
                customShrineController.text           = this.text;
                customShrineController.acceptText     = this.acceptText;
                customShrineController.declineText    = this.declineText;
                bool flag4 = this.interactableComponent == null;
                bool flag5 = flag4;
                bool flag6 = flag5;
                if (flag6)
                {
                    SimpleShrine simpleShrine = gameObject.AddComponent <SimpleShrine>();
                    simpleShrine.isToggle    = this.isToggle;
                    simpleShrine.OnAccept    = this.OnAccept;
                    simpleShrine.OnDecline   = this.OnDecline;
                    simpleShrine.CanUse      = this.CanUse;
                    simpleShrine.text        = this.text;
                    simpleShrine.acceptText  = this.acceptText;
                    simpleShrine.declineText = this.declineText;
                    simpleShrine.talkPoint   = transform;
                }
                else
                {
                    gameObject.AddComponent(this.interactableComponent);
                }
                gameObject.name = text;
                bool flag7 = !this.isBreachShrine;
                bool flag8 = flag7;
                bool flag9 = flag8;
                if (flag9)
                {
                    bool flag10 = !this.room;
                    bool flag11 = flag10;
                    bool flag12 = flag11;
                    if (flag12)
                    {
                        this.room = RoomFactory.CreateEmptyRoom(12, 12);
                    }
                    ShrineFactory.RegisterShrineRoom(gameObject, this.room, text, this.offset, this.RoomWeight);
                }
                ShrineFactory.registeredShrines.Add(text, gameObject);
                FakePrefab.MarkAsFakePrefab(gameObject);
                result = gameObject;
            }
            catch (Exception e)
            {
                Tools.PrintException(e, "FF0000");
                result = null;
            }
            return(result);
        }
Exemple #10
0
        ///maybe add some value proofing here (name != null, collider != IntVector2.Zero)
        public GameObject Build()
        {
            try
            {
                //Get texture and create sprite
                Texture2D tex    = ResourceExtractor.GetTextureFromResource(spritePath);
                var       shrine = SpecialItemPack.ItemAPI.SpriteBuilder.SpriteFromResource(spritePath, null, false);

                //Add (hopefully) unique ID to shrine for tracking
                string ID = $"{modID}:{name}".ToLower().Replace(" ", "_");
                shrine.name = ID;

                //Position sprite
                var sprite = shrine.GetComponent <tk2dSprite>();
                sprite.IsPerpendicular = true;
                sprite.PlaceAtPositionByAnchor(offset, tk2dBaseSprite.Anchor.LowerCenter);

                //Add speech bubble origin
                var talkPoint = new GameObject("talkpoint").transform;
                talkPoint.position = shrine.transform.position + talkPointOffset;
                talkPoint.SetParent(shrine.transform);

                //Set up collider
                if (!usesCustomColliderOffsetAndSize)
                {
                    IntVector2 spriteDimensions = new IntVector2(tex.width, tex.height);
                    colliderOffset = new IntVector2(0, 0);
                    colliderSize   = new IntVector2(spriteDimensions.x, spriteDimensions.y / 2);
                }
                var body = ItemAPI.SpriteBuilder.SetUpSpeculativeRigidbody(sprite, colliderOffset, colliderSize);

                var data = shrine.AddComponent <CustomShrineController>();
                data.ID             = ID;
                data.roomStyles     = roomStyles;
                data.isBreachShrine = true;
                data.offset         = offset;
                data.pixelColliders = body.specRigidbody.PixelColliders;
                data.factory        = this;
                data.OnAccept       = OnAccept;
                data.OnDecline      = OnDecline;
                data.CanUse         = CanUse;

                IPlayerInteractable interactable;
                //Register as interactable
                if (interactableComponent != null)
                {
                    interactable = shrine.AddComponent(interactableComponent) as IPlayerInteractable;
                }
                else
                {
                    var simpInt = shrine.AddComponent <SimpleInteractable>();
                    simpInt.isToggle    = this.isToggle;
                    simpInt.OnAccept    = this.OnAccept;
                    simpInt.OnDecline   = this.OnDecline;
                    simpInt.CanUse      = CanUse;
                    simpInt.text        = this.text;
                    simpInt.acceptText  = this.acceptText;
                    simpInt.declineText = this.declineText;
                    simpInt.talkPoint   = talkPoint;
                    interactable        = simpInt as IPlayerInteractable;
                }


                var prefab = FakePrefab.Clone(shrine);
                prefab.GetComponent <CustomShrineController>().Copy(data);
                prefab.name = ID;
                if (isBreachShrine)
                {
                    if (!RoomHandler.unassignedInteractableObjects.Contains(interactable))
                    {
                        RoomHandler.unassignedInteractableObjects.Add(interactable);
                    }
                }
                else
                {
                    if (!room)
                    {
                        room = RoomFactory.CreateEmptyRoom();
                    }
                    RegisterShrineRoom(prefab, room, ID, offset);
                }


                builtShrines.Add(ID, prefab);
                Tools.Print("Added shrine: " + ID);
                return(shrine);
            }
            catch (Exception e)
            {
                Tools.PrintException(e);
                return(null);
            }
        }