示例#1
0
        public static Entity SpawnText(EntityManager EntityManager, Entity parent, string text,
                                       float3 positionOffset, Color color, float fontSizer = 0.014f) // float2 iconSize,
        {
            float2     fontSize   = new float2(fontSizer, fontSizer);
            RenderText renderText = new RenderText();

            //renderText.alignment = 1;
            renderText.fontSize = fontSize.x;
            renderText.SetColor(color);
            renderText.SetText(text);
            float2 panelSize  = renderText.GetPanelSize();
            Entity textEntity = SpawnVisualElement(
                EntityManager,
                parent,
                positionOffset,         // + ((new float3(iconSize.x, -iconSize.y, 0) / 2f) - new float3(0, -fontSize.y, 0) / 2f),
                panelSize,
                null,
                null);

            // should get size from text when set - it will set size depending on individual font sizes

            /*if (isCentred == 1)
             * {
             *  renderText.offsetX = -panelSize.x * 0.5f;// uiDatam.skillbarIconSize / 2f;
             * }*/
            EntityManager.AddComponentData(textEntity, renderText);
            return(textEntity);
        }
示例#2
0
 private void OnCompletedDialogue(Entity e, ref DialogueUI dialogue, ref RenderText renderText)
 {
     //Debug.LogError("completedTree " + " 1!");
     dialogue.completedTree = 1;
     //dialogue.branchID = 0;
     //SetBranch(0, e, ref dialogue, ref renderText);
 }
示例#3
0
        public static Entity SpawnButtonWithText(EntityManager EntityManager, Entity panelUI, float3 position, float buttonFontSize, string text,
                                                 Material buttonMaterial, Color buttonColor, Color textColor)
        {
            //Childrens children = new Childrens { };
            //children.children = new BlitableArray<Entity>(1, Unity.Collections.Allocator.Persistent);
            //float buttonFontSize = 0.01f;
            //RenderTextSystem.SetLetterColor(EntityManager, button, Color.green);
            //children.children[0] = button;
            //EntityManager.AddComponentData(panelUI, children);
            Entity button = SpawnButton(
                EntityManager,
                panelUI,
                position,
                (new float2(buttonFontSize * text.Length * 1f, buttonFontSize)),
                null,
                buttonMaterial);

            SetEntityColor(EntityManager, button, buttonColor);
            RenderText buttonText = new RenderText {
            };

            buttonText.fontSize = buttonFontSize;
            buttonText.SetText(text);
            buttonText.SetColor(textColor);
            EntityManager.AddComponentData(button, buttonText);
            return(button);
        }
示例#4
0
        public void SetText(string text, ref RenderText newText)
        {
            byte updatedText;

            fontIndexes = RenderText.StringToBytes(text, fontIndexes, out updatedText);
            endIndex    = 0;
            maxIndex    = (byte)text.Length;
            newText.SetText(new BlitableArray <byte>(0, Unity.Collections.Allocator.Persistent));
        }
示例#5
0
        /// <summary>
        /// sets dialogue to a new speech bubble
        /// </summary>
        private void SetBranch(int newBranchID, Entity e, ref DialogueUI dialogue, ref RenderText renderText)
        {
            DialogueDatam dialogueTree = meta[dialogue.treeID];

            dialogue.branchID = newBranchID;
            var branch = dialogueTree.dialogueTree.branches[dialogue.branchID];

            dialogue.SetText(branch.speech, ref renderText);
            renderText.offsetX = ((-branch.speech.Length - 1f) / 2f) * renderText.fontSize;
            RefreshPanelSize(World.EntityManager, e, renderText.fontSize, branch.speech.Length);
        }
示例#6
0
        public Entity SpawnNewFontLetter(ref RenderText renderText, Entity panelUI, float fontSize)
        {
            Entity letter = UIUtilities.SpawnVisualElement(
                World.EntityManager,
                panelUI,
                new float3(0, 0, -0.005f),
                new float2(fontSize, fontSize),
                null,
                uiData.font.material, 8000);

            return(letter);
        }
