Ejemplo n.º 1
0
    private IEnumerator CheckAligningWithPosition(Vector2 cornerPosition)
    {
        Vector2 halfWorldScale        = VectorHelper.Abs(transform.localScale) / 2;
        Vector2 characterCornerOffset = VectorHelper.Multiply(halfWorldScale, playerVelocityRef.Get().MoveDirection);

        while (true)
        {
            Vector2 characterCornerPosition         = (Vector2)transform.position + characterCornerOffset;
            Vector2 offsetToCharacterCornerPosition = characterCornerPosition - cornerPosition;

            if (VectorHelper.VectorsAxisesHaveSameSigns(offsetToCharacterCornerPosition, cornerDirection))
            {
                if (OnAlignWithTarget != null)
                {
                    OnAlignWithTarget(cornerPosition);
                }
                break;
            }

            yield return(null);
        }

        currentTargetCornerTransform     = null;
        checkAligningWithTargetCoroutine = null;
    }
Ejemplo n.º 2
0
    public static int GetDifferenceInDirection(Vector3 position, Vector3 direction)
    {
        direction = direction.normalized;
        List <Vector3> inColumn    = new List <Vector3> ();
        Vector3        valueFinder = VectorHelper.BinaryInverse(direction);

        valueFinder = VectorHelper.Abs(valueFinder);
        Vector3 columnPosition = VectorHelper.Multiply(position, valueFinder);
        Vector3 valueGetter    = VectorHelper.Abs(direction);
        float   min            = -1;

        foreach (Vector3Int key in Level.Singleton.Entities.Keys)
        {
            Vector3 keyV = key.PositionFloats;
            if (!(position == keyV) &&
                VectorHelper.Eq(VectorHelper.Multiply(keyV, valueFinder), columnPosition))
            {
                Vector3 directionTemp = keyV - position;
                float   diff          = Vector3.Dot(direction, directionTemp);
                if (diff > 0)
                {
                    if (min == -1)
                    {
                        min = diff;
                    }
                    else
                    {
                        min = Mathf.Min(min, diff);
                    }
                }
            }
        }
        return(Mathf.RoundToInt(min));
    }
    private GameObject InstantiateRectangleStandardTile(List <Vector2> rectangle, Transform parent)
    {
        Vector2 centerGridPosition = rectangle.Center();
        Vector2 startGridPosition  = rectangle.Lowest();
        Vector2 endGridPosition    = rectangle.Highest();

        Vector2 centerWorldPosition = LevelEditorGridHelper.GridToNodePosition(centerGridPosition);

        Vector2 startWorldPosition = LevelEditorGridHelper.GridToNodePosition(startGridPosition);
        Vector2 endWorldPosition   = LevelEditorGridHelper.GridToNodePosition(endGridPosition);
        Vector2 offset             = VectorHelper.Abs(endWorldPosition - startWorldPosition);

        float nodeSize = LevelEditorGridNodeSizeLibrary.Instance.NodeSize;

        float   width  = offset.x + nodeSize;
        float   height = offset.y + nodeSize;
        Vector2 scale  = new Vector2(width, height);

        GenerateableTileNode generatableTileNode = GenerateableTileLibrary.GetGeneratableTileNode(TileType.Standard);
        GameObject           standardTile        = Object.Instantiate(generatableTileNode.Prefab, centerWorldPosition, new Quaternion(), parent);

        standardTile.transform.localScale = scale;

        return(standardTile);
    }
Ejemplo n.º 4
0
 private ComputationResult Abs(ComputationResult computationResult)
 {
     if (computationResult.IsValue)
     {
         return(new ComputationResult(Math.Abs(computationResult.LiteralValue)));
     }
     else if (computationResult.IsVectorResult)
     {
         var retVector = computationResult.Accumulator ? computationResult.VectorData : computationResult.VectorData.CreateSimilarArray <float>();
         var flat      = retVector.GetFlatData();
         VectorHelper.Abs(flat, computationResult.VectorData.GetFlatData());
         return(new ComputationResult(retVector, true));
     }
     else
     {
         var retMatrix = computationResult.Accumulator ? computationResult.OdData : computationResult.OdData.CreateSimilarArray <float>();
         var flat      = retMatrix.GetFlatData();
         VectorHelper.Abs(flat, computationResult.OdData.GetFlatData());
         return(new ComputationResult(retMatrix, true));
     }
 }