GetChildAt() public méthode

public GetChildAt ( int childIndex ) : FNode,
childIndex int
Résultat FNode,
Exemple #1
0
 public void clearMap()
 {
     enemyList.Clear();
     spawnPoints.Clear();
     warpPoints.Clear();
     if (tilemap != null)
     {
         tilemap.RemoveFromContainer();
         tilemap.RemoveAllChildren();
     }
     foreach (FTilemap f in otherTilemaps)
     {
         if (f != null)
         {
             f.RemoveFromContainer();
         }
     }
     if (tilemapCollision != null)
     {
         tilemapCollision.RemoveFromContainer();
     }
     if (objectGroup != null)
     {
         objectGroup.RemoveFromContainer();
     }
     for (int x = 0; x < playerLayer.GetChildCount(); x++)
     {
         playerLayer.RemoveChild(playerLayer.GetChildAt(x));
         x--;
     }
 }
Exemple #2
0
    public static Rect GetContentRect(this FContainer container)
    {
        int childCount = container.GetChildCount();

        if (childCount == 0)
        {
            return(new Rect(0, 0, 0, 0));
        }

        float minX = 1000000f;
        float maxX = -1000000f;
        float minY = 1000000f;
        float maxY = -1000000f;

        for (int i = 0; i < childCount; i++)
        {
            FSprite sprite = container.GetChildAt(i) as FSprite;

            float spriteMinX = sprite.textureRect.xMin + (sprite.textureRect.width - (sprite.scaleX * sprite.textureRect.width)) / 2;
            float spriteMaxX = sprite.textureRect.xMax - (sprite.textureRect.width - (sprite.scaleX * sprite.textureRect.width)) / 2;
            float spriteMinY = sprite.textureRect.yMin + (sprite.textureRect.height - (sprite.scaleX * sprite.textureRect.width)) / 2;
            float spriteMaxY = sprite.textureRect.yMax - (sprite.textureRect.height - (sprite.scaleX * sprite.textureRect.width)) / 2;

            minX = Mathf.Min(minX, spriteMinX);
            maxX = Mathf.Max(maxX, spriteMaxX);
            minY = Mathf.Min(minY, spriteMinY);
            maxY = Mathf.Max(maxY, spriteMaxY);
        }

        float width  = maxX - minX;
        float height = maxY - minY;

        minX = minX + (width - (container.scaleX * width) / 2);
        maxX = maxX + (width - (container.scaleX * width) / 2);
        minY = minY + (height - (container.scaleY * height) / 2);
        maxY = maxY + (height - (container.scaleY * height) / 2);

        width  = container.scaleX * width;
        height = container.scaleY * height;

        Rect rect = new Rect(minX, maxY, width, height);

        return(rect);
    }
        public override void DrawSprites(RoomCamera.SpriteLeaser sLeaser, RoomCamera rCam, float timeStacker, Vector2 camPos)
        {
            if (!hackToDelayDrawingUntilAfterTheLevelMoves)
            {
                _lastCamPos = camPos;
                return;
            }

            _lastEyePos = _eyePos;

            if (sLeaser == null || rCam == null)
            {
                return;
            }
            if (room == null || room.game == null || sLeaser.sprites == null)
            {
                return;
            }

            foreach (FSprite sprite in sLeaser.sprites)
            {
                sprite.isVisible = !hideAllSprites;
            }

            if (room.game.Players.Count > 0)
            {
                BodyChunk headChunk = room.game.Players[0].realizedCreature?.bodyChunks[0];
                // Thanks, screams
                if (headChunk != null)
                {
                    _eyePos = Vector2.Lerp(headChunk.lastPos, headChunk.pos, timeStacker);
                }
            }

            if (_overrideEyePos.HasValue)
            {
                _eyePos = Vector2.Lerp(_lastOverrideEyePos, _overrideEyePos.Value, timeStacker);
            }

            // Update FOV blocker mesh
            TriangleMesh fovBlocker = (TriangleMesh)sLeaser.sprites[0];

            if (_eyePos != _lastEyePos)
            {
                Vector2 pos;
                pos.x = 0f;
                pos.y = 0f;
                for (int i = 0, len = corners.Count / 2; i < len; i++)
                {
                    pos.Set(corners[i].x - _eyePos.x, corners[i].y - _eyePos.y);
                    pos.Normalize();
                    fovBlocker.vertices[i].Set(pos.x * 5f + corners[i].x, pos.y * 5f + corners[i].y);
                    fovBlocker.vertices[i + len].Set(pos.x * 10000f + _eyePos.x, pos.y * 10000f + _eyePos.y);
                }

                // Calculate FoV blocker UVs
                Rect bounds = rCam.levelGraphic.localRect;
                bounds.position += rCam.levelGraphic.GetPosition();
                for (int i = fovBlocker.UVvertices.Length - 1; i >= 0; i--)
                {
                    Vector2 wPos = fovBlocker.vertices[i] - _lastCamPos;
                    fovBlocker.UVvertices[i].x = InverseLerpUnclamped(bounds.xMin, bounds.xMax, wPos.x);
                    fovBlocker.UVvertices[i].y = InverseLerpUnclamped(bounds.yMin, bounds.yMax, wPos.y);
                }
                fovBlocker.Refresh();
            }

            fovBlocker.x = -_lastCamPos.x;
            fovBlocker.y = -_lastCamPos.y;

            if (!LineOfSightMod.classic && fovBlocker.element != rCam.levelGraphic.element)
            {
                fovBlocker.element = rCam.levelGraphic.element;
            }

            // Block the screen when inside a wall
            {
                IntVector2 tPos = room.GetTilePosition(_eyePos);
                if (tPos.x < 0)
                {
                    tPos.x = 0;
                }
                if (tPos.x >= room.TileWidth)
                {
                    tPos.x = room.TileWidth - 1;
                }
                if (tPos.y < 0)
                {
                    tPos.y = 0;
                }
                if (tPos.y >= room.TileHeight)
                {
                    tPos.y = room.TileHeight - 1;
                }
                if (_tiles[tPos.x, tPos.y].Solid)
                {
                    lastScreenblockAlpha = 1f;
                    screenblockAlpha     = 1f;
                }
            }

            // Move the screenblock
            float alpha = Mathf.Lerp(lastScreenblockAlpha, screenblockAlpha, timeStacker);

            if (alpha == 0f)
            {
                sLeaser.sprites[1].isVisible = false;
            }
            else
            {
                FSprite screenBlock = sLeaser.sprites[1];
                screenBlock.scaleX = rCam.levelGraphic.scaleX;
                screenBlock.scaleY = rCam.levelGraphic.scaleY;
                screenBlock.x      = rCam.levelGraphic.x;
                screenBlock.y      = rCam.levelGraphic.y;
                if (LineOfSightMod.classic)
                {
                    // Must be resized to fit the level image
                    screenBlock.width  = rCam.levelGraphic.width;
                    screenBlock.height = rCam.levelGraphic.height;
                }
                else if (screenBlock.element != rCam.levelGraphic.element)
                {
                    screenBlock.element = rCam.levelGraphic.element;
                }
                screenBlock.alpha = alpha;
            }

            if (!LineOfSightMod.classic)
            {
                // Update shortcut peek
                float peekAlpha = Mathf.Lerp(_lastPeekAlpha, _peekAlpha, timeStacker);
                if (peekAlpha > 0f)
                {
                    TriangleMesh peek = (TriangleMesh)sLeaser.sprites[2];
                    //if (peek.element != rCam.levelGraphic.element)
                    //    peek.element = rCam.levelGraphic.element;
                    if (_lastPeekAlpha != _peekAlpha)
                    {
                        Color[] cols = peek.verticeColors;
                        for (int i = 0; i < cols.Length; i++)
                        {
                            float vertAlpha = (i < 6) ? peekAlpha : 0f;
                            //cols[i] = new Color(1f, vertAlpha * 0.75f, 0f, vertAlpha);
                            cols[i] = new Color(1f, 1f, 1f, vertAlpha * 0.25f);
                        }
                    }

                    //Rect bounds = rCam.levelGraphic.localRect;
                    //bounds.position += rCam.levelGraphic.GetPosition();
                    //for (int i = peek.UVvertices.Length - 1; i >= 0; i--)
                    //{
                    //    Vector2 wPos = peek.vertices[i];
                    //    float rad = _peekAngle * Mathf.Deg2Rad;
                    //    wPos.Set(wPos.x * Mathf.Cos(rad) + wPos.y * Mathf.Sin(rad), wPos.y * Mathf.Cos(rad) - wPos.x * Mathf.Sin(rad));
                    //    wPos = wPos + _peekPos - camPos;
                    //    peek.UVvertices[i].x = InverseLerpUnclamped(bounds.xMin, bounds.xMax, wPos.x);
                    //    peek.UVvertices[i].y = InverseLerpUnclamped(bounds.yMin, bounds.yMax, wPos.y);
                    //}

                    peek.SetPosition(_peekPos - _lastCamPos);
                    peek.rotation = _peekAngle;
                }
                else
                {
                    sLeaser.sprites[2].isVisible = false;
                }
            }
            else
            {
                sLeaser.sprites[2].isVisible = false;
            }

            // Keep on top
            FContainer container = sLeaser.sprites[2].container;

            if (container.GetChildAt(container.GetChildCount() - 1) != sLeaser.sprites[2])
            {
                for (int i = 0; i < sLeaser.sprites.Length; i++)
                {
                    sLeaser.sprites[i].MoveToFront();
                }
            }
            base.DrawSprites(sLeaser, rCam, timeStacker, _lastCamPos);
        }