Example #1
0
        private void CheckForDirtAndCleanIfPossible()
        {
            if (_currentCapacity == 0)
            {
                return;
            }

            // Check tile below me
            var realWorldPosition = transform.position;

            var vLocPos = _doodadsBackgroundTilemap.transform.InverseTransformPoint(realWorldPosition);
            var gridX   = BrushUtil.GetGridX(vLocPos, _doodadsBackgroundTilemap.CellSize);
            var gridY   = BrushUtil.GetGridY(vLocPos, _doodadsBackgroundTilemap.CellSize);


            var gridPosition = TilemapUtils.GetGridPosition(
                _doodadsBackgroundTilemap,
                new Vector2(realWorldPosition.x, realWorldPosition.y)
                );

            gridPosition = new Vector2(gridX, gridY);

            var tileData = _doodadsBackgroundTilemap.GetTileData(gridPosition);

            // Remove the tile below me!
            if (IsDirtTile(tileData))
            {
                _doodadsBackgroundTilemap.Erase(gridPosition);
                _doodadsBackgroundTilemap.UpdateMesh();
                _currentCapacity--;
            }
        }
        public override object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var min                = (double)values[4];
            var max                = (double)values[5];
            var value              = (double)values[6];
            var direction          = (ProgressDirection)values[7];
            var orientation        = (Orientation)values[8];
            var foreground         = values[9] as Brush;
            var invertedForeground = values[10] as Brush;
            var actualWidth        = (orientation == Orientation.Horizontal ? values[0] : values[1]) as double? ?? 0;
            var textWidth          = (orientation == Orientation.Horizontal ? values[2] : values[3]) as double? ?? 0;

            if (textWidth == 0 || actualWidth == 0)
            {
                return(foreground);
            }

            var totalPercent = ((value - min) / (max - min));
            var percentWidth = actualWidth * totalPercent;
            var innerWidth   = percentWidth - ((actualWidth - textWidth) / 2);

            if (innerWidth <= 0)
            {
                return(foreground);
            }
            else if (innerWidth >= textWidth)
            {
                return(invertedForeground);
            }

            var innerPercent = innerWidth / textWidth;

            if (orientation == Orientation.Horizontal)
            {
                switch (direction)
                {
                case ProgressDirection.Normal:
                    return(BrushUtil.GetStackedVisualBrush(invertedForeground, foreground, Orientation.Horizontal, innerPercent));

                case ProgressDirection.Inverse:
                    return(BrushUtil.GetStackedVisualBrush(foreground, invertedForeground, Orientation.Horizontal, 1 - innerPercent));
                }
            }
            else
            {
                switch (direction)
                {
                case ProgressDirection.Normal:
                    return(BrushUtil.GetStackedVisualBrush(foreground, invertedForeground, Orientation.Vertical, 1 - innerPercent));

                case ProgressDirection.Inverse:
                    return(BrushUtil.GetStackedVisualBrush(invertedForeground, foreground, Orientation.Vertical, innerPercent));
                }
            }
            return(null);
        }
Example #3
0
        /// <summary>
        /// けしけし
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="layer"></param>
        /// <param name="position"></param>
        public override void Erase(GridLayout grid, GameObject layer, Vector3Int position)
        {
            foreach (var obj in AllObjects)
            {
                if (grid.WorldToCell(obj.transform.position) == position)
                {
                    DestroyImmediate(obj.gameObject);

                    EditorUtil.Select(BrushUtil.GetRootGrid(false).gameObject);
                    return;
                }
            }
        }
Example #4
0
    /// <summary>
    /// レイヤーの取得
    /// </summary>
    /// <returns></returns>
    public Transform GetLayer()
    {
        Transform layer = BrushUtil.GetRootGrid(false).transform.Find(_layerName);

        if (layer == null)
        {
            GameObject newGameObject = new GameObject(_layerName);
#if UNITY_EDITOR
            Undo.RegisterCreatedObjectUndo(newGameObject, "Create " + _layerName);
#endif
            layer = newGameObject.transform;
            layer.SetParent(BrushUtil.GetRootGrid(false).transform);
        }
        return(layer);
    }
Example #5
0
        /// <summary>
        /// 配置
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="brushTarget"></param>
        /// <param name="position"></param>
        public override void Paint(GridLayout grid, GameObject layer, Vector3Int position)
        {
            var target = GetObject(grid, position);

            if (target != null)
            {
                return;
            }

            if (ActiveObject != null)
            {
                EditorUtil.Select(BrushUtil.GetRootGrid(false).gameObject);
            }

            base.Paint(grid, layer, position);
        }
Example #6
0
 /// <summary>
 /// けしけし
 /// </summary>
 /// <param name="grid"></param>
 /// <param name="layer"></param>
 /// <param name="position"></param>
 public override void Erase(GridLayout grid, GameObject layer, Vector3Int position)
 {
     foreach (var door in AllObjects)
     {
         if (grid.WorldToCell(door.transform.position) == position)
         {
             DestroyDoor(door);
             EditorUtil.Select(BrushUtil.GetRootGrid(false).gameObject);
             return;
         }
         if (door._key != null && grid.WorldToCell(door._key.transform.position) == position)
         {
             DestroyImmediate(door._key.gameObject);
             door._key = null;
             EditorUtil.SetDirty(door);
         }
     }
 }
Example #7
0
        /// <summary>
        /// ペイント
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="layer"></param>
        /// <param name="position"></param>
        public override void Paint(GridLayout grid, GameObject layer, Vector3Int position)
        {
            if (ActiveObject != null)
            {
                if (ActiveObject._key == null)
                {
                    // キーを作成して設定
                    var newKey = EditorUtil.Instantiate(_keyPrefab, grid.LocalToWorld(grid.CellToLocalInterpolated(position + OffsetFromBottomLeft)), GetLayer());
                    var key    = newKey.GetComponent <Doorkey>();
                    key._event = ActiveObject;
                    EditorUtil.SetDirty(newKey);

                    ActiveObject._key = key;
                    EditorUtil.SetDirty(ActiveObject);
                }
                else
                {
                    EditorUtil.Select(BrushUtil.GetRootGrid(false).gameObject);
                }
            }
            base.Paint(grid, layer, position);
        }