Exemple #1
0
 public override bool Equals(object obj)
 {
     return(obj is LocalToCamera camera &&
            cameraLTW.Equals(camera.cameraLTW) &&
            clipPlane.Equals(camera.clipPlane) &&
            EqualityComparer <UILength> .Default.Equals(offsetX, camera.offsetX) &&
            EqualityComparer <UILength> .Default.Equals(offsetY, camera.offsetY) &&
            alignment == camera.alignment);
 }
Exemple #2
0
 public bool Equals(BoardConfig c)
 {
     if (!size.Equals(c.size))
     {
         return(false);
     }
     if (sdfTexture != c.sdfTexture)
     {
         return(false);
     }
     if (heightMap != c.heightMap)
     {
         return(false);
     }
     if (heightScale.Equals(c.heightScale))
     {
         return(false);
     }
     if (neighborThreshold.Equals(c.neighborThreshold))
     {
         return(false);
     }
     if (forceFactor.Equals(c.forceFactor))
     {
         return(false);
     }
     if (quadTree != c.quadTree)
     {
         return(false);
     }
     return(true);
 }
Exemple #3
0
 protected override void OnUpdate()
 {
     Entities.ForEach((ref MoveComponent moveComponent, ref PlayerComponent playerComponent) => {
         float2 dir = float2.zero;
         if (Input.GetKey(KeyCode.W))
         {
             dir.y = dir.y + 1;
         }
         if (Input.GetKey(KeyCode.S))
         {
             dir.y = dir.y - 1;
         }
         if (Input.GetKey(KeyCode.A))
         {
             dir.x = dir.x - 1;
         }
         if (Input.GetKey(KeyCode.D))
         {
             dir.x = dir.x + 1;
         }
         if (!dir.Equals(float2.zero))
         {
             moveComponent.dragDir      = math.normalize(dir);
             moveComponent.dragDirLenth = math.length(dir);
         }
         else
         {
             moveComponent.dragDir      = dir;
             moveComponent.dragDirLenth = 0;
         }
     });
 }
        public static bool IsSegmentIntersectsPoint(float2 segmentStart, float2 segmentEnd, float2 point, float radius = 0)
        {
            //получить уравнеие прямой
            var lineEquation = GetLineEquation(segmentStart, segmentEnd);
            //получить уравнение перпендикулярной прямой
            var perpendicularLineEquation = GetPerpendicularLineEquation(point, lineEquation);
            //найти точку пересечения прямых
            var crossPoint = GetLinesCrossPoint(lineEquation, perpendicularLineEquation);//совпадать прямые не могут!

            //если пересеччени нет, то это фалс
            if (float.IsNaN(crossPoint.x) || float.IsNaN(crossPoint.y))
            {
                return(false);
            }
            //если точки совпадают, то эта тру
            if (point.Equals(crossPoint))
            {
                return(true);
            }
            //определить находится ли пересечение в отрезке
            if (!PointInsideRect(segmentStart, segmentEnd, point))
            {
                return(false);
            }
            //найти расстояние от точки пересечения до point
            var sqrRadius = radius * radius;
            var sqrDist   = math.distancesq(crossPoint, point);

            //если оно не больше radius, то норм
            return(sqrDist <= sqrRadius);
        }
Exemple #5
0
        protected override void OnUpdate()
        {
            if (!_down)
            {
                EntityManager.DestroyEntity(_entityLineTempOld);
                _entityLineTempOld = _entityLineTemp;
            }


            if (_processBorder.Start != Entity.Null && _processBorder.End == Entity.Null && _down && _inputToActionSystem.Process)
            {
                if (_oldPos.Equals(_inputToActionSystem.PositionCurrent))
                {
                    return;
                }

                _oldPos = _inputToActionSystem.PositionCurrent;
                float3 posS   = EntityManager.GetComponentData <Translation>(_processBorder.Start).Value;
                float3 float3 = new float3(_inputToActionSystem.PositionCurrent.x, _inputToActionSystem.PositionCurrent.y, 0);


                EntityManager.DestroyEntity(_entityLineTempOld);
                _entityLineTempOld = _entityLineTemp;
                _entityLineTemp    = DrawLine(posS, float3);
            }
        }
Exemple #6
0
 void Update()
 {
     viewerPosition = new float2(viewer.position.x, viewer.position.z);
     if (!viewerPosition.Equals(LastPosViewer) || terrainChunkDico.Count == 0) // for some reason chunks created are disable
     {
         UpdateVisibleChunks();
         LastPosViewer = viewerPosition;
     }
 }
