예제 #1
0
    private void Awake()
    {
        CharacterMng.Instance.Init();
        UIMng.Instance.Init();
        AStarMng.Instance.Init();
        PlayerCharacter mainCharacter = CharacterMng.Instance.MainCharacter;

        UIMng.Instance.Open <VirtualJoystick>(UIMng.UIName.VirtualJoystick).Enabled(mainCharacter);
        UIMng.Instance.Open <MapUI>(UIMng.UIName.MapUI);

        string    path  = "Assets/AStarBuildArray.astar";
        TextAsset asset = new TextAsset(File.ReadAllText(path));

        string[]   value = asset.text.Split('_');
        GameObject obj   = new GameObject(typeof(AGrid).ToString(), typeof(AGrid));
        AGrid      grid  = obj.GetComponent <AGrid>();

        string[] arr = value[0].Split(',');
        grid.UnwalkableLayer = int.Parse(arr[0]);
        grid.NodeRadius      = float.Parse(arr[1]);
        grid.WorldSize.x     = float.Parse(arr[2]);
        grid.WorldSize.y     = float.Parse(arr[3]);
        grid.CreateGrid(value);
        AStarMng.Instance.Grid = grid;
    }
    void SetGrid(ref Vector2 size)
    {
        Vector2 uiSize = new Vector2(400, 20);

        size.y += 10;

        m_grid.UnwalkableLayer = EditorGUI.LayerField(new Rect(size, uiSize), m_grid.UnwalkableLayer);
        size.y += 30;

        m_grid.WorldSize = EditorGUI.Vector2Field(new Rect(size, uiSize), "WorldSize", m_grid.WorldSize);
        size.y          += 40;

        EditorGUI.LabelField(new Rect(size.x, size.y, uiSize.x * 0.4f, uiSize.y), "NodeRadius");
        m_grid.NodeRadius = EditorGUI.FloatField(new Rect(uiSize.x * 0.4f, size.y, uiSize.x * 0.6f, uiSize.y), m_grid.NodeRadius);
        size.y           += 40;

        if (m_grid.WorldSize != Vector2.zero && m_grid.NodeRadius > 0.1f && m_grid.UnwalkableLayer != 0)
        {
            if (GUI.Button(new Rect(size.x, size.y, uiSize.x, 20), "Create Grid"))
            {
                m_grid.CreateGrid();
            }

            size.y += 25;

            if (m_grid.Nodes != null)
            {
                if (GUI.Button(new Rect(size.x, size.y, uiSize.x, 20), "Test PathFinding"))
                {
                    AStarTestEditor.Window(m_grid);
                }

                size.y += 25;
            }

            if (GUI.Button(new Rect(size.x, size.y, uiSize.x, 20), "Build Grid"))
            {
                BuildPathGrid();
            }

            size.y += 25;
        }
    }
    static AGrid LoadPathGrid()
    {
        string path = "Assets/AStarBuildArray.astar";

        if (!File.Exists(path))
        {
            return(null);
        }

        TextAsset asset = new TextAsset(File.ReadAllText(path));

        string[]   value = asset.text.Split('_');
        GameObject obj   = new GameObject(typeof(AGrid).ToString(), typeof(AGrid));
        AGrid      grid  = obj.GetComponent <AGrid>();

        string[] arr = value[0].Split(',');
        grid.UnwalkableLayer = int.Parse(arr[0]);
        grid.NodeRadius      = float.Parse(arr[1]);
        grid.WorldSize.x     = float.Parse(arr[2]);
        grid.WorldSize.y     = float.Parse(arr[3]);
        grid.CreateGrid(value);
        return(grid);
    }