示例#7
0
 private void DestroChildAtIndex(EntityManager EntityManager, int index)
 {
     if (EntityManager.Exists(children[index]))
     {
         if (EntityManager.HasComponent <Childrens>(children[index]))
         {
             Childrens childrensChildren = EntityManager.GetComponentData <Childrens>(children[index]);
             childrensChildren.DestroyEntities(EntityManager);
         }
         if (EntityManager.HasComponent <RenderText>(children[index]))
         {
             RenderText text = EntityManager.GetComponentData <RenderText>(children[index]);
             text.DestroyLetters(EntityManager);
         }
         EntityManager.DestroyEntity(children[index]);
     }
 }
示例#8
0
        protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData)
        {
            var dialogueTree = Bootstrap.instance.data.dialogues[0].dialogueTree;
            //int startingDialogueID = dialogueTree.id;
            //DialogueDatam dialogueTree = meta[startingDialogueID];
            var        branch     = dialogueTree.branches[0];
            float      fontSize   = 0.03f;
            RenderText renderText = new RenderText
            {
                fontSize = fontSize,
                offsetX  = ((-branch.speech.Length - 1f) / 2f) * fontSize
            };

            renderText.SetColor(Color.blue);
            DialogueUI dialogueUI = new DialogueUI
            {
                treeID           = dialogueTree.id,
                timePerLetterMin = 0.07f,
                timePerLetterMax = 0.21f
            };

            dialogueUI.RandomizeCooldown();
            dialogueUI.SetText(branch.speech, ref renderText);
            //UnityEngine.Debug.LogError("Testing dialogue - self talking: " + dialogueTree.data[0].speech);
            World.EntityManager.AddComponentData(panelUI, dialogueUI);
            World.EntityManager.AddComponentData(panelUI, renderText);
            byte uiIndex = ((byte)((int)PlayerUIType.DialogueUI));

            World.EntityManager.SetComponentData(panelUI, new PanelUI
            {
                id          = uiIndex,
                characterID = World.EntityManager.GetComponentData <ZoxID>(character).id,
                size        = new float2((branch.speech.Length) * (fontSize * 1.1f), fontSize),
                dirty       = 1,
                orbitDepth  = uiDatam.orbitDepth,
                anchor      = (byte)UIAnchoredPosition.Middle
            });
            Childrens children = new Childrens {
            };

            World.EntityManager.AddComponentData(panelUI, children);
        }
示例#9
0
        public void IncreaseIndex(ref RenderText newText)
        {
            if (endIndex >= maxIndex + 1)
            {
                endIndex = 0;
            }
            if ((int)endIndex > fontIndexes.Length)
            {
                return;
            }
            //UnityEngine.Debug.LogError("Changing End Index: " + endIndex);
            BlitableArray <byte> culledArray = new BlitableArray <byte>((int)endIndex, Unity.Collections.Allocator.Persistent);

            for (int i = 0; i < (int)endIndex; i++)
            {
                culledArray[i] = fontIndexes[i];
            }
            newText.SetText(culledArray);
            endIndex++;
            //newText.SetText("hello world".Substring(0, (int)(endIndex)));
        }
示例#10
0
 public void SetItemUIText(Entity iconEntity, Entity character, int arrayIndex)
 {
     if (arrayIndex != -1)
     {
         Inventory inventory    = World.EntityManager.GetComponentData <Inventory>(character);
         string    numberString = inventory.items[arrayIndex].quantity.ToString();
         if (numberString == "0" || numberString == "1")
         {
             numberString = "";
         }
         //Childrens childrens = World.EntityManager.GetComponentData<Childrens>(uis[characterID]);
         Entity     textGrandChild = World.EntityManager.GetComponentData <Childrens>(iconEntity).children[0];
         RenderText text           = World.EntityManager.GetComponentData <RenderText>(textGrandChild);
         if (numberString == "0" || numberString == "1")
         {
             numberString = "";
         }
         text.SetText(numberString);
         World.EntityManager.SetComponentData(textGrandChild, text);
     }
 }
示例#11
0
 public void DestroyEntities(EntityManager EntityManager)
 {
     for (int i = 0; i < children.Length; i++)
     {
         if (EntityManager.Exists(children[i]))
         {
             if (EntityManager.HasComponent <Childrens>(children[i]))
             {
                 Childrens childrensChildren = EntityManager.GetComponentData <Childrens>(children[i]);
                 childrensChildren.DestroyEntities(EntityManager);
             }
             if (EntityManager.HasComponent <RenderText>(children[i]))
             {
                 RenderText text = EntityManager.GetComponentData <RenderText>(children[i]);
                 text.DestroyLetters(EntityManager);
             }
             EntityManager.DestroyEntity(children[i]);
         }
     }
     if (children.Length > 0)
     {
         children.Dispose();
     }
 }