Exemple #7
0
        public SimpleTerminal WithTileSize(float2 tileSize)
        {
            if (tileSize.Equals(_tileSize))
            {
                return(this);
            }

            _isDirty  = true;
            _tileSize = tileSize;
            _backend.WithTileSize(tileSize);
            return(this);
        }
Exemple #8
0
 public bool Equals(TerrainCollision t)
 {
     if (sdfTexture != t.sdfTexture)
     {
         return(false);
     }
     if (!size.Equals(t.size))
     {
         return(false);
     }
     return(true);
 }
Exemple #9
0
 public bool Equals(SimpleMaterial other)
 {
     return(texAlbedo.Equals(other.texAlbedo) &&
            texOpacity.Equals(other.texOpacity) &&
            constAlbedo.Equals(other.constAlbedo) &&
            constOpacity.Equals(other.constOpacity) &&
            (twoSided == other.twoSided) &&
            (blend == other.blend) &&
            (transparent == other.transparent) &&
            scale.Equals(other.scale) &&
            offset.Equals(other.offset));
 }
    protected override void OnGamePresentationUpdate()
    {
        if (SimWorld.TryGetComponent(SimEntity, out PhysicsVelocity velocity))
        {
            float2 velocity2D = (float2)velocity.Linear;

            if (!velocity2D.Equals(float2(0, 0)))
            {
                float angle = degrees(angle2d(velocity2D)) + _offset;
                _tr.rotation = Quaternion.Euler(Vector3.forward * angle);
            }
        }
    }
 protected override void OnUpdate()
 {
     foreach (var entity in GetEntities <Data>())
     {
         float2 p = entity.Position.Value;
         float2 h = entity.Heading.Value;
         entity.Output.position = new float3(p.x, 0, p.y);
         if (!h.Equals(new float2(0f, 0f)))
         {
             entity.Output.rotation = quaternion.LookRotation(new float3(h.x, 0f, h.y), new float3(0f, 1f, 0f));
         }
     }
 }
Exemple #12
0
 public bool Equals(HeightMap h)
 {
     if (heightMap != h.heightMap)
     {
         return(false);
     }
     if (!size.Equals(h.size))
     {
         return(false);
     }
     if (heightScale.Equals(h.heightScale))
     {
         return(false);
     }
     return(true);
 }
        public static int2 WorldToTileIndex(float3 worldPos,
                                            float3 terminalPos,
                                            int2 terminalSize,
                                            float2 tileSize = default)
        {
            if (tileSize.Equals(0))
            {
                tileSize = new float2(1, 1);
            }

            float3 local = (worldPos - terminalPos);

            local.xy /= tileSize;
            local.xy += terminalSize / 2;

            return((int2)math.floor(local.xy));
        }
    private              float3[] SimplifyPath(List <Node> path)
    {
        NativeList <float3> wayPoints = new NativeList <float3>(0);
        float2 directionOld           = float2.zero;

        for (int i = 1; i < path.Count; i++)
        {
            float2 directionNew = new float2(path[i - 1].gridX - path[i].gridX, path[i - 1].gridY - path[i].gridY);
            if (!directionNew.Equals(directionOld))
            {
                wayPoints.Add(path[i].worldPosition);
            }
            directionOld = directionNew;
        }
        float3[] points = wayPoints.ToArray();
        wayPoints.Dispose();
        return(points);
    }
Exemple #15
0
 public bool Equals(LitMaterial other)
 {
     return(texAlbedo.Equals(other.texAlbedo) &&
            texMetal.Equals(other.texMetal) &&
            texNormal.Equals(other.texNormal) &&
            texEmissive.Equals(other.texEmissive) &&
            texSmoothness.Equals(other.texSmoothness) &&
            texOpacity.Equals(other.texOpacity) &&
            constAlbedo.Equals(other.constAlbedo) &&
            constEmissive.Equals(other.constEmissive) &&
            constOpacity.Equals(other.constOpacity) &&
            constMetal.Equals(other.constMetal) &&
            constSmoothness.Equals(other.constSmoothness) &&
            normalMapZScale.Equals(other.normalMapZScale) &&
            (twoSided == other.twoSided) &&
            (transparent == other.transparent) &&
            (triangleSortTransparent == other.triangleSortTransparent) &&
            scale.Equals(other.scale) &&
            offset.Equals(other.offset));
 }
