Пример #1
0
        public override void ShowInfectedMap(MapBehaviour Map)
        {
            if (!IsLocalPlayer())
            {
                return;
            }
            if (!Map.IsOpen)
            {
                return;
            }

            Map.ColorControl.baseColor = Color;
            foreach (var Room in Map.infectedOverlay.rooms)
            {
                var Door = Room.door;
                if (Door == null)
                {
                    continue;
                }

                var DoorObject = Door.gameObject;
                Door.enabled = false;
                DoorObject.SetActive(false);
                DoorObject.active = false;
            }
        }
Пример #2
0
        public static MapBehaviour CreateMainMap(Type mapType, SizeInt mapSize, Size cellSize)
        {
            MapBehaviour currentMainMapBehaviour = MainMapBehaviour;

            if (currentMainMapBehaviour != null)
            {
                UnityEngine.Object.DestroyImmediate(currentMainMapBehaviour.gameObject);
                currentMainMapBehaviour = null;
            }

            GameObject mapGO = new GameObject("Map");

            mapGO.layer = LayerMask.NameToLayer(EditorStringReferences.ShadowWitchLayerName);
            MapBehaviour mapBehaviour = mapGO.AddComponent <MapBehaviour>();
            MapBase      map          = mapType.Assembly.CreateInstance(mapType.ToString()) as MapBase;

            map.Init(mapSize, cellSize);
            mapBehaviour.Init(map, CreateLayerGameObjects());
            mainMapBehaviour = mapBehaviour;
            BoxCollider boxCollider = mapGO.AddComponent <BoxCollider>();

            boxCollider.isTrigger = true;
            boxCollider.center    = new Vector3(mapSize.Width / 2f * cellSize.Width, 0f, -mapSize.Height / 2f * cellSize.Height);
            boxCollider.size      = new Vector3(mapSize.Width * cellSize.Width, 0f, mapSize.Height * cellSize.Height);
            return(mainMapBehaviour);
        }
Пример #3
0
 public static void Postfix(MapBehaviour __instance)
 {
     foreach (var Role in Role.ROLES)
     {
         Role.ShowInfectedMap(__instance);
     }
 }
Пример #4
0
    public override void OnInspectorGUI()
    {
        MapBehaviour myTarget = (MapBehaviour)target;

        serializedObject.Update();

        myTarget.width  = EditorGUILayout.IntField("Width", myTarget.width);
        myTarget.height = EditorGUILayout.IntField("Height", myTarget.height);

        if (GUILayout.Button("Set Default Tiles"))
        {
            ((MapBehaviour)target).SetDefaultTiles();
        }

        SerializedProperty tiles = serializedObject.FindProperty("tiles");

        EditorGUILayout.BeginVertical();

        for (int i = 0; i < tiles.arraySize; ++i)
        {
            EditorGUILayout.PropertyField(tiles.GetArrayElementAtIndex(i), new GUIContent(string.Format("({0},{1})", i / myTarget.height, i % myTarget.height)), true);
        }

        EditorGUILayout.EndVertical();

        serializedObject.ApplyModifiedProperties();
    }
Пример #5
0
 public static void Postfix(MapBehaviour __instance)
 {
     if (SelectedMap != null && SelectedMap.MiniMap != null)
     {
         __instance.transform.localPosition = SelectedMap.MapOffset * -1;
     }
 }
Пример #6
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        MapBehaviour mapBehaviour = (MapBehaviour)target;

        if (GUILayout.Button("Clear"))
        {
            mapBehaviour.Clear();
            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        }

        GUILayout.BeginHorizontal();
        int.TryParse(GUILayout.TextField(this.collapseAreaSize.ToString()), out this.collapseAreaSize);

        if (GUILayout.Button("Initialize " + this.collapseAreaSize + "x" + this.collapseAreaSize + " area"))
        {
            mapBehaviour.Initialize();
            var startTime = System.DateTime.Now;
            mapBehaviour.Map.Collapse(Vector3Int.zero, new Vector3Int(this.collapseAreaSize, mapBehaviour.Map.Height, this.collapseAreaSize), true);
            Debug.Log("Initialized in " + (System.DateTime.Now - startTime).TotalSeconds + " seconds.");
            mapBehaviour.BuildAllSlots();
        }
        GUILayout.EndHorizontal();
    }
