Пример #1
0
        public override bool HandleMouseInput(MouseInput mi)
        {
            if (ClickThrough || !RenderBounds.Contains(mi.Location))
            {
                return(false);
            }

            if (!Draggable || (moving && (!TakeMouseFocus(mi) || mi.Button != MouseButton.Left)))
            {
                return(true);
            }

            if (prevMouseLocation == null)
            {
                prevMouseLocation = mi.Location;
            }
            var vec = mi.Location - (int2)prevMouseLocation;

            prevMouseLocation = mi.Location;
            switch (mi.Event)
            {
            case MouseInputEvent.Up:
                moving = false;
                YieldMouseFocus(mi);
                break;

            case MouseInputEvent.Down:
                moving = true;
                Bounds = new Rectangle(Bounds.X + vec.X, Bounds.Y + vec.Y, Bounds.Width, Bounds.Height);
                break;

            case MouseInputEvent.Move:
                if (moving)
                {
                    Bounds = new Rectangle(Bounds.X + vec.X, Bounds.Y + vec.Y, Bounds.Width, Bounds.Height);
                }
                break;
            }

            return(true);
        }
Пример #2
0
        public override bool HandleInput(GestureSample gs)
        {
            if (ClickThrough || !RenderBounds.Contains(gs.Position.ToInt2()))
            {
                return(false);
            }


            if (!Draggable || (moving && (!TakeFocus(gs) || gs.GestureType == GestureType.Tap)))
            {
                return(true);
            }

            if (prevMouseLocation != null)
            {
                prevMouseLocation = gs.Position.ToInt2();
            }

            var vec = gs.Position.ToInt2() - (Int2)prevMouseLocation;

            prevMouseLocation = gs.Position.ToInt2();

            switch (gs.GestureType)
            {
            case GestureType.DragComplete:
                moving = false;
                YieldFocus(gs);
                break;

            case GestureType.Tap:
                moving = true;
                Bounds = new Rectangle(Bounds.X + vec.X, Bounds.Y + vec.Y, Bounds.Width, Bounds.Height);
                break;

            case GestureType.FreeDrag:
                //if (moving)
                Bounds = new Rectangle(Bounds.X + vec.X, Bounds.Y + vec.Y, Bounds.Width, Bounds.Height);
                break;
            }
            return(true);
        }
Пример #3
0
        public override bool HandleMouseInput(MouseInput mi)
        {
            if (IsDisabled())
            {
                return(false);
            }

            if (mi.Event != MouseInputEvent.Down)
            {
                return(false);
            }

            // Attempt to take keyboard focus
            if (!RenderBounds.Contains(mi.Location) || !TakeKeyboardFocus())
            {
                return(false);
            }

            blinkCycle = 15;

            return(true);
        }
Пример #4
0
        public override bool HandleMouseInput(MouseInput mi)
        {
            if (IsDisabled())
            {
                return(false);
            }

            if (mi.Event != MouseInputEvent.Down)
            {
                return(false);
            }

            // Attempt to take keyboard focus
            if (!RenderBounds.Contains(mi.Location) || !TakeKeyboardFocus())
            {
                return(false);
            }

            ResetBlinkCycle();
            CursorPosition = ClosestCursorPosition(mi.Location.X);
            return(true);
        }
Пример #5
0
        public RenderBounds MakeRenderBounds(MapRectangle imageBounds)
        {
            RenderBounds renderBounds = new RenderBounds();

            renderBounds.MinZoom       = this.ZoomRange.min;
            renderBounds.MaxZoom       = this.ZoomRange.max;
            renderBounds.TileSize      = this.GetTileSize();
            renderBounds.imageBounds   = imageBounds;
            renderBounds.tileRectangle = new TileRectangle[renderBounds.MaxZoom + 1];
            for (int i = renderBounds.MinZoom; i <= renderBounds.MaxZoom; i++)
            {
                renderBounds.tileRectangle[i]      = new TileRectangle();
                renderBounds.tileRectangle[i].zoom = i;
                LatLonZoom llz = new LatLonZoom(imageBounds.GetNW().lat, imageBounds.GetNW().lon, i);
                renderBounds.tileRectangle[i].TopLeft = this.GetTileContainingLatLonZoom(llz);
                llz = new LatLonZoom(imageBounds.GetSE().lat, imageBounds.GetSE().lon, i);
                renderBounds.tileRectangle[i].BottomRight = this.GetTileContainingLatLonZoom(llz);
                renderBounds.tileRectangle[i].StrideX     = 1;
                renderBounds.tileRectangle[i].StrideY     = 1;
            }
            return(renderBounds);
        }
