コード例 #1
0
ファイル: GameText.cs プロジェクト: avijmarks/3DGameText
    public void ChangeIsButton(TextNode node)
    {
        //creates button pad prefab instance and sets size based on TextSize
        if (node.GetComponentsInChildren <ButtonPad>().Length > 0)
        {
            ButtonPad[] oldButtons = node.GetComponentsInChildren <ButtonPad>();
            Destroy(oldButtons[0]);
        }
        char[] messageArray = node.Message.ToCharArray();
        if (node.IsButton)
        {
            float buttonScale = .3f;
            node.buttonPad           = Instantiate(buttonPadPrefab, node.transform);
            node.buttonPad.trigger   = node.trigger;
            node.buttonPad.textStyle = node.TextStyle;
            node.buttonPad.node      = node;
            node.buttonPad.transform.localPosition = new Vector3(0, 0, -(.05f * node.TextSize));

            float charactarSpace = node.TextStyle.textSize * .7f;
            float X = (charactarSpace * messageArray.Length) + (buttonScale * charactarSpace);
            float Y = charactarSpace + (buttonScale * charactarSpace);
            float Z = (.05f * charactarSpace);
            node.buttonPad.transform.localScale = new Vector3(X, Y, Z);
        }
    }
コード例 #2
0
ファイル: GameText.cs プロジェクト: avijmarks/3DGameText
    public void ChangeMessage(TextNode node)
    {
        if (node.GetComponentsInChildren <GameTextCharacter>().Length > 0)
        {
            GameTextCharacter[] previousCharacters = node.GetComponentsInChildren <GameTextCharacter>();
            for (int i = 0; i < previousCharacters.Length; i++)
            {
                Destroy(previousCharacters[i].gameObject);
            }
            ButtonPad previousPad = node.GetComponentInChildren <ButtonPad>();
            if (previousPad != null)
            {
                Destroy(previousPad.gameObject);
            }
        }

        char[]              messageArray            = node.Message.ToCharArray();
        Vector3[]           characterLocalPositions = GetCharacterPositions(node.transform, node.TextSize, messageArray);
        GameTextCharacter[] prefabArray             = new GameTextCharacter[messageArray.Length];
        for (int i = 0; i < messageArray.Length; i++)
        {
            GameTextCharacter instance = Instantiate(characters[messageArray[i]], node.transform);
            instance.transform.localPosition = characterLocalPositions[i];

            instance.transform.Rotate(0, 90, 90);

            prefabArray[i] = instance;
        }
        node.PrefabArray = prefabArray;
    }