Пример #7
0
 public static void PostfixShowNormalMap(MapBehaviour __instance)
 {
     if (__instance.IsOpen)
     {
         __instance.Close();
         return;
     }
     if (!PlayerControl.LocalPlayer.CanMove)
     {
         return;
     }
     HerePoints[PlayerControl.LocalPlayer.PlayerId] = __instance.HerePoint;
     if (PlayerControl.LocalPlayer.Data.IsDead)
     {
         foreach (var player in PlayerControl.AllPlayerControls)
         {
             if (!HerePoints.ContainsKey(player.PlayerId))
             {
                 var point = UnityEngine.Object.Instantiate(__instance.HerePoint, __instance.HerePoint.transform.parent);
                 point.enabled = true;
                 HerePoints[player.PlayerId] = point;
             }
             player.SetPlayerMaterialColors(HerePoints[player.PlayerId]);
         }
     }
     __instance.PDPJBNINLPF();
     __instance.taskOverlay.Show();
     __instance.ColorControl.SetColor(new Color(0.05f, 0.2f, 1f, 1f));
     DestroyableSingleton <HudManager> .Instance.SetHudActive(false);
 }
Пример #8
0
        public override void UpdateMap(MapBehaviour Map)
        {
            if (!IsLocalPlayer())
            {
                return;
            }
            if (!Map.IsOpen || !Map.infectedOverlay.gameObject.active)
            {
                return;
            }

            Map.ColorControl.baseColor = SabotageActive ? Color : Color.gray;
            var Percent = RepairUsed ? 1f : 0f;

            foreach (var Room in Map.infectedOverlay.rooms)
            {
                var Special = Room.special;
                if (Special == null)
                {
                    continue;
                }

                Special.material.SetFloat(Globals.DESAT, SabotageActive ? 0f : 1f);
                Special.enabled = true;

                var SpecialObject = Special.gameObject;
                SpecialObject.SetActive(true);
                SpecialObject.active = true;

                Room.special.material.SetFloat(Globals.PERCENT,
                                               PlayerControl.LocalPlayer.Data.IsDead ? 1f : Percent);
            }
        }
Пример #9
0
 static void Postfix(MapBehaviour __instance)
 {
     if (PlayerControl.LocalPlayer.isGM())
     {
         HudManager.Instance.UseButton.transform.localPosition = useButtonPos;
     }
 }
Пример #10
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        MapBehaviour mapBehaviour = (MapBehaviour)target;

        if (GUILayout.Button("Create module data"))
        {
            mapBehaviour.CreateModules();
        }

        if (GUILayout.Button("Simplify module data"))
        {
            mapBehaviour.CreateModules();
            mapBehaviour.SimplifyNeighborData();
        }

        GUILayout.Space(20f);

        if (GUILayout.Button("Clear"))
        {
            mapBehaviour.Clear();
        }

        GUILayout.BeginHorizontal();
        int.TryParse(GUILayout.TextField(this.collapseAreaSize.ToString()), out this.collapseAreaSize);

        if (GUILayout.Button("Initialize " + this.collapseAreaSize + "x" + this.collapseAreaSize + " area"))
        {
            mapBehaviour.Initialize();
            mapBehaviour.Map.Collapse(Vector3i.zero, new Vector3i(this.collapseAreaSize, mapBehaviour.Map.Height, this.collapseAreaSize), true);
            mapBehaviour.BuildAllSlots();
        }
        GUILayout.EndHorizontal();
    }
Пример #11
0
            static void Postfix(MapBehaviour __instance)
            {
                if (!PlayerControl.LocalPlayer.isPlayerRole("Engineer"))
                {
                    return;
                }
                if (!__instance.IsOpen || !__instance.infectedOverlay.gameObject.active)
                {
                    return;
                }
                __instance.ColorControl.baseColor =
                    !Main.Logic.sabotageActive ? Color.gray : Main.Palette.engineerColor;

                var perc = Main.Logic.getRolePlayer("Engineer").UsedAbility ? 1f : 0f;

                foreach (var room in __instance.infectedOverlay.rooms)
                {
                    if (room.special == null)
                    {
                        continue;
                    }
                    room.special.material.SetFloat("_Desat", !Main.Logic.sabotageActive ? 1f : 0f);

                    room.special.enabled = true;
                    room.special.gameObject.SetActive(true);
                    room.special.gameObject.active = true;
                    room.special.material.SetFloat("_Percent", !PlayerControl.LocalPlayer.Data.IsDead ? perc : 1f);
                }
            }
