void SwitchDestination() { if (tank.isNear(beijingLocation)) { tank.MoveTo(kathmanduLocation, 0.1f); } else { tank.MoveTo(beijingLocation, 0.1f); } }
IEnumerator FireThis(float delay, GameObjectAnimator bulletAnim, Vector3 startAnchor, Vector2 destination, float bulletSpeed, float arcMultiplier = 1f, bool testAnchor = false) { yield return(new WaitForSeconds(delay)); Renderer renderer = bulletAnim.gameObject.GetComponent <Renderer> (); if (renderer != null) { renderer.enabled = true; } bulletAnim.heightMode = HEIGHT_OFFSET_MODE.ABSOLUTE_CLAMPED; bulletAnim.pivotY = 0f; bulletAnim.autoRotation = false; bulletAnim.terrainCapability = TERRAIN_CAPABILITY.Any; bulletAnim.autoScale = autoScale; bulletAnim.arcMultiplier = arcMultiplier; Vector3 worldPos = transform.TransformPoint(startAnchor); if (testAnchor) { bulletAnim.transform.position = worldPos; yield break; } Vector2 startingPosition = map.WorldToMap2DPosition(worldPos); bulletAnim.startingMap2DLocation = startingPosition; float h = map.WorldToAltitude(worldPos); bulletAnim.altitudeStart = h; bulletAnim.altitudeEnd = 0; float duration = Vector2.Distance(destination, startingPosition) * 200f / bulletSpeed; bulletAnim.MoveTo(destination, duration); }
// Executes on each frame - move ships and tanks around void Update() { Vector2 destination; if (units != null) { // Make units move around the board unitIndex++; if (unitIndex >= units.Count) { unitIndex = 0; } GameObjectAnimator unit = units [unitIndex]; if (!unit.isMoving) { if (unit.type == (int)UNIT_TYPE.TANK) { destination = GetRandomCityPosition(); } else // it's a ship { destination = GetRandomWaterPosition(); } unit.MoveTo(destination, 0.1f); } } if (Input.GetKeyDown(KeyCode.A)) { ship.visible = !ship.visible; } }
/// <summary> /// Smoothly moves this game object to given map destination along route of points. /// </summary> /// <param name="durationType">Step: each step will take the same duration, Route: the given duration is for the entire route, MapLap: the duration is the time to cross entire map. Default duration type is 'Step'. Use 'MapLap' if you pass a custom set of non-continuous points to ensure a consistent speed of movement.</param> public static GameObjectAnimator WMSK_MoveTo(this GameObject o, List <Vector2> route, float duration, DURATION_TYPE durationType = DURATION_TYPE.Step) { GameObjectAnimator anim = o.GetComponent <GameObjectAnimator>() ?? o.AddComponent <GameObjectAnimator>(); anim.MoveTo(route, duration, durationType); return(anim); }
void Start() { // Get a reference to the World Map API: map = WMSK.instance; // Get a reference to the viewport gameobject (we'll enable/disable it when changing modes) viewport = GameObject.Find("Viewport"); // Get the material of the fade plane fadePlane = Camera.main.transform.Find("FadePlane").gameObject; fadeMaterial = fadePlane.GetComponent <Renderer>().sharedMaterial; // UI Setup - non-important, only for this demo buttonStyle = new GUIStyle(); buttonStyle.alignment = TextAnchor.MiddleCenter; buttonStyle.normal.background = Texture2D.whiteTexture; buttonStyle.normal.textColor = Color.white; // setup GUI resizer - only for the demo GUIResizer.Init(800, 500); map.CenterMap(); // Create tank kathmanduLocation = map.GetCity("Kathmandu", "Nepal").unity2DLocation; beijingLocation = map.GetCity("Beijing", "China").unity2DLocation; tank = DropTankOnPosition(kathmanduLocation); // Start movement tank.MoveTo(beijingLocation, 0.1f); tank.OnMoveEnd += (anim) => SwitchDestination(); }
/// <summary> /// Moves the tank with path finding. /// </summary> void MoveTankWithPathFinding(Vector2 destination) { bool canMove = false; canMove = tank.MoveTo(destination, 0.1f); if (!canMove) { Debug.Log("Can't move to destination!"); } }
void MapClickEvent(float x, float y, int mouseButtonIndex) { // If tank is created, try to move tank over that position if (tank != null) { tank.MoveTo(new Vector2(x, y), 100f, DURATION_TYPE.MapLap); } }
void HandleOnCellClick(int cellIndex, int buttonIndex) { if (path != null) { startCellIndex = cellIndex; tank.MoveTo(path, 0.5f); tank.maxSearchCost -= pathCost; ClearPreviousPath(); } }
/// <summary> /// Checks if tank is near Paris. Then moves it to Moscow. Otherwise, moves it back to Paris. /// </summary> void MoveTankAndFollow() { string destinationCity, destinationCountry; if (tank == null) { DropTankOnCity(); } // Gets position of Paris in map Vector2 parisPosition = map.GetCity("Paris", "France").unity2DLocation; // Is the tank nearby (less than 50 km)? Then set destination to Moscow, otherwize Paris again if (map.calc.Distance(tank.currentMap2DLocation, parisPosition) < 50000) { destinationCity = "Moscow"; destinationCountry = "Russia"; } else { destinationCity = "Paris"; destinationCountry = "France"; } // Get position of destination Vector2 destination = map.GetCity(destinationCity, destinationCountry).unity2DLocation; Debug.Log(destinationCity + " " + destinationCountry + " " + destination); // For this movement, we will move the tank following a straight line tank.terrainCapability = TERRAIN_CAPABILITY.Any; // Move the tank to the new position with smooth ease tank.easeType = EASE_TYPE.SmoothStep; // Use a close zoom during follow - either current zoom level or 0.1f maximum so tank is watched closely tank.follow = true; tank.followZoomLevel = Mathf.Min(0.1f, map.GetZoomLevel()); // Move it! tank.MoveTo(destination, 4.0f); }
/// <summary> /// Smoothly moves this game object to given map position with options. /// </summary> /// <returns>The GameObjectAnimator component.</returns> /// <param name="destination">destination in -0.5 ... 0.5 range for X/Y coordinates</param> /// <param name="duration">duration in seconds</param> /// <param name="durationType">Step: each step will take the same duration, Route: the given duration is for the entire route, MapLap: the duration is the time to cross entire map. Default duration type is 'Step'. Use 'MapLap' if you pass a custom set of non-continuous points to ensure a consistent speed of movement.</param> /// <param name="scaleOnZoom">If set to <c>true</c> the gameobject will increase/decrease its scale when zoomin in/out.</param> public static GameObjectAnimator WMSK_MoveTo(this GameObject o, Vector2 destination, float duration = 0, DURATION_TYPE durationType = DURATION_TYPE.Step, bool scaleOnZoom = true, float altitude = 0) { GameObjectAnimator anim = o.GetComponent <GameObjectAnimator>() ?? o.AddComponent <GameObjectAnimator>(); if (altitude == 0) { anim.heightMode = HEIGHT_OFFSET_MODE.RELATIVE_TO_GROUND; } else { anim.heightMode = HEIGHT_OFFSET_MODE.ABSOLUTE_CLAMPED; anim.altitude = altitude; } anim.autoScale = scaleOnZoom; anim.MoveTo(destination, duration, durationType); return(anim); }
/// <summary> /// Moves the tank with path finding. /// </summary> void MoveTankWithPathFinding(Vector2 destination) { // Ensure tank is limited terrain, avoid water if (tank == null) { DropTankOnCity(); return; } // If current path is visible then fade it. if (pathLine != null) { pathLine.FadeOut(1.0f); } tank.terrainCapability = TERRAIN_CAPABILITY.OnlyGround; tank.MoveTo(destination, 0.1f); }
void Start() { // Get a reference to the World Map API: map = WMSK.instance; // setup GUI resizer - only for the demo GUIResizer.Init(800, 500); // setup GUI styles labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleCenter; labelStyle.normal.textColor = Color.white; buttonStyle = new GUIStyle(labelStyle); buttonStyle.alignment = TextAnchor.MiddleLeft; buttonStyle.normal.background = Texture2D.whiteTexture; buttonStyle.normal.textColor = Color.white; // Listen to click event to move the ship around map.OnClick += (float x, float y, int buttonIndex) => { ship.MoveTo(new Vector2(x, y), 0.1f); }; LaunchShip(); }