Пример #1
0
        private void SetItemUIIcon(Entity iconEntity, Entity character, int arrayIndex)
        {
            Inventory inventory = World.EntityManager.GetComponentData <Inventory>(character);

            UnityEngine.Texture2D iconTexture = null;
            var itemMetaID = inventory.items[arrayIndex].data.id;

            if (itemMetaID != 0)
            {
                ItemDatam itemDatam = meta[itemMetaID];
                if (itemDatam != null && itemDatam.texture)
                {
                    iconTexture = itemDatam.texture.texture;
                }
            }
            else
            {
                iconTexture = defaultIconTexture;
            }
            //Childrens childrens = World.EntityManager.GetComponentData<Childrens>(uis[characterID]);
            //Entity iconEntity = childrens.children[arrayIndex]; //icons[characterID].entities[arrayIndex];
            var renderer = World.EntityManager.GetSharedComponentData <Unity.Rendering.RenderMesh>(iconEntity);

            renderer.material.SetTexture("_BaseMap", iconTexture);
            //World.EntityManager.SetSharedComponentData(iconEntity, renderer);
        }
Пример #2
0
        public void QueueItem(float3 spawnPosition, ItemDatam data, int quantity)
        {
            Entity e = World.EntityManager.CreateEntity();

            World.EntityManager.AddComponentData(e, new SpawnItemCommand
            {
                data          = data.data,
                quantity      = quantity,
                spawnPosition = spawnPosition,
                spawnRotation = quaternion.identity
            });
        }
Пример #3
0
        private void SpawnItem(SpawnItemCommand command)
        {
            if (meta.ContainsKey(command.data.id) == false)
            {
                Debug.LogError("Item not in meta.");
                return;
            }
            ItemDatam itemDatam = meta[command.data.id];
            Entity    entity    = World.EntityManager.CreateEntity(itemArchtype);
            int       id        = Bootstrap.GenerateUniqueID();

            World.EntityManager.SetComponentData(entity, new WorldItem {
                id       = id,
                data     = command.data,
                quantity = command.quantity
            });
            World.EntityManager.SetComponentData(entity, new ItemBob {
                originalPosition = command.spawnPosition
            });
            World.EntityManager.SetComponentData(entity, new Translation {
                Value = command.spawnPosition
            });
            World.EntityManager.SetComponentData(entity, new NonUniformScale {
                Value = itemDatam.model.data.scale
            });                                                                                                       // itemDatam.Value.scale * 0.5f });
            World.EntityManager.SetComponentData(entity, new Rotation {
                Value = Quaternion.Euler(0, UnityEngine.Random.Range(-180, 180), 0)
            });

            RenderMesh newRenderer = new RenderMesh();

            newRenderer.castShadows    = UnityEngine.Rendering.ShadowCastingMode.On;
            newRenderer.receiveShadows = true;
            newRenderer.mesh           = new Mesh(); //itemDatam.model.bakedMesh;
            newRenderer.material       = Bootstrap.GetVoxelMaterial();
            World.EntityManager.SetSharedComponentData(entity, newRenderer);
            WorldSpawnSystem.QueueUpdateModel(World.EntityManager, entity, id, itemDatam.model.data);
            items.Add(id, entity);
        }
