コード例 #1
0
        /// <summary>
        /// Creates ship. Main function called from button UI.
        /// </summary>
        void LaunchShip()
        {
            // Get a coastal city and a water entrypoint
            int     cityIndex = Random.Range(0, map.cities.Length);
            Vector2 cityPosition;
            Vector2 waterPosition = Misc.Vector2zero;
            int     safeAbort     = 0;

            do
            {
                cityIndex++;
                if (cityIndex >= map.cities.Length)
                {
                    cityIndex = 0;
                }
                cityPosition = map.cities [cityIndex].unity2DLocation;
                if (safeAbort++ > 8000)
                {
                    break;
                }
            } while (!map.ContainsWater(cityPosition, 0.0001f, out waterPosition));

            if (safeAbort > 8000)
            {
                return;
            }

            // Create ship
            if (ship != null)
            {
                DestroyImmediate(ship.gameObject);
            }
            ship = DropShipOnPosition(waterPosition, true);

            // Fly to the location of ship with provided zoom level
            map.FlyToLocation(waterPosition, 2.0f, 0.1f);

            // Enable move on click in this demo
            enableAddTowerOnClick = false;
            enableClickToMoveTank = false;
            enableClickToMoveShip = true;
        }
コード例 #2
0
        /// <summary>
        /// Creates ship. Main function called from button UI.
        /// </summary>
        void LaunchShip()
        {
            if (ship != null)
            {
                DestroyImmediate(ship.gameObject);
            }

            // Get a coastal city and a water entrypoint
            int     cityIndex = (Time.frameCount + map.cities.Count) % map.cities.Count;         // Random.Range (0, map.cities.Count);
            Vector2 cityPosition;
            Vector2 waterPosition = Misc.Vector2zero;
            int     safeAbort     = 0;

            do
            {
                cityIndex++;
                if (cityIndex >= map.cities.Count)
                {
                    cityIndex = 0;
                }
                cityPosition = map.cities [cityIndex].unity2DLocation;
                if (safeAbort++ > 8000)
                {
                    break;
                }
            } while (!map.ContainsWater(cityPosition, 0.001f, out waterPosition));

            if (safeAbort > 8000)
            {
                Debug.Log("No water position found!");
                return;
            }

            // Create ship
            ship = DropShipOnPosition(waterPosition);

            // Fly to the location of ship with provided zoom level
            map.FlyToLocation(waterPosition, 2.0f, 0.1f);
        }