Example #1
0
    public Door(bool isHorizontal, int startRow, int startCol) : base("doorVertClosed")
    {
        doorIsHorizontal = isHorizontal;

        this.startRow = startRow;
        this.startCol = startCol;

        SetDoorPosition();

        _frameElements = new FAtlasElement[4];

        FAtlasManager am = Futile.atlasManager;

        _frameElements[doorHorzOpen]   = am.GetElementWithName("doorHorzOpen");
        _frameElements[doorHorzClosed] = am.GetElementWithName("doorHorzClosed");
        _frameElements[doorVertOpen]   = am.GetElementWithName("doorVertOpen");
        _frameElements[doorVertClosed] = am.GetElementWithName("doorVertClosed");

        if (isHorizontal)
        {
            this.element = _frameElements[doorHorzClosed];
        }

        SetDoorStatus(false);

        ListenForUpdate(HandleUpdate);
    }
Example #2
0
    public BMonkey() : base("Monkey_0.png")
    {
        _frameElements = new FAtlasElement[numFrames];

        FAtlasManager am = Futile.atlasManager;

        //of course there are way smarter ways to do this, but this is fast
        //it's a ping ponging animation, which is why I did it this way, it's not a straight loop
        _frameElements[0]  = am.GetElementWithName("Monkey_0.png");
        _frameElements[1]  = am.GetElementWithName("Monkey_1.png");
        _frameElements[2]  = am.GetElementWithName("Monkey_2.png");
        _frameElements[3]  = am.GetElementWithName("Monkey_3.png");
        _frameElements[4]  = am.GetElementWithName("Monkey_4.png");
        _frameElements[5]  = am.GetElementWithName("Monkey_5.png");
        _frameElements[6]  = am.GetElementWithName("Monkey_6.png");
        _frameElements[7]  = am.GetElementWithName("Monkey_7.png");
        _frameElements[8]  = am.GetElementWithName("Monkey_8.png");
        _frameElements[9]  = am.GetElementWithName("Monkey_9.png");
        _frameElements[10] = am.GetElementWithName("Monkey_8.png");
        _frameElements[11] = am.GetElementWithName("Monkey_7.png");
        _frameElements[12] = am.GetElementWithName("Monkey_6.png");
        _frameElements[13] = am.GetElementWithName("Monkey_5.png");
        _frameElements[14] = am.GetElementWithName("Monkey_4.png");
        _frameElements[15] = am.GetElementWithName("Monkey_3.png");
        _frameElements[16] = am.GetElementWithName("Monkey_2.png");
        _frameElements[17] = am.GetElementWithName("Monkey_1.png");
        _frameElements[18] = am.GetElementWithName("Monkey_0.png");
    }
Example #3
0
    public BMonkey() : base("Monkey_0")
    {
        _frameElements = new FAtlasElement[19];

        FAtlasManager am = Futile.atlasManager;

        //of course there are way smarter ways to do this, but this is fast
        //it's a ping ponging animation, which is why I did it this way, it's not a straight loop
        _frameElements[0]  = am.GetElementWithName("Monkey_0");
        _frameElements[1]  = am.GetElementWithName("Monkey_1");
        _frameElements[2]  = am.GetElementWithName("Monkey_2");
        _frameElements[3]  = am.GetElementWithName("Monkey_3");
        _frameElements[4]  = am.GetElementWithName("Monkey_4");
        _frameElements[5]  = am.GetElementWithName("Monkey_5");
        _frameElements[6]  = am.GetElementWithName("Monkey_6");
        _frameElements[7]  = am.GetElementWithName("Monkey_7");
        _frameElements[8]  = am.GetElementWithName("Monkey_8");
        _frameElements[9]  = am.GetElementWithName("Monkey_9");
        _frameElements[10] = am.GetElementWithName("Monkey_8");
        _frameElements[11] = am.GetElementWithName("Monkey_7");
        _frameElements[12] = am.GetElementWithName("Monkey_6");
        _frameElements[13] = am.GetElementWithName("Monkey_5");
        _frameElements[14] = am.GetElementWithName("Monkey_4");
        _frameElements[15] = am.GetElementWithName("Monkey_3");
        _frameElements[16] = am.GetElementWithName("Monkey_2");
        _frameElements[17] = am.GetElementWithName("Monkey_1");
        _frameElements[18] = am.GetElementWithName("Monkey_0");

        ListenForUpdate(HandleUpdate);
    }
