Ejemplo n.º 1
0
    void DrawDebugCellGrid()
    {
        Color    color       = new Color(1, 0, 0, 0.3f);
        Color    freeColor   = new Color(1, 1, 1, 0.03f);
        Vector2i pos         = Iso.Snap(Iso.MapToIso(Camera.main.transform.position));
        int      debugWidth  = 100;
        int      debugHeight = 100;

        pos.x -= debugWidth / 2;
        pos.y -= debugHeight / 2;
        int index = instance.MapToIndex(pos);

        for (int y = 0; y < debugHeight; ++y)
        {
            for (int x = 0; x < debugWidth; ++x)
            {
                if (index + x < 0 || index + x >= instance.map.Length)
                {
                    continue;
                }

                if (!instance.map[index + x].passable)
                {
                    Iso.DebugDrawTile(pos + new Vector3(x, y), color, 0.9f);
                }
                else
                {
                    Iso.DebugDrawTile(pos + new Vector3(x, y), freeColor, 0.9f);
                }
            }
            index += width;
        }
    }
Ejemplo n.º 2
0
    static public RaycastHit Raycast(Vector2 from, Vector2 to, float rayLength = Mathf.Infinity, float maxRayLength = Mathf.Infinity, int size = 1, GameObject ignore = null, bool debug = false)
    {
        var hit     = new RaycastHit();
        var diff    = to - from;
        var stepLen = 0.2f;

        if (rayLength == Mathf.Infinity)
        {
            rayLength = Mathf.Min(diff.magnitude, maxRayLength);
        }
        int stepCount = Mathf.RoundToInt(rayLength / stepLen);
        var step      = diff.normalized * stepLen;
        var pos       = from;

        for (int i = 0; i < stepCount; ++i)
        {
            pos += step;
            if (debug)
            {
                Iso.DebugDrawTile(Iso.Snap(pos), margin: 0.3f, duration: 0.5f);
            }
            Cell cell     = GetCell(pos);
            bool passable = Passable(pos, size, debug, ignore);
            if (!passable)
            {
                hit.hit        = !passable;
                hit.gameObject = cell.gameObject;
                hit.pos        = pos;
                break;
            }
        }
        return(hit);
    }
Ejemplo n.º 3
0
 void Update()
 {
     TryUseSkill();
     OperateWithTarget();
     _hasMoved = false;
     MoveToTargetPoint();
     Turn();
     Iso.DebugDrawTile(iso.pos, party == Party.Good ? Color.green : Color.red, 0.3f);
 }
Ejemplo n.º 4
0
 void Update()
 {
     TryUseSkill();
     OperateWithTarget();
     hasMoved = false;
     MoveToTargetPoint();
     Turn();
     Iso.DebugDrawTile(iso.pos, 0.3f);
 }
Ejemplo n.º 5
0
    private void DrawDebugCellGrid()
    {
        Color    occupiedColor = new Color(1, 0, 0, 0.3f);
        Color    passableColor = new Color(1, 1, 1, 0.03f);
        Vector2i origin        = Iso.Snap(Iso.MapToIso(Camera.main.transform.position));
        int      debugWidth    = 100;
        int      debugHeight   = 100;

        origin.x -= debugWidth / 2;
        origin.y -= debugHeight / 2;
        for (int y = 0; y < debugHeight; ++y)
        {
            for (int x = 0; x < debugWidth; ++x)
            {
                var   pos      = origin + new Vector2i(x, y);
                bool  passable = CollisionMap.Passable(pos, layers);
                Color color    = passable ? passableColor : occupiedColor;
                Iso.DebugDrawTile(pos, color, 0.9f);
            }
        }
    }
Ejemplo n.º 6
0
    public static bool Passable(int index, int size = 1, bool debug = false, GameObject ignore = null)
    {
        UnityEngine.Profiling.Profiler.BeginSample("PassableTile");
        if (index - size - size * instance.width < 0 || index + size + size * instance.width >= instance.map.Length)
        {
            return(false);
        }

        index = index - size / 2 - size / 2 * instance.height;
        int step = instance.width - size;

        for (int y = 0; y < size; ++y)
        {
            int end = index + size;
            while (index < end)
            {
                if (debug)
                {
                    var tilePos = instance.MapToIso(index);
                    Iso.DebugDrawTile(tilePos, 0.1f);
                }

                var cell = instance.map[index];
                if (!cell.passable && (ignore == null || ignore != cell.gameObject))
                {
                    UnityEngine.Profiling.Profiler.EndSample();
                    return(false);
                }
                ++index;
            }
            index += step;
        }

        UnityEngine.Profiling.Profiler.EndSample();

        return(true);
    }