Пример #1
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);
    }
Пример #2
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);
    }
Пример #3
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);
    }
 public override void Connect()
 {
     _touchManager=null;
     FContainer parent=_node.container;
     //Find a FScrollContainer in the tree of upper containers, if so subscribe to its touch manager, otherwise subscribe to futile's touch manager
     while (parent!=null) {
         FScrollContainer scrollContainer=parent as FScrollContainer;
         if (scrollContainer!=null) {
             _touchManager=scrollContainer.touchManager;
             //Debug.Log ("FScrollContainer found");
             break;
         }
         parent=parent.container;
     }
     if (_touchManager==null) {
         _touchManager=Futile.touchManager;
     }
     _touchManager.AddSingleTouchTarget(_node as FSingleTouchableInterface);
 }
Пример #5
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();
    }
Пример #7
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();
    }