Example #4
0
    public void Init(FutileParams futileParams)
    {
        enabled       = true;
        _futileParams = futileParams;

        Application.targetFrameRate = _futileParams.targetFrameRate;

        FShader.Init();         //set up the basic shaders
        FFacetType.Init();      //set up the types of facets (Quads, Triangles, etc)

        screen = new FScreen(_futileParams);

        //
        //Camera setup from https://github.com/prime31/UIToolkit/blob/master/Assets/Plugins/UIToolkit/UI.cs
        //

        if (existingCamera != null)
        {
            _cameraHolder = existingCamera.gameObject;
            _camera       = existingCamera;
        }
        else
        {
            _cameraHolder = new GameObject();
            _camera       = _cameraHolder.AddComponent <Camera>();
        }

        _cameraHolder.transform.parent = gameObject.transform;

        _camera.tag             = "MainCamera";
        _camera.clearFlags      = CameraClearFlags.SolidColor;
        _camera.nearClipPlane   = 0.0f;
        _camera.farClipPlane    = 500.0f;
        _camera.depth           = 100;
        _camera.rect            = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
        _camera.backgroundColor = _futileParams.backgroundColor;

        //we multiply this stuff by scaleInverse to make sure everything is in points, not pixels
        _camera.orthographic     = true;
        _camera.orthographicSize = screen.pixelHeight / 2 * displayScaleInverse;

        UpdateCameraPosition();

        touchManager = new FTouchManager();

        atlasManager = new FAtlasManager();

        CreateDefaultAtlases();


        _stages = new List <FStage>();

        stage = new FStage("Futile.stage");

        AddStage(stage);
    }
Example #5
0
    public Crew() : base("walkRight0")
    {
        this.defaultVelocity = 100;
        this.currentVelocity = this.defaultVelocity;

        int randomDirection = RXRandom.Range(0, 4);

        this.direction = VectorDirection.Up;         // (VectorDirection)randomDirection;

        if (randomDirection == 1)
        {
            this.direction = VectorDirection.Left;
        }
        else if (randomDirection == 2)
        {
            this.direction = VectorDirection.Right;
        }
        else if (randomDirection == 3)
        {
            this.direction = VectorDirection.Down;
        }


        _leftFrameElements  = new FAtlasElement[4];
        _rightFrameElements = new FAtlasElement[4];
        _upFrameElements    = new FAtlasElement[4];
        _downFrameElements  = new FAtlasElement[4];

        FAtlasManager am = Futile.atlasManager;

        _rightFrameElements[0] = am.GetElementWithName("walkRight0");
        _rightFrameElements[1] = am.GetElementWithName("walkRight1");
        _rightFrameElements[2] = am.GetElementWithName("walkRight2");
        _rightFrameElements[3] = am.GetElementWithName("walkRight3");

        _leftFrameElements[0] = am.GetElementWithName("walkLeft0");
        _leftFrameElements[1] = am.GetElementWithName("walkLeft1");
        _leftFrameElements[2] = am.GetElementWithName("walkLeft2");
        _leftFrameElements[3] = am.GetElementWithName("walkLeft3");

        _upFrameElements[0] = am.GetElementWithName("walkUp0");
        _upFrameElements[1] = am.GetElementWithName("walkUp1");
        _upFrameElements[2] = am.GetElementWithName("walkUp2");
        _upFrameElements[3] = am.GetElementWithName("walkUp3");

        _downFrameElements[0] = am.GetElementWithName("walkDown0");
        _downFrameElements[1] = am.GetElementWithName("walkDown1");
        _downFrameElements[2] = am.GetElementWithName("walkDown2");
        _downFrameElements[3] = am.GetElementWithName("walkDown3");


        ListenForUpdate(HandleUpdate);
    }