Пример #4
0
        private void StartDying(Entity statsEntity, int zoxID)
        {
            float3 position = World.EntityManager.GetComponentData <Translation>(statsEntity).Value;

            if (World.EntityManager.HasComponent <Character>(statsEntity))
            {
                CharacterDatam characterDatam = characterSpawnSystem.meta[World.EntityManager.GetComponentData <Character>(statsEntity).metaID];
                for (int i = 0; i < characterDatam.dropItems.Count; i++)
                {
                    ItemDatam itemToDrop = characterDatam.dropItems[i].GetItem();
                    itemSpawnSystem.QueueItem(position,// + new float3(UnityEngine.Random.Range(-1f, 1f), 0, UnityEngine.Random.Range(-1f, 1f)),
                                              itemToDrop, characterDatam.dropItems[i].GetQuantity());
                }
            }

            playerSpawnSystem.RemoveControllerCharacter(statsEntity);

            // game stuff
            if (World.EntityManager.HasComponent <Skills>(statsEntity))
            {
                World.EntityManager.RemoveComponent <Skills>(statsEntity);
            }
            skillsSystem.RemoveSkills(statsEntity);
            if (World.EntityManager.HasComponent <Stats>(statsEntity))
            {
                World.EntityManager.RemoveComponent <Stats>(statsEntity);
            }
            if (World.EntityManager.HasComponent <BulletHitTaker>(statsEntity))
            {
                World.EntityManager.RemoveComponent <BulletHitTaker>(statsEntity);
            }
            // movement
            if (World.EntityManager.HasComponent <Body>(statsEntity))
            {
                World.EntityManager.RemoveComponent <Body>(statsEntity);
            }
            if (World.EntityManager.HasComponent <WorldBound>(statsEntity))
            {
                World.EntityManager.RemoveComponent <WorldBound>(statsEntity);
            }
            if (World.EntityManager.HasComponent <BodyForce>(statsEntity))
            {
                World.EntityManager.RemoveComponent <BodyForce>(statsEntity);
            }
            if (World.EntityManager.HasComponent <BodyTorque>(statsEntity))
            {
                World.EntityManager.RemoveComponent <BodyTorque>(statsEntity);
            }
            if (World.EntityManager.HasComponent <BodyInnerForce>(statsEntity))
            {
                World.EntityManager.RemoveComponent <BodyInnerForce>(statsEntity);
            }
            // ai
            if (World.EntityManager.HasComponent <Targeter>(statsEntity))
            {
                World.EntityManager.RemoveComponent <Targeter>(statsEntity);
            }
            if (World.EntityManager.HasComponent <Wander>(statsEntity))
            {
                World.EntityManager.RemoveComponent <Wander>(statsEntity);
            }
            if (World.EntityManager.HasComponent <Mover>(statsEntity))
            {
                World.EntityManager.RemoveComponent <Mover>(statsEntity);
            }
            if (World.EntityManager.HasComponent <AIState>(statsEntity))
            {
                World.EntityManager.RemoveComponent <AIState>(statsEntity);
            }
            else
            {
                CrosshairSpawnSystem.RemoveUI(World.EntityManager, statsEntity);
            }

            // int uiIndex = StatbarSystem.GetListIndex(statsComponent.id);
            if (StatbarSystem.frontBars.ContainsKey(zoxID))
            //   if (uiIndex != -1)
            {
                Entity    characterHealthBar = StatbarSystem.frontBars[zoxID];
                StatBarUI statBar1           = World.EntityManager.GetComponentData <StatBarUI>(characterHealthBar);
                statBar1.isDead           = 1;
                statBar1.targetPercentage = 0;
                //statBar1.timeStateChanged = UnityEngine.Time.time;
                World.EntityManager.SetComponentData(characterHealthBar, statBar1);
            }
            if (characterSpawnSystem.characters.ContainsKey(zoxID))
            {
                characterSpawnSystem.characters.Remove(zoxID);
            }
            World.EntityManager.AddComponentData(statsEntity, new DyingOne
            {
                timeOfDeath = UnityEngine.Time.time
            });
            if (TurretSpawnerSystem.bases.ContainsKey(zoxID))
            {
                World.EntityManager.AddComponentData(TurretSpawnerSystem.bases[zoxID], new ScaleLerper
                {
                    createdTime = UnityEngine.Time.time,
                    lifeTime    = deadbodyRemovalTime,
                    scaleBegin  = World.EntityManager.GetComponentData <NonUniformScale>(TurretSpawnerSystem.bases[zoxID]).Value,
                    scaleEnd    = float3.zero
                });
            }
            World.EntityManager.AddComponentData(statsEntity, new ScaleLerper
            {
                createdTime = UnityEngine.Time.time,
                lifeTime    = deadbodyRemovalTime,
                scaleBegin  = World.EntityManager.GetComponentData <NonUniformScale>(statsEntity).Value,
                scaleEnd    = float3.zero
            });
        }
Пример #5
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);
        }
Пример #6
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);
        }