Esempio n. 1
0
        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);
                }
            }
        }
Esempio n. 2
0
        protected override void OnUpdate()
        {
            Entities.WithAll <Controller, Targeter>().ForEach((Entity e, ref Controller controller, ref Targeter targeter) =>
            {
                // if target and new target
                // change material of character to selected
                // change last selected entity to deselected!
                if (controller.gameState != ((byte)GameState.InGame))
                {
                    return;
                }

                // seperate into another system later
                if (controller.mappingType == ((byte)ControllerMapping.Character))
                {
                    if (targeter.hasTarget == 1 && controller.Value.buttonA == 1)
                    {
                        // if clicked on target
                        //UnityEngine.Debug.LogError("Started talking with character: " + targeter.nearbyCharacter.character.Index);
                        // start dialogue here!
                        controller.mappingType = 1;
                        DialogueUISpawnSystem.SpawnUI(World.EntityManager, e);
                    }
                }
                else if (controller.mappingType == ((byte)ControllerMapping.Dialogue))
                {
                    if (controller.Value.buttonB == 1)
                    {
                        FinishedSpeaking(e, ref controller);
                    }
                    CameraLink clink     = World.EntityManager.GetComponentData <CameraLink>(e);
                    CharacterUIList list = World.EntityManager.GetComponentData <CharacterUIList>(clink.camera);
                    var uis = list.uis.ToArray();
                    //Debug.LogError("UIs: " + uis.Length);
                    for (int i = 0; i < uis.Length; i++)
                    {
                        if (World.EntityManager.HasComponent <DialogueUI>(uis[i]))
                        {
                            //Debug.LogError("UI is dialogue: " + i);
                            if (World.EntityManager.GetComponentData <DialogueUI>(uis[i]).completedTree == 1)
                            {
                                FinishedSpeaking(e, ref controller);
                            }
                            break;
                        }
                        //else {
                        //    Debug.LogError("UI isnt' dialogue: " + i);
                        //}
                    }
                }
            });
        }
Esempio n. 3
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);
        }