Example #6
0
    public MoveTile() : base("moveTileUp0")
    {
        _leftFrameElements  = new FAtlasElement[4];
        _rightFrameElements = new FAtlasElement[4];
        _upFrameElements    = new FAtlasElement[4];
        _downFrameElements  = new FAtlasElement[4];

        FAtlasManager am = Futile.atlasManager;

        _leftFrameElements[0] = am.GetElementWithName("moveTileLeft0");
        _leftFrameElements[1] = am.GetElementWithName("moveTileLeft1");
        _leftFrameElements[2] = am.GetElementWithName("moveTileLeft2");
        _leftFrameElements[3] = am.GetElementWithName("moveTileLeft3");

        _rightFrameElements[0] = am.GetElementWithName("moveTileRight0");
        _rightFrameElements[1] = am.GetElementWithName("moveTileRight1");
        _rightFrameElements[2] = am.GetElementWithName("moveTileRight2");
        _rightFrameElements[3] = am.GetElementWithName("moveTileRight3");

        _upFrameElements[0] = am.GetElementWithName("moveTileUp0");
        _upFrameElements[1] = am.GetElementWithName("moveTileUp1");
        _upFrameElements[2] = am.GetElementWithName("moveTileUp2");
        _upFrameElements[3] = am.GetElementWithName("moveTileUp3");

        _downFrameElements[0] = am.GetElementWithName("moveTileDown0");
        _downFrameElements[1] = am.GetElementWithName("moveTileDown1");
        _downFrameElements[2] = am.GetElementWithName("moveTileDown2");
        _downFrameElements[3] = am.GetElementWithName("moveTileDown3");

        _placedAt = 0.0f;

        int randomDirection = RXRandom.Range(0, 4);

        this.direction = VectorDirection.Up;         // (VectorDirection)randomDirection;

        if (randomDirection == 1)
        {
            this.direction = VectorDirection.Left;
            this.element   = _leftFrameElements[0];
        }
        else if (randomDirection == 2)
        {
            this.direction = VectorDirection.Right;
            this.element   = _rightFrameElements[0];
        }
        else if (randomDirection == 3)
        {
            this.direction = VectorDirection.Down;
            this.element   = _downFrameElements[0];
        }

        ListenForUpdate(HandleUpdate);
    }
Example #7
0
    public void Init(FutileParams futileParams)
    {
        enabled       = true;
        _futileParams = futileParams;

        //设置游戏帧率
        Application.targetFrameRate = _futileParams.targetFrameRate;
        //设置basic shaders
        FShader.Init();
        //设置facets' types (Quads, Triangles, etc)
        FFacetType.Init();

        //初始化各引擎组件实例
        screen = new FScreen(_futileParams);

        touchManager = new FTouchManager();

        atlasManager = new FAtlasManager();

        //设置主相机参数:Setup from https://github.com/prime31/UIToolkit/blob/master/Assets/Plugins/UIToolkit/UI.cs

        _cameraHolder = new GameObject();
        _cameraHolder.transform.parent = gameObject.transform;

        _camera      = _cameraHolder.AddComponent <Camera>();
        _camera.tag  = "MainCamera";
        _camera.name = "Camera";
        //_camera.clearFlags = CameraClearFlags.Depth; //TODO: check if this is faster or not?
        _camera.clearFlags      = CameraClearFlags.SolidColor;
        _camera.nearClipPlane   = 0.0f;
        _camera.farClipPlane    = 500.0f;
        _camera.depth           = 100;
        _camera.rect            = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
        _camera.backgroundColor = _futileParams.backgroundColor;

        //we multiply this stuff by scaleInverse to make sure everything is in points, not pixels
        _camera.orthographic     = true;
        _camera.orthographicSize = screen.pixelHeight / 2 * displayScaleInverse;

        UpdateCameraPosition();

        //创建默认Atlas
        CreateDefaultAtlases();

        //初始化Stage管理
        _stages = new List <FStage>();

        stage = new FStage("Futile.stage");

        AddStage(stage);
    }
Example #8
0
    public void Init(FutileParams futileParams)
    {
        enabled       = true;
        _futileParams = futileParams;

        Application.targetFrameRate = _futileParams.targetFrameRate;

        FShader.Init();         //set up the basic shaders

        Futile.startingQuadsPerLayer  = _futileParams.startingQuadsPerLayer;
        Futile.quadsPerLayerExpansion = _futileParams.quadsPerLayerExpansion;
        Futile.maxEmptyQuadsPerLayer  = _futileParams.maxEmptyQuadsPerLayer;

        screen = new FScreen(_futileParams);

        //
        //Camera setup from https://github.com/prime31/UIToolkit/blob/master/Assets/Plugins/UIToolkit/UI.cs
        //

        _cameraHolder = new GameObject();
        _cameraHolder.transform.parent = gameObject.transform;

        _camera      = _cameraHolder.AddComponent <Camera>();
        _camera.name = "Camera";
        //_camera.clearFlags = CameraClearFlags.Depth; //TODO: check if this is faster or not?
        _camera.clearFlags      = CameraClearFlags.SolidColor;
        _camera.nearClipPlane   = -50.0f;
        _camera.farClipPlane    = 50.0f;
        _camera.depth           = 100;
        _camera.rect            = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
        _camera.backgroundColor = _futileParams.backgroundColor;

        //we multiply this stuff by scaleInverse to make sure everything is in points, not pixels
        _camera.orthographic     = true;
        _camera.orthographicSize = screen.pixelHeight / 2 * displayScaleInverse;

        UpdateCameraPosition();

        touchManager = new FTouchManager();

        atlasManager = new FAtlasManager();

        _stages = new List <FStage>();

        stage = new FStage("Futile.stage");

        AddStage(stage);
    }