Exemple #16
0
        protected UvTransform?TextureRotationSlider(
            Material material,
            UvTransform?uvTransform,
            int scaleTransformPropertyId,
            int rotationPropertyId,
            bool freezeScale = false
            )
        {
            UvTransform oldUvTransform;
            UvTransform newUvTransform;

            if (uvTransform.HasValue)
            {
                oldUvTransform = uvTransform.Value;
                newUvTransform = uvTransform.Value;
            }
            else
            {
                GetUvTransform(material, scaleTransformPropertyId, rotationPropertyId, out oldUvTransform);
                newUvTransform = new UvTransform();
            }

            GUILayout.BeginHorizontal();
            GUILayout.Label("Texture Rotation");
            var newUvRotation = EditorGUILayout.Slider(oldUvTransform.rotation, 0, 360);

            GUILayout.EndHorizontal();

            float2 newUvScale = new float2(1, 1);

            if (!freezeScale)
            {
                GUILayout.BeginHorizontal();
                newUvScale = EditorGUILayout.Vector2Field("Scale", oldUvTransform.scale);
                GUILayout.EndHorizontal();
            }

            if (!uvTransform.HasValue)
            {
                newUvTransform.rotation = newUvRotation;
                newUvTransform.scale    = newUvScale;
            }

            bool update = false;

            if (Math.Abs(newUvRotation - oldUvTransform.rotation) > TOLERANCE)
            {
                newUvTransform.rotation = newUvRotation;
                update = true;
            }

            if (!freezeScale && !newUvScale.Equals(oldUvTransform.scale))
            {
                newUvTransform.scale = newUvScale;
                update = true;
            }

            if (update)
            {
                var      cos = math.cos(newUvTransform.rotation * Mathf.Deg2Rad);
                var      sin = math.sin(newUvTransform.rotation * Mathf.Deg2Rad);
                var      currentScaleTransform = material.GetVector(scaleTransformPropertyId);
                float2x2 rotScale = math.mul(new float2x2(cos, sin, -sin, cos), new float2x2(newUvTransform.scale.x, 0, 0, newUvTransform.scale.y));
                material.SetVector(scaleTransformPropertyId, new Vector4(rotScale.c0.x, rotScale.c1.y, currentScaleTransform.z, currentScaleTransform.w));
                material.SetVector(rotationPropertyId, new Vector4(rotScale.c1.x, rotScale.c0.y, 0, 0));
                if (newUvTransform.rotation == 0)
                {
                    material.DisableKeyword(KW_UV_ROTATION);
                }
                else
                {
                    material.EnableKeyword(KW_UV_ROTATION);
                }
                return(newUvTransform);
            }

            return(uvTransform);
        }
