Example #1
0
        protected override void OnUpdate()
        {
            Entities.WithAll <PanelUI>().ForEach((Entity e, ref PanelUI panelUI) =>
            {
                if (panelUI.dirty == 1)
                {
                    panelUI.dirty = 0;
                    // , ref GridUI gridUI
                    // resize panel
                    float2 panelSize = panelUI.size; // etGridPanelSize(gridUI.gridSize, gridUI.iconSize, gridUI.margins, gridUI.padding);

                    /*Debug.LogError("Setting children: " + childrens.children.Length + " for grid."
                     + " Panel Size is: " + panelSize
                     + ". Icon Size is: " + gridUI.iconSize);*/
                    UIUtilities.UpdateOrbiter(World.EntityManager, e, GetOrbitPosition(panelUI), uiData.orbitLerpSpeed);
                    Mesh mesh       = MeshUtilities.CreateQuadMesh(panelSize);
                    var renderMesh  = World.EntityManager.GetSharedComponentData <Unity.Rendering.RenderMesh>(e);
                    renderMesh.mesh = mesh;
                    World.EntityManager.SetSharedComponentData(e, renderMesh);
                    RenderBounds b = new RenderBounds
                    {
                        Value = new AABB
                        {
                            Extents = new float3(panelSize.x, panelSize.y, 0.5f)
                        }
                    };
                    EntityManager.SetComponentData(e, b);
                    panelUI.outlineDirty = 1;
                }

                if (panelUI.outlineDirty == 1)
                {
                    panelUI.outlineDirty = 0;
                    if (World.EntityManager.HasComponent <OutlineLink>(e))
                    {
                        float2 panelSize = panelUI.size;
                        RenderBounds b   = new RenderBounds
                        {
                            Value = new AABB
                            {
                                Extents = new float3(panelSize.x, panelSize.y, 0.5f)
                            }
                        };
                        //Debug.LogError("Updating Outline Render Mesh.");
                        var outlineLink            = World.EntityManager.GetComponentData <OutlineLink>(e);
                        var outline                = outlineLink.outline;
                        var outlineRenderMesh      = World.EntityManager.GetSharedComponentData <Unity.Rendering.RenderMesh>(outline);
                        Mesh mesh2                 = MeshUtilities.CreateReverseQuadMesh(panelSize, 0.004f);
                        outlineRenderMesh.mesh     = mesh2;
                        outlineRenderMesh.material = uiData.defaultPlayerOutline;
                        World.EntityManager.SetSharedComponentData(outline, outlineRenderMesh);
                        World.EntityManager.SetComponentData(outline, b);
                    }
                }
            });
        }
Example #2
0
        private static void RefreshPanelSize(EntityManager entityManager, Entity panelUI, float fontSize, int textLength)
        {
            float2 panelSize = new float2(textLength * fontSize, fontSize);

            //UnityEngine.Debug.LogError("Resized dialogue panel to: " + panelSize);
            Unity.Rendering.RenderMesh renderMesh =
                entityManager.GetSharedComponentData <Unity.Rendering.RenderMesh>(panelUI);
            renderMesh.mesh = MeshUtilities.CreateQuadMesh(panelSize);
            entityManager.SetSharedComponentData(panelUI, renderMesh);
            var panel = entityManager.GetComponentData <PanelUI>(panelUI);

            panel.size         = panelSize;
            panel.outlineDirty = 1;
            entityManager.SetComponentData(panelUI, panel);
        }
