Esempio n. 1
0
    void Update()
    {
        ModeUpdate();
        if (!activated)
        {
            return;
        }

        // tool state update
        if (lastIcon != constructionUI.selectedIcon)
        {
            LoadBrush(constructionUI.selectedIcon);
            lastIcon = constructionUI.selectedIcon;
        }

        // pointing the world
        if (!eventsystem.IsPointerOverGameObject() && !constructionUI.helpVideo.activeSelf)
        {
            RaycastHit hit;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 200f, 1 << LayerMask.NameToLayer("Ground")))
            {
                Vector2Int chunkPointing = MapChunk.WorldToCell(hit.point);
                Vector3Int tilePointing  = modifier.WorldToCell(hit.point);
                Vector3    pointing      = modifier.GetTileCenter(tilePointing);

                // make chunk batches disabled
                if (grid.grid.ContainsKey(chunkPointing) && lastChunkPointing != chunkPointing)
                {
                    if (grid.grid.ContainsKey(lastChunkPointing))
                    {
                        grid.grid[lastChunkPointing].SetBatchVisible(true);
                    }
                    grid.grid[chunkPointing].SetBatchVisible(false);
                    lastChunkPointing = chunkPointing;
                }

                // update depending on selected tool
                if (brush != null)
                {
                    BrushToolUpdate(tilePointing, pointing);
                }
                else if (targetLayer && targetLayer.layerType == ConstructionLayer.LayerType.Delete)
                {
                    DeleteToolUpdate(tilePointing, pointing);
                }
            }
        }
    }
Esempio n. 2
0
    void Update()
    {
        if (focusAgent != null)
        {
            Vector3 d = focusAgent.position - lastUpdatePosition;
            if (Mathf.Abs(d.x) > streamingThresholds.x || Mathf.Abs(d.z) > streamingThresholds.y)
            {
                Vector3Int agentCell = modifier.tilemap.WorldToCell(focusAgent.position);
                agentCell = new Vector3Int(agentCell.x, agentCell.y, (int)modifier.tilemap.transform.position.z);

                TerrainUpdate(agentCell);
                lastUpdatePosition = modifier.GetTileCenter(modifier.tilemap.WorldToCell(focusAgent.position));
            }
        }
    }