// ----------------------------------------------------------------------------- void StartFloatyAt(FloatyObject obj, Vector3 vector) // ----------------------------------------------------------------------------- { if (obj.Behavior.RandomPositioning) { vector.x += (Random.value * RandomOffset) - (RandomOffset / 2); vector.y += (Random.value * RandomOffset) - (RandomOffset / 2); vector.z += (Random.value * RandomOffset) - (RandomOffset / 2); } obj.Object.transform.position = vector; obj.Object.SetActive(true); }
// ----------------------------------------------------------------------------- FloatyObject GetFloatyText() // ----------------------------------------------------------------------------- { Debug.Assert(_floatyTextPool != null); if (_floatyTextPool.Count() == 0) { AddToFloatyPool(); } FloatyObject floaty = _floatyTextPool.Pop(); floaty.StartTime = Time.time; return(floaty); }
private Vector3 CalculateCenterpointOfRigidbody(int zx) { //Debug.Log("Doing calsdkfja;sldfkj;aljfd"); //get this to return a vector3 at world pos Rigidbody rb = rbList[zx]; FloatyObject fo = foList[zx]; Transform t = tList[zx]; //add all x values v3List.Clear(); insideme.Clear(); x = 0; y = 0; z = 0; insideMeLength = 0; for (int i = 0; i < fo.points.Count; i++) { v3List.Add(fo.points[i].position); } for (int i = 0; i < v3List.Count; i++) { if (self.bounds.Contains(v3List[i])) { insideme.Add(v3List[i]); //instantiates a shere //GameObject vis = Instantiate(visualiser, v3List[i], Quaternion.identity, gameObject.transform); //vis.transform.SetParent(null); //vis.transform.localScale = new Vector3(1, 1, 1); } } insideMeLength = insideme.Count; //get length of list foreach (Vector3 v3 in insideme) { x += v3.x; y += v3.y; z += v3.z; } Vector3 result = new Vector3(x / insideMeLength, y / insideMeLength, z / insideMeLength); return(result); }
// ----------------------------------------------------------------------------- void AddToFloatyPool() // ----------------------------------------------------------------------------- { for (int i = 0; i < 10; i++) { FloatyObject fo = new FloatyObject(); fo.Object = GameObject.Instantiate(TemplateFloatyText); fo.Text = fo.Object.GetComponent <Text>(); _floatyTextPool.Push(fo); fo.Object.transform.SetParent(WorldCanvas.transform, false); fo.Object.SetActive(false); fo.InitialColor = fo.Text.color; Color f = fo.Text.color; f.a = 0.0f; fo.FinalColor = f; fo.Id = _nextFloatyId++; } }
// ----------------------------------------------------------------------------- public int ShowFloatyText(Vector3 position, string val, FloatyObjectBehavior behavior = null) // ----------------------------------------------------------------------------- { FloatyObject floaty = GetFloatyText(); floaty.Text.text = val; if (behavior == null) { behavior = _defaultBehavior; } floaty.Behavior = behavior; StartFloatyAt(floaty, position); if (behavior.IsTimed) { _activeFloatyText.Add(floaty); } return(floaty.Id); }