/// <summary> /// Creates a new ship on position. /// </summary> GameObjectAnimator DropShipOnPosition(Vector2 position, bool addAOE) { // Create ship GameObject shipGO = Instantiate(shipPrefab); shipGO.transform.localScale = Misc.Vector3one * 0.25f; ship = shipGO.WMSK_MoveTo(position); ship.type = (int)UNIT_TYPE.SHIP; ship.terrainCapability = TERRAIN_CAPABILITY.OnlyWater; ship.autoRotation = true; // Add circle of area of effect if (addAOE) { GameObject circle = map.AddCircle(ship.currentMap2DLocation, 450, 0.9f, 1f, new Color(255, 255, 0, 0.33f)); // Hook event OnMove to sync circle position and destroy it when ship no longer exists ship.OnMove += (ship) => circle.transform.localPosition = new Vector3(ship.currentMap2DLocation.x, ship.currentMap2DLocation.y, 0); // Show/hide also with ship ship.OnVisibleChange += (ship) => circle.SetActive(ship.isVisibleInViewport); // Optionally hook OnKilled - so we don't have to remember to remove the circle when ship is destroyed ship.OnKilled += (ship) => Destroy(circle); // WHY circle is not parented to child? // Because circle should represent an accurate area of the world map. Units added to the viewport with WMSK_MoveTo(), are parented to the viewport object // and they get scaled in a way that's not realistic (the aim is to ensure unit visibility, hence when you zoom out, units still are visible, they're tiny but visible) // However, objects that are not parented to the viewport, but are parented to the 2D Map (which is also on the scene) will be visible through the viewport but keep their // appropriate scale (this is the case of circles, lines, ... markers in general) } return(ship); }
IEnumerator AddCircleExplosion(float delay, Vector2 mapPos, Color color) { float start = Time.time; while (Time.time - start < delay) { yield return(null); } GameObject circleObj = null; float radius = UnityEngine.Random.Range(80f, 100f); for (int k = 0; k < 100; k++) { if (circleObj != null) { DestroyImmediate(circleObj); } float ringStart = Mathf.Clamp01((k - 50f) / 50f); float ringEnd = Mathf.Clamp01(k / 50f); circleObj = map.AddCircle(mapPos, radius, ringStart, ringEnd, color); yield return(new WaitForSeconds(1 / 60f)); } Destroy(circleObj); }
void UpdateCircle(Vector2 position) { if (circle != null) { Destroy(circle); } if (!showCircle) { return; } circle = map.AddCircle(position, circleRadius, circleRingStart, circleRingEnd, circleColor); }