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; }
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) { 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) { 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); }