示例#12
0
        private void IncrementDialogue(Entity e, ref DialogueUI dialogue, ref RenderText renderText)
        {
            int           linkChoice    = dialogue.confirmedChoice - 1;
            DialogueDatam dialogueTree  = meta[dialogue.treeID];
            var           currentBranch = dialogueTree.dialogueTree.branches[dialogue.branchID];
            int           branchID      = -1;

            if (currentBranch.links.Length > 0 && linkChoice < currentBranch.links.Length)
            {
                //Debug.LogError("linkChoice was " + linkChoice);
                branchID = currentBranch.links[linkChoice];
            }
            if (branchID == -1)
            {
                OnCompletedDialogue(e, ref dialogue, ref renderText);
                return;
            }
            int linkIndex = -1;

            for (int i = 0; i < dialogueTree.dialogueTree.branches.Length; i++)
            {
                if (dialogueTree.dialogueTree.branches[i].id == branchID)
                {
                    linkIndex = i;
                    break;
                }
            }
            if (linkIndex == -1)
            {
                OnCompletedDialogue(e, ref dialogue, ref renderText);
            }
            else
            {
                SetBranch(linkIndex, e, ref dialogue, ref renderText);
            }
        }
示例#13
0
        public void UpdateStatUI(UpdateStatUICommand command)
        {
            ZoxID zoxID = World.EntityManager.GetComponentData <ZoxID>(command.character);

            if (!uis.ContainsKey(zoxID.id))
            {
                return; // character died
            }
            Stats     stats        = World.EntityManager.GetComponentData <Stats>(command.character);
            Entity    ui           = uis[zoxID.id];
            Childrens children     = World.EntityManager.GetComponentData <Childrens>(ui);
            int       uiArrayIndex = command.statIndex;

            if (command.statType == (byte)StatType.Base)
            {
                Staz      stat  = stats.stats[command.statIndex];
                Entity    icon  = children.children[uiArrayIndex];
                Childrens texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
            }
            else
            {
                uiArrayIndex += stats.stats.Length;
            }
            if (command.statType == (byte)StatType.State)
            {
                StateStaz stat  = stats.states[command.statIndex];
                Entity    icon  = children.children[uiArrayIndex];
                Childrens texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);

                /*Entity textEntity2 = texts.children[0];
                 * RenderText renderText2 = World.EntityManager.GetComponentData<RenderText>(textEntity2);
                 * renderText2.SetText(((int)stat.maxValue).ToString());
                 * World.EntityManager.SetComponentData(textEntity2, renderText2);*/
            }
            else
            {
                uiArrayIndex += stats.states.Length;
            }
            if (command.statType == (byte)StatType.Regen)
            {
                RegenStaz stat  = stats.regens[command.statIndex];
                Entity    icon  = children.children[uiArrayIndex];
                Childrens texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
            }
            else
            {
                uiArrayIndex += stats.regens.Length;
            }
            if (command.statType == (byte)StatType.Attribute)
            {
                AttributeStaz stat  = stats.attributes[command.statIndex];
                Entity        icon  = children.children[uiArrayIndex];
                Childrens     texts = World.EntityManager.GetComponentData <Childrens>(icon);

                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
            }
            else
            {
                uiArrayIndex += stats.attributes.Length;
            }
            if (command.statType == (byte)StatType.Level)
            {
                Level      stat       = stats.levels[command.statIndex];
                Entity     icon       = children.children[uiArrayIndex];
                Childrens  texts      = World.EntityManager.GetComponentData <Childrens>(icon);
                Entity     textEntity = texts.children[0];
                RenderText renderText = World.EntityManager.GetComponentData <RenderText>(textEntity);
                renderText.SetText(((int)stat.value).ToString());
                World.EntityManager.SetComponentData(textEntity, renderText);
                // experience required

                /*Entity textEntity2 = texts.children[1];
                 * RenderText renderText2 = World.EntityManager.GetComponentData<RenderText>(textEntity2);
                 * renderText2.SetText(((int)stat.experienceGained).ToString());
                 * World.EntityManager.SetComponentData(textEntity2, renderText2);
                 * // experience gained
                 * Entity textEntity3 = texts.children[2];
                 * RenderText renderText3 = World.EntityManager.GetComponentData<RenderText>(textEntity3);
                 * renderText3.SetText(((int)stat.experienceRequired).ToString());
                 * World.EntityManager.SetComponentData(textEntity3, renderText3);*/
            }
        }
