private Bar CreateBar(GameObject originalBar, BarType type, Canvas canvas) { GameObject cloned = Instantiate(originalBar, canvas.transform, true); cloned.transform.localScale = new Vector3(0.0007f, 0.0007f, 0.0007f); cloned.transform.rotation = canvas.transform.rotation; uGUI_CircularBar newBar = cloned.GetComponentInChildren <uGUI_CircularBar>(); newBar.texture = originalBar.GetComponentInChildren <uGUI_CircularBar>().texture; newBar.overlay = originalBar.GetComponentInChildren <uGUI_CircularBar>().overlay; switch (type) { case BarType.HEALTH: newBar.color = HEALTH_BAR_COLOR; newBar.borderColor = HEALTH_BAR_BORDER_COLOR; cloned.transform.localPosition = new Vector3(-0.075f, 0.35f, 0f); cloned.name = playerName + "'s Health"; cloned.RequireTransform("Icon").localRotation = Quaternion.Euler(0f, 0f, 0f); Destroy(cloned.GetComponent <uGUI_HealthBar>()); cloned.transform.localScale = new Vector3(0.0007f, 0.0007f, 0.0007f); break; case BarType.OXYGEN: newBar.color = OXYGEN_BAR_COLOR; newBar.borderColor = OXYGEN_BAR_BORDER_COLOR; cloned.transform.localPosition = new Vector3(-0.025f, 0.35f, 0f); cloned.name = playerName + "'s Oxygen"; cloned.RequireTransform("OxygenTextLabel").localRotation = Quaternion.Euler(0f, 270f, 0f); Destroy(cloned.GetComponent <uGUI_OxygenBar>()); cloned.transform.localScale = new Vector3(0.0003f, 0.0003f, 0.0003f); break; case BarType.FOOD: newBar.color = FOOD_BAR_COLOR; newBar.borderColor = FOOD_BAR_BORDER_COLOR; cloned.transform.localPosition = new Vector3(0.025f, 0.35f, 0f); cloned.name = playerName + "'s Food"; cloned.RequireTransform("Icon").localRotation = Quaternion.Euler(0f, 0f, 0f); Destroy(cloned.GetComponent <uGUI_FoodBar>()); cloned.transform.localScale = new Vector3(0.0007f, 0.0007f, 0.0007f); break; case BarType.WATER: newBar.color = WATER_BAR_COLOR; newBar.borderColor = WATER_BAR_BORDER_COLOR; cloned.transform.localPosition = new Vector3(0.075f, 0.35f, 0f); cloned.name = playerName + "'s Water"; cloned.RequireTransform("Icon").localRotation = Quaternion.Euler(0f, 0f, 0f); Destroy(cloned.GetComponent <uGUI_WaterBar>()); cloned.transform.localScale = new Vector3(0.0007f, 0.0007f, 0.0007f); break; default: Log.Info("Unhandled bar type: " + type); break; } return(new Bar(newBar.gameObject, new SmoothedValue(100, 100, 100, 100))); }
private Bar CreateBar(uGUI_HealthBar originalBar, Color color, Color borderColor, string smoothedValueUnit) { GameObject cloned = Instantiate(originalBar.gameObject); cloned.transform.SetParent(originalBar.gameObject.transform.parent.transform); Destroy(cloned.GetComponent <uGUI_HealthBar>()); cloned.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f); cloned.transform.localRotation = originalBar.gameObject.transform.localRotation; cloned.RequireTransform("Icon").localRotation = Quaternion.Euler(0f, 180, 0f); Canvas canvas = originalBar.gameObject.GetComponentInParent <Canvas>(); // Not sure why this is needed, but if a initial transform is not set // then it will be in a weird, inconsistent state. SetBarPostion(cloned.gameObject, new Vector2(0, 0), canvas); uGUI_CircularBar newBar = cloned.GetComponentInChildren <uGUI_CircularBar>(); newBar.texture = originalBar.bar.texture; newBar.overlay = originalBar.bar.overlay; newBar.color = color; newBar.borderColor = borderColor; return(new Bar(cloned, new SmoothedValue(100, 100, 100, 100), smoothedValueUnit)); }
public void UpdateVisual() { ThrowIfDisposed(); float vel = 0; smoothedValue.CurrentValue = Mathf.SmoothDamp(smoothedValue.CurrentValue, smoothedValue.TargetValue, ref vel, smoothedValue.SmoothTime); uGUI_CircularBar circularBar = gameObject.GetComponentInChildren <uGUI_CircularBar>(); circularBar.value = smoothedValue.CurrentValue / smoothedValue.MaxValue; }
private void setBarAmount(Bar bar, float amount, float max) { uGUI_CircularBar circularBar = bar.GameObject.GetComponentInChildren <uGUI_CircularBar>(); circularBar.value = amount / max; int rounded = Mathf.RoundToInt(amount); Text text = bar.GameObject.GetComponentInChildren <Text>(); text.text = ((int)rounded).ToString() + bar.ValueUnit; }
private Bar CreateBar(Color color, Color borderColor, String smoothedValueUnit) { uGUI_HealthBar healthBar = FindObjectOfType <uGUI_HealthBar>(); if (healthBar == null) { Console.WriteLine("healthBar does not exist. Are you playing on creative?"); // TODO: clean this up, now it generates many NRE's. // Also make sure it works when the world changes back to survival return(null); } GameObject cloned = Instantiate(healthBar.gameObject); cloned.transform.SetParent(healthBar.gameObject.transform.parent.transform); Destroy(cloned.GetComponent <uGUI_HealthBar>()); cloned.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f); cloned.transform.localRotation = healthBar.gameObject.transform.localRotation; cloned.transform.Find("Icon").localRotation = Quaternion.Euler(0f, 180, 0f); Canvas canvas = healthBar.gameObject.GetComponentInParent <Canvas>(); //Not sure why this is needed, but if a initial transform is not set //then it will be in a weird, inconsistent state. SetBarPostion(cloned.gameObject, new Vector2(0, 0), canvas); uGUI_CircularBar newBar = cloned.GetComponentInChildren <uGUI_CircularBar>(); newBar.texture = healthBar.bar.texture; newBar.overlay = healthBar.bar.overlay; newBar.color = color; newBar.borderColor = borderColor; return(new Bar(cloned, new SmoothedValue(100, 100, 100, 100), smoothedValueUnit)); }
private void SetBarAmount(Bar bar, float amount, float max) { uGUI_CircularBar circularBar = bar.GameObject.GetComponentInChildren <uGUI_CircularBar>(); circularBar.value = amount / max; }