Example #9
0
    //TBorderLayer border;

    public TWalkingCharacter(string headImage)
    {
        FAtlasManager am = Futile.atlasManager;

        frameElements       = new FAtlasElement[8];
        crouchFrameElements = new FAtlasElement[8];

        frameElements[0] = am.GetElementWithName("walkAnim/walk0.png");
        frameElements[1] = am.GetElementWithName("walkAnim/walk1.png");
        frameElements[2] = am.GetElementWithName("walkAnim/walk2.png");
        frameElements[3] = am.GetElementWithName("walkAnim/walk3.png");
        frameElements[4] = am.GetElementWithName("walkAnim/walk4.png");
        frameElements[5] = am.GetElementWithName("walkAnim/walk1.png");
        frameElements[6] = am.GetElementWithName("walkAnim/walk2.png");
        frameElements[7] = am.GetElementWithName("walkAnim/walk3.png");

        crouchFrameElements[0] = am.GetElementWithName("squashedWalkAnim/squashedWalk0.png");
        crouchFrameElements[1] = am.GetElementWithName("squashedWalkAnim/squashedWalk1.png");
        crouchFrameElements[2] = am.GetElementWithName("squashedWalkAnim/squashedWalk2.png");
        crouchFrameElements[3] = am.GetElementWithName("squashedWalkAnim/squashedWalk3.png");
        crouchFrameElements[4] = am.GetElementWithName("squashedWalkAnim/squashedWalk4.png");
        crouchFrameElements[5] = am.GetElementWithName("squashedWalkAnim/squashedWalk1.png");
        crouchFrameElements[6] = am.GetElementWithName("squashedWalkAnim/squashedWalk2.png");
        crouchFrameElements[7] = am.GetElementWithName("squashedWalkAnim/squashedWalk3.png");

        bodySprite         = new FSprite("walkAnim/walk0.png");
        bodySprite.scale   = 0.5f;
        bodySprite.anchorY = 0;
        bodySprite.y       = -200f;
        AddChild(bodySprite);

        headSprite          = new FSprite(headImage);
        headSprite.y        = 25f;
        headSprite.x       -= 5f;
        headSprite.scale    = 0.5f;
        headSprite.anchorY  = 0;
        headSprite.rotation = -3f;
        AddChild(headSprite);

        Tween rotateOut = new Tween(headSprite, 0.3f, new TweenConfig().floatProp("rotation", 3f));
        Tween rotateIn  = new Tween(headSprite, 0.3f, new TweenConfig().floatProp("rotation", -3f));

        chain = new TweenChain();
        chain.setIterations(-1);
        chain.append(rotateOut).append(rotateIn);
        Go.addTween(chain);
    }
Example #10
0
    public Clock() : base("clock0")
    {
        _frameElements = new FAtlasElement[11];
        _lastAnimated  = Main.GameTime;

        FAtlasManager am = Futile.atlasManager;

        _frameElements[0]  = am.GetElementWithName("clock0");
        _frameElements[1]  = am.GetElementWithName("clock1");
        _frameElements[2]  = am.GetElementWithName("clock2");
        _frameElements[3]  = am.GetElementWithName("clock3");
        _frameElements[4]  = am.GetElementWithName("clock4");
        _frameElements[5]  = am.GetElementWithName("clock5");
        _frameElements[6]  = am.GetElementWithName("clock6");
        _frameElements[7]  = am.GetElementWithName("clock7");
        _frameElements[8]  = am.GetElementWithName("clock8");
        _frameElements[9]  = am.GetElementWithName("clock9");
        _frameElements[10] = am.GetElementWithName("clock10");


        ListenForUpdate(HandleUpdate);
    }
