void Update() { if (!editorGrid && !(editorGrid = GameObject.FindGameObjectWithTag("EditorGrid").GetComponent <EditorGrid>())) { Debug.LogWarning("No GameObject with tag `EditorGrid`"); return; } if (oldOffset != editorGrid.offset) { Vector3 cur_offset = editorGrid.offset; Vector3Int temp_cell = editorGrid.LocalToCell(transform.localPosition, oldOffset); transform.localPosition = editorGrid.CellToLocal(temp_cell, cur_offset); oldOffset = editorGrid.offset; transform.hasChanged = false; } else if (transform.hasChanged) { transform.localPosition = editorGrid.GetCellSnappedPosition(transform.localPosition); transform.hasChanged = false; } }
bool LevelRaycast() { Ray r = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(r, out RaycastHit hit, 100f, LayerMask.GetMask(new string[] { "Level", "Friendly", "Hostile" }))) { int level_layer = LayerMask.NameToLayer("Level"); int friendly_layer = LayerMask.NameToLayer("Friendly"); int hostile_layer = LayerMask.NameToLayer("Hostile"); hovering_block = hit.transform.gameObject; int layer = hovering_block.layer; // Level tile if (layer == level_layer) { hovering_target.transform.position = hit.transform.position; Target.Dir dir = Target.GetDir(hit.normal.normalized); hovering_target.Direction = dir; } else { hovering_target.transform.position = g.transform.localToWorldMatrix * g.CellToLocal(g.LocalToCell(hit.transform.localPosition) + Vector3Int.down); hovering_target.Direction = Target.Dir.Up; } // Set target color if (layer == friendly_layer) { hovering_target.SetColor(friendlyColor, defaultTargetAlpha); } else if (layer == hostile_layer) { hovering_target.SetColor(hostileColor, defaultTargetAlpha); } else { hovering_target.SetColor(neutralColor, defaultTargetAlpha); } // Activate target if (!hovering_target.gameObject.activeSelf) { hovering_target.gameObject.SetActive(true); } // Return return(true); }