Пример #12
0
    public static void SimulateIntegral(Unit u, float dt, MapBehaviour mapBehaviour)
    {
        float v = Mathf.Sqrt(u.vx * u.vx + u.vz * u.vz);

        if (v > 0)
        {
            Tile  tile     = mapBehaviour.GetTile(new Vector3(u.x, 10, u.z));
            float friction = 1;
            //            Debug.Log(tile);
            if (tile != null)
            {
                friction = mapPhysicsMaterials[tile.type].friction;
            }
            float fx   = -u.vx / v * friction;
            float fz   = -u.vz / v * friction;
            float fxdt = fx * dt;
            float fzdt = fz * dt;
            float vx1  = u.vx + fxdt;
            float vz1  = u.vz + fzdt;
            if (vx1 * u.vx > 0)
            {
                u.vx = vx1;
                u.vz = vz1;
            }
            else
            {
                u.vx = 0;
                u.vz = 0;
            }
        }
        u.x1 += u.vx * dt;
        u.z1 += u.vz * dt;
    }
Пример #13
0
            static void Postfix(MapBehaviour __instance)
            {
                if (PlayerControl.LocalPlayer.isGM())
                {
                    if (mapIcons == null || corpseIcons == null)
                    {
                        initializeIcons(__instance);
                    }

                    __instance.taskOverlay.Hide();
                    foreach (byte id in mapIcons.Keys)
                    {
                        GameData.PlayerInfo playerById = GameData.Instance.GetPlayerById(id);
                        PlayerControl.SetPlayerMaterialColors(playerById.Object.CurrentOutfit.ColorId, mapIcons[id]);
                        mapIcons[id].enabled = !playerById.IsDead;
                    }

                    foreach (DeadBody b in Object.FindObjectsOfType <DeadBody>())
                    {
                        byte id = b.ParentId;
                        GameData.PlayerInfo playerById = GameData.Instance.GetPlayerById(id);
                        PlayerControl.SetPlayerMaterialColors(playerById.Object.CurrentOutfit.ColorId, corpseIcons[id]);
                        corpseIcons[id].enabled = true;
                    }
                }
            }
Пример #14
0
 public static void Postfix(MapBehaviour __instance)
 {
     foreach (var Role in Role.ROLES)
     {
         Role.UpdateMap(__instance);
     }
 }
Пример #15
0
        public void PreGen(MapBehaviour mapBehaviour)
        {
            // Player Position
            mapBehaviour.gameObject.transform.FindChild("HereIndicatorParent").localPosition = new Vector3(0, 5.0f, -0.1f);

            // Map
            map = new Minimap(mapBehaviour);

            // Generators
            generators = new Generator[]
            {
                new BGGenerator(map),
                new LabelGenerator(map),
                new AdminGenerator(map),
                new SabGenerator(map)
            };

            // Generate
            foreach (Generator gen in generators)
            {
                foreach (MapAsset asset in shipRooms)
                {
                    gen.Generate(asset);
                }
            }
        }
Пример #16
0
 private void OnDestroy()
 {
     if (_main == this)
     {
         // allows another map to be loaded later
         _main = null;
     }
 }
Пример #17
0
 public static void Postfix(MapBehaviour __instance)
 {
     try
     {
         __instance.HerePoint.transform.localScale = new Vector3(iconSize, iconSize, __instance.HerePoint.transform.localScale.z);
     }
     catch { }
 }
Пример #18
0
 public void Initialize()
 {
     this.MapBehaviour      = this.GetComponent <MapBehaviour>();
     this.RoomsByPosition   = new Dictionary <Vector3Int, Room>();
     this.portalsByPosition = new Dictionary <Vector3Int, Portal[]>();
     this.outdatedSlots     = new HashSet <Vector3Int>();
     this.Chunks            = new Dictionary <Vector3Int, Chunk>();
     this.ChunksInRange     = new List <Chunk>();
 }
Пример #19
0
 static void Prefix(MapBehaviour __instance)
 {
     if (PlayerControl.LocalPlayer.isGM())
     {
         useButtonPos = HudManager.Instance.UseButton.transform.localPosition;
     }
     CustomOverlays.hideInfoOverlay();
     CustomOverlays.hideRoleOverlay();
 }
Пример #20
0
 static bool Prefix(ref bool __result, MapBehaviour __instance)
 {
     if (PlayerControl.LocalPlayer.isRole(RoleType.EvilHacker) && CustomOptionHolder.evilHackerCanMoveEvenIfUsesAdmin.getBool())
     {
         __result = false;
         return(false);
     }
     return(true);
 }
