hOW to convert 45.67890 in 45.7 in google sheets
- User
hOW to convert 45.67890 in 45.7 in google sheets
- Assistant
In Google Sheets, if you want to display the number 45.67890 as 45.7, you would round the number to one decimal place. You can achieve this using the ROUND function. Here's how:
- Suppose the value 45.67890 is in cell A1.
- In a new cell where you want to display the rounded value, type the formula:
=ROUND(A1, 1)
This formula rounds the number in cell A1 to 1 decimal place, which will give you the result 45.7.
Alternatively, if you simply want to change the display format without altering the data, you can use the toolbar formatting options:
- Click on the cell that contains the value 45.67890.
- Go to the Format menu, choose 'Number', and then select 'Custom number format...'
- In the custom number format dialogue, enter
0.0into the text box and press "Apply."
The cell will now display the number with only one decimal place (45.7), even though the underlying value will still be 45.67890.
- User
Sort column but not title on sheets
- Assistant
To sort a column in Google Sheets without including the title (or header), follow these steps:
- Click on the cell below the header in the column you want to sort. For example, if your header is in the first row and you want to sort column A, click on cell A2.
- Hold down the Shift key, then click on the last cell in the column with data that you want to include in the sort. This will select the range that you want to sort without including the header.
- Once the range is selected, go to the "Data" menu at the top of the page.
- Choose either "Sort range by column A-Z" or "Sort range by column Z-A" (depending on whether you want an ascending or descending sort) and the corresponding letter for your column.
- For an ascending sort: "Sort range A → Z"
- For a descending sort: "Sort range Z → A"
Make sure the selection does not include the header row.
Alternatively, you can use the "Sort range" option for more control:
- Select the range you want to sort (excluding the header).
- Go to the "Data" menu at the top of the page.
- Click on "Sort range" instead of "Sort range A–Z" or "Sort range Z–A".
- In the pop-up window, select the column you want to sort by and choose whether it should be sorted A→Z or Z→A (ascending or descending).
- Make sure the "Data has header row" option is unchecked since you are not selecting the header.
- Click "Sort."
This will sort the selected range, leaving the header row in place.
- User
How do i set my header row
- Assistant
Google Sheets allows you to designate a row as a header (also known as a "frozen" row) so that it remains visible as you scroll through the sheet. Here's how you can freeze the first row as a header:
- Open your Google Sheets spreadsheet.
- Click on the row number of the row you want to set as the header to highlight the entire row. Usually, this is row 1.
- Go to the "View" menu.
- Hover over the "Freeze" option in the drop-down menu.
- Select "1 row" from the submenu. (If you wish to freeze more than one row, for example, the first two rows, then select "2 rows" instead.)
After you complete these steps, you'll notice a thicker grey line appears underneath the frozen row(s), indicating that the row has been set as the header. Now, when you scroll down through your sheet, the top row(s) will remain visible.
Alternatively, you can freeze the header row using the separator bar:
- Locate the gray bar that separates the row numbers from the sheet's grid. It will be right above the row numbers on the left side.
- Hover over the gray bar until your cursor turns into a hand icon.
- Click and drag the gray bar downward to cover the number of rows you want to freeze.
- Release the mouse button when the desired row(s) are highlighted.
The rows above the bar will now be frozen and will remain visible as you scroll through the spreadsheet.
- User
Check if collider is all inside another collider Unity
- Assistant
In Unity, to check if one collider (let's call it "Collider A") is entirely inside another collider ("Collider B"), you'll need to write some custom logic since there isn't an out-of-the-box method in Unity that directly checks for this condition.
Here is a general approach using the
Physicsclass and assuming we are working withCollidercomponents, notCollider2D(used for 2D physics). Note that the specifics might vary based on the types of colliders you’re using (e.g., box, sphere, capsule, mesh), but this should provide a starting point:-
Get the Bounds: First, get the
boundsproperty of both colliders. This will provide you with the world space bounding volumes of the colliders. -
Check Corners or Points: For a simple box collider, you can check if all the corners (or a set of sufficient points) of Collider A are within Collider B. For more complex shapes, you might need to check more points to ensure accuracy.
Here is an example of how you might check if all corners of a BoxCollider A are inside another BoxCollider B:
bool IsColliderInsideAnother(Collider inner, Collider outer) { BoxCollider innerBoxCollider = inner as BoxCollider; // Assume collider A is of type BoxCollider if (innerBoxCollider == null) return false; // Calculate the local space bounds of the inner collider var innerMin = innerBoxCollider.center - innerBoxCollider.size * 0.5f; var innerMax = innerBoxCollider.center + innerBoxCollider.size * 0.5f; // Calculate world space positions of the corners of the inner collider var innerCorners = new Vector3[8] { innerBoxCollider.transform.TransformPoint(innerMin), innerBoxCollider.transform.TransformPoint(new Vector3(innerMax.x, innerMin.y, innerMin.z)), innerBoxCollider.transform.TransformPoint(new Vector3(innerMin.x, innerMax.y, innerMin.z)), innerBoxCollider.transform.TransformPoint(new Vector3(innerMax.x, innerMax.y, innerMin.z)), innerBoxCollider.transform.TransformPoint(new Vector3(innerMin.x, innerMin.y, innerMax.z)), innerBoxCollider.transform.TransformPoint(new Vector3(innerMax.x, innerMin.y, innerMax.z)), innerBoxCollider.transform.TransformPoint(new Vector3(innerMin.x, innerMax.y, innerMax.z)), innerBoxCollider.transform.TransformPoint(innerMax) }; // Test each corner to see if it is within the outer collider's bounds foreach (Vector3 corner in innerCorners) { if (!outer.bounds.Contains(corner)) { return false; // At least one corner is outside the outer collider } } return true; // All corners are inside the outer collider }Keep in mind this is a simplified example. It assumes that the inner collider is a box shape and that checking the corners is sufficient to confirm that it's entirely inside the outer collider. For other collider types (i.e., spheres, capsules, or mesh colliders), you would have to adapt the code to ensure all relevant points of Collider A are within Collider B. For non-box shapes, it might be necessary to sample more points on the surface or within the volume of the collider, not just the corners.
Moreover, this code doesn't take into consideration rotation or complex mesh shapes; Collider B is assumed here to have bounds that can be accurately represented with a bounding box.
For a more nuanced approach that works with any type of Collider, you might need to implement a custom solution that handles all the subtleties of the involved shapes. In some cases, the Physics.ComputePenetration method could be useful for determining whether colliders intersect, but additional logic would be needed to determine if one is fully inside the other.
-
- User
how to create a evento handler with bool value
- Assistant
In C# and Unity, you can create an event handler that accepts a bool value by using the
EventHandlerclass with a customEventArgssubclass or by defining a custom delegate. Here's how you can do both:Using EventHandler with Custom EventArgs
First, create a custom
EventArgssubclass to hold your boolean value:public class BoolEventArgs : EventArgs { public bool Value { get; private set; } public BoolEventArgs(bool value) { Value = value; } }Next, you can define an event with this custom
EventArgs:public event EventHandler<BoolEventArgs> OnBoolEvent; protected virtual void RaiseBoolEvent(bool val) { OnBoolEvent?.Invoke(this, new BoolEventArgs(val)); }Now, you can subscribe to the event and handle it like this:
void OnEnable() { // Subscribe to the event someClassInstance.OnBoolEvent += HandleBoolEvent; } void OnDisable() { // Unsubscribe from the event someClassInstance.OnBoolEvent -= HandleBoolEvent; } private void HandleBoolEvent(object sender, BoolEventArgs e) { // Handle the event bool receivedValue = e.Value; // Do something with the received value }Using a Custom Delegate
Alternatively, you can define a custom delegate type that accepts a
boolparameter directly:// Define the delegate type public delegate void BoolEventHandler(bool value); // Define the event based on the delegate type public event BoolEventHandler OnBoolEvent; protected virtual void RaiseBoolEvent(bool val) { OnBoolEvent?.Invoke(val); }Then, you can also subscribe to and handle the event in a similar manner:
void OnEnable() { // Subscribe to the event someClassInstance.OnBoolEvent += HandleBoolEvent; } void OnDisable() { // Unsubscribe from the event someClassInstance.OnBoolEvent -= HandleBoolEvent; } private void HandleBoolEvent(bool value) { // Handle the event // Do something with the received value }Both methods are effective, and the choice depends on your specific needs. If you are going to pass only a boolean value and nothing else, the custom delegate method is more straightforward. If you anticipate needing to pass additional data along with your event in the future, using EventHandler with custom EventArgs is more flexible and adheres to .NET conventions.
- User
And what if I want to send two arguments
- Assistant
If you want to send two arguments with an event in Unity or C#, you'll have to create a custom
EventArgssubclass or define a custom delegate that accepts multiple parameters.Here's how you can do this using both methods:
Using EventHandler with Custom EventArgs
Create a custom
EventArgssubclass to hold your multiple values:public class CustomEventArgs : EventArgs { public bool BoolValue { get; private set; } public int IntValue { get; private set; } public CustomEventArgs(bool boolValue, int intValue) { BoolValue = boolValue; IntValue = intValue; } }Now, define your event with this new custom
EventArgs:public event EventHandler<CustomEventArgs> OnCustomEvent; protected virtual void RaiseCustomEvent(bool boolVal, int intVal) { OnCustomEvent?.Invoke(this, new CustomEventArgs(boolVal, intVal)); }Subscribe and handle the event:
void OnEnable() { someClassInstance.OnCustomEvent += HandleCustomEvent; } void OnDisable() { someClassInstance.OnCustomEvent -= HandleCustomEvent; } private void HandleCustomEvent(object sender, CustomEventArgs e) { bool receivedBool = e.BoolValue; int receivedInt = e.IntValue; // Do something with the received values }Using a Custom Delegate
Define a custom delegate type that accepts the multiple parameters you need:
// Define the delegate type public delegate void CustomEventHandler(bool boolValue, int intValue); // Define the event with your custom delegate public event CustomEventHandler OnCustomEvent; protected virtual void RaiseCustomEvent(bool boolVal, int intVal) { OnCustomEvent?.Invoke(boolVal, intVal); }Subscribe and handle the event:
void OnEnable() { someClassInstance.OnCustomEvent += HandleCustomEvent; } void OnDisable() { someClassInstance.OnCustomEvent -= HandleCustomEvent; } private void HandleCustomEvent(bool boolValue, int intValue) { // Handle the event // Do something with the received values }Again, the choice between using
EventHandler<CustomEventArgs>or defining a custom delegate depends on your preference and needs. CustomEventArgsare recommended if you plan to follow .NET conventions and want to keep options open for extending the event data in the future. However, for a simple case where the event arguments are unlikely to change or grow, a custom delegate is more straightforward. - User
It doesnot work, could be because it is not in global coordinates?
private bool IsColliderInsideAnother(Collider inner, Collider outer) { BoxCollider innerBoxCollider = inner as BoxCollider; // Assume collider A is of type BoxCollider if (innerBoxCollider == null) return false;
// Calculate the local space bounds of the inner collider var innerMin = innerBoxCollider.center - innerBoxCollider.size * 0.5f; var innerMax = innerBoxCollider.center + innerBoxCollider.size * 0.5f; // Calculate world space positions of the corners of the inner collider var innerCorners = new Vector3[8] { innerBoxCollider.transform.TransformPoint(innerMin), innerBoxCollider.transform.TransformPoint(new Vector3(innerMax.x, innerMin.y, innerMin.z)), innerBoxCollider.transform.TransformPoint(new Vector3(innerMin.x, innerMax.y, innerMin.z)), innerBoxCollider.transform.TransformPoint(new Vector3(innerMax.x, innerMax.y, innerMin.z)), innerBoxCollider.transform.TransformPoint(new Vector3(innerMin.x, innerMin.y, innerMax.z)), innerBoxCollider.transform.TransformPoint(new Vector3(innerMax.x, innerMin.y, innerMax.z)), innerBoxCollider.transform.TransformPoint(new Vector3(innerMin.x, innerMax.y, innerMax.z)), innerBoxCollider.transform.TransformPoint(innerMax) }; // Test each corner to see if it is within the outer collider’s bounds foreach (Vector3 corner in innerCorners) { if (!outer.bounds.Contains(corner)) { return false; // At least one corner is outside the outer collider } } return true; // All corners are inside the outer collider } - Assistant
Apologies for the confusion earlier. If you want to check if a
Collideris entirely inside another, the provided method should already be working with world space coordinates considering it usesTransform.TransformPointto convert local points to world space andouter.bounds.Containsto check if the points are within the outer bounds also in world space.However, if it isn't working as expected, there could be several reasons why the
IsColliderInsideAnothermethod may fail:-
Collider Types: If
innerorouterare notBoxCollidertypes or have different types (like SphereCollider, CapsuleCollider, MeshCollider, etc.), the method would not work because it assumes a box shape for both colliders. -
Rotation: If the
innercollider has a rotation that isn't aligned with the world axes, the corners might not accurately reflect the true extremities in all directions. Theouter.bounds.Containsmethod works with an axis-aligned bounding box, which might not align with the rotated collider's actual shape. -
Inner Collider Bounds: The method for finding
innerMinandinnerMaxseems to be taking half the size from the center, which is correct for local space, but then incorrectly using them to find the world space corners. You should use theinnerBoxCollider.boundsto get the correct world space corners.
Here's an adjusted method taking into account
innerBoxCollider.bounds:private bool IsColliderInsideAnother(Collider inner, Collider outer) { BoxCollider innerBoxCollider = inner as BoxCollider; if (innerBoxCollider == null) return false; Bounds innerBounds = innerBoxCollider.bounds; Bounds outerBounds = outer.bounds; Vector3[] innerCorners = new Vector3[8] { innerBounds.min, new Vector3(innerBounds.max.x, innerBounds.min.y, innerBounds.min.z), new Vector3(innerBounds.min.x, innerBounds.max.y, innerBounds.min.z), new Vector3(innerBounds.max.x, innerBounds.max.y, innerBounds.min.z), new Vector3(innerBounds.min.x, innerBounds.min.y, innerBounds.max.z), new Vector3(innerBounds.max.x, innerBounds.min.y, innerBounds.max.z), new Vector3(innerBounds.min.x, innerBounds.max.y, innerBounds.max.z), innerBounds.max }; foreach (Vector3 corner in innerCorners) { if (!outerBounds.Contains(corner)) { return false; // At least one corner is outside the outer collider } } return true; // All corners are inside the outer collider }Remember that this method only checks the corners of an axis-aligned box. If the
innercollider rotates or if the colliders are not box-shaped, this method will not be accurate. For non-box colliders, you would need a much more complex method that accounts for the shape and rotation of the colliders.For
MeshCollider,SphereCollider, and other more complex shapes, geometric intersection tests become much more complicated. In such cases, you might need to rely on computational geometry libraries or algorithms suited to those specific shapes. -
- User
Update this method, I want to use Time.deltatime to update a progress bar
private IEnumerator TrainSoldier() { yield return new WaitForSeconds(timeToTrain); // Wait for the soldier to be trained
if(pendingSoldiers <= 0) yield break; pendingSoldiers--; // Get the next villager from the queue CreateSoldier(); isTraining = false; // Reset training flag } - Assistant
To update a progress bar using
Time.deltaTime, you need to modify theTrainSoldiercoroutine to incrementally update the progress over thetimeToTraininterval. Let's assume you have aProgressBarscript that controls the visual representation of your progress bar with a methodSetProgress(float progress)that takes a value between 0 and 1 to represent 0% to 100% progress.Here's an updated version of the
TrainSoldiercoroutine with a progress bar update:private IEnumerator TrainSoldier() { float elapsedTime = 0; // Track the elapsed time // Loop for the duration of 'timeToTrain' while (elapsedTime < timeToTrain) { // Wait until the next frame yield return null; // Increment the elapsed time by the time since the last frame elapsedTime += Time.deltaTime; // Calculate the training progress as a percentage float progress = Mathf.Clamp01(elapsedTime / timeToTrain); // Update the progress bar's visual representation UpdateProgressBar(progress); } if (pendingSoldiers <= 0) yield break; pendingSoldiers--; // Get the next villager from the queue CreateSoldier(); isTraining = false; // Reset training flag } private void UpdateProgressBar(float progress) { // Assuming you have a ProgressBar component progressBar.SetProgress(progress); }In the example above,
UpdateProgressBar(float progress)is a placeholder for your progress bar update logic. You should replaceprogressBar.SetProgress(progress);with the actual call to your progress bar's update method.Here's the breakdown of the changes made:
-
A
whileloop is used to keep the coroutine running untilelapsedTimeis greater than or equal totimeToTrain. -
Time.deltaTimeis used to track the elapsed time across frames. -
Mathf.Clamp01()is used to calculate the progress as a value between 0 and 1, making sure it does not go above 100%. -
The progress bar is updated every frame inside the loop.
-
After the loop ends (when the training time is completed), we proceed to decrement
pendingSoldiers, create a new soldier, and reset theisTrainingflag as before.
-
- User
If want buildingPanelManager.UpdateProduction(this, isDay, progress, message); always Updated with the correct values, now it is not doing it , how do I fix it?
using System; using System.Collections; using System.Collections.Generic; using Game.ImprovedAI; using Unity.Mathematics; using UnityEngine; using UnityEngine.Serialization; using Random = UnityEngine.Random;
namespace Game.Systems.Buildings { public class ArcherCamp : BuildingBase {
[Header("Building Stats")] [SerializeField] private GameObject archerPrefab; [SerializeField] private float timeToTrain = 5f; private List<ArcherController> archers = new List<ArcherController>(); private List<ArcherController> disabledArchers = new List<ArcherController>(); private bool isTraining = false; // Indicates if soldier is currently being trained private GameObject currentArcher; private Bounds spawnBounds; private string message; private float progress; public override void Init() { base.Init(); isDay = true; GameManager.Instance.OnDayStart += DayAction; GameManager.Instance.OnNightStart += NightAction; GameManager.Instance.BuilderManager.AddBuildingToQueue(this); GameManager.Instance.VillagerTracker.AddSoldierBuilding(this); if (GameManager.Instance.immediateBuild) { MarkAsComplete(); } else { GameManager.Instance.BuilderManager.AddBuildingToQueue(this); } message = "0 Soldiers in Queue"; progress = 0; } public override void InitPanel() { base.InitPanel(); showingPanel = true; buildingPanelManager.Init(BuildingPanelType.D, name, description, this); } private void Update() { if (!isTraining && pendingSoldiers > 0) { StartTraining(); } if (buildingPanelManager != null && showingPanel) { buildingPanelManager?.UpdateHealth(this, buildingHealth.health, buildingHealth.maxHealth); buildingPanelManager.UpdateProduction(this, isDay, progress, message); } } public override void BuildingAction() { base.BuildingAction(); } public override void AssignedVillager() { base.AssignedVillager(); pendingSoldiers++; // If training is not in progress, start training if (!isTraining) { StartTraining(); } } public override void RemoveVillager() { base.RemoveVillager(); if (assignedVillagers > 0) { assignedVillagers--; ArcherController archer = archers[0]; archer.gameObject.SetActive(false); disabledArchers.Add(archer); archers.RemoveAt(0); archer.DisableUnit(); } } public void RegenerateSoldier(ArcherController archer) { pendingSoldiers++; disabledArchers.Add(archer); archers.Remove(archer); } private void StartTraining() { if (pendingSoldiers > 0) { isTraining = true; // Set training flag to true StartCoroutine(TrainSoldier()); // Start the training coroutine } } private IEnumerator TrainSoldier() { float elapsedTime = 0; // Track the elapsed time // Loop for the duration of ‘timeToTrain’ while (elapsedTime < timeToTrain) { // Increment the elapsed time by the time since the last frame if (isDay) { elapsedTime += Time.deltaTime; } // Calculate the training progress as a percentage progress = Mathf.Clamp01(elapsedTime / timeToTrain); message = pendingSoldiers > 0 ? $"Soldiers in Queue {pendingSoldiers}"; // Wait until the next frame yield return null; } if (pendingSoldiers <= 0) { message = $"No soldiers in Queue"; progress = 0; yield break; } pendingSoldiers--; // Get the next villager from the queue CreateSoldier(); isTraining = false; // Reset training flag } private void CreateSoldier() { if (disabledArchers.Count == 0) { GameObject archerGO = Instantiate(archerPrefab, GetRandomPositionInArea(), Quaternion.Euler(0, 180, 0)); ArcherController archer = archerGO.GetComponent<ArcherController>(); if (archer != null) { archer.Init(this, archerGO.transform.position); archers.Add(archer); } } else { ArcherController soldier = disabledArchers[0]; soldier.gameObject.SetActive(true); soldier.transform.position = GetRandomPositionInArea(); soldier.transform.rotation = quaternion.Euler(0, 180, 0); soldier.Init(this, soldier.transform.position); disabledArchers.RemoveAt(0); archers.Add(soldier); } } public Vector3 GetRandomPositionInArea() { // Set the center of the spawn area. It is the position of the GameObject this script is attached to. Vector3 center = spawnPoint.transform.position; Vector3 areaSize = new Vector3(3.8f, 0f, 1.8f); // Calculate the min and max bounds for X and Z coordinates. Vector3 min = center - areaSize * 0.5f; Vector3 max = center + areaSize * 0.5f; // Choose a random position within the defined bounds Vector3 randomPosition = new Vector3( Random.Range(min.x, max.x), center.y, // This example spawns objects at the height of the center. Random.Range(min.z, max.z) ); return randomPosition; } public void DayAction(object sender, EventArgs args) { isDay = true; } public void NightAction(object sender, EventArgs args) { isDay = false; } public override void DemolishedAction() { base.DemolishedAction(); if (pendingSoldiers > 0) { GameManager.Instance.VillagersPlacer.AddVillagers(assignedVillagers); } buildingHealth.TakeDamage(float.MaxValue, true); GameManager.Instance.VillagerTracker.RemoveSoldierBuilding(this); } public override void DestroyedAction() { base.DestroyedAction(); if (showingPanel) { GameManager.Instance.BuildingPanelManager.DisableAllPanels(); } StopAllCoroutines(); } void OnDestroy() { // Stop all coroutines when the farm object is destroyed StopAllCoroutines(); GameManager.Instance.OnDayStart -= DayAction; GameManager.Instance.OnNightStart -= NightAction; } }}
- Assistant
It appears that you would like the progress bar (
buildingPanelManager.UpdateProduction) and the message (message) to be consistently updated throughout the duration of theTrainSoldiercoroutine, reflecting the current state of the soldier training process.To achieve this, you can modify the
TrainSoldiercoroutine to updatebuildingPanelManager.UpdateProductionat each step of the loop. This will ensure that the UI updates happen in real-time.Here's how your modified
TrainSoldiercoroutine might look:private IEnumerator TrainSoldier() { float elapsedTime = 0; // Track the elapsed time // Loop for the duration of ‘timeToTrain’ while (elapsedTime < timeToTrain) { // Increment the elapsed time by the time since the last frame if (isDay) { elapsedTime += Time.deltaTime; } // Calculate the training progress as a percentage progress = Mathf.Clamp01(elapsedTime / timeToTrain); // Update the message message = pendingSoldiers > 0 ? $"Soldiers in Queue: {pendingSoldiers}" : "No soldiers in Queue"; // Update the production display each frame as the soldier is being trained buildingPanelManager.UpdateProduction(this, isDay, progress, message); // Wait until the next frame yield return null; } if (pendingSoldiers <= 0) { message = "No soldiers in Queue"; progress = 0; buildingPanelManager.UpdateProduction(this, isDay, progress, message); yield break; } pendingSoldiers--; // Get the next villager from the queue CreateSoldier(); // Update the message and progress one final time after the soldier is trained message = pendingSoldiers > 0 ? $"Soldiers in Queue: {pendingSoldiers}" : "No soldiers in Queue"; progress = 0; // Reset progress after the soldier is trained buildingPanelManager.UpdateProduction(this, isDay, progress, message); isTraining = false; // Reset training flag }Additionally, since you want these updates to happen consistently, you need to also ensure that when
isTrainingturnsfalse, andpendingSoldiersare decremented, you also update the UI for the final time before exiting the coroutine.Note that the call to
buildingPanelManager.UpdateProduction()is now inside the coroutine loop, so it will update the UI each time the loop runs (each frame), reflecting the latest training state. Also, you have an update after the loop for when the training is complete, so the progress goes back to zero and the message is updated accordingly.The
Update()method in theArcherCampclass will no longer need to callbuildingPanelManager.UpdateProduction()every frame since it's now being handled inside the coroutine. However, if the value ofisDaycan change while the coroutine is running, you may still want to keep those updates in theUpdate()method to reflect that real-time change in the UI. You have to design this part based on how your day/night cycle influences the training process and whether it should interrupt the coroutine or simply pause it.