public override void OnInspectorGUI() { EditorUtility.SetDirty(target); //ensures repaint on value change UBulletCollider uCollider = (UBulletCollider)target; //Radius if (uCollider.radius < 0f) { uCollider.radius = 0f; //forcefully avoid negative values } bool is_radius_over_suggested_max = (uCollider.radius > UBulletCollider.GetSuggestedMaxRadius()); if (is_radius_over_suggested_max) { GUI.color = Color.yellow; } uCollider.radius = EditorGUILayout.FloatField("Collider Radius", uCollider.radius); GUI.color = Color.white; if (is_radius_over_suggested_max) { EditorGUILayout.HelpBox("Exceeding UCollider suggested radius range", MessageType.Warning); } EditorGUILayout.HelpBox("UDEngine currently requires all collider to have the shape of circle to ensure good performance. To simulate other shapes, consider multiple circle colliders", MessageType.Info); // default the .trans prop as its own parent if (uCollider.trans == null) { if (uCollider.transform.parent != null) { uCollider.SetTransform(uCollider.transform.parent); } else { uCollider.SetTransform(uCollider.transform); } } uCollider.SetTransform(EditorGUILayout.ObjectField("Transform", uCollider.trans, typeof(Transform), true) as Transform); uCollider.bulletObject = EditorGUILayout.ObjectField("Bullet Object", uCollider.bulletObject, typeof(UBulletObject), true) as UBulletObject; uCollider.actor = EditorGUILayout.ObjectField("Actor", uCollider.actor, typeof(UBulletActor), true) as UBulletActor; uCollider.SetLayer(EditorGUILayout.IntField("Layer", uCollider.layer)); uCollider.SetEnable(EditorGUILayout.Toggle("Enabled", uCollider.IsEnabled())); uCollider.SetRecyclable(EditorGUILayout.Toggle("Recyclable", uCollider.IsRecyclable()), false); }
IEnumerator TestCoroutine() { int count = 0; while (true) { count++; GameObject newBullet = Instantiate(bulletPrefab, shooter.transform.position, Quaternion.identity) as GameObject; Vector3 randVec = Random.insideUnitCircle; randVec.Scale(new Vector3(8f, 8f, 0f)); newBullet.transform.DOMove(randVec, 5f); UBulletCollider ubc = newBullet.GetComponentInChildren <UBulletCollider>(); ubc.SetEnable(true); ubc.GetActor().AddDefaultCallback(() => { ubc.trans.GetComponentInChildren <SpriteRenderer>().color = Color.white; }); ubc.GetActor().AddCollisionCallback(() => { ubc.trans.GetComponentInChildren <SpriteRenderer>().color = Color.red; }); ubc.GetActor().AddBoundaryCallback(() => { newBullet.transform.DOKill(); ubc.GetActor().ClearDefaultCallbacks(); ubc.GetActor().ClearDefaultCallbacks(); ubc.trans.GetComponentInChildren <SpriteRenderer>().color = Color.blue; ubc.GetActor().ClearBoundaryCallbacks(); }); monitor.AddBulletCollider(ubc); yield return(new WaitForSeconds(0.03f)); if (count % 100 == 0) { //Debug.Log ("Bullet: " + count.ToString ()); txt.text = "Bullet: " + count.ToString(); } } }
// Use this for initialization void Start() { for (int i = 0; i < 4000; i++) { GameObject newBullet = Instantiate(bulletPrefab, new Vector3(Random.Range(-5f, 5f), Random.Range(-6f, 6f), 0f), Quaternion.identity) as GameObject; newBullet.transform.DOMove(new Vector3(Random.Range(-5f, 5f), Random.Range(-6f, 6f), 0f), 5f).SetEase(Ease.Linear).SetLoops(-1, LoopType.Yoyo); UBulletCollider ubc = newBullet.GetComponentInChildren <UBulletCollider>(); ubc.SetEnable(true); ubc.GetActor().AddDefaultCallback(() => { ubc.trans.GetComponentInChildren <SpriteRenderer>().color = Color.white; }); ubc.GetActor().AddCollisionCallback(() => { ubc.trans.GetComponentInChildren <SpriteRenderer>().color = Color.red; }); monitor.AddBulletCollider(ubc); } var mousePos = Input.mousePosition; mousePos.z = 10; // select distance = 10 units from the camera // mouseBullet = Instantiate (bulletPrefab, Camera.main.ScreenToWorldPoint(mousePos), Quaternion.identity) as GameObject; // // mouseBullet.transform.localScale = new Vector3 (1f, 1f, 1f); // mouseBullet.GetComponent<UCircleCollider> ().SetRadius (0.15f); mouseBullet.GetComponentInChildren <SpriteRenderer> ().color = Color.green; mouseBullet.GetComponentInChildren <UTargetCollider> ().SetEnable(true); monitor.AddTargetCollider(mouseBullet.GetComponentInChildren <UTargetCollider>()); // Add monitor to executor for mono-like update and start //executor.AddModule (monitor); }