示例#14
0
        public void UpdateRenderText(Entity renderTextEntity, ref RenderText renderText)//, float3 position, float fontSize, FontDatam font)
        {
            int desiredLength = renderText.fontIndexes.Length;
            int actualLength  = renderText.letters.Length;

            //UnityEngine.Debug.LogError("Spawning Render Text. Desired Length is: " + desiredLength + " and actualLength is: " + actualLength);
            if (desiredLength > actualLength)
            {
                //UnityEngine.Debug.Log("Adding [" + (desiredLength - actualLength) + "] New Characters.");
                BlitableArray <Entity> newLetters = new BlitableArray <Entity>(desiredLength, Unity.Collections.Allocator.Persistent);
                for (int i = 0; i < desiredLength; i++)
                {
                    if (i < renderText.letters.Length)
                    {
                        newLetters[i] = renderText.letters[i];
                    }
                    else
                    {
                        newLetters[i] = SpawnNewFontLetter(ref renderText, renderTextEntity, renderText.fontSize);
                    }
                }
                if (renderText.letters.Length > 0)
                {
                    renderText.letters.Dispose();
                }
                renderText.letters = newLetters;
            }
            // Remove Excess Digits
            if (actualLength > desiredLength)
            {
                BlitableArray <Entity> newLetters = new BlitableArray <Entity>(desiredLength, Unity.Collections.Allocator.Persistent);
                //UnityEngine.Debug.Log("Removing [" + (actualLength - desiredLength) + "] Old Characters.");
                for (int i = 0; i < renderText.letters.Length; i++)
                {
                    if (i < newLetters.Length)
                    {
                        newLetters[i] = renderText.letters[i];
                    }
                    else
                    {
                        World.EntityManager.DestroyEntity(renderText.letters[i]);
                    }
                }
                if (renderText.letters.Length > 0)
                {
                    renderText.letters.Dispose();
                }
                renderText.letters = newLetters;
            }
            // now set them all
            float3 offset = float3.zero;

            // first get total size
            // now we know the offset for centring
            if (renderText.alignment == 0)
            {
                // no alignment
                offset.x = ((-desiredLength - 1f) / 2f) * renderText.fontSize;// should be offset by half total size
            }
            if (renderText.alignment == 1)
            {
                // right aligned
                offset.x = (-desiredLength - 0.5f) * renderText.fontSize + renderText.offsetX;
            }
            if (renderText.offsetX != 0)
            {
                offset.x = renderText.offsetX;
            }
            offset.z = -0.005f;
            for (int i = 0; i < renderText.letters.Length; i++)
            {
                // set position first
                offset.x += renderText.fontSize;  // should be based on particular font
                if (renderText.fontIndexes[i] != 255)
                {
                    Translation translation = World.EntityManager.GetComponentData <Translation>(
                        renderText.letters[i]);
                    translation.Value = offset;
                    World.EntityManager.SetComponentData(renderText.letters[i], translation);

                    // Set Texture
                    // should check if changed or not
                    Unity.Rendering.RenderMesh render =
                        World.EntityManager.GetSharedComponentData <Unity.Rendering.RenderMesh>(renderText.letters[i]);
                    render.material.SetTexture("_BaseMap", uiData.font.textures[(int)renderText.fontIndexes[i]]);
                    World.EntityManager.SetSharedComponentData(renderText.letters[i], render);
                    SetLetterColor(World.EntityManager, renderText.letters[i], renderText.GetColor());
                }
                else
                {
                    SetLetterColor(World.EntityManager, renderText.letters[i],
                                   new UnityEngine.Color(0, 0, 0, 0));
                }
            }
        }
示例#15
0
 private void IncrementLetters(ref DialogueUI dialogue, ref RenderText renderText)
 {
     dialogue.RandomizeCooldown();
     dialogue.IncreaseIndex(ref renderText);
     //RefreshPanelSize(e, newText);
 }