Пример #21
0
 // Start is called before the first frame update
 void Awake()
 {
     if (interScene != null)
     {
         mapname = interScene.MapName;
     }
     map      = MapLoader.loadMap(mapname);
     instance = this;
 }
Пример #22
0
        private static void move(MapBehaviour map, Vector3 direction)
        {
            var displacement = Quaternion.Euler(Vector3.up * map.CameraYaw) * direction * 400.0f * Time.deltaTime * map.MetersPerPixel;

            double[] newMapCenter = new double[2] {
                map.CenterEPSG900913[0] - displacement.x,
                map.CenterEPSG900913[1] + displacement.z
            };
            map.CenterEPSG900913 = newMapCenter;
        }
Пример #23
0
    /// <summary>
    /// イベントを待機リストに追加
    /// </summary>
    /// <returns>イベント発火可能ならtrue</returns>
    /// <param name="aEventKey">worldが持つイベントのKey</param>
    /// <param name="aInvoker">起動者</param>
    /// <param name="aInvoked">イベント所持者</param>
    /// <param name="aInvokedCollider">イベント所持者のcollider</param>
    public bool addEvent(string aEventKey, MapCharacter aInvoker, MapBehaviour aInvoked, Collider aInvokedCollider)
    {
        Operator tOperator = new Operator(this, mWorld.mEvents[aEventKey]);

        tOperator.mInvoker         = aInvoker;
        tOperator.mInvoked         = aInvoked;
        tOperator.mInvokedCollider = aInvokedCollider;

        return(addOperator(tOperator));
    }
Пример #24
0
    /// <summary>
    /// イベントを待機リストに追加
    /// </summary>
    /// <returns>イベント発火可能ならtrue</returns>
    /// <param name="aEvent">実行するイベント</param>
    /// <param name="aInvoker">起動者</param>
    /// <param name="aInvoked">イベント所持者</param>
    /// <param name="aInvokedCollider">イベント所持者のcollider</param>
    public bool addEvent(MapEvent aEvent, MapCharacter aInvoker, MapBehaviour aInvoked, Collider aInvokedCollider)
    {
        Operator tOperator = new Operator(this, aEvent);

        tOperator.mInvoker         = aInvoker;
        tOperator.mInvoked         = aInvoked;
        tOperator.mInvokedCollider = aInvokedCollider;

        return(addOperator(tOperator));
    }
Пример #25
0
 static void Postfix(MapBehaviour __instance)
 {
     if (TryGetSpecialRole(PlayerControl.LocalPlayer.PlayerId, out Engineer engineer))
     {
         engineer?.UpdateMap(__instance);
     }
     else if (TryGetSpecialRole(PlayerControl.LocalPlayer.PlayerId, out Tracker tracker))
     {
         tracker?.UpdateMap(__instance);
     }
 }
Пример #26
0
 public static void Postfix(MapBehaviour __instance)
 {
     if (SelectedMap != null && SelectedMap.MiniMap != null)
     {
         var Map = __instance;
         Map.ColorControl.GetComponent <SpriteRenderer>().sprite = SelectedMap.MiniMap;
         Map.transform.Find("RoomNames").gameObject.SetActive(false);
         ShipStatus.Instance.MapScale             = SelectedMap.MapScale;
         Map.ColorControl.transform.localPosition = SelectedMap.MapOffset;
     }
 }
Пример #27
0
 protected virtual void Start()
 {
     if (_main != null)
     {
         Debug.LogWarning("Multiple map components found. Only 1 should exist");
     }
     _main      = this;
     _tileTypes = BuildMap();
     _width     = _tileTypes.GetLength(0);
     _height    = _tileTypes.GetLength(1);
 }
Пример #28
0
 private void Update()
 {
     // update map when in editor, but not during gameplay
     // allows for changing values and seeing results immediately
     // make sure derived class has ExecuteInEditModeAttribute
     if (!Application.isPlaying)
     {
         _main = null;
         Start();
     }
 }
Пример #29
0
 public void MyAwake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(gameObject);
     }
 }
Пример #30
0
    void Start()
    {
        this.generatedChunks = new HashSet <Vector3Int>();
        this.mapBehaviour    = this.GetComponent <MapBehaviour>();
        this.mapBehaviour.Initialize();
        this.map = this.mapBehaviour.Map;
        this.generate();
        this.mapBehaviour.BuildAllSlots();

        this.thread = new Thread(this.generatorThread);
        this.thread.Start();
    }
