Пример #1
0
        private void ConstructQuadTree(CaseContentGrid caseContentGrid)
        {
            //_quadTree = new CoordQuadTree(new Rect(Position - Size/2, Size));

            //_quadTree.MAX_OBJECTS = _maxObjectCount;
            //_quadTree.MAX_LEVELS = _maxLevelCount;

            //float caseSideLength = caseContentGrid.CaseSize - _offset*2;

            //Vector2 caseSize = new Vector2(caseSideLength, caseSideLength);
            //Vector2 offset = caseSize/2 - new Vector2(_offset, _offset);

            //Rect caseBounds = new Rect(new Vector2(), caseSize);

            //for (int i = 0; i < caseContentGrid.width; i++)
            //{
            //    for (int j = 0; j < caseContentGrid.height; j++)
            //    {
            //        if (caseContentGrid[i][j] == ECaseContent.Blocking)
            //        {
            //            caseBounds.position = caseContentGrid.GetCasePosition(i, j) - offset;

            //            _quadTree.Insert(new Vector2i(i, j), caseBounds);
            //        }
            //    }
            //}
        }
Пример #2
0
        private void CreateNew(string name)
        {
            string path = folder;

            string guid = AssetDatabase.CreateFolder(path, name);

            path = AssetDatabase.GUIDToAssetPath(guid);

            name = Path.GetFileName(path);

            _data = ScriptableObjectUtility.CreateAsset <MapEditorData>(path, name);
            CaseContentGrid grid = ScriptableObjectUtility.CreateAsset <CaseContentGrid>(path, name + "_grid");

            _data.Grid = grid;

            int colorsSize = 2;

            _data.Colors = new List <ColorContent>(colorsSize);

            for (int i = 0; i < colorsSize; i++)
            {
                _data.Colors.Add(new ColorContent((ECaseContent)i));
            }

            mapEditor.Data = _data;

            _serializedData = new SerializedObject(_data);
            _serializedGrid = new SerializedObject(_data.Grid);
        }
Пример #3
0
        //// source : http://playtechs.blogspot.nl/2007/03/raytracing-on-grid.html
        //private List<Vector2i> MyRaytrace(float x0, float y0, float x1, float y1)
        //{
        //    List<Vector2i> visitedCoords = new List<Vector2i>();

        //    float dx = Mathf.Abs(x1 - x0);
        //    float dy = Mathf.Abs(y1 - y0);

        //    Vector2i startCoord = GetCoordAt(x0, y0).Value;
        //    Vector2i endCoord = GetCoordAt(x1, y1).Value;

        //    Vector2 startCasePosition = GetCasePosition(startCoord);
        //    //Vector2 endCasePosition = GetCasePosition(endCoord);

        //    Debug.Log("Start : " + startCoord);
        //    Debug.Log("End : " + endCoord);

        //    int n = 1;
        //    int x_inc, y_inc;
        //    float error;

        //    if (dx == 0)
        //    {
        //        x_inc = 0;
        //        error = float.PositiveInfinity;
        //    }
        //    else if (x1 > x0)
        //    {
        //        x_inc = 1;
        //        n += endCoord.x - startCoord.x;
        //        error = (startCasePosition.x + 1 - x0) * dy;
        //    }
        //    else
        //    {
        //        x_inc = -1;
        //        n += startCoord.x - endCoord.x;
        //        error = (x0 - startCasePosition.x) * dy;
        //    }

        //    if (dy == 0)
        //    {
        //        y_inc = 0;
        //        error -= float.PositiveInfinity;
        //    }
        //    else if (y1 > y0)
        //    {
        //        y_inc = 1;
        //        n += endCoord.y - startCoord.y;
        //        error -= (startCasePosition.y + 1 - y0) * dx;
        //    }
        //    else
        //    {
        //        y_inc = -1;
        //        n += startCoord.y - endCoord.y;
        //        error -= (y0 - startCasePosition.y) * dx;
        //    }

        //    for (; n > 0; --n)
        //    {
        //        Vector2i visitedCoord = new Vector2i(startCoord.x, startCoord.y);

        //        visitedCoords.Add(visitedCoord);

        //        Debug.Log("Visit : " + visitedCoord + " (error : " + error + ")");

        //        if (error > 0)
        //        {
        //            startCoord.y += y_inc;
        //            error -= dx;
        //        }
        //        else
        //        {
        //            startCoord.x += x_inc;
        //            error += dy;
        //        }
        //    }

        //    return visitedCoords;
        //}

        //// source : http://playtechs.blogspot.nl/2007/03/raytracing-on-grid.html
        //private List<Vector2i> Raytrace(float x0, float y0, float x1, float y1)
        //{
        //    List<Vector2i> visitedCoords = new List<Vector2i>();

        //    float dx = Mathf.Abs(x1 - x0);
        //    float dy = Mathf.Abs(y1 - y0);

        //    int x = (int) Mathf.Floor(x0);
        //    int y = (int) Mathf.Floor(y0);

        //    int n = 1;
        //    int x_inc, y_inc;
        //    float error;

        //    if (dx == 0)
        //    {
        //        x_inc = 0;
        //        error = float.PositiveInfinity;
        //    }
        //    else if (x1 > x0)
        //    {
        //        x_inc = 1;
        //        n += (int)(Mathf.Floor(x1)) - x;
        //        error = (Mathf.Floor(x0) + 1 - x0) * dy;
        //    }
        //    else
        //    {
        //        x_inc = -1;
        //        n += x - (int) Mathf.Floor(x1);
        //        error = (x0 - Mathf.Floor(x0)) * dy;
        //    }

        //    if (dy == 0)
        //    {
        //        y_inc = 0;
        //        error -= float.PositiveInfinity;
        //    }
        //    else if (y1 > y0)
        //    {
        //        y_inc = 1;
        //        n += (int)(Mathf.Floor(y1)) - y;
        //        error -= (Mathf.Floor(y0) + 1 - y0) * dx;
        //    }
        //    else
        //    {
        //        y_inc = -1;
        //        n += y - (int)(Mathf.Floor(y1));
        //        error -= (y0 - Mathf.Floor(y0)) * dx;
        //    }

        //    for (; n > 0; --n)
        //    {
        //        visitedCoords.Add(new Vector2i(x, y));

        //        if (error > 0)
        //        {
        //            y += y_inc;
        //            error -= dx;
        //        }
        //        else
        //        {
        //            x += x_inc;
        //            error += dy;
        //        }
        //    }

        //    return visitedCoords;
        //}

        private void ConstructNavGrid(CaseContentGrid caseContentGrid)
        {
            _cases = new List <List <NodeRecord> >();

            ResizeFrom(caseContentGrid);

            for (int i = 0; i < caseContentGrid.width; i++)
            {
                for (int j = 0; j < caseContentGrid.height; j++)
                {
                    if (caseContentGrid[i][j] == ECaseContent.None)
                    {
                        this[i][j] = new NodeRecord(new Vector2i(i, j));
                    }
                }
            }
        }
Пример #4
0
        //[SerializeField] private CoordQuadTree _quadTree;

        public void ConstructFrom(CaseContentGrid caseContentGrid)
        {
            ConstructNavGrid(caseContentGrid);
            ConstructQuadTree(caseContentGrid);
        }