Search Unity

DMMap Minimap System 2.0! Procedural, Multilayer & Vector-like maps, uGUI! NOW FREE and OPEN SOURCE

Discussion in 'Assets and Asset Store' started by DMeville, Aug 8, 2014.

  1. kimsama

    kimsama

    Joined:
    Jan 2, 2009
    Posts:
    166
    Thanks you for your proceedings.

    I solved that problem as doing what you've mentioned.

    Thanks again.

    -Kim
     
    DMeville likes this.
  2. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
    When I try to start my scene I get this error:

    Unable to find a triangle on path.
     
  3. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @katasteel Are you running one of the demo scenes? If not what does your map shapes look like?
    Can you post the actual error (call stack, line number)?
     
  4. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
    Lol, sorry about my non-descript post.

    My levels are created procedurally, and my player is spawned after the level is created.

    If I just add DMMap to the scene it does not error out.
    But of course I need the map to follow the player so I added this script after my player is created.

    Code (CSharp):
    1.             foreach (DMMapConfig dmc in DMMap.instance.configs)
    2.             {
    3.                 dmc.objectToFocusOn = transform.parent.transform;
    4.             }
    5.  
    6.             DMMap.instance.Generate();
    Then it produces the following error:

    Exception: Unable to find a triangle on path.
    TriangleNet.Meshing.ConstraintMesher.FindDirection (TriangleNet.Topology.Otri& searchtri, TriangleNet.Geometry.Vertex searchpoint) (at Assets/DMMap/Lib/Triangle.NET/Triangle/Meshing/ConstraintMesher.cs:573)
    TriangleNet.Meshing.ConstraintMesher.ScoutSegment (TriangleNet.Topology.Otri& searchtri, TriangleNet.Geometry.Vertex endpoint2, Int32 newmark) (at Assets/DMMap/Lib/Triangle.NET/Triangle/Meshing/ConstraintMesher.cs:754)
    TriangleNet.Meshing.ConstraintMesher.InsertSegment (TriangleNet.Geometry.Vertex endpoint1, TriangleNet.Geometry.Vertex endpoint2, Int32 newmark) (at Assets/DMMap/Lib/Triangle.NET/Triangle/Meshing/ConstraintMesher.cs:1095)
    TriangleNet.Meshing.ConstraintMesher.FormSkeleton (IPolygon input) (at Assets/DMMap/Lib/Triangle.NET/Triangle/Meshing/ConstraintMesher.cs:235)
    TriangleNet.Mesh.ApplyConstraints (IPolygon input, TriangleNet.Meshing.ConstraintOptions options, TriangleNet.Meshing.QualityOptions quality) (at Assets/DMMap/Lib/Triangle.NET/Triangle/Mesh.cs:386)
    TriangleNet.Meshing.GenericMesher.Triangulate (IPolygon polygon, TriangleNet.Meshing.ConstraintOptions options, TriangleNet.Meshing.QualityOptions quality) (at Assets/DMMap/Lib/Triangle.NET/Triangle/Meshing/GenericMesher.cs:56)
    TriangleNet.Geometry.ExtensionMethods.Triangulate (IPolygon polygon) (at Assets/DMMap/Lib/Triangle.NET/Triangle/Geometry/ExtensionMethods.cs:17)
    DMM.DMMap.GenerateMeshLayer (Int32 layer) (at Assets/DMMap/Scripts/DMMap.cs:599)
    DMM.DMMap.Generate () (at Assets/DMMap/Scripts/DMMap.cs:202)
    Apoth.PlayerCharacter.SetCharacterData (Apoth.CharacterData cd) (at Assets/Apoth/Scripts/Character/Player/PlayerCharacter.cs:567)
    Apoth.GameManager.SetupPlayerCharacter (Apoth.PlayerCharacter pc) (at Assets/Apoth/Scripts/Managers/GameManager.cs:231)
    Apoth.GameManager.AddCharacter (Apoth.Character character) (at Assets/Apoth/Scripts/Managers/GameManager.cs:221)
    Apoth.GameManager.Add (UnityEngine.GameObject go) (at Assets/Apoth/Scripts/Managers/GameManager.cs:206)
    Apoth.PlayerSpawn.Spawn () (at Assets/Apoth/Scripts/Spawn/PlayerSpawn.cs:82)
    Apoth.PlayerSpawn.Apex.Services.IHandleMessage<Apex.Messages.GridStatusMessage>.Handle (Apex.Messages.GridStatusMessage message) (at Assets/Apoth/Scripts/Spawn/PlayerSpawn.cs:58)
    Apex.Services.BasicMessageBus+<BalancedPoster>c__Iterator2B`1[Apex.Messages.GridStatusMessage].MoveNext () (at Assets/AssetStore/Apex/Apex Path/Scripts/Services/BasicMessageBus.cs:130)
    Apex.LoadBalancing.LongRunningAction.ExecuteUpdate (Single deltaTime, Single nextInterval) (at Assets/AssetStore/Apex/Apex Path/Scripts/LoadBalancing/LongRunningAction.cs:78)
    Apex.LoadBalancing.LoadBalancedQueue.Update () (at Assets/AssetStore/Apex/Apex Path/Scripts/LoadBalancing/LoadBalancedQueue.cs:250)
    Apex.LoadBalancing.LoadBalancerComponent.Update () (at Assets/AssetStore/Apex/Apex Path/Scripts/LoadBalancing/LoadBalancerComponent.cs:74)

    Here are some pictures of my setup.

    https://www.dropbox.com/s/81wbu8yq2mb15s6/DMMAP1.JPG?dl=0
    https://www.dropbox.com/s/0oygq0gd0d6pumk/DMMAP2.JPG?dl=0
    https://www.dropbox.com/s/govajnl9avf6cng/DMMAP3.JPG?dl=0

    Other question would be:

    -How do I change the shape of the map to square?
    -How do I remap the full-screen map key?
    -How to I change the placement of the map?
     
  5. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @katasteel Thanks for that. I'll have to see if I can reproduce this. In the meantime there is a procedural demo scene that comes with DMMap that does work without a problem - perhaps you could take a look there and see how it compares to your setup. It seems like it's an error with the triangulation library, which means it could be having problems with your specific placement of DMMap shape points.

    Regarding your other questions;
    - You can change the shape of the map by creating a square mask in photoshop (white square on a black background) and use that for your mask texture on the DMMap material.
    - I don't remember if DMMap does anything for this automatically, so you might have to listen for keyboard input yourself somewhere, and just toggle fullscreen on the DMMap.instance.
    - The map is rendered into a uGUI image, you can move it just like any other uGUI elements!
     
  6. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    I should also point out that you can simply assign the player transform the way you have before or after the map is generated. There's no need to call DMMap.instance.Generate() again after you assign the transform. If this is the first time that you're generating the map though that's no problem, just make sure generateOnStart is toggled off in the DMMap inspector so you're not generating the map twice (which can be slow). The procedural demo shows an example of this!
     
  7. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
    I was wrong it still gives the error even if I don't add the player to the objectToFocusOn.

    Here is another screenshot with debug info on:

    https://www.dropbox.com/s/kkijgtusxinfyt6/DMMAP4.JPG?dl=0

    One question is do the shapes have to overlap?
    I am outlining my rooms so the lines are probably just side by side not overlapping.
     
  8. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    The shapes don't need to overlap, they only need to overlap if you want them to look connected on the minimap. The reason for this is it generates a mesh using the shape points as verticies. Depending on precision this can leave to unwanted gaps between rooms on the minimap.

    What could be happening is two verticies landing on the exact same place and the triangulation library not knowing how to resolve them (which I think was a problem I thought I fixed last year when I first wrote DMMap). This can be a problem with grid aligned things, which is why it can be easier to just make things overlap slightly, but I'll take a look and see what I find!
     
  9. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @katasteel I spent this morning trying to recreate your problem, but I can't seem to reproduce your error. Would it be possible to somehow zip up a minimal project so I can see what's happening or something?
     
  10. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
    I pulled in the points a little to see if it made a difference and I don't get errors like that.
    So it must be that the points are landing on top of each other.

    How do I zoom in/out and switch back and forth from mini to fullscreen?
     
  11. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    I tested that by spawning the same tiles right ontop of eachother but it didn't break, so I'm not sure, but I'm glad it's working now. Sorry about that!

    If you take a look at the DMMapUIControls.cs file that's in the DMMap/Demo/DemoAssets folder there's an example of how to control zoom and fullscreen.

    To change the zoom you can change DMMap.instance.configs[DMMap.instance.loadedConfig].zoom = floatValue;
    And to enter fullscreen you just have to load the Fullscreen config: DMMap.instance.LoadConfig(1);
    And to exit fullscreen you can load: DMMap.instance.LoadConfig(0);
     
  12. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
    One last question is there currently a way to pan the map or to use the mouse to move the map?
     
  13. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
    Anything special I need to do to get the icons to show up on the map?

    I see the icon listed under DMMap->Icons at runtime but it's not displaying on the map.
     
  14. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @katasteel Nope, there's no built in way to pan the map right now. This runs into an issue I've mentioned before about supporting a whole bunch of different ways to do things - it's hard :p Instead I've made it so DMMap is pretty easy to do stuff like this with a little bit of coding knowhow, because everyone has different needs it's impossible for me to manage them all without this becoming a full time project :)

    That being said, you can pan the map by moving the DMMap camera manually, you'll have to create a system do move it (e.g., hook into input), here's a simple example of doing this with they keyboard arrow keys. It should be noted this only works when there's no object to focus on, because DMMap.update locks the camera position to the target every frame if you're following something. There needs to be some system to smartly unlock the camera when panning, and a way to lock back smoothly. It might be a good idea to add a cameraOffset Vector3 to the configs and use that for panning in DMMap.update. I'll keep this in mind for the next update

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using DMM;
    5.  
    6. public class DMMapKeyboardPan : MonoBehaviour {
    7.  
    8.     public Vector3 offset = new Vector3();
    9.     public float panSpeed = 50f;
    10.  
    11.     private void Update () {
    12.         offset = Vector3.zero;
    13.         if (Input.GetKey(KeyCode.LeftArrow)) {
    14.             offset.x += panSpeed;
    15.         }
    16.         if (Input.GetKey(KeyCode.RightArrow)) {
    17.             offset.x -= panSpeed;
    18.         }
    19.         if (Input.GetKey(KeyCode.UpArrow)) {
    20.             offset.z -= panSpeed;
    21.         }
    22.         if (Input.GetKey(KeyCode.DownArrow)) {
    23.             offset.z += panSpeed;
    24.         }
    25.  
    26.         DMMap.instance.DMMapCamera.transform.position += offset * Time.deltaTime;
    27.     }
    28. }
    29.  
    As for your icons, make sure your icons have a colour with an alpha of > 0!
     
    sarynth likes this.
  15. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
    Is there anyway to have some shapes draw as different colors?
    For example I would like doors to be a different color
     
  16. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @katasteel Yep, check out the TopDown_Demo, it shows an example of rendering different map shapes with different materials. DMMapShapes have a Layer int - this value corresponds to what material is used to draw it. The materials are defined on the configs, "Mesh Layer Material". Shapes with layer = 0, will use meshLayerMaterial[0].

    You could duplicate the 2DPolygonOutline material and change the colours on the duplicate, and assign that in element 1 of the array, then assign your door shapes layer a value of 1.
     
  17. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
    D,

    You have been very helpful, thanks.

    Correct me if I'm wrong please:

    The problem I see is that you are using the same variable for material layer as you do for map layer.
    So if I have a map with 100 layers(unexplored rooms) that all use the same material. I would need to add the same material under the config 100 times!
     
  18. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Hmm that's a good point, they could/should probably be separated. I'll need to think of a nicer way to do this.

    In the meantime I should note that if you have 100 layers, but only one material defined in the MeshLayerMaterial array it will fall back to the default material (defined at the top of the DMMap inspector) and use that for any other meshes.

    For example. Say you have 10 layers [0-10], and only the default material and materials[0] defined in your config. Layer 0 will get materials[0], and layers [1-9] will get the default material.

    Hope that helps!
     
  19. IndieGameHustle

    IndieGameHustle

    Joined:
    Jul 25, 2012
    Posts:
    66
    Hello,

    I have just received a error :
    error CS0519: 'TriangleNet.Log' clashes with a predefined namespace
     
  20. IndieGameHustle

    IndieGameHustle

    Joined:
    Jul 25, 2012
    Posts:
    66
    Hello,

    I have just received a error :
    error CS0519: 'TriangleNet.Log' clashes with a predefined namespace
     
  21. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @GameIntern It sounds like it doesn't like the TriangleNet namespace, which is the triangulation library I'm using to generate the meshes. This makes me think you already have a copy of the TriangleNet library somewhere in your project, and importing DMMap made a duplicate which now unity doesn't like that there's two or something.

    If that's not the case, not sure what else would cause that, does it give you a line number/script name where the error is coming from specifically or anything?
     
  22. IndieGameHustle

    IndieGameHustle

    Joined:
    Jul 25, 2012
    Posts:
    66
    Yes I think that another asset ( Probuilder ) is using the same namespace somewhere. When I installed the update to PB that is when it caused this. Do you know of a way to avoid this like changing the namespace to something else. I am depending on your asset for my mini map big time! :) I am not a coder so my knowledge is little on a solution.

    Thanks!

     
  23. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @GameIntern You might be able to just delete one of the duplicate libraries, find the DMMap/Lib/TriangleNET folder and just delete it. If both pro builder and DMMap are using the same version of this library it shouldn't matter where it's located in your project, so long as there's only one copy. That might be the easiest solution, but I'd recommend backing up your project before trying this, because I'm not exactly sure if this would work. Admittedly it was almost 2 years ago when I last dug into the TriangleNET code, I can't actually remember if I made any changes to it, but I think there were a few bug fixes I made.

    If that doesn't work the other option is going through every *.cs file in that folder individually and changing the namespace to something other than "TriangleNET"
     
    Last edited: Apr 10, 2016
  24. IndieGameHustle

    IndieGameHustle

    Joined:
    Jul 25, 2012
    Posts:
    66
    Ok, changing the name spaces did work! I made all the changes to the namespaces. I changed TrianlgeNet to TriangleNetdm (Everywhere).

    Thank You!!!!
     
    Last edited: Apr 12, 2016
    DMeville likes this.
  25. connectt01

    connectt01

    Joined:
    Aug 14, 2014
    Posts:
    4
    Hello, I've noticed that the minimap is broken on Mac running in fullscreen. The minimap content covers the whole screen. Just wanted to ask if this is a known problem and for some tips on fixing this. Thanks!
     
    DMeville likes this.
  26. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @connectt01 Hey! Seems like something changed with regards to how fullscreen works in some recent version of Unity that I must have overlooked.

    Try adding this code at the top of the Update function in DMMap.cs (line 396) and let me know if that fixes your problem (seems to work for me!)

    Code (CSharp):
    1.  
    2. if (mainRenderTexture == null || !mainRenderTexture.IsCreated()) {
    3.           InitializeRenderTexture();
    4.           DMMapCamera.targetTexture = mainRenderTexture;
    5.           mapImage.texture = mainRenderTexture;
    6.           mapImage.material.SetTexture("_MainTex", DMMapCamera.targetTexture);
    7.           DMMapCamera.backgroundColor = configs[loadedConfig].mapBackgroundColor;
    8.           DMMapCamera.orthographicSize = configs[loadedConfig].zoom;
    9. }
    10.  
     
    connectt01 likes this.
  27. connectt01

    connectt01

    Joined:
    Aug 14, 2014
    Posts:
    4
    @DMeville Thanks for the really quick response! Your code worked perfectly! Thanks!
     
    DMeville likes this.
  28. dpolyakov

    dpolyakov

    Joined:
    Dec 18, 2015
    Posts:
    16
    Hi, are there any plans for fog of war? or any ideas how to make it?
     
    Superjayjay likes this.
  29. chilberto

    chilberto

    Joined:
    Nov 18, 2013
    Posts:
    21
    @DMeville Thank you - I had an issue where in the build the camera was showing fullscreen as opposed to only in the minimap as @connectt01 had. My build was windows.

    I added your fix to Update function in DMMap.cs (line 396) and all is working!

    Cheers
     
    DMeville likes this.
  30. jococo

    jococo

    Joined:
    Dec 15, 2012
    Posts:
    232
    I don't use UGUI only the Unity5 UI canvas. This will still work?
     
    DMeville likes this.
  31. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Yes, UGUI and the Unity 5 UI canvas are the same thing!
    DMMap uses the Canvas and RectTransforms for alignment, so you can integrate the Minimap seamlessly with other UI elements. It renders the minimap into an Image component, and also uses Image components for map icons, etc!
     
    jococo likes this.
  32. Elzean

    Elzean

    Joined:
    Nov 25, 2011
    Posts:
    584
    I just imported DMMap and i got those errors:
    upload_2017-1-24_11-49-38.png

    im using unity 5.4.4.p1

    Do you know how i can fix those ?
     
  33. Rusted_Games

    Rusted_Games

    Joined:
    Aug 29, 2010
    Posts:
    135
    I just imported on a brand new project with Unity 5.4.4p1 and got no errors, do you have other assets already?
    I had a similar issue when using DMMap and ProBuilder assets in the same project, they use a similar Triangle.NET library and I needed to change the namespace of the one referenced by DMMap since it offers the soure code.
     
  34. Elzean

    Elzean

    Joined:
    Nov 25, 2011
    Posts:
    584
    I dont have probuilder in this project, but i have many other stuff. I do not have another Triangle.NET lib.

    I deleted the file "AssemblyInfo.cs" didnt seems to have anything important inside, do you think it's fine ?

    It seems to work without it now.
     
  35. Rusted_Games

    Rusted_Games

    Joined:
    Aug 29, 2010
    Posts:
    135
    I don`t have that file on my project either but yes its fine to remove it since its a file used when you compile your code into a dll,
    EDIT
    Actually yes it's inside the 2.2 version but somehow it didn't get imported with my quick test, @DMeville maybe will be good idea to remove it from your package
     
  36. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @alardaen Thanks for testing this so quickly!

    @Elzean I also have no issues importing into 5.4.4p1, but that is very interesting about the AssemblyInfo.cs. I'm not even sure what this file is doing, but it was something that came from Tringle.NET lib.

    I'll take a look at removing it from DMMap :)
     
    Last edited: Jan 25, 2017
  37. Elzean

    Elzean

    Joined:
    Nov 25, 2011
    Posts:
    584
    Actually another asset, "Rainbow Folder", also have an "AssemblyInfo.cs" with same kind of stuff inside. So it seems having it twice was causing those errors.
     
    DMeville likes this.
  38. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Hi @DMeville , I've just discovered this great looking asset and I would like to buy it. I really like the multi level functionality.

    I'm wondering though, is it possible to use a texture for the map instead of using the vector shapes? I am intending to use this in ArchViz to be able to show a top down view of different floors of a building. I would need to have a more detailed style minimap which would show the interior of each room, eg. furniture, floor surface, wall colors etc.

    How would I go about using a texture for each floor, is this possible?
     
    Last edited: Mar 4, 2017
  39. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Hey @Hamesh81

    I don't think DMMap will work for what you're looking to do. DMMap's strength lies in auto-generating nice vector looking minimaps at runtime or for procedurally generated levels. There is the option to customize the shader used on the generated shapes, but I don't think that's will work for what you're after.

    It sounds like you're looking for a more "traditional" way of rendering a minimap. You could set up a top down camera to render into a render texture, and then plug that into a UI image to capture a full colour and detail version of your scene like a minimap. There's quite a few tutorials floating around on making minimaps using this method, and I think even some of the other minimap packages on the asset store do it this way too, which might be worth looking into.

    Hope that helps!
     
  40. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Thanks for your reply @DMeville . Let me clarify this a little; I was thinking of instead of using the mesh generated by the vector shape tool, I would instead use my own quad mesh (2 triangles) and then manually apply a material with an alpha texture to this mesh. So I would not actually need the texture to update at runtime, it would simply allow me to have more creative control over the look of the minimap output if that makes sense. I'm not sure though how using my own geometry would affect the multi floor functionality of the minimap; for example if I would need one quad mesh for each floor or if all of the floors would need to be combined into one mesh. Would this work?

    I have looked at other minimap solutions on the asset store as well, but none of them have the multi level/floor functionality that this great asset does. Please let me know your thoughts.
     
    DMeville likes this.
  41. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @Hamesh81 The multi-floor stuff that DMMap does isn't anything special and would be pretty easy to recreate!

    If I recall correctly (it's been a long time since I've looked at the DMMap code...) all this does is checks the player's (or minimap target transform's) y-position, toggles off all layers and then toggles on whichever layer the player's y-position is closest to. The DMMap code is all commented and pretty clean so it could work as a good starting point, but it might just be simpler to start from scratch as DMMap isn't really doing anything special in this regard!
     
  42. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Thinking about it, you might be able to pre-generate some "dummy" geometry with DMMap, and then just replace it with your own textured quads and untick "Generate on Start". You might have to tweak things until they align properly, but I don't see why this shouldn't work.. I've never tried it though! :p
     
    Hamesh81 likes this.
  43. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    No problems I will try this out and see how I go. Thanks a lot ;)
     
  44. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Hi @DMeville , I managed to resolve this very easily. On line 352 where the call is made to UpdateMaterial I simply wrapped a conditional around this to only do so if there is a default material set. I then created a DM Mesh manually with the different floors and I am using the included script to enable disable them by height. Thank you for this great asset :)

    Just one issue I'm having is with the DM Icon script. For some reason the icon is not showing in the minimap. I have watched the tutorial and followed the quick start guide and I can't see what I'm doing wrong. Any ideas on this?
     
  45. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @Hamesh81 Glad to hear it worked out!

    By default when creating a new DMMapIcon the colour alpha is set to 0, make sure to crank that up to 1 and you should see your icons!
     
  46. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Yes that was it :D
    Thanks heaps!

    Sorry one more question. If I want to make the area that is rendered smaller but leave the graphics (map & overlay) at the same size how can I do this? I have tried changing the "Map" gameobject and "Minimap-RectTransform" but on play they snap back to their original values. Is there somewhere else that I need to change this?
     
    Last edited: Mar 9, 2017
  47. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    @Hamesh81 Are you looking for the "zoom" property? It can be found on the DMMap component, in the configs array!
     
  48. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    No it's not the zoom actually. I was having an issue with the icon distance threshold since I am creating a square minimap, and therefore the threshold diagonally towards the corners is further then horizontally or vertically. As a result the icons are turning into directional indicators too early when near the corners. Not sure if there is an easy fix for this though.
     
  49. DMeville

    DMeville

    Joined:
    May 5, 2013
    Posts:
    418
    Hmm yeah. I think icons only change to directional indicators based on radius from the player/map center, if you want them to work "properly" on a square map, you'll have to change the logic in DMMapIcon::UpdateIcons() a little bit. I just whipped this up, but it seems to work right.

    Try changing the code in DMMapIcon::UpdateIcons() to this:
    Code (CSharp):
    1.  
    2. public void UpdateIcons() {
    3.             mapPosition = DMMap.instance.WorldtoUI(this.gameObject.transform.position);
    4.             //since camera will always be aligned to the mapImage UI, just us that
    5.  
    6.             mapPosition.z = 0f;
    7.             if (useDirectionIndicator) {
    8.                 float threshold = DMMap.instance.configs[DMMap.instance.loadedConfig].iconDistanceThreshold;
    9.                 //if the icon is further away from the center than allowed by the threshold value
    10.                 //this can be extended (or doing a similar check) to have the icon fade off or something.
    11.                 //Perhaps by extending this class and overriding this function
    12.  
    13.                 if(mapPosition.x < -threshold || mapPosition.x > threshold || mapPosition.y < -threshold || mapPosition.y > threshold) {
    14.                     iconGO.GetComponent<Image>().sprite = directionIcon;
    15.                     if(mapPosition.x < -threshold) mapPosition.x = -threshold;
    16.                     if(mapPosition.x > threshold) mapPosition.x = threshold;
    17.                     if(mapPosition.y < -threshold) mapPosition.y = -threshold;
    18.                     if(mapPosition.y > threshold) mapPosition.y = threshold;
    19.  
    20.                     this.iconGO.transform.localPosition = mapPosition;
    21.                     float angle = Mathf.Atan2(mapPosition.y, mapPosition.x) + (Mathf.Deg2Rad*rotationOffset);
    22.                     iconGO.GetComponent<Image>().transform.rotation = Quaternion.AngleAxis(Mathf.Rad2Deg*angle, Vector3.forward);
    23.                 } else {
    24.                     RotateIcon();
    25.                     iconGO.GetComponent<Image>().sprite = icon;
    26.                     this.iconGO.transform.localPosition = mapPosition;
    27.                 }
    28.             } else {
    29.                 RotateIcon();
    30.                 this.iconGO.transform.localPosition = mapPosition;
    31.             }
    32.  
    33.             float scale;
    34.             float zoom;
    35.             switch (DMMap.instance.configs[DMMap.instance.loadedConfig].iconScaleMode) {
    36.                 case IconScaleMode.NoScale:
    37.                     scale = DMMap.instance.configs[DMMap.instance.loadedConfig].globalIconScale;
    38.                     iconGO.transform.localScale = new Vector3(scale, scale, scale);
    39.                     break;
    40.                 case IconScaleMode.ScaleWithZoom:
    41.                     scale = DMMap.instance.configs[DMMap.instance.loadedConfig].globalIconScale;
    42.                     zoom = DMMap.instance.configs[DMMap.instance.loadedConfig].zoom;
    43.                     if (Mathf.Abs(zoom) < 0.0001) {
    44.                         zoom = 0.001f * Mathf.Sign(zoom); //prevent x/0 = inf errors
    45.                     }
    46.                     iconGO.transform.localScale = new Vector3(scale + (1 / zoom), scale + (1 / zoom), scale + (1 / zoom));
    47.                     break;
    48.                 case IconScaleMode.DefinedPerIcon:
    49.                     if (this.scaleWithZoom) {
    50.                         scale = DMMap.instance.configs[DMMap.instance.loadedConfig].globalIconScale;
    51.                         zoom = DMMap.instance.configs[DMMap.instance.loadedConfig].zoom;
    52.                         if (Mathf.Abs(zoom) < 0.0001) {
    53.                             zoom = 0.001f * Mathf.Sign(zoom); //prevent x/0 = inf errors
    54.                         }
    55.                         iconGO.transform.localScale = new Vector3(scale + (1 / zoom), scale + (1 / zoom), scale + (1 / zoom));
    56.                     } else {
    57.                         scale = DMMap.instance.configs[DMMap.instance.loadedConfig].globalIconScale;
    58.                         iconGO.transform.localScale = new Vector3(scale, scale, scale);
    59.                     }
    60.                     break;
    61.             }
    62.         }
     
    Hamesh81 likes this.
  50. Hamesh81

    Hamesh81

    Joined:
    Mar 9, 2012
    Posts:
    405
    Oh wow thanks a lot, I wasn't expecting that! It works really well now. I've put in a bool to be able to switch between the circular or square code from the config setup.