Пример #31
0
		/// <summary>
		/// Zoom the specified <see cref="UnitySlippyMap.Map.MapBehaviour"/> instance.
		/// </summary>
		/// <param name="map">Map.</param>
		public static bool Zoom(MapBehaviour map)
		{
			GUILayout.BeginVertical();
			
			GUILayout.Label("Zoom: " + map.CurrentZoom);
    		
			bool pressed = false;
    		if (GUILayout.RepeatButton("+"))
    		{
    			map.Zoom(1.0f);
				pressed = true;
    		}
    		if (GUILayout.RepeatButton("-"))
    		{
    			map.Zoom(-1.0f);
				pressed = true;
    		}
			
			GUILayout.EndVertical();
			
			return pressed;
		}
Пример #32
0
		/// <summary>
		/// Returns WGS84 given a RaycastHit and Map instance.
		/// </summary>
		/// <returns>The WGS84 coordinates of the point hit.</returns>
		/// <param name="map"><see cref="UnitySlippyMap.Map.MapBehaviour"/> instance.</param>
		/// <param name="r">The red component.</param>
		public static double[] RaycastHitToWGS84(MapBehaviour map, RaycastHit r)
		{
			double[] RaycastHitToEPSG900913 = new double[]{(map.CenterEPSG900913[0]) + (r.point.x/map.ScaleMultiplier) , (map.CenterEPSG900913[1]) + (r.point.z/map.ScaleMultiplier)};
			return map.EPSG900913ToWGS84Transform.Transform(RaycastHitToEPSG900913);
		}
