Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Grid Framework [scripting and editor plugins]

Discussion in 'Assets and Asset Store' started by hiphish, Jul 24, 2012.

  1. nguyennk91

    nguyennk91

    Joined:
    Sep 16, 2015
    Posts:
    10
    Wondering if is there anyway to get the grid that is nearest to mouse?
    Currently i have a building system work with 1 grid already by checking the max/min of that grid
    But now i need to have more than 1 grid so is there any way to obtain the grid object that is nearest to mouse?
     
  2. ezaz12121

    ezaz12121

    Joined:
    Oct 7, 2015
    Posts:
    22
    I have questions , I know I can use this framework to save my level out to txt file and load up levels that way , how ever can I use this with the mad level manager asset, I want to have 10 stages with 10 or so levels each , is that possible with your grid framwork, save the levels and use that asset to load them accordingly in each stage?
     
  3. aaronjbaptiste

    aaronjbaptiste

    Joined:
    Dec 4, 2012
    Posts:
    62
    I'm having trouble getting this to work with Vectrosity 5:

    Assets/Grid Framework/Examples/Vectrosity/Scripts/BouncyGrid.js(25,35): BCE0024: The type 'Vectrosity.VectorLine' does not have a visible constructor that matches the argument list '(String, UnityEngine.Vector3[], UnityEngine.Material, float)'.

    Using Unity 5.2

    Looks like it's passing a Vector3[] and it's expecting a List<Vector3>. Will the GridFramework plugin be updated?

    Thanks
     
  4. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Nearest anything to the mouse is always tricky because the mouse cursor is in 2D screen space and the grid is in 3D world space. The way I usually do it is use the mouse cursor and the main camera to cast a ray and see where it hits first. There needs to be a collider, so you will have to wrap a box collider around your grids like this:
    Code (csharp):
    1. GFGrid grid;
    2. BoxCollider c = grid.gameObject.AddComponent<BoxCollider();
    3.  
    4. // Wrap the visible portion of the grid
    5. void WrapGrid(GFGrid grid) {
    6.    c.center = grid.originOffset;
    7.    if (grid.customRenderRange) {
    8.        c.center += (grid.renderTo + grid.renderFrom) / 2.0f;
    9.        c.size = grid.renderFrom - grid.renderTo;
    10.    } else {
    11.        c.size = 2.0f * grid.size * grid.relativeSize ? grid.spacing : 1.0f
    12.     }
    13. }
    You will have to call this code every time you change your grid's origin offset of size in order to re-wrap your grid.

    Then you raycast from your main camera:
    Code (csharp):
    1. Camera cam = Camera.main;
    2. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    3. RaycastHit hit;
    4. GFGrid grid;
    5. if (Physics.Raycast(ray, out hit, 100)) {
    6.     grid = hit.collider.gameObject.GetComponent<GFGrid>();
    7. }
    In practice you will want to assign your grid collider to a particular layer so they don't interfere with the rest of the game. You then have to pass a layer mask to the raycasting function.
    http://docs.unity3d.com/ScriptReference/Physics.Raycast.html

    I theory yes, but I don't see any documentation on Mad Level Manager's level format. If you had that you could write to it, Grid Framework does not help nor hinder any file writing. Have a template level file and then fill the placeholders with values according to the specifications.
     
  5. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    I'll look into it, seems like Vectrosity changed its API. Here is how to fix Grid Framework: open the file Assets/Plugins/Grid Framework/Abstracts/GFGrid.cs and change the methods GetVectrosityPoints(from, to) (line 972) and GetVectrosityPoints() (line 984) to read the following:
    Code (csharp):
    1. public List<Vector3> GetVectrosityPoints(Vector3 from, Vector3 to) {
    2.     Vector3[][] seperatePoints = GetVectrosityPointsSeparate(from, to);
    3.     var returnedPoints = new List<Vector3>();
    4.     returnedPoints.AddRange(seperatePoints[0]);
    5.     returnedPoints.AddRange(seperatePoints[1]);
    6.     returnedPoints.AddRange(seperatePoints[2]);
    7.     return returnedPoints;
    8. }
    EDIT: Also add this somewhere to the top of the file
    Code (csharp):
    1. using System.Collections.Generic;

    public List<Vector3> GetVectrosityPoints() {
    return useCustomRenderRange ? GetVectrosityPoints(renderFrom, renderTo) : GetVectrosityPoints(-size, size);
    }[/code]

    Here is my problem: I can import Unity 4 projects in Unity 5, but not the other way around, so I still need to be on Unity 4 in order to build packages for that version. Vectorsity 5 does not work in Unity 4 however, so I have to juggle back and forth between two projects. I really need to find a more elegant way of handling this.

    On top of that there is no way of checking the version of Vectrosity at compile time. In older languages like C or C++ you could define a macro like
    Code (csharp):
    1. #define VECTROSITY_VERSION  5
    2.  
    3. // in the actual source
    4. #if VECTROSITY_VERSION >= 5
    5. // modern code
    6. # else
    7. // legacy code
    8. #endif
    and use that to control which code gets compiled. In C# it's not that easy, you have to set your definitions in the editor, you can't just ship them with a file.

    I'll have to see what to do about this, maybe the best solution would be to remove Vectorosity support and make it a separate plugin (free of course), even if that's less convenient.
     
    Last edited: Oct 21, 2015
  6. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    New website
    Over the last few months I have been busy redesigning the website and we are finally live now. Check it out:


    The new website has been rewritten from scratch, but all the old links are still valid. It is now a modern site that looks good on desktops, on tablets, on phones and even in text mode. All content is static and the site works fine with and without JavaScript enabled in your browser.

    Showcase your work
    Judging by the five-star reviews you all seem to like Grid Framework, but what are you using it for? I want to have a showcase page on the website where I can show off some of the games made using Grid Framework. If you want your game featured drop me a line, include a screenshot (or give me permission to pick one myself) and a few sentences about your game and what you used Grid Framework for. I'm looking forward to seeing all the cool uses you came up with.

    About the new website
    The original website was made from hand-written HTML and CSS. While I like the pure hands-on approach it became quickly apparent that that wouldn't cut it in the long run. Take for example the navigation bar: It has to appear on every page, it has to be the same everywhere and the currently active item has to be highlighted. HTML has no interactive elements and no way to include snippets. I could have used JavaScript, but then the site would break down it people don't have JavaScript enabled.

    I was looking into different solutions and settled for Pelican. Pelican is a static site generator, meaning you write template HTML pages with placeholders and you write your content separately. Pelican then generates the finished website from your template, content and a number of settings. This has all the benefits of being static while being easy to maintain.

    For the actual website I decided instead of reinventing the wheel I would just leverage the work of people who know more about web development than me. I use Bootstrap as my CSS framework and jQuery for light JavaScript decoration. I also now have a proper gallery using Pretty Photo library. You can find a list of all components on the about page.

    One final note about JavaScript if you are concerned about proprietary code: all the foreign code is free software and the code I have written is free as well (MIT licensed), no need to worry.

    What is still missing is the blog. Because I intend the Workshop to be home to all my projects it would be a bad idea to lump all news into the same blog. Pelican has no capability of producing multiple blogs, I will have to write a multiblog plugin instead. Until then this blog stays the news site.
     
  7. aaronjbaptiste

    aaronjbaptiste

    Joined:
    Dec 4, 2012
    Posts:
    62
    New website looks great!

    I'm using the Grid Framework in the upcoming game MYMMO - A city builder where you design an MMO RPG. It's an instrumental part of the world building toolset. I was able to get grid snapping and Sim City style zoning tools working with minimal hassle, love it. Video of it in action.

    If you need me to create an image let me know your preferred resolution :)
     
  8. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Hi, the video looks pretty cool. The image resolution is not that important, I just set the maximum width via CSS. Being larger than the minimum is good, that way when the user zooms in the image stays crisp. I was thinking about making it 500 pixels wide. (EDIT: screw that, make the picture as large as you want, I'll use Pretty Photo (the gallery plugin) to make the screenshots clickable)

    I need a quote that's presentable to total strangers. How about this?
    I think the image in update 5 looks good, it shows grids in action, but I need a still frame. If it's OK with you I can grab a frame from the GIF, or you can send me one yourself.
     
    Last edited: Oct 26, 2015
  9. aaronjbaptiste

    aaronjbaptiste

    Joined:
    Dec 4, 2012
    Posts:
    62
    Full resolution image: http://i.imgur.com/b6pnVBH.png

    MYMMO is a Sim City inspired city builder with a twist: you are the designer of an MMO RPG. Grid Framework is an instrumental part of the world building toolset, I was able to get grid snapping and zoning tools working with minimal hassle, love it.

    :) thanks buddy, goodluck with the new site.
     
  10. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
  11. aaronjbaptiste

    aaronjbaptiste

    Joined:
    Dec 4, 2012
    Posts:
    62
    You can put my real name and indie studio: Aaron John-Baptiste, Gravity Apple

    Yes please link to the forum thread for the moment, dedicated website is in the works.
     
  12. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
  13. aaronjbaptiste

    aaronjbaptiste

    Joined:
    Dec 4, 2012
    Posts:
    62
    Thanks Hiphish. Quick question, I'm having trouble getting the grid to render correctly when using a Deferred rendering camera. If I add even single transparent object to the scene (Standard shader set to rendering mode transparent) the grid renders on top of everything else (opaque objects included). Any ideas?
     
  14. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    I think that's because of the standard shader. You can read its source code in the user manual, when no custom shader is supplied that's the one used. It's a very simple barebones shader, just so you have some way of getting it to display the grid. I know there used to be a bug in mobile builds of Unity and people have had good success with unlit shaders, like these ones:
    http://owlchemylabs.com/content/

    Here is an idea for a workaround if you don't want to write shaders: attach a second camera to your main camera, make its position and rotation (0,0,0) so it matches up with the main camera and add the grid rendering script to it. Keep your main camera deferred and set the grid camera to forward or something else.
     
  15. aaronjbaptiste

    aaronjbaptiste

    Joined:
    Dec 4, 2012
    Posts:
    62
    Thanks Hiphish. I've tried quite a few materials for the grid lines, and I've tried going the custom shader route but to no avail.

    I've also tried the multiple camera trick, but it looks like there's a long standing (since 2011) bug with having a deferred camera rendering with depth only. The buffer never clears and I get extreme smearing all over the place.
     
  16. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    If it helps you: Grid Framework is using Unity's GL class to draw the lines onto the camera directly.
    http://docs.unity3d.com/ScriptReference/GL.html

    Another approach would be to generate a mesh from the grid and render its edges. That's the approach Vectorsity is using. I hate telling people to get another plugin, but it has way better vector line rendering capabilities than I could write.
     
  17. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    Great product!

    I just noticed that the Editor section gets automatically imported into the top level Editor folder. In my case, that folder is used for my own Editor scripts. Unfortunately, that folder gets wiped clean every time I do a build from my build engine.While I'm sure I could do a workaround to avoid wiping your Editor scripts, I would suggest a more robust solution as I'm sure I'm not the only one this happens too.

    Suggest you place the Editor scripts within a GridFramework/Editor heirarchy which would eliminate potential conflicts with other users of the top-level Editor folder.

    Thanks for the consideration.
     
  18. Maxii

    Maxii

    Joined:
    May 28, 2012
    Posts:
    45
    FYI - Your Vectrosity example scripts are no longer compatible with Eric's new version of Vectrosity as he has moved to Lists from Arrays.
     
  19. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Hi, I'll answer your questions individually.
    I was considering that, but polluting people's root Assets directory is rude. The way it is now one can just throw away or uncheck the Grid Framework directory and it will work. I'm not really sure what to do about it, both sides have a point.

    Yes, I'm aware of that, there is a fix a few posts above:
    Grid Framework [scripting and editor plugins]

    I want to fix it, but currently I'm fighting the project setup:
    http://forum.unity3d.com/threads/one-project-in-unity-4-and-5.362659/

    Once I have things figured out I'll push an update, it's a quick fix.
     
  20. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Grid Framework has a new news blog now, replacing the old one.

    http://hiphish.github.io/grid-framework/news/2015/11/12/new-blog/
     
  21. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Two pieces of news: RSS & Atom feeds and no more Korean Asset Store presentation.
    http://hiphish.github.io/blog/2015/11/14/feeds-live-now/

    http://hiphish.github.io/grid-framework/news/2015/11/17/no-korean/
     
  22. Der_Kevin

    Der_Kevin

    Joined:
    Jan 2, 2013
    Posts:
    517
    hey, i wanted to set up the SnappingUnits.cs so that it finds the GFGrid on its own instead of droping the reference always in the inspector by hand. so i editied the script that way:

    Code (CSharp):
    1. public class SnappingUnits : MonoBehaviour {
    2.  
    3.     ///<summary>the grid we want to snap to </summary>
    4.     public GFGrid _grid;
    5.     ///<summary> A collider attached to the grid, will be used for handling mouse input. </summary>
    6.     private Collider gridCollider;
    7.    
    8.     ///<summary> True while the player is dragging the block around, otherwise false. </summary>
    9.     private bool beingDragged;
    10.     ///<summary>  The previous valid position. </summary>
    11.     private Vector3 oldPosition;
    12.  
    13.     void Awake () {
    14.         gridCollider = _grid.gameObject.GetComponent<Collider> ();
    15.         //perform an initial align and snap the objects to the bottom
    16.         _grid.AlignTransform (transform);
    17.         transform.position = CalculateOffsetY ();
    18.         //store the first safe position
    19.         oldPosition = transform.position;
    20.         // setup the rigidbody for collision and contstruct a trigger
    21.         SetupRigidbody();
    22.         ConstructTrigger();
    23.         //find the Grid Component
    24.         //_grid = GameObject.Find("RectangularGrid").GetComponent(GFGrid)as GFGrid;
    25.         _grid = GameObject.Find("RectangularGrid").GetComponent(GFGrid);
    26.     }
    so, this is the important line:

    Code (CSharp):
    1. _grid = GameObject.Find("RectangularGrid").GetComponent(GFGrid);
    but somehow that doesent seam to work?
     
  23. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Hi, the problem is your use of GetComponent. Here is how it is defined in scripting reference:
    http://docs.unity3d.com/ScriptReference/GameObject.GetComponent.html

    The type returned is Component, but the variable you have declared is of type GFGrid, which is a subclass of Component (more precisely, a subclass of MonoBehaviour which is a subclass of Component). You have to either use a cast, or even better use the generic version of GetComponent:
    Code (csharp):
    1. _grid = GameObject.Find("RectangularGrid").GetComponent<GFGrid>();
    http://docs.unity3d.com/Manual/GenericFunctions.html

    This is one part of the Unity documentation that is really lacking.
     
  24. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Grid Framework version 1.8.4 released
    http://hiphish.github.io/grid-framework/news/2015/11/23/version-184/
     
  25. Der_Kevin

    Der_Kevin

    Joined:
    Jan 2, 2013
    Posts:
    517
    ah, thanks! that makes sense.
    and its also working fine now :)
    thank you
     
  26. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Spheric grid rendering
     
  27. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Spherical grid coordinate systems
     
  28. olszewskim

    olszewskim

    Joined:
    Oct 26, 2015
    Posts:
    11
    Hello,
    Do you have any solution how solve this situation? I have a problem with objects with scale greater than 1. They don't fit with grid edge to edge. At present they stop at center of object. upload_2015-12-10_11-45-54.png
     
  29. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Hi,

    that's because the position of the blocks is not clamped to the visible area. The reason the blocks don't go completely off the visible grid is because input detection uses raycasting and the collider we cast against is as large as the visible portion.

    Because grids are infinitely large we have to clamp the objects in code. Im am writing a sort of FAQ/snippets chapter for the manual, this part is relevant to your question:
    Feel free to chop off the parts you don't need from the snippet.
     
    olszewskim likes this.
  30. olszewskim

    olszewskim

    Joined:
    Oct 26, 2015
    Posts:
    11
    Thanks for the response! In this solution space between edge of grid and object is too big. But I edit scale computing and now it's working perfectly :)

    Code (CSharp):
    1.   // We must also take into account the size of the object itself
    2.         for (int i = 0; i < 3; ++i)
    3.         {
    4.             from[i] += obj.lossyScale[i] / 2*spacing[i];
    5.             to[i] -= obj.lossyScale[i] / 2*spacing[i];
    6.         }
    upload_2015-12-11_13-34-24.png
     
  31. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Yikes, you're right and I was just about to submit the faulty snippet. The scale of an object the its entire width but we only want to subtract half of its width. Thank you.
     
    olszewskim likes this.
  32. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Grid Framework version 1.9.0 released
     
    Tinjaw likes this.
  33. ProtoPoly

    ProtoPoly

    Joined:
    Jan 5, 2014
    Posts:
    34
    I have been trying to learn how to use your framework however all your examples and tutorials are in javascript (even in the manual). Not everyone using your library has the skill/knowledge to translate from js to c# (myself included in this statement)
     
  34. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Which ones do you mean? I use C# myself and only the Vectrosity examples are written exclusively in UnityScript, but they are so basic they use the same syntax. All other examples are either exclusively in C# or in both languages. I might have missed a spot in the manual, but the API is documented in C# only because that's what the framework is written in and what Doxygen supports.

    Where are you seeing UnityScript instances? I just went through the examples and can't find any that are UnityScript only. (and FYI just in case, that's not JavaScript what Unity uses, it's UnityScript which has little to nothing in common with JavaScript, it's more like C# on autopilot, the differences are very small)
     
  35. ProtoPoly

    ProtoPoly

    Joined:
    Jan 5, 2014
    Posts:
    34
    I am not an experienced programmer, this is why I purchased grid framework. I have no idea how to even use the library. All documentation i can find is all js
     
  36. ProtoPoly

    ProtoPoly

    Joined:
    Jan 5, 2014
    Posts:
    34
    maybe a helpful thing that could help newbie/amateur programmers which is a good portion of your target market. How to read and use your API documentation.
     
  37. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Just to make sure we are on the same page: you find the documentation when you go in Unity to Help -> Grid Framework documentation. Some people miss that. Or maybe something went wrong when importing into your project, try re-importing.

    It all depends on what kind of game you want to make. The basic non-programming concepts have their explanations in the manual as their own chapter. You can find them on the main page and in the side bar. Read those first. Then you can click the Classes tab, it contains a list of all classes used in Grid Framework. Every type of grid has its own class and they all inherit from the GFGrid class. Click one of them and you will be taken to its API documentation.

    Let's take GFGrid as an example: the first thing you see is a short description followed by an inheritance diagram that shows you how the class relates to other classes in the framework. Next are lists of methods, attributes, properties and events for that class. Every items contains the syntax and a short description. Click the item to get the full description.

    This is all exactly like Unity's API reference. If you know how to use Unity's reference you basically know how to use mine. The tricky part is in knowing what you need. There are some well-commented example projects included with Grid Framework intended for people to get started. You can also find a synopsis explaining the basic idea on my website:
    http://hiphish.github.io/grid-framework/examples/
    Note that the most useful functions are GridToWorld, WorldToGrid and their variants for grids with more than one coordinate system. Another common pattern is to loop over a grid's size:
    Code (csharp):
    1. for (int i = grid.renderFrom.x; i < grid.renderTo.x; ++i) {
    2.     for (int j = grid.renderFrom.y; j < grid.renderTo.y; ++j) {
    3.         // Do something for every grid face, vertex or whatever
    4.     }
    5. }
    This is not not the case in my experience, I have intentionally named it Grid Framework instead of "Grid Kit" or "Easygrid" or something like else that might lead people to think it's a "just add water" type of solution. There is even a "what Grid Framework is not" part on the main page. My user bases consists mainly of people who know fairly well how to program but don't have the time or knowledge to implement the math.

    I can help you get started if you need more pointers, but I need to know what exactly your problems are and what you want to achieve.
     
  38. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    596
    I've been using the framework for a while and I really like how it's implemented. Great work!

    I am using Vectrosity and was wondering a couple of things. One, is there a way to not display the Y lines of a 3D grid using Vectrosity? I'd like to implement something like your Hide Axis on the Draw and Render settings. The switch color sample is a start, but it seems to iterate through all points and I cannot figure how to limit rendering or points selected to a specific axis.

    Secondly, your guide states that your draw function is really fast, but Vectrosity may be better for large grids. I have a smallish grid for a mobile VR project using Google Cardboard. I can put your GFGridRenderCamera on both the Left and Right eye camera. It works, but rendering is a little unpredictable and it seems like running the script twice would be less performant than using a single Vectrosity instance. Does that seem correct?
     
  39. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    You can use GetVectrosityPointsSeparate to get three sets of Vectrosity points, you can then decide which ones to use.

    For your second question, it would help to first understand how Grid Framework and Vectrosity differ. Vectrosity uses meshes generated at runtime from points provided at runtime. The downside of this is that you cannot preview your results in the editor.

    I wanted to be able to see grids in the editor as well, that's why I decided to draw actual lines. In the editor it's simple, just use gizmos. At runtime however I have to use the GL class of Unity. In every frame I run the same commands to re-render the grid.

    Larger grids have more lines to render and we have to loop over all of them every frame. Meshes are designed to have lots of vertices and Unity is designed to render lots of meshes. That's why using Vectrosity might be faster, but of course you would have to profile things to know for sure.

    What do you mean with unpredictable? Anyway, performance might be less because Unity is optimised for rendering meshes the standard way, but you would have to make measurements to see if the difference is even noticeable.
     
  40. Voronoi

    Voronoi

    Joined:
    Jul 2, 2012
    Posts:
    596
    Thanks, this is the C# code to get this to happen in case anyone else is trying the same
    Code (CSharp):
    1.         Vector3 fromG = new Vector3 (-grid.size.x, -grid.size.y, -grid.size.z);
    2.         Vector3 toG = new Vector3 (grid.size.x, grid.size.y, grid.size.z);
    3.  
    4.         List<List<Vector3>> allPoints = grid.GetVectrosityPointsSeparate (fromG, toG);
    5.  
    6.         List<Vector3> returnedPoints = new List<Vector3> ();
    7.  
    8.         returnedPoints.AddRange (allPoints [0]);
    9.         returnedPoints.AddRange (allPoints [2]);
    10.  
    11.         gridLine = new Vectrosity.VectorLine ("Resizing Lines", returnedPoints, texture, width);
    I found Vectrosity to be faster, although the line quality was better using your built-in system. The Google API is having to render and distort two cameras, so there is a lot of overhead before doing anything really. Every time I add to my project I have to profile because the low-end device I'm targeting drops from 30fps to 10fps pretty easily. Vectrosity dropped to 24fps, while your built-in drawing dropped to 3fps.

    The unpredictable part of your built-in drawing is the line width. With the VR cameras it works when set to 1, but anymore than that it displays either really thick lines or has filled in the hexagons as a solid color.
     
    Last edited: Dec 30, 2015
  41. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    434
    Hi, before purchase I'd like to know, can GridFramework generate grid on mesh surface(say a sphere) during runtime?
     
    Last edited: Jan 9, 2016
  42. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    I don't quite understand what you mean, can you please be more specific? If you want to match a sphere (like a planet) with a grid at runtime you can instantiate a new instance of a spherical grid:
    Code (csharp):
    1. GameObject sphere; // this is your sphere
    2. GFSphereGrid grid = sphere.AddComponent<GFSphereGrid>(); // add a new grid
    3.  
    4. // Set the properties
    5. grid.radius = 10; // and so on
    Is that what you meant? If you are asking about grids that aren't straight, for example to fit the surface contour of irregular terrain, that can't be done. Only spherical and polar grids have curved lines, but those are all circles, not arbitrarily curved lines.
     
    zhuchun likes this.
  43. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    434
    Yes, actually I want to have a coordinate system to manage buildings on a planet. Pointy/Flat hexagonal grid(from another asset) sounds promising but cells near polar circles are squeezed and their size are smaller than normal. If player build things near polar circles, he may find buildings overlap each other.
    Can GridFramework solve these things?;)
     
  44. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    This is what a spherical grid looks like (don't worry about the choppy framerate, that's just to keep the file small)


    You can set the radius, number or meridians and number of parallels. You can hide the radial (red) lines if you want to, or hide any other lines as well.

    I don't understand how you want to solve that problem. Can you please provide a drawing of what you would want to have? Any faces near the poles will always be smaller in a geographic grid and the faces adjacent to the poles will be triangles. You can set the number of parallels so that the faces don't get too small but the math cannot avoid the face surface getting smaller.
     
  45. mrmoto

    mrmoto

    Joined:
    Jun 8, 2015
    Posts:
    3
    Hello hiphish!
    How can i made same thing like Runtime snapping example, but with ability to place cube one on another?
    Actually, i made a couple draggable cube with playmaker, and they moving like i want. Remain adding snapping to grid, but i dont know how.
    How to make grid framework actions appear in playmaker? I create a file called smcs.rsp with the following contents:
    -define:GRID_FRAMEWORK_PLAYMAKER
    and place it in Assets folder, but nothing happen.
     
  46. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    Hello

    You have to force the compiler to run again. Just edit some random script or create a new one (you can delete it later again), that should force Unity to re-compile again.

    The idea behind snapping is to first move the object normally and immediately after "correct" its position:
    Code (csharp):
    1. Vector3 position; // the unsnapped position
    2. GFGrid grid;
    3. position = grid.AlignVector3(position); // correct it
    If you want more control over it you can go to a lower level:
    Code (csharp):
    1. Vector3 gridPosition = grid.WorldToGrid(position); // grid coordinates
    2.  
    3. // Correct only X- and Z coordinate
    4. gridPosition.x = Math.Round(position.x - 0.5f) + 0.5f;
    5. gridPosition.z = Math.Round(position.z - 0.5f) + 0.5f;
    6.  
    7. // Back to world coordinates
    8. position = grid.GridToWorld(gridPosition);
    The weird formula 'Math.Round(position.x - 0.5f) + 0.5f' comes from the fact that every face has half grid-coordinates, i.e. the first face has an X-coordinate of 0.5, the second 1.5 and so on. We subtract that offset, round to the nearest integer and add the offset back.

    Now all that's left is the Y-coordinate so that your cubes stack on top of each other. This is outside the domain of Grid Framework and depends on how your game works. You can for example use collision detection to adjust the Y-coordinate when two triggers are intersecting, or use raycasting. My tip is to get that part working first without snapping and then perform the snap afterwards, the code snipped above does not modify the Y-coordinate. If it works for continuous movement it will also work for discrete movement.
     
  47. mrmoto

    mrmoto

    Joined:
    Jun 8, 2015
    Posts:
    3
    Thank you for detailed answer! But i`m afraid without playmaker i not be able perform your guide:rolleyes:
    I try this way, but in Actions window nothing change. Leastways searching "grid' nothing found.
    I should create file smcs.rsp.txt, right?
     
  48. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    No, the file extension is "rsp". If you created the file in the Unity editor the file extension will be hidden. Open the file in you regular file browser, make sure file extensions are not hidden and make sure the file is called "smcs.rsp". The type is just regular plain text. I don't know if line ending matter, but just in case: I have Unix newlines (a \n byte) and there is a newline after the definition.
     
  49. mrmoto

    mrmoto

    Joined:
    Jun 8, 2015
    Posts:
    3
    Thank you, its worked :)
     
  50. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    626
    First major step towards 2.0