Example #11
0
        public static void ApplyPositionChangeHook(On.RoomCamera.orig_ApplyPositionChange orig, RoomCamera rCam)
        {
            WWW       www     = (WWW)typeof(RoomCamera).GetField("www", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(rCam);
            Texture2D texture = rCam.game.rainWorld.persistentData.cameraTextures[rCam.cameraNumber, 0];

            if (ShouldScroll(rCam, GetRoomName(www.url)))
            {
                texture.Resize(www.texture.width, www.texture.height, TextureFormat.ARGB32, false);
            }
            else
            {
                texture.Resize(1400, 800, TextureFormat.ARGB32, false); // default
            }
            texture.Apply();

            FAtlasManager manager = Futile.atlasManager;
            List <FAtlas> atlases = (List <FAtlas>) typeof(FAtlasManager).GetField("_atlases", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(manager);
            Dictionary <string, FAtlasElement> allElementsByName = (Dictionary <string, FAtlasElement>) typeof(FAtlasManager).GetField("_allElementsByName", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(manager);
            FAtlas atlas = manager.GetAtlasWithName("LevelTexture");

            atlases.Remove(atlas);
            allElementsByName.Remove("LevelTexture");
            atlas = null;
            manager.LoadAtlasFromTexture("LevelTexture", texture);

            rCam.ReturnFContainer("Foreground").RemoveChild(rCam.levelGraphic);
            rCam.levelGraphic           = new FSprite("LevelTexture", true);
            rCam.levelGraphic.anchorX   = 0;
            rCam.levelGraphic.anchorY   = 0;
            rCam.levelGraphic.isVisible = true;
            rCam.levelGraphic.shader    = rCam.game.rainWorld.Shaders["LevelColor"];
            rCam.ReturnFContainer("Foreground").AddChild(rCam.levelGraphic);

            rCam.currentCameraPosition = 0;
            orig(rCam);
        }
Example #12
0
    public void Init(FutileParams futileParams)
    {
        enabled = true;
        _futileParams = futileParams;

        Application.targetFrameRate = _futileParams.targetFrameRate;

        FShader.Init(); //set up the basic shaders
        FFacetType.Init(); //set up the types of facets (Quads, Triangles, etc)

        screen = new FScreen(_futileParams);

        //
        //Camera setup from https://github.com/prime31/UIToolkit/blob/master/Assets/Plugins/UIToolkit/UI.cs
        //

        _cameraHolder = new GameObject();
        _cameraHolder.transform.parent = gameObject.transform;

        _camera = _cameraHolder.AddComponent<Camera>();
        _camera.tag = "MainCamera";
        _camera.name = "Camera";
        //_camera.clearFlags = CameraClearFlags.Depth; //TODO: check if this is faster or not?
        _camera.clearFlags = CameraClearFlags.SolidColor;
        _camera.nearClipPlane = 0.0f;
        _camera.farClipPlane = 500.0f;
        _camera.depth = 100;
        _camera.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
        _camera.backgroundColor = _futileParams.backgroundColor;

        //we multiply this stuff by scaleInverse to make sure everything is in points, not pixels
        _camera.orthographic = true;
        _camera.orthographicSize = screen.pixelHeight/2 * displayScaleInverse;

        UpdateCameraPosition();

        touchManager = new FTouchManager();

        atlasManager = new FAtlasManager();

        CreateDefaultAtlases();

        _stages = new List<FStage>();

        stage = new FStage("Futile.stage");

        AddStage (stage);
    }
    public void Init(FutileParams futileParams)
    {
        enabled       = true;
        _futileParams = futileParams;

        Application.targetFrameRate = _futileParams.targetFrameRate;

                #if UNITY_IPHONE || UNITY_ANDROID
        TouchScreenKeyboard.autorotateToLandscapeLeft      = false;
        TouchScreenKeyboard.autorotateToLandscapeRight     = false;
        TouchScreenKeyboard.autorotateToPortrait           = false;
        TouchScreenKeyboard.autorotateToPortraitUpsideDown = false;
                #endif

        //Non-mobile unity always defaults to portrait for some reason, so fix this manually
        if (Screen.height > Screen.width)
        {
            _currentOrientation = ScreenOrientation.Portrait;
        }
        else
        {
            _currentOrientation = ScreenOrientation.LandscapeLeft;
        }

        //get the correct orientation if we're on a mobile platform
                #if !UNITY_EDITOR && (UNITY_IPHONE || UNITY_ANDROID)
        _currentOrientation = Screen.orientation;
                #endif

        //special "single orientation" mode
        if (_futileParams.singleOrientation != ScreenOrientation.Unknown)
        {
            _currentOrientation = _futileParams.singleOrientation;
        }
        else         //if we're not in a supported orientation, put us in one!
        {
            if (_currentOrientation == ScreenOrientation.LandscapeLeft && !_futileParams.supportsLandscapeLeft)
            {
                if (_futileParams.supportsLandscapeRight)
                {
                    _currentOrientation = ScreenOrientation.LandscapeRight;
                }
                else if (_futileParams.supportsPortrait)
                {
                    _currentOrientation = ScreenOrientation.Portrait;
                }
                else if (_futileParams.supportsPortraitUpsideDown)
                {
                    _currentOrientation = ScreenOrientation.PortraitUpsideDown;
                }
            }
            else if (_currentOrientation == ScreenOrientation.LandscapeRight && !_futileParams.supportsLandscapeRight)
            {
                if (_futileParams.supportsLandscapeLeft)
                {
                    _currentOrientation = ScreenOrientation.LandscapeLeft;
                }
                else if (_futileParams.supportsPortrait)
                {
                    _currentOrientation = ScreenOrientation.Portrait;
                }
                else if (_futileParams.supportsPortraitUpsideDown)
                {
                    _currentOrientation = ScreenOrientation.PortraitUpsideDown;
                }
            }
            else if (_currentOrientation == ScreenOrientation.Portrait && !_futileParams.supportsPortrait)
            {
                if (_futileParams.supportsPortraitUpsideDown)
                {
                    _currentOrientation = ScreenOrientation.PortraitUpsideDown;
                }
                else if (_futileParams.supportsLandscapeLeft)
                {
                    _currentOrientation = ScreenOrientation.LandscapeLeft;
                }
                else if (_futileParams.supportsLandscapeRight)
                {
                    _currentOrientation = ScreenOrientation.LandscapeRight;
                }
            }
            else if (_currentOrientation == ScreenOrientation.PortraitUpsideDown && !_futileParams.supportsPortraitUpsideDown)
            {
                if (_futileParams.supportsPortrait)
                {
                    _currentOrientation = ScreenOrientation.Portrait;
                }
                else if (_futileParams.supportsLandscapeLeft)
                {
                    _currentOrientation = ScreenOrientation.LandscapeLeft;
                }
                else if (_futileParams.supportsLandscapeRight)
                {
                    _currentOrientation = ScreenOrientation.LandscapeRight;
                }
            }
        }

        Screen.orientation = _currentOrientation;

        Futile.startingQuadsPerLayer  = _futileParams.startingQuadsPerLayer;
        Futile.quadsPerLayerExpansion = _futileParams.quadsPerLayerExpansion;
        Futile.maxEmptyQuadsPerLayer  = _futileParams.maxEmptyQuadsPerLayer;

        _screenLongLength  = Math.Max(Screen.height, Screen.width);
        _screenShortLength = Math.Min(Screen.height, Screen.width);

        if (_currentOrientation == ScreenOrientation.Portrait || _currentOrientation == ScreenOrientation.PortraitUpsideDown)
        {
            pixelWidth  = _screenShortLength;
            pixelHeight = _screenLongLength;
        }
        else         //landscape
        {
            pixelWidth  = _screenLongLength;
            pixelHeight = _screenShortLength;
        }


        //get the resolution level - the one we're closest to WITHOUT going over, price is right rules :)
        _resLevel = null;

        foreach (FResolutionLevel resLevel in _futileParams.resLevels)
        {
            if (_screenLongLength <= resLevel.maxLength)            //we've found our resLevel
            {
                _resLevel = resLevel;
                break;
            }
        }

        //if we couldn't find a res level, it means the screen is bigger than the biggest one, so just choose that one
        if (_resLevel == null)
        {
            _resLevel = _futileParams.resLevels.GetLastObject();
            if (_resLevel == null)
            {
                throw new Exception("You must add at least one FResolutionLevel!");
            }
        }

        Futile.resourceSuffix = _resLevel.resourceSuffix;

        //this is what helps us figure out the display scale if we're not at a specific resolution level
        //it's relative to the next highest resolution level

        float displayScaleModifier = 1.0f;

        if (_futileParams.shouldLerpToNearestResolutionLevel)
        {
            displayScaleModifier = _screenLongLength / _resLevel.maxLength;
        }

        displayScale        = _resLevel.displayScale * displayScaleModifier;
        displayScaleInverse = 1.0f / displayScale;

        resourceScale        = _resLevel.resourceScale;
        resourceScaleInverse = 1.0f / resourceScale;

        width  = pixelWidth * displayScaleInverse;
        height = pixelHeight * displayScaleInverse;

        halfWidth  = width / 2.0f;
        halfHeight = height / 2.0f;

        _originX = _futileParams.origin.x;
        _originY = _futileParams.origin.y;

        Debug.Log("Futile: Display scale is " + displayScale);

        Debug.Log("Futile: Resource scale is " + resourceScale);

        Debug.Log("Futile: Resource suffix is " + _resLevel.resourceSuffix);

        Debug.Log("Futile: Screen size in pixels is (" + pixelWidth + "px," + pixelHeight + "px)");

        Debug.Log("Futile: Screen size in points is (" + width + "," + height + ")");

        Debug.Log("Futile: Origin is at (" + _originX * width + "," + _originY * height + ")");

        Debug.Log("Futile: Initial orientation is " + _currentOrientation);

        //
        //Camera setup from https://github.com/prime31/UIToolkit/blob/master/Assets/Plugins/UIToolkit/UI.cs
        //

        name = "Futile";

        _cameraHolder = new GameObject();
        _cameraHolder.transform.parent = gameObject.transform;
        _cameraHolder.AddComponent <Camera>();

        _camera      = _cameraHolder.camera;
        _camera.name = "FCamera";
        //_camera.clearFlags = CameraClearFlags.Depth; //TODO: check if this is faster or not?
        _camera.clearFlags      = CameraClearFlags.SolidColor;
        _camera.nearClipPlane   = -50.3f;
        _camera.farClipPlane    = 50.0f;
        _camera.depth           = 100;
        _camera.rect            = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
        _camera.backgroundColor = _futileParams.backgroundColor;

        //we multiply this stuff by scaleInverse to make sure everything is in points, not pixels
        _camera.orthographic     = true;
        _camera.orthographicSize = pixelHeight / 2 * displayScaleInverse;

        UpdateCameraPosition();

        _didJustResize = true;

        touchManager = new FTouchManager();

        atlasManager = new FAtlasManager();

        stage = new FStage();
    }
Example #14
0
    public void Init(FutileParams futileParams)
    {
        enabled = true;
        _futileParams = futileParams;

        Application.targetFrameRate = _futileParams.targetFrameRate;

        #if UNITY_IPHONE || UNITY_ANDROID
        TouchScreenKeyboard.autorotateToLandscapeLeft = false;
        TouchScreenKeyboard.autorotateToLandscapeRight = false;
        TouchScreenKeyboard.autorotateToPortrait = false;
        TouchScreenKeyboard.autorotateToPortraitUpsideDown = false;
        #endif

        //Non-mobile unity always defaults to portrait for some reason, so fix this manually
        if(Screen.height > Screen.width)
        {
            _currentOrientation = ScreenOrientation.Portrait;
        }
        else
        {
            _currentOrientation = ScreenOrientation.LandscapeLeft;
        }

        //get the correct orientation if we're on a mobile platform
        #if !UNITY_EDITOR && (UNITY_IPHONE || UNITY_ANDROID)
            _currentOrientation = Screen.orientation;
        #endif

        //special "single orientation" mode
        if(_futileParams.singleOrientation != ScreenOrientation.Unknown)
        {
            _currentOrientation = _futileParams.singleOrientation;
        }
        else //if we're not in a supported orientation, put us in one!
        {
            if(_currentOrientation == ScreenOrientation.LandscapeLeft && !_futileParams.supportsLandscapeLeft)
            {
                if(_futileParams.supportsLandscapeRight) _currentOrientation = ScreenOrientation.LandscapeRight;
                else if(_futileParams.supportsPortrait) _currentOrientation = ScreenOrientation.Portrait;
                else if(_futileParams.supportsPortraitUpsideDown) _currentOrientation = ScreenOrientation.PortraitUpsideDown;
            }
            else if(_currentOrientation == ScreenOrientation.LandscapeRight && !_futileParams.supportsLandscapeRight)
            {
                if(_futileParams.supportsLandscapeLeft) _currentOrientation = ScreenOrientation.LandscapeLeft;
                else if(_futileParams.supportsPortrait) _currentOrientation = ScreenOrientation.Portrait;
                else if(_futileParams.supportsPortraitUpsideDown) _currentOrientation = ScreenOrientation.PortraitUpsideDown;
            }
            else if(_currentOrientation == ScreenOrientation.Portrait && !_futileParams.supportsPortrait)
            {
                if(_futileParams.supportsPortraitUpsideDown) _currentOrientation = ScreenOrientation.PortraitUpsideDown;
                else if(_futileParams.supportsLandscapeLeft) _currentOrientation = ScreenOrientation.LandscapeLeft;
                else if(_futileParams.supportsLandscapeRight) _currentOrientation = ScreenOrientation.LandscapeRight;
            }
            else if(_currentOrientation == ScreenOrientation.PortraitUpsideDown && !_futileParams.supportsPortraitUpsideDown)
            {
                if(_futileParams.supportsPortrait) _currentOrientation = ScreenOrientation.Portrait;
                else if(_futileParams.supportsLandscapeLeft) _currentOrientation = ScreenOrientation.LandscapeLeft;
                else if(_futileParams.supportsLandscapeRight) _currentOrientation = ScreenOrientation.LandscapeRight;
            }
        }

        Screen.orientation = _currentOrientation;

        Futile.startingQuadsPerLayer = _futileParams.startingQuadsPerLayer;
        Futile.quadsPerLayerExpansion = _futileParams.quadsPerLayerExpansion;
        Futile.maxEmptyQuadsPerLayer = _futileParams.maxEmptyQuadsPerLayer;

        _screenLongLength = Math.Max(Screen.height, Screen.width);
        _screenShortLength = Math.Min(Screen.height, Screen.width);

        if(_currentOrientation == ScreenOrientation.Portrait || _currentOrientation == ScreenOrientation.PortraitUpsideDown)
        {
            pixelWidth = _screenShortLength;
            pixelHeight = _screenLongLength;
        }
        else //landscape
        {
            pixelWidth = _screenLongLength;
            pixelHeight = _screenShortLength;
        }

        //get the resolution level - the one we're closest to WITHOUT going over, price is right rules :)
        _resLevel = null;

        foreach(FResolutionLevel resLevel in _futileParams.resLevels)
        {
            if(_screenLongLength <= resLevel.maxLength) //we've found our resLevel
            {
                _resLevel = resLevel;
                break;
            }
        }

        //if we couldn't find a res level, it means the screen is bigger than the biggest one, so just choose that one
        if(_resLevel == null)
        {
            _resLevel = _futileParams.resLevels.GetLastObject();
            if(_resLevel == null)
            {
                throw new Exception("You must add at least one FResolutionLevel!");
            }
        }

        Futile.resourceSuffix = _resLevel.resourceSuffix;

        //this is what helps us figure out the display scale if we're not at a specific resolution level
        //it's relative to the next highest resolution level

        float displayScaleModifier = 1.0f;

        if(_futileParams.shouldLerpToNearestResolutionLevel)
        {
            displayScaleModifier = _screenLongLength/_resLevel.maxLength;
        }

        displayScale = _resLevel.displayScale * displayScaleModifier;
        displayScaleInverse = 1.0f/displayScale;

        resourceScale = _resLevel.resourceScale;
        resourceScaleInverse = 1.0f/resourceScale;

        width = pixelWidth*displayScaleInverse;
        height = pixelHeight*displayScaleInverse;

        halfWidth = width/2.0f;
        halfHeight = height/2.0f;

        _originX = _futileParams.origin.x;
        _originY = _futileParams.origin.y;

        Debug.Log ("Futile: Display scale is " + displayScale);

        Debug.Log ("Futile: Resource scale is " + resourceScale);

        Debug.Log ("Futile: Resource suffix is " + _resLevel.resourceSuffix);

        Debug.Log ("Futile: Screen size in pixels is (" + pixelWidth +"px," + pixelHeight+"px)");

        Debug.Log ("Futile: Screen size in points is (" + width + "," + height+")");

        Debug.Log ("Futile: Origin is at (" + _originX*width + "," + _originY*height+")");

        Debug.Log ("Futile: Initial orientation is " + _currentOrientation);

        //
        //Camera setup from https://github.com/prime31/UIToolkit/blob/master/Assets/Plugins/UIToolkit/UI.cs
        //

        name = "Futile";

        _cameraHolder = new GameObject();
        _cameraHolder.transform.parent = gameObject.transform;
        _cameraHolder.AddComponent<Camera>();

        _camera = _cameraHolder.camera;
        _camera.name = "FCamera";
        //_camera.clearFlags = CameraClearFlags.Depth; //TODO: check if this is faster or not?
        _camera.clearFlags = CameraClearFlags.SolidColor;
        _camera.nearClipPlane = -50.3f;
        _camera.farClipPlane = 50.0f;
        _camera.depth = 100;
        _camera.rect = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
        _camera.backgroundColor = _futileParams.backgroundColor;

        //we multiply this stuff by scaleInverse to make sure everything is in points, not pixels
        _camera.orthographic = true;
        _camera.orthographicSize = pixelHeight/2 * displayScaleInverse;

        UpdateCameraPosition();

        _didJustResize = true;

        touchManager = new FTouchManager();

        atlasManager = new FAtlasManager();

        stage = new FStage();
    }