Пример #33
0
        Start()
	{
        // setup the gui scale according to the screen resolution
        guiXScale = (Screen.orientation == ScreenOrientation.Landscape ? Screen.width : Screen.height) / 480.0f;
        guiYScale = (Screen.orientation == ScreenOrientation.Landscape ? Screen.height : Screen.width) / 640.0f;
		// setup the gui area
		guiRect = new Rect(16.0f * guiXScale, 4.0f * guiXScale, Screen.width / guiXScale - 32.0f * guiXScale, 32.0f * guiYScale);

		// create the map singleton
		map = MapBehaviour.Instance;
		map.CurrentCamera = Camera.main;
		map.InputDelegate += UnitySlippyMap.Input.MapInput.BasicTouchAndKeyboard;
		map.CurrentZoom = 15.0f;
		// 9 rue Gentil, Lyon
		map.CenterWGS84 = new double[2] { 4.83527, 45.76487 };
		map.UsesLocation = true;
		map.InputsEnabled = true;
		map.ShowsGUIControls = true;

		map.GUIDelegate += Toolbar;

        layers = new List<LayerBehaviour>();

		// create an OSM tile layer
        OSMTileLayer osmLayer = map.CreateLayer<OSMTileLayer>("OSM");
        osmLayer.BaseURL = "http://a.tile.openstreetmap.org/";
		
        layers.Add(osmLayer);

		// create a WMS tile layer
        WMSTileLayerBehaviour wmsLayer = map.CreateLayer<WMSTileLayerBehaviour>("WMS");
        wmsLayer.BaseURL = "http://129.206.228.72/cached/osm?"; // http://www.osm-wms.de : seems to be of very limited use
        wmsLayer.Layers = "osm_auto:all";
#if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9
        wmsLayer.gameObject.SetActiveRecursively(false);
#else
		wmsLayer.gameObject.SetActive(false);
#endif

        layers.Add(wmsLayer);

		// create a VirtualEarth tile layer
        VirtualEarthTileLayerBehaviour virtualEarthLayer = map.CreateLayer<VirtualEarthTileLayerBehaviour>("VirtualEarth");
        // Note: this is the key UnitySlippyMap, DO NOT use it for any other purpose than testing
        virtualEarthLayer.Key = "ArgkafZs0o_PGBuyg468RaapkeIQce996gkyCe8JN30MjY92zC_2hcgBU_rHVUwT";
#if UNITY_WEBPLAYER
        virtualEarthLayer.ProxyURL = "http://reallyreallyreal.com/UnitySlippyMap/demo/veproxy.php";
#endif
#if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9
        virtualEarthLayer.gameObject.SetActiveRecursively(false);
#else
		virtualEarthLayer.gameObject.SetActive(false);
#endif

        layers.Add(virtualEarthLayer);

#if !UNITY_WEBPLAYER // FIXME: SQLite won't work in webplayer except if I find a full .NET 2.0 implementation (for free)
		// create an MBTiles tile layer
		bool error = false;
		// on iOS, you need to add the db file to the Xcode project using a directory reference
		string mbTilesDir = "MBTiles/";
		string filename = "UnitySlippyMap_World_0_8.mbtiles";
		string filepath = null;
		if (Application.platform == RuntimePlatform.IPhonePlayer)
		{
			filepath = Application.streamingAssetsPath + "/" + mbTilesDir + filename;
		}
		else if (Application.platform == RuntimePlatform.Android)
		{
			// Note: Android is a bit tricky, Unity produces APK files and those are never unzip on the device.
			// Place your MBTiles file in the StreamingAssets folder (http://docs.unity3d.com/Documentation/Manual/StreamingAssets.html).
			// Then you need to access the APK on the device with WWW and copy the file to persitentDataPath
			// to that it can be read by SqliteDatabase as an individual file
			string newfilepath = Application.temporaryCachePath + "/" + filename;
			if (File.Exists(newfilepath) == false)
			{
				Debug.Log("DEBUG: file doesn't exist: " + newfilepath);
				filepath = Application.streamingAssetsPath + "/" + mbTilesDir + filename;
				// TODO: read the file with WWW and write it to persitentDataPath
				WWW loader = new WWW(filepath);
				yield return loader;
				if (loader.error != null)
				{
					Debug.LogError("ERROR: " + loader.error);
					error = true;
				}
				else
				{
					Debug.Log("DEBUG: will write: '" + filepath + "' to: '" + newfilepath + "'");
					File.WriteAllBytes(newfilepath, loader.bytes);
				}
			}
			else
				Debug.Log("DEBUG: exists: " + newfilepath);
			filepath = newfilepath;
		}
        else
		{
			filepath = Application.streamingAssetsPath + "/" + mbTilesDir + filename;
		}
		
		if (error == false)
		{
            Debug.Log("DEBUG: using MBTiles file: " + filepath);
			MBTilesLayerBehaviour mbTilesLayer = map.CreateLayer<MBTilesLayerBehaviour>("MBTiles");
			mbTilesLayer.Filepath = filepath;
#if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9
            mbTilesLayer.gameObject.SetActiveRecursively(false);
#else
			mbTilesLayer.gameObject.SetActive(false);
#endif

            layers.Add(mbTilesLayer);
		}
        else
            Debug.LogError("ERROR: MBTiles file not found!");

#endif

        // create some test 2D markers
		GameObject go = TileBehaviour.CreateTileTemplate(TileBehaviour.AnchorPoint.BottomCenter).gameObject;
		go.renderer.material.mainTexture = MarkerTexture;
		go.renderer.material.renderQueue = 4001;
		go.transform.localScale = new Vector3(0.70588235294118f, 1.0f, 1.0f);
		go.transform.localScale /= 7.0f;
        go.AddComponent<CameraFacingBillboard>().Axis = Vector3.up;
		
		GameObject markerGO;
		markerGO = Instantiate(go) as GameObject;
		map.CreateMarker<MarkerBehaviour>("test marker - 9 rue Gentil, Lyon", new double[2] { 4.83527, 45.76487 }, markerGO);

		markerGO = Instantiate(go) as GameObject;
		map.CreateMarker<MarkerBehaviour>("test marker - 31 rue de la Bourse, Lyon", new double[2] { 4.83699, 45.76535 }, markerGO);
		
		markerGO = Instantiate(go) as GameObject;
		map.CreateMarker<MarkerBehaviour>("test marker - 1 place St Nizier, Lyon", new double[2] { 4.83295, 45.76468 }, markerGO);

		DestroyImmediate(go);
		
		// create the location marker
		go = TileBehaviour.CreateTileTemplate().gameObject;
		go.renderer.material.mainTexture = LocationTexture;
		go.renderer.material.renderQueue = 4000;
		go.transform.localScale /= 27.0f;
		
		markerGO = Instantiate(go) as GameObject;
		map.SetLocationMarker<LocationMarkerBehaviour>(markerGO);

		DestroyImmediate(go);
	}
Пример #34
0
	void OnApplicationQuit()
	{
		map = null;
	}
