Exemple #1
0
    private void EyedropperInput(MapTileGridCreator.Core.Cell selectedCell)
    {
        if (Event.current.type == EventType.Layout)
        {
            HandleUtility.AddDefaultControl(0);             // Consume the event
        }

        //Select prefab from pallett and got to paint
        if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
        {
            GameObject prefabInstance = selectedCell.gameObject;
            GameObject prefab         = FuncEditor.GetPrefabFromInstance(prefabInstance);

            int newIndex = _pallet.FindIndex(x => x.Equals(prefab));
            if (newIndex >= 0)
            {
                _mode_paint   = (int)PaintMode.Single;
                _pallet_index = newIndex;
                Debug.Log("Prefab " + prefab.name + " selected.");
            }
            else
            {
                Debug.LogError("Prefab is not from the pallet");
            }
        }
        //Cancel
        else if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
        {
            _mode_paint = PaintMode.Single;
        }
    }
Exemple #2
0
    /// <summary>
    /// Check if it's a authorized move :
    ///		-Destination is not a cell existing (occupied).
    ///		-Destination above an existing cell that have a layer in ground's layermask
    /// </summary>
    /// <param name="futureIndex"> The index to test.</param>
    /// <returns>True if it's ok, false otherwise.</returns>
    private bool CheckIndexMovable(Vector3Int futureIndex)
    {
        Vector3Int groundInd = futureIndex;

        groundInd.y--;
        MapTileGridCreator.Core.Cell ground = _grid.TryGetCellByIndex(ref groundInd);
        return(_grid.HaveCell(ref groundInd) && !_grid.HaveCell(ref futureIndex) && _ground_layermask.HaveLayer(ground.gameObject.layer));
    }
Exemple #3
0
    private void EraseInput(Vector3 input)
    {
        if (Event.current.type == EventType.Layout)
        {
            HandleUtility.AddDefaultControl(0);
        }

        //Erase cell
        if ((Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseDrag) && Event.current.button == 0)
        {
            Vector3Int index = _grid.GetIndexByPosition(ref input);
            MapTileGridCreator.Core.Cell cell = _grid.TryGetCellByIndex(ref index);

            if (cell != null)
            {
                _grid.DeleteCell(cell);
                Selection.SetActiveObjectWithContext(_grid.gameObject, null);
                Undo.DestroyObjectImmediate(cell.gameObject);
            }
        }
    }
Exemple #4
0
    /// <summary>
    /// Test selection for auto link grid to the window.
    /// </summary>
    public void SelectionGridSceneView()
    {
        GameObject select = Selection.activeGameObject;

        if (select != null)
        {
            Grid3D grid = null;
            if (FuncEditor.IsGameObjectSceneView(select))
            {
                grid = select.GetComponent <Grid3D>();
                if (grid == null)
                {
                    MapTileGridCreator.Core.Cell cell = select.GetComponent <MapTileGridCreator.Core.Cell>();
                    grid = cell != null?cell.GetGridParent() : null;
                }
            }

            if (grid != null)
            {
                UpdateGridSelected(grid);
            }
        }
    }
Exemple #5
0
    ////////////////////////////////////////
    // Paint differents modes

    private void PaintEdit()
    {
        switch (_mode_paint)
        {
        case PaintMode.Single:
        {
            Vector3 input = GetGridPositionInput(0.5f, _collide_with_plane);
            PaintInput(input);
            DebugCellAtPosition(input, DebugsColor.destination_editor);
        }
        break;

        case PaintMode.Erase:
        {
            Vector3 input = GetGridPositionInput(-0.5f, false);
            EraseInput(input);
            MapTileGridCreator.Core.Cell selected = _grid.TryGetCellByPosition(ref input);
            if (selected != null)
            {
                DebugCellAtPosition(input, DebugsColor.erase_editor, 1.5f);
            }
        }
        break;

        case PaintMode.Eyedropper:
        {
            Vector3 input = GetGridPositionInput(-0.1f, false);
            MapTileGridCreator.Core.Cell selected = _grid.TryGetCellByPosition(ref input);
            EyedropperInput(selected);
            if (selected != null)
            {
                DebugCellAtPosition(selected.transform.position, DebugsColor.eyedropper_editor, 1.05f);
            }
        }
        break;
        }
    }