Exemple #17
0
        protected float midDisp2d(float2 target, Func <float2, float> getter,
                                  float2 topLeftIndex, float topLeftValue, float2 topRightIndex, float topRightValue,
                                  float2 bottomLeftIndex, float bottomLeftValue, float2 bottomRightIndex, float bottomRightValue)
        {
            if (target.Equals(topLeftIndex))
            {
                return(topLeftValue);
            }

            if (target.Equals(topRightIndex))
            {
                return(topRightValue);
            }

            if (target.Equals(bottomLeftIndex))
            {
                return(bottomLeftValue);
            }

            if (target.x == topLeftIndex.x)
            {
                return(midDisp1d(target.y, y => getter(new float2(target.x, y)), topLeftIndex.y, topLeftValue, bottomLeftIndex.y, bottomLeftValue));
            }

            if (target.y == topLeftIndex.y)
            {
                return(midDisp1d(target.x, x => getter(new float2(x, target.y)), topLeftIndex.x, topLeftValue, topRightIndex.x, topRightValue));
            }

            if (target.Equals(bottomRightIndex))
            {
                return(bottomRightValue);
            }

            if (target.x == bottomRightIndex.x)
            {
                return(midDisp1d(target.y, y => getter(new float2(target.x, y)),
                                 topRightIndex.x, topRightValue, bottomRightIndex.y, bottomRightValue));
            }

            if (target.y == bottomRightIndex.y)
            {
                return(midDisp1d(target.x, x => getter(new float2(x, target.y)),
                                 bottomLeftIndex.y, bottomLeftValue, bottomRightIndex.y, bottomRightValue));
            }

            for (var i = 0; i < divisions; i++)
            {
                var centerLeftIndex = (topLeftIndex + bottomLeftIndex) / 2;
                var centerLeftValue = (topLeftValue + bottomLeftValue) / 2 + getter(centerLeftIndex);

                var centerTopIndex = (topLeftIndex + topRightIndex) / 2;
                var centerTopValue = (topLeftValue + topRightValue) / 2 + getter(centerTopIndex);

                var centerRightIndex = (topRightIndex + bottomRightIndex) / 2;
                var centerRightValue = (topRightValue + bottomRightValue) / 2 + getter(centerRightIndex);

                var centerBottomIndex = (bottomLeftIndex + bottomRightIndex) / 2;
                var centerBottomValue = (bottomLeftValue + bottomRightValue) / 2 + getter(centerBottomIndex);

                var centerIndex = new float2(centerTopIndex.x, centerLeftIndex.y);
                var centerValue = (centerLeftValue + centerTopValue + centerRightValue + centerBottomValue) / 4;

                if (target.Equals(centerIndex))
                {
                    return(centerValue);
                }

                if (target.x == centerIndex.x)
                {
                    if (target.y < centerIndex.y)
                    {
                        return(midDisp1d(target.y, y => getter(new float2(target.x, y)),
                                         centerTopIndex.y, centerTopValue, centerIndex.y, centerValue));
                    }
                    else if (target.y > centerIndex.y)
                    {
                        return(midDisp1d(target.y, y => getter(new float2(target.x, y)),
                                         centerIndex.y, centerValue, centerBottomIndex.y, centerBottomValue));
                    }
                }
                else if (target.y == centerIndex.y)
                {
                    if (target.x < centerIndex.x)
                    {
                        return(midDisp1d(target.x, x => getter(new float2(x, target.y)),
                                         centerLeftIndex.x, centerLeftValue, centerIndex.x, centerValue));
                    }
                    else if (target.x > centerIndex.x)
                    {
                        return(midDisp1d(target.x, x => getter(new float2(x, target.y)),
                                         centerIndex.x, centerValue, centerRightIndex.x, centerRightValue));
                    }
                }

                if (target.x < centerIndex.x)
                {
                    if (target.y < centerIndex.y)
                    {
                        bottomLeftIndex = centerLeftIndex;
                        bottomLeftValue = centerLeftValue;

                        bottomRightIndex = centerIndex;
                        bottomRightValue = centerValue;

                        topRightIndex = centerTopIndex;
                        topRightValue = centerTopValue;
                    }
                    else if (target.y > centerIndex.y)
                    {
                        topLeftIndex = centerLeftIndex;
                        topLeftValue = centerLeftValue;

                        topRightIndex = centerIndex;
                        topRightValue = centerValue;

                        bottomRightIndex = centerBottomIndex;
                        bottomRightValue = centerBottomValue;
                    }
                }
                else if (target.x > centerIndex.x)
                {
                    if (target.y < centerIndex.y)
                    {
                        topLeftIndex = centerTopIndex;
                        topLeftValue = centerTopValue;

                        bottomLeftIndex = centerIndex;
                        bottomLeftValue = centerValue;

                        bottomRightIndex = centerRightIndex;
                        bottomRightValue = centerRightValue;
                    }
                    else if (target.y > centerIndex.y)
                    {
                        bottomLeftIndex = centerBottomIndex;
                        bottomLeftValue = centerBottomValue;

                        topLeftIndex = centerIndex;
                        topLeftValue = centerValue;

                        topRightIndex = centerRightIndex;
                        topRightValue = centerRightValue;
                    }
                }
            }

            return(float.NaN);
        }
Exemple #18
0
 /// <summary>
 /// Returns true iff this equals rhs component-wise.
 /// </summary>
 public static bool Equals(float2 v, float2 rhs) => v.Equals(rhs);
 public bool Equals(PointSampleLocal other)
 {
     return(position.Equals(other.position) && headingRadians.Equals(other.slope));
 }
 public static bool Float2Equals(ref float2 a, ref float2 b)
 {
     return(a.Equals(b));
 }
 public bool Equals(GcHitResult other)
 => HitPoint.Equals(other.HitPoint) &&
 HitNormal.Equals(other.HitNormal) &&
 SinkVecInv.Equals(other.SinkVecInv);
Exemple #22
0
 /// <summary>
 /// Returns true iff this equals rhs type- and component-wise.
 /// </summary>
 public static bool Equals(float2 v, object obj) => v.Equals(obj);
Exemple #23
0
 public bool Equals(FBoundSection Target)
 {
     return(boundBox.Equals(Target.boundBox) && pivotPosition.Equals(Target.pivotPosition));
 }
 public bool Equals(Line other)
 {
     // fixed later
     return(pos.Equals(other.pos) &&
            vec.Equals(other.vec));
 }
Exemple #25
0
 public bool Equals(PhysicsTransform other)
 {
     return(Translation.Equals(other.Translation) && Rotation.Equals(other.Rotation));
 }