Пример #35
0
		/// <summary>
		/// Handles inputs on touch devices and desktop.
		/// The <see cref="UnitySlippyMap.Map.MapBehaviour"/> instance is told to update its layers and markers once a movement is complete.
		/// When panning the map, the map's root GameObject is moved. Once the panning is done, all the children are offseted and the root's position is reset.
		/// </summary>
		/// <param name="map">Map.</param>
		/// <param name="wasInputInterceptedByGUI">If set to <c>true</c> was input intercepted by GU.</param>
		public static void BasicTouchAndKeyboard (MapBehaviour map, bool wasInputInterceptedByGUI)
		{
			bool panning = false;
			bool panningStopped = false;
			Vector3 screenPosition = Vector3.zero;
    
			bool zooming = false;
			bool zoomingStopped = false;
			float zoomFactor = 0.0f;

			if (Application.platform == RuntimePlatform.IPhonePlayer
				|| Application.platform == RuntimePlatform.Android) {
				if (wasInputInterceptedByGUI == false) {
					int touchCount = UnityEngine.Input.touchCount;
					if (touchCount > 0) {
						// movements
						panning = true;
						panningStopped = true;
                    
						int validTouchCount = touchCount;
						foreach (Touch touch in UnityEngine.Input.touches) {
							if (touch.phase != TouchPhase.Ended) {
								screenPosition += new Vector3 (touch.position.x, touch.position.y);
								panningStopped = false;
							} else {
								--validTouchCount;
							}
    					
							// reset the last hit position to avoid a sudden jump when a finger is added or removed
							if (touch.phase == TouchPhase.Began
								|| touch.phase == TouchPhase.Ended)
								lastHitPosition = Vector3.zero;
						}
    				
						if (validTouchCount != 0)
							screenPosition /= validTouchCount;
						else {
							screenPosition = Vector3.zero;
							panningStopped = true;
						}
                    
						if (panningStopped)
							panning = false;
					}
                
					if (touchCount > 1) {
						// zoom
						zooming = true;
						zoomingStopped = true;
						bool newFingerSetup = false;

						int validTouchCount = touchCount;
						for (int i = 0; i < touchCount; ++i) {
							Touch touch = UnityEngine.Input.GetTouch (i);
                        
							if (touch.phase != TouchPhase.Ended) {
								zoomFactor += Vector3.Distance (screenPosition, new Vector3 (touch.position.x, touch.position.y));
								zoomingStopped = false;
							} else {
								--validTouchCount;
							}
    					
							// reset the last zoom factor to avoid a sudden jump when a finger is added or removed
							if (touch.phase == TouchPhase.Began
								|| touch.phase == TouchPhase.Ended)
								newFingerSetup = true;
						}
                    
						if (validTouchCount != 0)
							zoomFactor /= validTouchCount * 10.0f;
						else {
							zoomFactor = 0.0f;
							zoomingStopped = true;
						}
                    
						/*
                    Debug.Log("DEBUG: zooming: touch count: " + validTouchCount + ", factor: " + zoomFactor + ", zooming stopped: " + zoomingStopped + ", new finger setup: " + newFingerSetup);
                    string dbg = "DEBUG: touches:\n";
                    for (int i = 0; i < touchCount; ++i)
                    {
                        Touch touch = Input.GetTouch(i);
                        dbg += touch.phase + "\n";
                    }
                    Debug.Log(dbg);
                    */
    				
						if (newFingerSetup)
							lastZoomFactor = zoomFactor;
						if (zoomingStopped)
							zooming = false;
					}
				}
			} else {
				if (wasInputInterceptedByGUI == false) {
					// movements
					if (UnityEngine.Input.GetMouseButton (0)) {
						panning = true;
						screenPosition = UnityEngine.Input.mousePosition;
					} else if (UnityEngine.Input.GetMouseButtonUp (0)) {
						panningStopped = true;
					}
	    			
					// zoom
					if (UnityEngine.Input.GetKey (KeyCode.Z)) {
						zooming = true;
						zoomFactor = 1.0f;
						lastZoomFactor = 0.0f;
					} else if (UnityEngine.Input.GetKeyUp (KeyCode.Z)) {
						zoomingStopped = true;
					}
					if (UnityEngine.Input.GetKey (KeyCode.S)) {
						zooming = true;
						zoomFactor = -1.0f;
						lastZoomFactor = 0.0f;
					} else if (UnityEngine.Input.GetKeyUp (KeyCode.S)) {
						zoomingStopped = true;
					}
				}
			}
			
			if (panning) {
				// disable the centerWGS84 update with the last location
				map.UpdatesCenterWithLocation = false;
    			
				// apply the movements
				Ray ray = map.CurrentCamera.ScreenPointToRay (screenPosition);
				RaycastHit hitInfo;
				if (Physics.Raycast (ray, out hitInfo)) {
					Vector3 displacement = Vector3.zero;
					if (lastHitPosition != Vector3.zero) {
						displacement = hitInfo.point - lastHitPosition;
					}
					lastHitPosition = new Vector3 (hitInfo.point.x, hitInfo.point.y, hitInfo.point.z);
    				
					if (displacement != Vector3.zero) {
						// update the centerWGS84 property to the new centerWGS84 wgs84 coordinates of the map
						double[] displacementMeters = new double[2] {
							displacement.x / map.RoundedScaleMultiplier,
							displacement.z / map.RoundedScaleMultiplier
						};
						double[] centerMeters = new double[2] {
							map.CenterEPSG900913 [0],
							map.CenterEPSG900913 [1]
						};
						centerMeters [0] -= displacementMeters [0];
						centerMeters [1] -= displacementMeters [1];
						map.CenterEPSG900913 = centerMeters;
    					
						#if DEBUG_LOG
    					Debug.Log("DEBUG: Map.Update: new centerWGS84 wgs84: " + centerWGS84[0] + ", " + centerWGS84[1]);
						#endif
					}
    
					map.HasMoved = true;
				}
			} else if (panningStopped) {
				// reset the last hit position
				lastHitPosition = Vector3.zero;
    			
				// trigger a tile update
				map.IsDirty = true;
			}
    
			// apply the zoom
			if (zooming) {			
				map.Zoom (zoomFactor - lastZoomFactor);
				lastZoomFactor = zoomFactor;
			} else if (zoomingStopped) {
				lastZoomFactor = 0.0f;
			}
		}