コード例 #3
0
ファイル: UI.cs プロジェクト: wangscript007/Fusee
        //Build a scene graph consisting out of a canvas and other UI elements.
        private SceneContainer CreateNineSliceScene()
        {
            var vsTex       = AssetStorage.Get <string>("texture.vert");
            var psTex       = AssetStorage.Get <string>("texture.frag");
            var vsNineSlice = AssetStorage.Get <string>("nineSlice.vert");
            var psNineSlice = AssetStorage.Get <string>("nineSliceTile.frag");

            var canvasScaleFactor = _initWindowWidth / _canvasWidth;

            float borderScaleFactor = 1;

            if (_canvasRenderMode == CanvasRenderMode.Screen)
            {
                borderScaleFactor = canvasScaleFactor;
            }

            var fps = new TextNode(
                "FPS: 0.00",
                "FPSText",
                vsTex,
                psTex,
                UIElementPosition.GetAnchors(AnchorPos.DownDownRight),
                new MinMaxRect
            {
                Min = new float2(-2, 0),
                Max = new float2(0, 1)
            },
                _fontMap,
                ColorUint.Tofloat4(ColorUint.White),
                HorizontalTextAlignment.Center,
                VerticalTextAlignment.Center
                );

            _fpsText = fps.GetComponentsInChildren <GUIText>().FirstOrDefault();

            var text = new TextNode(
                "The five\n" +
                "boxing wizards\n" +
                "jump\n" +
                "quickly.",
                "ButtonText",
                vsTex,
                psTex,
                UIElementPosition.GetAnchors(AnchorPos.StretchAll),
                new MinMaxRect
            {
                Min = new float2(1f, 0.5f),
                Max = new float2(-1f, -0.5f)
            },
                _fontMap,
                ColorUint.Tofloat4(ColorUint.Greenery),
                HorizontalTextAlignment.Center,
                VerticalTextAlignment.Center);

            var catTextureNode = new TextureNode(
                "Cat",
                AssetStorage.Get <string>("nineSlice.vert"),
                AssetStorage.Get <string>("nineSliceTile.frag"),
                //Set the albedo texture you want to use.
                new Texture(AssetStorage.Get <ImageData>("Kitti.jpg")),

                //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent.
                //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled.
                UIElementPosition.GetAnchors(AnchorPos.StretchHorizontal),//Anchor is in the lower left corner of the parent. Anchor is in the lower right corner of the parent.

                //Define Offset and therefor the size of the element.
                //Min: distance to this elements Min anchor.
                //Max: distance to this elements Max anchor.
                UIElementPosition.CalcOffsets(AnchorPos.StretchHorizontal, new float2(_initCanvasWidth / 2 - 2.5f, 0), _initCanvasHeight, _initCanvasWidth, new float2(5, 4)),
                //Choose in how many tiles you want to split the inner part of the texture. Use float2.one if you want it stretched.
                new float2(5, 5),
                //Tell how many percent of the texture, seen from the edges, belongs to the border. Order: left, right, top, bottom.
                new float4(0.11f, 0.11f, 0.06f, 0.17f),
                4, 4, 4, 4,
                borderScaleFactor

                )
            {
                Children = new ChildList()
                {
                    text
                }
            };

            catTextureNode.Components.Add(_btnCat);

            var bltTextureNode = new TextureNode(
                "Blt",
                vsTex,
                psTex,
                //Set the albedo texture you want to use.
                _bltDestinationTex,
                //_fontMap.Image,
                //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent.
                //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled.
                UIElementPosition.GetAnchors(AnchorPos.DownDownLeft),//Anchor is in the lower left corner of the parent. Anchor is in the lower right corner of the parent.

                //Define Offset and therefor the size of the element.
                //Min: distance to this elements Min anchor.
                //Max: distance to this elements Max anchor.
                UIElementPosition.CalcOffsets(AnchorPos.DownDownLeft, new float2(0, 0), _initCanvasHeight, _initCanvasWidth, new float2(4, 4)));

            var quagganTextureNode1 = new TextureNode(
                "Quaggan1",
                vsNineSlice,
                psNineSlice,
                new Texture(AssetStorage.Get <ImageData>("testTex.jpg")),
                //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all.
                UIElementPosition.GetAnchors(AnchorPos.TopTopLeft), //Anchor is in the lower right corner.Anchor is in the lower left corner.
                UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, new float2(2.5f, 0), 3, 6, new float2(1, 1)),

                new float2(1, 1),
                new float4(0.1f, 0.1f, 0.1f, 0.09f),
                1, 1, 1, 1,
                borderScaleFactor
                );

            var nineSliceTextureNode = new TextureNode(
                "testImage",
                vsNineSlice,
                psNineSlice,
                new Texture(AssetStorage.Get <ImageData>("9SliceSprites-4.png")),
                //In this setup the element will stay in the upper right corner of the parent and will not be stretched at all.
                UIElementPosition.GetAnchors(AnchorPos.TopTopRight),//Anchor is in the upper right corner.//Anchor is in the upper right corner.

                UIElementPosition.CalcOffsets(AnchorPos.TopTopRight, new float2(_initCanvasWidth - 6, _initCanvasHeight - 3), _initCanvasHeight, _initCanvasWidth, new float2(6, 3)),

                new float2(2, 3),
                new float4(0.1f, 0.1f, 0.1f, 0.1f),
                2.5f, 2.5f, 2.5f, 2.5f,
                borderScaleFactor
                )
            {
                Children = new ChildList()
                {
                    quagganTextureNode1, text
                }
            };

            var quagganTextureNode = new TextureNode(
                "Quaggan",
                vsNineSlice,
                psNineSlice,
                new Texture(AssetStorage.Get <ImageData>("testTex.jpg")),
                //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all.
                UIElementPosition.GetAnchors(AnchorPos.TopTopLeft), //Anchor is in the lower right corner.Anchor is in the lower left corner.
                UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, new float2(0, _initCanvasHeight - 1), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)),
                new float2(5, 1),
                new float4(0.1f, 0.1f, 0.1f, 0.09f),
                1, 1, 1, 1,
                borderScaleFactor
                );

            var quagganTextureNode2 = new TextureNode(
                "Quaggan",
                vsNineSlice,
                psNineSlice,
                new Texture(AssetStorage.Get <ImageData>("testTex.jpg")),
                //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all.
                UIElementPosition.GetAnchors(AnchorPos.TopTopLeft), //Anchor is in the lower right corner.Anchor is in the lower left corner.
                UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, new float2(0, _initCanvasHeight - 3), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)),
                new float2(5, 1),
                new float4(0.1f, 0.1f, 0.1f, 0.09f),
                1, 1, 1, 1,
                borderScaleFactor
                );

            var quagganTextureNode3 = new TextureNode(
                "Quaggan",
                vsNineSlice,
                psNineSlice,
                new Texture(AssetStorage.Get <ImageData>("testTex.jpg")),
                //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all.
                UIElementPosition.GetAnchors(AnchorPos.StretchVertical), //Anchor is in the lower right corner. Anchor is in the lower left corner.
                UIElementPosition.CalcOffsets(AnchorPos.StretchVertical, new float2(0, _initCanvasHeight - 5), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)),
                new float2(5, 1),
                new float4(0.1f, 0.1f, 0.1f, 0.09f),
                1, 1, 1, 1,
                borderScaleFactor
                );

            var canvas = new CanvasNode(
                "Canvas",
                _canvasRenderMode,
                new MinMaxRect
            {
                Min = new float2(-_canvasWidth / 2, -_canvasHeight / 2f),
                Max = new float2(_canvasWidth / 2, _canvasHeight / 2f)
            })
            {
                Children = new ChildList()
                {
                    //Simple Texture Node, contains a Blt"ed" texture.
                    bltTextureNode,
                    //Add nine sliced textures to canvas
                    catTextureNode,
                    quagganTextureNode,
                    nineSliceTextureNode,
                    quagganTextureNode2,
                    quagganTextureNode3,
                    fps
                }
            };

            var canvasMat = ShaderCodeBuilder.MakeShaderEffect(new float4(1, 0, 0, 1));

            canvas.AddComponent(canvasMat);
            canvas.AddComponent(new Plane());
            canvas.AddComponent(_btnCanvas);

            return(new SceneContainer
            {
                Children = new List <SceneNode>
                {
                    //Add canvas.

                    new SceneNode()
                    {
                        Components = new List <SceneComponent>()
                        {
                            new Transform()
                            {
                                Translation = new float3(0, 0, 0)
                            }
                        },
                        Children = new ChildList()
                        {
                            canvas
                        }
                    },
                }
            });
        }