Пример #6
0
        protected virtual void InternalDraw(SKCanvas canvas)
        {
            using (var paint = new SKPaint())
            {
                if (BackgroundColor.A > 0)
                {
                    paint.Color = BackgroundColor.ToSKColor();
                    canvas.DrawRect(RenderBounds.ToSKRect(), paint);
                }

                if (FrameColor.A > 0)
                {
                    paint.Color       = FrameColor.ToSKColor();
                    paint.IsStroke    = true;
                    paint.StrokeWidth = (float)FrameThickness;
                    canvas.DrawRect(RenderBounds.ToSKRect(), paint);
                }
            }

            if (Drawing != null)
            {
                Drawing(canvas);
            }
        }
Пример #7
0
 public override bool HandleInput(GestureSample gs)
 {
     return(!ClickThrough && RenderBounds.Contains(gs.Position.ToInt2()));
 }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
0
 public override bool HandleMouseInput(MouseInput mi)
 {
     return(RenderBounds.Contains(mi.Location) && Skippable);
 }
Пример #11
0
		public RenderBounds MakeRenderBounds(MapRectangle imageBounds)
		{
			RenderBounds renderBounds = new RenderBounds();
			renderBounds.MinZoom = this.ZoomRange.min;
			renderBounds.MaxZoom = this.ZoomRange.max;
			renderBounds.TileSize = this.GetTileSize();
			renderBounds.imageBounds = imageBounds;
			renderBounds.tileRectangle = new TileRectangle[renderBounds.MaxZoom + 1];
			for (int i = renderBounds.MinZoom; i <= renderBounds.MaxZoom; i++)
			{
				renderBounds.tileRectangle[i] = new TileRectangle();
				renderBounds.tileRectangle[i].zoom = i;
				LatLonZoom llz = new LatLonZoom(imageBounds.GetNW().lat, imageBounds.GetNW().lon, i);
				renderBounds.tileRectangle[i].TopLeft = this.GetTileContainingLatLonZoom(llz);
				llz = new LatLonZoom(imageBounds.GetSE().lat, imageBounds.GetSE().lon, i);
				renderBounds.tileRectangle[i].BottomRight = this.GetTileContainingLatLonZoom(llz);
				renderBounds.tileRectangle[i].StrideX = 1;
				renderBounds.tileRectangle[i].StrideY = 1;
			}
			return renderBounds;
		}
Пример #12
0
 public RenderBoundsPresent(RenderBounds renderBounds)
 {
     this.renderBounds = renderBounds;
 }
Пример #13
0
 public HitResult HitTest(Vector2 hitPosition)
 {
     return(bodyGeometry?.HitTest(this, hitPosition) ?? (RenderBounds.Contains(hitPosition) ? new HitResult(this, HitTarget.Node) : null));
 }
