예제 #1
0
        private void SpawnPlayerBar(Entity character)//, float heightAddition)
        {
            ZoxID zoxID = World.EntityManager.GetComponentData <ZoxID>(character);

            if (frontBars.ContainsKey(zoxID.id))
            {
                Debug.LogError("Trying to add duplicate statbar onto character.");
                return;
            }
            Translation translation = World.EntityManager.GetComponentData <Translation>(character);
            Entity      backbar     = UIUtilities.SpawnPanel(World.EntityManager, character, uiData.backBarMaterial, null, panelSize);
            Entity      frontbar    = CreateBarUI(frontbarArchtype, translation.Value, uiData.frontBarMaterial, healthbarMesh);

            frontBars.Add(zoxID.id, frontbar);
            backBars.Add(zoxID.id, backbar);
            // backbar
            World.EntityManager.AddComponentData(backbar, zoxID);
            World.EntityManager.SetComponentData(frontbar, new Parent {
                Value = backbar
            });
            World.EntityManager.SetComponentData(frontbar, new StatBarUI {
                width = panelSize.x
            });
            World.EntityManager.SetComponentData(frontbar, zoxID);
            UIUtilities.UpdateOrbiter(World.EntityManager, backbar, orbitPosition, uiData.crosshairLerpSpeed);
        }
예제 #2
0
파일: CameraSystem.cs 프로젝트: Deus0/zoxel
        private void CreateRenderTextureTexture(int id, CameraData cameraData, Camera camera, UnityEngine.UI.RawImage image)//, int textureWidth, int textureHeight)
        {
            // Debug.LogError("NewRender Size: " + image.rectTransform.rect.size.ToString());
            int textureWidth  = (int)(image.rectTransform.rect.size.x) / cameraData.textureDivision;
            int textureHeight = (int)(image.rectTransform.rect.size.y) / cameraData.textureDivision;

            if (cameraRenders.ContainsKey(id))
            {
                GameObject.Destroy(cameraRenders[id]);
                cameraRenders.Remove(id);
            }
            RenderTexture newTexture = new RenderTexture(textureWidth, textureHeight, 16, UnityEngine.RenderTextureFormat.ARGB32);

            newTexture.filterMode = FilterMode.Point;
            newTexture.name       = camera.gameObject.name;
            image.texture         = newTexture;
            camera.targetTexture  = newTexture;
            cameraRenders.Add(id, newTexture);
            if (cameras.ContainsKey(id) == false)
            {
                Debug.LogError("Camera does not exist: " + id);
                return;
            }

            if (World.EntityManager.HasComponent <CameraLink>(cameras[id]))
            {
                CameraLink cameraLink = World.EntityManager.GetComponentData <CameraLink>(cameras[id]);
                cameraLink.aspectRatio = ((float)textureWidth) / ((float)textureHeight);
                World.EntityManager.SetComponentData(cameras[id], cameraLink);
            }
            else
            {
                int characterID = World.EntityManager.GetComponentData <ZoxID>(cameras[id]).creatorID;
                if (characterSpawnSystem.characters.ContainsKey(characterID))
                {
                    if (World.EntityManager.HasComponent <CameraLink>(characterSpawnSystem.characters[characterID]))
                    {
                        CameraLink cameraLink = World.EntityManager.GetComponentData <CameraLink>(characterSpawnSystem.characters[characterID]);
                        cameraLink.aspectRatio = ((float)textureWidth) / ((float)textureHeight);
                        World.EntityManager.SetComponentData(characterSpawnSystem.characters[characterID], cameraLink);
                    }
                }
            }
            // connected UIs
            CharacterUIList uiList = World.EntityManager.GetComponentData <CharacterUIList>(cameras[id]);

            Entity[] uis = uiList.uis.ToArray();
            for (int i = 0; i < uis.Length; i++)
            {
                if (World.EntityManager.Exists(uis[i]))
                {
                    CameraLink cameraLink = World.EntityManager.GetComponentData <CameraLink>(uis[i]);
                    cameraLink.aspectRatio = ((float)textureWidth) / ((float)textureHeight);
                    World.EntityManager.SetComponentData(uis[i], cameraLink);
                    //World.EntityManager.SetComponentData(uis[i], orbitor);
                    OrbitCamera orbitor = World.EntityManager.GetComponentData <OrbitCamera>(uis[i]);
                    UIUtilities.UpdateOrbiter(World.EntityManager, uis[i], orbitor.orbitPosition, orbitor.lerpSpeed);
                }
            }
        }
예제 #3
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);
                    }
                }
            });
        }
예제 #4
0
        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);
        }