Пример #36
0
	bool Toolbar(MapBehaviour map)
	{
		GUI.matrix = Matrix4x4.Scale(new Vector3(guiXScale, guiXScale, 1.0f));
		
		GUILayout.BeginArea(guiRect);
		
		GUILayout.BeginHorizontal();
		
		//GUILayout.Label("Zoom: " + map.CurrentZoom);
		
		bool pressed = false;
        if (GUILayout.RepeatButton("+", GUILayout.ExpandHeight(true)))
		{
			map.Zoom(1.0f);
			pressed = true;
		}
        if (Event.current.type == EventType.Repaint)
        {
            Rect rect = GUILayoutUtility.GetLastRect();
            if (rect.Contains(Event.current.mousePosition))
                pressed = true;
        }

        if (GUILayout.Button("2D/3D", GUILayout.ExpandHeight(true)))
		{
			if (isPerspectiveView)
			{
				destinationAngle = -perspectiveAngle;
			}
			else
			{
				destinationAngle = perspectiveAngle;
			}
			
			animationStartTime = Time.time;
			
			isPerspectiveView = !isPerspectiveView;
		}
        if (Event.current.type == EventType.Repaint)
        {
            Rect rect = GUILayoutUtility.GetLastRect();
            if (rect.Contains(Event.current.mousePosition))
                pressed = true;
        }

        if (GUILayout.Button("Center", GUILayout.ExpandHeight(true)))
        {
            map.CenterOnLocation();
        }
        if (Event.current.type == EventType.Repaint)
        {
            Rect rect = GUILayoutUtility.GetLastRect();
            if (rect.Contains(Event.current.mousePosition))
                pressed = true;
        }

        string layerMessage = String.Empty;
        if (map.CurrentZoom > layers[currentLayerIndex].MaxZoom)
            layerMessage = "\nZoom out!";
        else if (map.CurrentZoom < layers[currentLayerIndex].MinZoom)
            layerMessage = "\nZoom in!";
        if (GUILayout.Button(((layers != null && currentLayerIndex < layers.Count) ? layers[currentLayerIndex].name + layerMessage : "Layer"), GUILayout.ExpandHeight(true)))
        {
#if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9
            layers[currentLayerIndex].gameObject.SetActiveRecursively(false);
#else
			layers[currentLayerIndex].gameObject.SetActive(false);
#endif
            ++currentLayerIndex;
            if (currentLayerIndex >= layers.Count)
                currentLayerIndex = 0;
#if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9
            layers[currentLayerIndex].gameObject.SetActiveRecursively(true);
#else
			layers[currentLayerIndex].gameObject.SetActive(true);
#endif
            map.IsDirty = true;
        }

        if (GUILayout.RepeatButton("-", GUILayout.ExpandHeight(true)))
		{
			map.Zoom(-1.0f);
			pressed = true;
		}
        if (Event.current.type == EventType.Repaint)
        {
            Rect rect = GUILayoutUtility.GetLastRect();
            if (rect.Contains(Event.current.mousePosition))
                pressed = true;
        }
		
		GUILayout.EndHorizontal();
					
		GUILayout.EndArea();
		
		return pressed;
	}