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); }
public void Start() { sys = new SystemsManager(data, "ZoxelGame"); sys.voxelSystemGroup.voxelPreviewSystem.Test(); gameText = UIUtilities.SpawnText(EntityManager, new Entity(), "Zoxel", new float3(0, 1f, 0.3f), titleColor, 0.07f); startText = UIUtilities.SpawnText(EntityManager, new Entity(), "Press Any Key to Start", new float3(0, 0.85f, 0.3f), subTitleColor, 0.022f); game = sys.gameSystemGroup.gameStartSystem.CreateGame(data); sys.gameSystemGroup.gameStartSystem.OnStarted += () => { EntityManager.DestroyEntity(gameText); EntityManager.DestroyEntity(startText); }; sys.uiSystemGroup.menuSpawnSystem.game = game; }
private Entity SpawnUI(Entity character) { Entity crosshair = UIUtilities.SpawnPanel(World.EntityManager, character, uiData.crosshairMaterial, null, //uiData.crosshairPosition, new float2(uiData.crosshairSize, uiData.crosshairSize)); UIUtilities.UpdateOrbiter(World.EntityManager, crosshair, new float3(0, 0, 0.5f), uiData.crosshairLerpSpeed); /*OrbitCamera orbit = World.EntityManager.GetComponentData<OrbitCamera>(crosshair); * orbit.lerpSpeed = uiData.crosshairLerpSpeed; * World.EntityManager.SetComponentData(crosshair, orbit);*/ //crosshairs.Add(World.EntityManager.GetComponentData<ZoxID>(character).id, crosshair); return(crosshair); }
protected override void OnCreate() { orbitPosition = UIUtilities.GetOrbitAnchors(UIAnchoredPosition.TopMiddle, orbitPosition, panelSize); orbitPosition.y += 0.01f; healthbarMesh = CreateQuadMesh(panelSize, true); healthbarMeshNPC = CreateQuadMesh(panelSizeNPC, true); healthbarMeshBackNPC = CreateQuadMesh(panelSizeNPC, false); backbarArchtype = World.EntityManager.CreateArchetype( typeof(ZoxID), typeof(FaceCameraComponent), typeof(UITrailer), // transform typeof(LocalToWorld), typeof(Translation), typeof(Rotation), typeof(NonUniformScale), // renderer typeof(RenderMesh), typeof(RenderBounds) ); frontbarArchtype = World.EntityManager.CreateArchetype( // unique typeof(StatBarUI), typeof(ZoxID), // transforms typeof(Parent), typeof(LocalToParent), typeof(LocalToWorld), // transform typeof(Translation), typeof(Rotation), typeof(NonUniformScale), // renderer typeof(RenderMesh), typeof(RenderBounds) ); }
protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData) { // spawn stat icon for each thing ZoxID zoxID = World.EntityManager.GetComponentData <ZoxID>(character); Stats stats = World.EntityManager.GetComponentData <Stats>(character); #region StatIcons List <Entity> statIcons = new List <Entity>(); //List<Entity> statTexts = new List<Entity>(); float2 iconSize = uiDatam.defaultIconSize; for (int i = 0; i < stats.stats.Length; i++) { if (meta.ContainsKey(stats.stats[i].id) == false) { continue; } statIcons.Add(UIUtilities.SpawnButton( World.EntityManager, panelUI, float3.zero, iconSize, meta[stats.stats[i].id].texture.texture, uiDatam.defaultPlayerIcon)); var textA = UIUtilities.SpawnText(World.EntityManager, statIcons[statIcons.Count - 1], ((int)stats.stats[i].value).ToString());//, iconSize); Childrens children2 = new Childrens { }; children2.children = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent); children2.children[0] = textA; World.EntityManager.AddComponentData(statIcons[statIcons.Count - 1], children2); } for (int i = 0; i < stats.states.Length; i++) { if (meta.ContainsKey(stats.states[i].id) == false) { continue; } statIcons.Add(UIUtilities.SpawnButton( World.EntityManager, panelUI, float3.zero, iconSize, meta[stats.states[i].id].texture.texture, uiDatam.defaultPlayerIcon)); var textA = UIUtilities.SpawnText(World.EntityManager, statIcons[statIcons.Count - 1], ((int)stats.states[i].value).ToString());//,// iconSize, // new float3(0, iconSize.y / 2f, 0)); //var textB = UIUtilities.SpawnText(World.EntityManager, statIcons[statIcons.Count - 1], // ((int)stats.states[i].maxValue).ToString());//, iconSize); Childrens children2 = new Childrens { }; children2.children = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent); children2.children[0] = textA; //children2.children[1] = textB; World.EntityManager.AddComponentData(statIcons[statIcons.Count - 1], children2); } for (int i = 0; i < stats.regens.Length; i++) { Entity icon = UIUtilities.SpawnButton( World.EntityManager, panelUI, float3.zero, iconSize, meta[stats.regens[i].id].texture.texture, uiDatam.defaultPlayerIcon); Entity textA = UIUtilities.SpawnText(World.EntityManager, icon, ((int)stats.regens[i].value).ToString());//, iconSize); statIcons.Add(icon); Childrens children2 = new Childrens { }; children2.children = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent); children2.children[0] = textA; World.EntityManager.AddComponentData(statIcons[statIcons.Count - 1], children2); } for (int i = 0; i < stats.attributes.Length; i++) { Entity icon = UIUtilities.SpawnButton( World.EntityManager, panelUI, float3.zero, iconSize, meta[stats.attributes[i].id].texture.texture, uiDatam.defaultPlayerIcon); statIcons.Add(icon); var textA = UIUtilities.SpawnText(World.EntityManager, icon, ((int)stats.attributes[i].value).ToString());//, iconSize); //statTexts.Add(text); Childrens children2 = new Childrens { }; children2.children = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent); children2.children[0] = textA; World.EntityManager.AddComponentData(statIcons[statIcons.Count - 1], children2); } for (int i = 0; i < stats.levels.Length; i++) { Entity icon = UIUtilities.SpawnButton( World.EntityManager, panelUI, float3.zero, iconSize, meta[stats.levels[i].id].texture.texture, uiDatam.defaultPlayerIcon); statIcons.Add(icon); var textA = UIUtilities.SpawnText(World.EntityManager, icon, ((int)stats.levels[i].value).ToString());//, iconSize); /*var textB = UIUtilities.SpawnText(World.EntityManager, icon, * ((int)stats.levels[i].experienceGained).ToString(), * //iconSize, * new float3(0, iconSize.y / 3, 0)); * var textC = UIUtilities.SpawnText(World.EntityManager, icon, * ((int)stats.levels[i].experienceRequired).ToString(), * //iconSize, * new float3(0, 2 * iconSize.y / 3, 0));*/ Childrens children2 = new Childrens { }; children2.children = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent); children2.children[0] = textA; /*children2.children[1] = textB; * children2.children[2] = textC;*/ World.EntityManager.AddComponentData(icon, children2); } #endregion Childrens children = new Childrens { }; children.children = new BlitableArray <Entity>(statIcons.Count, Unity.Collections.Allocator.Persistent); for (int i = 0; i < statIcons.Count; i++) { children.children[i] = statIcons[i]; } World.EntityManager.AddComponentData(panelUI, children); //float2 iconSize = new float2(uiDatam.skillbarIconSize, uiDatam.skillbarIconSize); World.EntityManager.AddComponentData(panelUI, new GridUI { dirty = 1, gridSize = uiDatam.statsUIGridSize, iconSize = iconSize, margins = new float2(0.003f, 0.003f), padding = new float2(0.003f, 0.003f), }); byte uiIndex = ((byte)((int)PlayerUIType.StatsUI)); World.EntityManager.SetComponentData(panelUI, new PanelUI { id = uiIndex, characterID = zoxID.id, orbitDepth = uiDatam.orbitDepth, anchor = (byte)UIAnchoredPosition.Middle }); //characterStatUIs.Add(zoxID.id, CharacterStatUIData); //CreateSelected(character, panelUI, ((byte)PlayerUIType.StatsUI), iconSize); OnSelectedButton(zoxID.id, 0); }
protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData) { var position = World.EntityManager.GetComponentData <ChunkStreamPoint>(character).chunkPosition; //EntityBunch icons = new EntityBunch(); List <Entity> icons2 = new List <Entity>(); int mapResolution = 4; if (Bootstrap.instance) { mapResolution = Bootstrap.instance.mapResolution; } int rowsCount = mapResolution; int columnsCount = mapResolution; float2 iconSize = uiDatam.defaultIconSize; //for (int j = -(columnsCount / 2); j < (columnsCount / 2); j++) for (int j = (columnsCount / 2) - 1; j >= -(columnsCount / 2); j--) { for (int i = -(rowsCount / 2); i < (rowsCount / 2); i++) { float2 mapPosition = new float2(i + position.x, j + position.z); if (chunkMapSystem.maps.ContainsKey(mapPosition)) { float3 localMapPosition = float3.zero;// GetGridPosition(i + rowsCount / 2, -(j - (columnsCount / 2) + 1), rowsCount, columnsCount); // + columnsCount / 2 icons2.Add(UIUtilities.SpawnVisualElement( World.EntityManager, panelUI, localMapPosition, iconSize, chunkMapSystem.maps[mapPosition], uiDatam.mapIcon)); } else { //Debug.LogError("Could not find map for positoin: " + mapPosition.ToString()); } } } Childrens children = new Childrens { }; children.children = new BlitableArray <Entity>(icons2.Count, Unity.Collections.Allocator.Persistent); for (int i = 0; i < icons2.Count; i++) { children.children[i] = icons2[i]; // icons2.Count - 1 - } World.EntityManager.AddComponentData(panelUI, children); World.EntityManager.AddComponentData(panelUI, new GridUI { dirty = 1, gridSize = new float2(mapResolution, mapResolution), iconSize = iconSize, margins = new float2(0.003f, 0.003f), padding = new float2(0.00f, 0.00f), }); byte uiIndex = ((byte)((int)PlayerUIType.SkillbookUI)); ZoxID characterID = World.EntityManager.GetComponentData <ZoxID>(character); World.EntityManager.SetComponentData(panelUI, new PanelUI { id = uiIndex, characterID = characterID.id, orbitDepth = uiDatam.orbitDepth, anchor = (byte)UIAnchoredPosition.Middle }); /*icons.entities = icons2.ToArray();; * if (mapIcons.ContainsKey(characterID.id)) * { * mapIcons.Remove(characterID.id); * // Debug.LogError("Map Icons in there twice for: " + characterID.id); * } * mapIcons.Add(characterID.id, icons);*/ }
protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData) { if (World.EntityManager.HasComponent <QuestLog>(character) == false) { Debug.LogError("Tried to add character without questlog."); return; } int zoxID = World.EntityManager.GetComponentData <ZoxID>(character).id; QuestLog questlog = World.EntityManager.GetComponentData <QuestLog>(character); //EntityBunch iconGroup = new EntityBunch(); //EntityBunch textGroup = new EntityBunch(); List <Entity> statIcons = new List <Entity>(); List <Entity> statTexts = new List <Entity>(); float2 iconSize = uiDatam.defaultIconSize; for (int i = 0; i < questlog.quests.Length; i++) { Texture2D iconTexture = null; if (questlog.quests[i].metaID != 0) { QuestDatam questMeta = meta[questlog.quests[i].metaID]; if (questMeta != null && questMeta.texture) { iconTexture = questMeta.texture.texture; } } float3 position = float3.zero;// GetGridPosition(i, 3, 3); Entity icon = UIUtilities.SpawnVisualElement( World.EntityManager, panelUI, position, iconSize, iconTexture, uiDatam.defaultPlayerIcon); //Entity text = SpawnText(icon, ((int)questlog.quests[i].GetCompleted()).ToString()); Entity text = UIUtilities.SpawnText(World.EntityManager, icon, ((int)questlog.quests[i].GetCompleted()).ToString());//, iconSize); statIcons.Add(icon); statTexts.Add(text); } //iconGroup.entities = statIcons.ToArray(); // new Entity[stats.stats.Length]; //textGroup.entities = statTexts.ToArray(); // new Entity[stats.stats.Length]; Childrens children = new Childrens { }; children.children = new BlitableArray <Entity>(statIcons.Count, Unity.Collections.Allocator.Persistent); for (int i = 0; i < statIcons.Count; i++) { children.children[i] = statIcons[i]; } World.EntityManager.AddComponentData(panelUI, children); World.EntityManager.AddComponentData(panelUI, new GridUI { dirty = 1, gridSize = uiDatam.questlogGridSize, iconSize = iconSize, margins = new float2(0.003f, 0.003f), padding = new float2(0.003f, 0.003f), }); byte uiIndex = ((byte)((int)PlayerUIType.QuestlogUI)); World.EntityManager.SetComponentData(panelUI, new PanelUI { id = uiIndex, characterID = zoxID, orbitDepth = uiDatam.orbitDepth, anchor = (byte)UIAnchoredPosition.Middle }); OnSelectedButton(zoxID, 0); }
//public override void OnClickedButton(int characterID, int arrayIndex) //{ //int originalArrayIndex = arrayIndex; //Entity character = characterSpawnSystem.characters[characterID]; //Stats stats = World.EntityManager.GetComponentData<Stats>(character); //} protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData) { // spawn stat icon for each thing ZoxID zoxID = World.EntityManager.GetComponentData <ZoxID>(character); Skills skills = World.EntityManager.GetComponentData <Skills>(character); #region StatIcons List <Entity> statIcons = new List <Entity>(); //List<Entity> statTexts = new List<Entity>(); float2 iconSize = uiDatam.defaultIconSize; for (int i = 0; i < skills.skills.Length; i++) { int metaID = skills.skills[i].id; if (meta.ContainsKey(metaID)) { statIcons.Add(UIUtilities.SpawnButton( World.EntityManager, panelUI, float3.zero, iconSize, meta[metaID].texture.texture, uiDatam.defaultPlayerIcon)); Childrens textLink = new Childrens { children = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent) }; textLink.children[0] = UIUtilities.SpawnText(World.EntityManager, statIcons[statIcons.Count - 1], ((int)skills.skills[i].attackDamage).ToString()); //, iconSize); World.EntityManager.AddComponentData(statIcons[statIcons.Count - 1], textLink); } else { Debug.LogError("Trying to add meta id in StatsUI (Stats(" + i + ")) that doesn't exist: " + metaID); } } #endregion Childrens children = new Childrens { }; children.children = new BlitableArray <Entity>(statIcons.Count, Unity.Collections.Allocator.Persistent); for (int i = 0; i < statIcons.Count; i++) { children.children[i] = statIcons[i]; } World.EntityManager.AddComponentData(panelUI, children); World.EntityManager.AddComponentData(panelUI, new GridUI { dirty = 1, gridSize = uiDatam.inventoryGridSize, iconSize = iconSize, margins = new float2(0.003f, 0.003f), padding = new float2(0.003f, 0.003f), }); byte uiIndex = ((byte)((int)PlayerUIType.SkillbookUI)); World.EntityManager.SetComponentData(panelUI, new PanelUI { id = uiIndex, characterID = zoxID.id, orbitDepth = uiDatam.orbitDepth, anchor = (byte)UIAnchoredPosition.Middle }); OnSelectedButton(zoxID.id, 0); }
protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData) { int zoxID = World.EntityManager.GetComponentData <ZoxID>(character).id; var inventory = World.EntityManager.GetComponentData <Equipment>(character); List <Entity> cells = new List <Entity>(); float2 iconSize = uiDatam.defaultIconSize; for (int i = 0; i < inventory.body.Length; i++) { var piece = inventory.body[i]; Texture2D iconTexture = null; if (piece.data.id != 0) { ItemDatam itemDatam = meta[piece.data.id]; if (itemDatam != null && itemDatam.texture) { iconTexture = itemDatam.texture.texture; } } Entity icon = UIUtilities.SpawnButton( World.EntityManager, panelUI, float3.zero, iconSize, iconTexture, uiDatam.defaultPlayerIcon); cells.Add(icon); } /*for (int i = 0; i < inventory.gear.Length; i++) * { * var piece = inventory.gear[i]; * Texture2D iconTexture = null; * if (piece.metaID != 0) * { * ItemDatam itemDatam = meta[piece.metaID]; * if (itemDatam != null && itemDatam.texture) * { * iconTexture = itemDatam.texture.texture; * } * } * float3 position = float3.zero; // GetGridPosition(i, 3, 3); * Entity icon = UIUtilities.SpawnVisualElement( * World.EntityManager, * panelUI, * position, * iconSize, * iconTexture, * uiDatam.defaultPlayerIcon); * Childrens textLink = new Childrens { children = new BlitableArray<Entity>(1, Unity.Collections.Allocator.Persistent) }; * textLink.children[0] = UIUtilities.SpawnText(World.EntityManager, icon, ((int)piece.durability).ToString()); //, iconSize); * World.EntityManager.AddComponentData(icon, textLink); * icons.Add(icon); * }*/ Childrens children = new Childrens { }; children.children = new BlitableArray <Entity>(cells.Count, Unity.Collections.Allocator.Persistent); for (int i = 0; i < cells.Count; i++) { children.children[i] = cells[i]; } World.EntityManager.AddComponentData(panelUI, children); World.EntityManager.AddComponentData(panelUI, new GridUI { dirty = 1, gridSize = uiDatam.inventoryGridSize, iconSize = iconSize, margins = new float2(0.003f, 0.003f), padding = new float2(0.003f, 0.003f), }); byte uiIndex = ((byte)((int)PlayerUIType.EquipmentUI)); World.EntityManager.SetComponentData(panelUI, new PanelUI { id = uiIndex, characterID = zoxID, orbitDepth = uiDatam.orbitDepth, anchor = (byte)UIAnchoredPosition.Middle }); OnSelectedButton(zoxID, 0); }
protected override void OnSpawnedPanel(Entity character, Entity panelUI, object spawnData) { if (World.EntityManager.HasComponent <Inventory>(character) == false) { Debug.LogError("Cannot spawn Inventory UI as character does not have inventory."); return; } int zoxID = World.EntityManager.GetComponentData <ZoxID>(character).id; Inventory inventory = World.EntityManager.GetComponentData <Inventory>(character); List <Entity> buttons = new List <Entity>(); float2 iconSize = uiDatam.defaultIconSize; for (int i = 0; i < inventory.items.Length; i++) { Texture2D iconTexture = null; if (inventory.items[i].data.id != 0 && meta.ContainsKey(inventory.items[i].data.id)) { ItemDatam itemDatam = meta[inventory.items[i].data.id]; if (itemDatam != null && itemDatam.texture) { iconTexture = itemDatam.texture.texture; } } Entity button = UIUtilities.SpawnButton( World.EntityManager, panelUI, float3.zero, iconSize, iconTexture, uiDatam.defaultPlayerIcon); World.EntityManager.AddComponentData(button, new ItemUI { index = i }); buttons.Add(button); Childrens textLink = new Childrens { children = new BlitableArray <Entity>(1, Unity.Collections.Allocator.Persistent) }; string numberString = ((int)inventory.items[i].quantity).ToString(); if (numberString == "0" || numberString == "1") { numberString = ""; } textLink.children[0] = UIUtilities.SpawnText(World.EntityManager, button, numberString, float3.zero, uiDatam.overlayTextColor); World.EntityManager.AddComponentData(button, textLink); } Childrens children = new Childrens { }; children.children = new BlitableArray <Entity>(buttons.Count, Unity.Collections.Allocator.Persistent); for (int i = 0; i < buttons.Count; i++) { children.children[i] = buttons[i]; } World.EntityManager.AddComponentData(panelUI, children); World.EntityManager.AddComponentData(panelUI, new GridUI { dirty = 1, gridSize = uiDatam.inventoryGridSize, iconSize = iconSize, margins = new float2(0.003f, 0.003f), padding = new float2(0.003f, 0.003f), }); byte uiIndex = ((byte)((int)PlayerUIType.InventoryUI)); World.EntityManager.SetComponentData(panelUI, new PanelUI { id = uiIndex, characterID = zoxID, orbitDepth = uiDatam.orbitDepth, anchor = (byte)UIAnchoredPosition.Middle }); OnSelectedButton(zoxID, 0); }
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 } } } }); }