Exemple #26
0
    public int CreateEntity(string name, bool _place, float2 _location = new float2())
    {
        float  entityHealth = 50;
        float  fcellSize    = 0.32f;
        float2 ValueF       = new float2(0f, 0f);

        if (ValueF.Equals(_location))
        {
            ValueF = SetRandomLocation();
        }
        else
        {
            ValueF = _location;
        }
        int2 ValueI      = ConvertFloat2(ValueF);
        bool isWalkabler = PathfindingGridSetup.Instance.pathfindingGrid.GetGridObject(ValueI.x, ValueI.y).IsWalkable();

        if (_place)
        {
            if (!isWalkabler)
            {
                Debug.Log("not walkable");
                return(-1);
            }
        }
        ValueF = ValueF * fcellSize;
        var    settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore);
        Entity myPrefab;

        if (name == "kobolt")
        {
            myPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(koboltPrefab, settings);
        }
        else if (name == "dragon")
        {
            myPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(dragonPrefab, settings);
        }
        else
        {
            myPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(smithyPrefab, settings);
        }

        var instance = entityManager.Instantiate(myPrefab);

        if (name == "kobolt")
        {
            entityManager.AddComponentData(instance, new RaceComponent()
            {
                race = 0
            });
            entityManager.AddComponentData(instance, new Kobolt()
            {
            });
            entityManager.AddComponentData(instance, new SectorEntity {
                typeEnum = SectorEntity.TypeEnum.Unit
            });
            entityManager.AddComponentData(instance, new HealthComponent()
            {
                maxHealth = 30, health = 30
            });
            entityManager.AddComponentData(instance, new AttackComponent()
            {
                isAttacking = false, nrOfAttacks = 1, timer = 1, range = 2, weapon = 0
            });
            entityManager.AddComponentData(instance, new WeaponComponent()
            {
                weapon = 0, toHit = 0, damage = 5
            });
            entityManager.AddComponentData(instance, new MoraleComponent()
            {
                baseMorale = 5
            });
            entityHealth = 30;
        }
        else
        {
            entityManager.AddComponentData(instance, new RaceComponent()
            {
                race = 1
            });
            entityManager.AddComponentData(instance, new Dragon()
            {
            });
            entityManager.AddComponentData(instance, new SectorEntity {
                typeEnum = SectorEntity.TypeEnum.Target
            });
            entityManager.AddComponentData(instance, new HealthComponent()
            {
                maxHealth = 100, health = 100
            });
            entityManager.AddComponentData(instance, new AttackComponent()
            {
                isAttacking = false, nrOfAttacks = 4, timer = 1, range = 1, weapon = 0
            });
            entityManager.AddComponentData(instance, new WeaponComponent()
            {
                weapon = 0, toHit = 2, damage = 20
            });
            entityManager.AddComponentData(instance, new SeekComponent()
            {
            });
            entityHealth = 100;
        }
        entityManager.SetComponentData(instance, new Translation()
        {
            Value = new float3(new float3(ValueF.x, ValueF.y, -0.1f))
        });
        entityManager.AddComponentData(instance, new IDComponent()
        {
            id = GameController.Instance.GetID()
        });
        entityManager.AddComponentData(instance, new MovementComponent()
        {
            isMoving = false, speed = 1.2f
        });
        entityManager.AddComponentData(instance, new PathFollow()
        {
        });
        entityManager.AddComponentData(instance, new Selected()
        {
            isSelected = false
        });
        entityManager.AddComponentData(instance, new FactionComponent()
        {
        });
        entityManager.AddComponentData(instance, new DeathComponent()
        {
            isDead = false, corpseTimer = 50.0f
        });
        entityManager.AddComponentData(instance, new TargetableComponent()
        {
        });
        entityManager.AddComponentData(instance, new TargetComponent()
        {
        });
        entityManager.AddComponentData(instance, new RoamingComponent()
        {
        });
        entityManager.AddComponentData(instance, new StateComponent()
        {
        });
        entityManager.AddComponentData(instance, new OrderComponent()
        {
            hasOrders = false
        });
        entityManager.AddBuffer <PathPosition>(instance);
        PathPosition someBufferElement          = new PathPosition();
        DynamicBuffer <PathPosition> someBuffer = entityManager.GetBuffer <PathPosition>(instance);

        someBufferElement.position = new int2(ValueI.x, ValueI.y);
        someBuffer.Add(someBufferElement);
        someBufferElement.position = new int2(ValueI.x, ValueI.y);
        someBuffer.Add(someBufferElement);
        GameController.Instance.AddUnit(name, new Vector3(ValueF.x, ValueF.y, -0.1f), entityHealth);
        return(0);
    }