Example #3
0
        public static Entity SpawnVisualElement(EntityManager EntityManager, Entity parent, float3 localPosition, float2 iconSize, Texture2D iconTexture, Material baseIconMaterial, int queuePriority = 5000)
        {
            if (iconArchtype.Valid == false)
            {
                iconArchtype = EntityManager.CreateArchetype(
                    typeof(Parent),
                    typeof(LocalToParent),
                    typeof(LocalToWorld),
                    //transform
                    typeof(Translation),
                    typeof(Rotation),
                    typeof(NonUniformScale),
                    // renderer
                    typeof(RenderMesh));
            }
            Material iconMaterialInstance = null;

            if (baseIconMaterial != null)
            {
                iconMaterialInstance = new Material(baseIconMaterial);
                iconMaterialInstance.enableInstancing = true;
                //iconMaterialInstance.renderQueue = 6666;
                // iconMaterialInstance.SetFloat("_QueueOffset", queuePriority);
                if (iconTexture != null)
                {
                    iconMaterialInstance.SetTexture("_BaseMap", iconTexture);
                }
            }
            Mesh   iconMesh = MeshUtilities.CreateQuadMesh(iconSize);
            Entity newBar   = EntityManager.CreateEntity(iconArchtype);

            if (EntityManager.Exists(parent))
            {
                EntityManager.SetComponentData(newBar, new Parent {
                    Value = parent
                });
            }
            else
            {
                EntityManager.RemoveComponent <Parent>(newBar);
                EntityManager.RemoveComponent <LocalToParent>(newBar);
                EntityManager.AddComponentData(newBar, new FaceCameraComponent {
                });
            }
            EntityManager.SetComponentData(newBar, new Translation {
                Value = localPosition
            });
            EntityManager.SetComponentData(newBar, new Rotation {
                Value = quaternion.identity
            });
            EntityManager.SetComponentData(newBar, new NonUniformScale {
                Value = new float3(1, 1, 1)
            });
            EntityManager.SetSharedComponentData(newBar, new RenderMesh
            {
                material    = iconMaterialInstance,
                mesh        = iconMesh,
                castShadows = UnityEngine.Rendering.ShadowCastingMode.Off
            });
            RenderBounds b = new RenderBounds
            {
                Value = new AABB
                {
                    Extents = new float3(iconSize.x, iconSize.y, 0.5f)
                }
            };

            EntityManager.AddComponentData(newBar, b);
            return(newBar);
        }
Example #4
0
        public static Entity SpawnPanel(EntityManager EntityManager, Entity character, Material baseMaterial, Material outlineMaterial, float2 panelSize)
        {
            //float3 orbitPosition = float3.zero;
            if (panelArchtype.Valid == false)
            {
                panelArchtype = EntityManager.CreateArchetype(
                    typeof(PanelUI),
                    typeof(CameraLink),
                    typeof(OrbitCamera),
                    typeof(RenderBounds),
                    // transform
                    typeof(Translation),
                    typeof(Rotation),
                    typeof(NonUniformScale),
                    typeof(LocalToWorld),
                    // renderer
                    typeof(RenderMesh));
            }
            //float3 spawnPosition = EntityManager.GetComponentData<Translation>(character).Value;
            Material materialInstance = new Material(baseMaterial);
            //materialInstance.SetFloat("_QueueOffset", 100);
            Mesh   panelMesh   = MeshUtilities.CreateQuadMesh(panelSize);
            Entity characterUI = EntityManager.CreateEntity(panelArchtype);
            // fix bounds flickers mesh
            RenderBounds b = new RenderBounds {
                Value = new AABB {
                    Extents = new float3(panelSize.x, panelSize.y, 0.5f)
                }
            };

            EntityManager.SetComponentData(characterUI, b);
            EntityManager.SetComponentData(characterUI, new Rotation {
                Value = quaternion.identity
            });
            EntityManager.SetComponentData(characterUI, new NonUniformScale {
                Value = new float3(1, 1, 1)
            });
            EntityManager.SetSharedComponentData(characterUI, new RenderMesh {
                material       = materialInstance,
                mesh           = panelMesh,
                receiveShadows = true
            });
            if (EntityManager.HasComponent <CameraLink>(character))
            {
                CameraLink cameraLink = EntityManager.GetComponentData <CameraLink>(character);
                EntityManager.SetComponentData(characterUI, cameraLink);
                if (EntityManager.HasComponent <CharacterUIList>(cameraLink.camera))
                {
                    // update UI List
                    CharacterUIList uiList = EntityManager.GetComponentData <CharacterUIList>(cameraLink.camera);
                    // expand list
                    Entity[]      oldUIs  = uiList.uis.ToArray();
                    List <Entity> uisList = new List <Entity>();
                    for (int i = 0; i < oldUIs.Length; i++)
                    {
                        if (EntityManager.Exists(oldUIs[i]))
                        {
                            uisList.Add(oldUIs[i]);
                        }
                    }
                    uisList.Add(characterUI);
                    uiList.uis = new BlitableArray <Entity>(uisList.Count, Unity.Collections.Allocator.Persistent);
                    for (int i = 0; i < uisList.Count; i++)
                    {
                        uiList.uis[i] = uisList[i];
                    }
                    // uiList.uis[uis.Length] = characterUI;
                    EntityManager.SetComponentData(cameraLink.camera, uiList);
                }
            }
            else
            {
                Debug.LogError("No Camera link assigned on character..");
            }
            if (outlineMaterial)
            {
                // Debug.LogError("Spawning Outline Renderer.");
                var outline = SpawnVisualElement(EntityManager, characterUI, float3.zero, float2.zero, null, outlineMaterial);
                EntityManager.AddComponentData(characterUI, new OutlineLink {
                    outline = outline
                });
            }
            return(characterUI);
        }