Пример #14
0
    void CreateLodEntity(float3 position, List <LodElelement> lodElements, float4 lodDistances)
    {
        EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

        //Create a LOD group Component.
        var lodGroupType = entityManager.CreateArchetype(
            typeof(LocalToWorld),         // Even if the group entity here has no renderer, it requires LocalToWorld
            typeof(Translation),          // Transform position. The Lod-Distance is calculated against this.
                                          //typeof(Rotation), // Transform rotation - doesn't seem to be required
                                          //typeof(Scale), // Transform scale (version with X, Y and Z)  - doesn't seem to be required
            typeof(MeshLODGroupComponent) //MeshLODGroupComponent defines the distances and the local reference point.
            );

        // Create an entity which represents the LOD group
        Entity lodGroupEntity = entityManager.CreateEntity(lodGroupType);

        entityManager.SetComponentData(lodGroupEntity, new Translation()
        {
            Value = position
        });

        entityManager.SetComponentData(lodGroupEntity, new MeshLODGroupComponent()
        {
            LODDistances0       = lodDistances,
            LODDistances1       = lodDistances, //XXX:What are LODDistances1 for? Addional Detail Levels?
            LocalReferencePoint = float3.zero   //XXX:Why is a reference point needed for distance calculation? Setting this to the position of the element gives strange results.
        });

        //
        // The creation of the simple LOD group Component is finished here. Next step is adding addional entities which could be rendered.
        //

        //Generate RenderBounds for LOD Entities
        RenderBounds bounds = new RenderBounds
        {
            Value = GetBoxRenderBounds(new float3(1, 1, 1))
        };

        float3     pos   = position;
        Quaternion rot   = Quaternion.identity;
        float      scale = 1f;

        //Create the Archetype for the LOD Trees (The things actually rendered)
        var treeType = entityManager.CreateArchetype(
            typeof(RenderMesh),           // Rendering mesh
            typeof(LocalToWorld),         // Needed for rendering
            typeof(Translation),          // Transform position
            typeof(Rotation),             // Transform rotation
            typeof(Scale),                // Transform scale (version with X, Y and Z)
            typeof(RenderBounds),         //Bounds to tell the Renderer where it is
            typeof(MeshLODComponent),     //The actual LOD Component
            typeof(PerInstanceCullingTag) // Required for Occlusion Culling
            );
        //Create an Array of the LOD entities
        NativeArray <Entity> lods = new NativeArray <Entity>(4, Allocator.Temp);

        //Create all the LOD Entities in bulk
        entityManager.CreateEntity(treeType, lods);

        //Loop through each entity of a detail level
        for (int i = 0; i < 4; i++)
        {
            CreateLOD(lods[i], lodGroupEntity, lodElements[i].mesh, lodElements[i].mat, GetLODMask(i), pos, rot, scale, bounds, entityManager);
        }

        lods.Dispose();
    }
Пример #15
0
    /// <summary>
    /// Sets up the various information for a single LOD entity.
    /// </summary>
    /// <param name="lodLevelEntity"> An rendered Entity for a specific detail level </param>
    /// <param name="lodGroupEntity"> The manager for the LOD group. A single entity with 'MeshLODGroupComponent' </param>
    /// <param name="mesh">The mesh for this detail level</param>
    /// <param name="mat">The material for this detail level</param>
    /// <param name="LODMask">The LODMask (does this define which view range applies in some kind of bitfield-manner?) </param>
    /// <param name="position">The mesh world position</param>
    /// <param name="rotation">The mesh rotation</param>
    /// <param name="size">The mesh scale</param>
    /// <param name="bounds">The render bounds of the mesh</param>
    /// <param name="manager">The entity manager to set component data</param>
    void CreateLOD(Entity lodLevelEntity, Entity lodGroupEntity, Mesh mesh, Material mat, int LODMask, float3 position, quaternion rotation, float size, RenderBounds bounds, EntityManager manager)
    {
        //Create Render Mesh fpr the Index
        RenderMesh renderMesh = new RenderMesh
        {
            mesh           = mesh,
            material       = mat,
            subMesh        = 0,
            castShadows    = ShadowCastingMode.Off,
            receiveShadows = false
        };

        //Set all Data
        manager.SetComponentData(lodLevelEntity, new Translation {
            Value = position
        });
        manager.SetComponentData(lodLevelEntity, new Scale {
            Value = size
        });
        manager.SetSharedComponentData(lodLevelEntity, renderMesh);
        manager.SetComponentData(lodLevelEntity, bounds);
        manager.SetComponentData(lodLevelEntity, new Rotation {
            Value = rotation
        });

        //Setup the LOD Component. Set the Group to be the Parent, and get a Mask for the LOD
        manager.SetComponentData(lodLevelEntity, new MeshLODComponent {
            Group = lodGroupEntity, LODMask = LODMask
        });
    }
