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]); } }
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(); } }
protected override void OnUpdate() { Entities.WithAll <DialogueUI, RenderText>().ForEach((Entity e, ref DialogueUI dialogue, ref RenderText renderText) => { if (UnityEngine.Time.time - dialogue.timeBegun >= dialogue.timePerLetter) { if (dialogue.HasFinished()) { // spawn next button now // if has not spawned next buttons if (dialogue.hasSpawnedButtons == 0) { dialogue.hasSpawnedButtons = 1; Color textColor = Color.blue; // uiDatam.menuTextColor DialogueDatam dialogueTree = meta[dialogue.treeID]; var currentBranch = dialogueTree.dialogueTree.branches[dialogue.branchID]; Childrens children = new Childrens { }; if (currentBranch.links.Length <= 1) { // spawn next button children.children = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent); float3 buttonPosition = new float3(0, (-renderText.fontSize / 2f - buttonFontSize / 2f), 0); string dialogueOptionA = "Next"; children.children[0] = UIUtilities.SpawnButtonWithText(World.EntityManager, e, buttonPosition, buttonFontSize, dialogueOptionA, uiDatam.menuButton, uiDatam.defaultMenuColor, textColor); } else { children.children = new BlitableArray <Entity>(currentBranch.links.Length, Unity.Collections.Allocator.Persistent); // spawn a button for all links float3 offset = new float3(); children.children = new BlitableArray <Entity>(currentBranch.links.Length, Unity.Collections.Allocator.Persistent); DialogueDatam dialogueDatam = meta[dialogue.treeID]; for (int i = 0; i < currentBranch.links.Length; i++) { float3 buttonPosition = new float3(0, (-renderText.fontSize / 2f - buttonFontSize / 2f), 0); buttonPosition += offset; offset = buttonPosition; string dialogueOptionA = "Leave"; for (int j = 0; j < dialogueDatam.dialogueTree.branches.Length; j++) { var otherBranch = dialogueDatam.dialogueTree.branches[j]; if (otherBranch.id == currentBranch.links[i]) { dialogueOptionA = otherBranch.speech; break; } } children.children[i] = UIUtilities.SpawnButtonWithText(World.EntityManager, e, buttonPosition, buttonFontSize, dialogueOptionA, uiDatam.menuButton, uiDatam.defaultMenuColor, textColor); } } World.EntityManager.SetComponentData(e, children); // set navigation dirty var panelUI = World.EntityManager.GetComponentData <PanelUI>(e); panelUI.navigationDirty = 1; World.EntityManager.SetComponentData(e, panelUI); } // or spawn dialogue options else if (dialogue.confirmedChoice != 0) { IncrementDialogue(e, ref dialogue, ref renderText); dialogue.confirmedChoice = 0; dialogue.hasSpawnedButtons = 0; // remove previous buttons Childrens childrens = World.EntityManager.GetComponentData <Childrens>(e); childrens.DestroyEntities(World.EntityManager); World.EntityManager.SetComponentData(e, new Childrens { }); var panelUI = World.EntityManager.GetComponentData <PanelUI>(e); panelUI.navigationDirty = 1; World.EntityManager.SetComponentData(e, panelUI); } } else { IncrementLetters(ref dialogue, ref renderText); if (dialogue.confirmedChoice != 0) { dialogue.confirmedChoice = 0; // shouldn't be able to get here } } } }); }