Пример #16
0
		public RenderBoundsPresent(RenderBounds renderBounds)
		{
			this.renderBounds = renderBounds;
		}
        private void EnemyCollision(ref EnemyData _enemyData, Translation _targetPos, ref Translation _bulletPos, ref RenderBounds _bounds, ref BulletData _bullet)
        {
            float3 bound = _bounds.Value.Extents;

            if (_bulletPos.Value.x - bound.x <= _targetPos.Value.x && _targetPos.Value.x <= _bulletPos.Value.x + bound.x &&
                _bulletPos.Value.y - bound.y <= _targetPos.Value.y && _targetPos.Value.y <= _bulletPos.Value.y + bound.y &&
                _bulletPos.Value.z - bound.z <= _targetPos.Value.z && _targetPos.Value.z <= _bulletPos.Value.z + bound.z)
            {
                // バレットを消すように見せかける
                Debug.Log($"EnemyHit\nRange ({_bulletPos.Value.x -bound.x}, {_bulletPos.Value.x +bound.x})\n({_bulletPos.Value.y -bound.y}, {_bulletPos.Value.y +bound.y})\n({_bulletPos.Value.z -bound.z}, {_bulletPos.Value.z +bound.z})\n");
                _bulletPos.Value.x = GameConst.SCREEN_WIDTH;
                _bulletPos.Value.z = GameConst.SCREEN_HEIGHT;
                _enemyData.HP     -= _bullet.Damage;
                _bullet.IsCollide  = true;
            }
        }
        private void PlayerCollision(ref PlayerData _playerData, Translation _targetPos, ref Translation _bulletPos, ref RenderBounds _bounds, ref BulletData _bullet)
        {
            float3 bound = _bounds.Value.Extents;

            if (_bulletPos.Value.x - bound.x <= _targetPos.Value.x && _targetPos.Value.x <= _bulletPos.Value.x + bound.x &&
                _bulletPos.Value.y - bound.y <= _targetPos.Value.y && _targetPos.Value.y <= _bulletPos.Value.y + bound.y &&
                _bulletPos.Value.z - bound.z <= _targetPos.Value.z && _targetPos.Value.z <= _bulletPos.Value.z + bound.z)
            {
                // バレットを消すように見せかける
                _bulletPos.Value.x = GameConst.SCREEN_WIDTH;
                _bulletPos.Value.z = GameConst.SCREEN_HEIGHT;
                _playerData.Life  -= _bullet.Damage;
                _bullet.IsCollide  = true;
            }
        }
Пример #19
0
 public override bool HandleMouseInput(MouseInput mi)
 {
     return(!ClickThrough && RenderBounds.Contains(mi.Location));
 }
Пример #20
0
        private void SpawnParticles(int count)
        {
            float2 bottomLeft = (Vector2)Camera.main.ScreenToWorldPoint(new Vector2(0, 0));
            float2 topRight   = (Vector2)Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, Screen.height));

            RenderMesh rm = new RenderMesh
            {
                mesh           = _particleMesh,
                material       = _particleMaterial,
                castShadows    = ShadowCastingMode.Off,
                receiveShadows = false
            };

            RenderBounds bounds = new RenderBounds {
                Value = { Extents = new float3(1, 1, 1) }
            };

            NativeArray <Entity> particles = new NativeArray <Entity>(count, Allocator.TempJob);

            _entityManager.CreateEntity(_particleType, particles);

            Random r = new Random((uint)(1 + count + Time.time * 1000));

            float2 minVal = new float2(-_particleMaxSpeed, -_particleMaxSpeed);
            float2 maxVel = new float2(_particleMaxSpeed, _particleMaxSpeed);

            for (int i = 0; i < particles.Length; i++)
            {
                float mass   = r.NextFloat(_particleMass.x, _particleMass.y);
                float radius = math.pow(3 / (4 * math.PI) * mass / _particleDensity, 1f / 3f);
                float scale  = radius * 2f;

                Translation pos = new Translation()
                {
                    Value = new float3(r.NextFloat2(bottomLeft, topRight), 0f)
                };

                Entity particle = particles[i];
                _entityManager.SetComponentData(particle, pos);
                _entityManager.SetComponentData(particle, bounds);
                _entityManager.SetSharedComponentData(particle, rm);
                _entityManager.SetComponentData(particle, new Mass()
                {
                    Value = mass
                });
                _entityManager.SetComponentData(particle, new Velocity()
                {
                    Value = r.NextFloat2(minVal, maxVel)
                });
                _entityManager.SetComponentData(particle, new Radius()
                {
                    Value = radius
                });
                _entityManager.SetComponentData(particle, new Scale()
                {
                    Value = scale
                });
            }

            particles.Dispose();
        }