Search Unity

  1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  6. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

Grid Framework [scripting and editor plugins]

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

  1. anthbmagic

    anthbmagic

    Joined:
    Aug 30, 2012
    Posts:
    2
    I recently bought grid framework and i'm very impressed so far, keep up the good work.

    thanks a million
    anthony
     
    Last edited: Oct 24, 2012
  2. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    So you just want to position the camera on a certain vertex of a grid?
    Code (csharp):
    1.  
    2. myCamera.transform.position = myGrid.GridToWorld(desiredPosition);
    3.  
    desiredPosition has to be in grid coordinates. That means if you want on unit right and two units above the origin just pass a (1, 2, 0) vector. GridToWorld then takes that and returns the world position of that point. This will only move the camera's position, you need to set the roation yourself, like for example the grid's rotation:
    Code (csharp):
    1.  
    2. myCam.transform.rotation = myGrid.transform.rotation;
    3.  
    myGrid refers to the specif grid you want to use for the calculation, it can be either of type Grid or RectGrid. RectGrid is more specific but gives you access to spacing, while Grid is more general and you could just use a hex grid (once I finish them) without changing the source code. The included scripting reference give you more information on the difference between the two classes.
     
  3. Daniel-Talis

    Daniel-Talis

    Joined:
    Dec 10, 2011
    Posts:
    331
    Hi there hiphish,
    I bought this 'Grid Framework' and have been experimenting with it. The first issue I have come across is as follows.
    When I make a grid with the settings..

    size 3,3,3
    spacing 1,1,1
    min spacing 1,1,1

    I get a Grid that has the size 6,6,6

    Am I missing something, Why is the Grid twice as big?
     
    Last edited: Sep 4, 2012
  4. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    No, that's because the size gets applied in all directions. If you want to render a 3x3x3 grid use the custom rendering range setting, that will let you set the from and to coordinates by hand. The "size" is only the visual representation of your grid, the actual grid is infinite in size. I could change the code to use the custom rendering range for drawing as well, not just rendering, if it really bothers you. It's a leftover from an earlier version before I had custom rendering range and since the size setting doesn't affect the calculations and rendering can get its own range I just didn't think it was that important.

    EDIT:
    Version 1.1.4 has been approved. It doesn't add anything new for a change, instead it fixes a bug where lines with a width larger than 1 were drawn on top of things they were supposed to be under.
     
    Last edited: Sep 5, 2012
  5. Daniel-Talis

    Daniel-Talis

    Joined:
    Dec 10, 2011
    Posts:
    331
    I think it is important, will try the customising idea.
     
  6. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    As per request the custom rendering range now affects drawing as well, not just rendering. If you are wondering why this wasn't the case before, it was a leftover from before the custom rendering range got implemented. Originally the custom range was only meant for rendering because that would be what the layer sees in the final game, not the drawing, whether they are the same or not. Also, the drawing is only a drawing, the grid keeps working beyond what's visible, being infinite. That's why the drawing had low priority and I worked on other parts instead.
     
  7. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    Important Note: The classes Grid and RectGrid have been renamed to GFGrid and GFRectGrid, you will need to change your source code accordingly.

    You might be wondering why I would do such a thing more than one month after releasing the package. Using regular Englsih words is simple and intuitive; however, the danger of name collision with another class called the same is quite large. Let's say a user has already a class called Grid for something in his or her project. When they buy Grid Frmework all of the sudden they will get compilation errors because now there are two classes called Grid. It would be unreasonable to expect users to change their class, especially if that class is already part of a more complex chain of dependencies or inheritance. They could change my code, but then they would have to change it after each single update of Grid Framework. If the class Grid is already defined in some other third party extension it gets even worse.

    Adding the GF in front of both classes reduces the change of name collision. I apologize to all my existing customers for having to change their source code because I didn't think about this in time, but I had to resolve this before it becomes an issue and the sooner I get it sorted out the less customers will have to change their source code. I am very sorry, but this should fix the problem once and for all.

    Aside from that the GFRectGrid class contains some minor code cleanup and performance boosts, so it's not all bad news.
     
  8. Rafes

    Rafes

    Joined:
    Jun 2, 2011
    Posts:
    764
    I think Unity 4 will have component namespaces
     
  9. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,061
    Would this be useful for a tap? As in tap gridA, squareA8, object move to that grid's square's central point?
     
  10. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    What do you mean by tap? Like in a chess game where you click on a field and then an object moves there? Yes, that could be done very easily, you just need to get the point of your mouseclick (or fingertap on mobile devices). In the Lights Out example, which is included, I had every tile be a cube with a CubeCollider, but you could also do a raycast with the mouse or any other way to find that point. Once you have it all you would need would be this
    Code (csharp):
    1.  
    2. go.transform.position = myGrid.FindNearestFace(myPoint);
    3.  
    where go is your object, myGrid is the grid you are using and myPoint is the point inside the square. FindNearestFace returns the world coordiantes of the central point of the face nearest to the specified point. Of course you would use a nice movement function instead of instantly changing the object's position, but that's how you can find the central point of a square.

    I couldn't find an official confirmation, but even if they do, I can't force someone just to upgrade to Unity 4 or dig through all their existing scripts just because of a stupid naming convention. Maybe they don't want yet to upgrade or maybe there is some bug in Unity 4 that prevents them from updating. I don't think there will be a reason not to upgrade, but you never know.
     
  11. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,061
    Thanks. What about object placement? Meaning, if you look at Temple Racer (google) you will see tiles laid out. 2 things, how does the placement or art, get placed in? If I needed a 1000 tiles, would I need to pool them and place them all, individually by hand? Or do you have some other type of system so that graphics are handled by this system, including placement.

    Secondly, are the tiles only square? Or can you make adjustments to the proportions?

    Thanks
     
  12. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    There is no tile mapper built in, but it's one of those things I will definitely look into once i have all the grid types in (currently only rectangular grids fully work and I'm working on hex grids). The thing is that for a good tile mapper it#s not enough to just place objects, it needs things like batching as well; if your scene has 50 cubes next to each other you don't want 50 individual box colliders, you want one big collider for all of them.
    Grid Framework has an alignment and scaling panel built into it, so if you do it by hand you could have the tiles snap automatically to the grid. Another thing that would be well possible is to do the deisng in a text file and then write a small text parser that reads the file and places objects accodingly. For example if you take this
    Code (csharp):
    1.  
    2. AA0AAA00BBA0
    3. A0BBAA000ABA
    4. AABB000AABBA
    5.  
    then the parser would look up the first letter, place the appropriate object in the grid at the (0,0,0) tile, then move to the next tile, read the next letter, put the object there, move to the next tile... I haven't looked into text parsers yet, another thing on the list of things to do. The good part about this approach is that you would have a very simple format for levels, you could have a sort of level editor built into the game that does the opposite and writes to a text file.

    Tiles are not limited to squares, any rectangle proportions work. A grid is a component, its position and rotation depend on on the Transform of the object. The size of the rectangles is set in the grid's spacing variable. All grids are three-dimensional, so you can set the Z too if you want.
     
  13. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    Version 1.1.6 has been approved. Please remember to change the names of your classes accordingly: Grid becomes GFGrid and RectGrid becomes GFRectGrid
     
  14. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,061
    Ok good. Thanks.
    If you developed a system which allowed for a grid to be laid out, adjust the member shapes, rectangle or square (which you do), is low on memory for mobile and would allow for each grid member, or any pattern of my choosing like a tile mapper, but allow each tile to have a collider it would be very handy for some future projects I am considering.


    If you look at Temple Racer: The Beginning, for the iOS. This was a game I made. It uses tiles, but each, is an object that I had to place by hand. Very tedious work.
     
  15. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    Making a video tutorial how to design levels in a plain text format and have a text parser build the level in the game fromt hat is one of the things on my to-do list. You'd stell need to design the level by hand but it would be much easier to write to a text file than move tiles in the editor. You could even make it so that users could drop in their own text files for their own levels, imagine a Breakout style game where anyone could design new levels without you having to provide a level editor. The tiles you want to place would be designed once in the editor as prefabs with whatever mesh, sprite, collider and script you would want and then the parser picks the proper prefab based on what letter it has read (like type A, type B or nothing if it's a 0)

    Grid Framework was disgned as a scripting extension in the first place, mostly for stuff like grid-based game logic. The aligning and scaling panel was a consequence of that, ti's really kust a few of the existing functions rolled into an editor extension. If you are looking for a full tile mapper with batching then there are tile mappers out there that specialized in that sort of thing, but they arent for scripting game logic. Of course you can also use both a tile mapper and Grid Framework hand in hand, one for what the game looks like and the other for what the game plays like.
     
  16. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,061
    So I am unfamiliar with text files. Are you saying that somehow, if I apply a text file to a grid, component, that I can layout the pattern of the active tiles? And that an active tile could be what ever I want it to be?



    Also, is a text file really just
    AA00AA
    0AAAA0
    00AA00



    :?
     
  17. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    This guy explains the idea better:
    http://www.mindthecube.com/blog/2009/11/reading-text-data-into-a-unity-game

    You have a plain text file in your project among the assets, then you write a text parser, a small script that can read the text firle and process the information from the text file into something useful for the engine. In my example a parser would read the first line, then in that line go letter by letter. It sees an A, so it places a prefab of type A (whatever that is) at 0,0 in the grid, then it moves to the next letter, finds an A and places a new object A at 1,0 in the grid. It moves to the next letter, sees a zero and does nothing, it moves to the next, sees a zero, does nothing, moves on, sees an A, places a new object A at 4,0 in the grid, goes on, places another object A at 5,0. Then it parses the next row and does the same thing one row above 8or below) in the grid. You wouldn't be limited background to tiles, you could place enemies, power ups or anything else that way as well.

    Text parsing uses some C# classes, you can do it in JavaScript but Unity's documentation oesn't explain those classes, so you'll need to jump between Unity docimentation and .NET documentation. If you give me some time I'll make an example video for using text parsers with Grid Framework; I have been very busy with university stuff over the last few months, so I haven't had much time for Grid Framewaork and when i had time it was used for programing instead of making tutorial videos. I guess I can have the video made until the end of the week.
     
  18. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    OK, I've written a amall text parser that reads a plain text file and builds a Breakout level from it:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.IO; //needed for the StringReader class
    5.  
    6. public class LevelTextParser : MonoBehaviour {
    7.    
    8.     //FileInfo levelFile = null; //this object would be needed if you wanted to read files not included with the game (mods, DLC)
    9.     StringReader reader = null;
    10.     public TextAsset levelData;
    11.     public GFRectGrid levelGrid;
    12.    
    13.     public Transform redCube;
    14.     public Transform greenCube;
    15.     public Transform blueCube;
    16.    
    17.     public void Awake(){
    18.         BuildLevel(levelData, levelGrid);
    19.     }
    20.  
    21.     public void BuildLevel(TextAsset levelData, GFRectGrid levelGrid){
    22.         if(!redCube || !greenCube || !blueCube)
    23.             return;
    24.        
    25.         reader = new StringReader(levelData.text);
    26.         string line;
    27.         int row = 0;
    28.        
    29.         while( (line = reader.ReadLine()) != null){
    30.             //Debug.Log("-->" + line);
    31.             for(int i = 0; i < line.Length; i++){
    32.                 //Debug.Log(line[i] + " at " + i + "/" + row);
    33.                 switch(line[i]){
    34.                     case 'R':
    35.                         Instantiate(redCube, levelGrid.GridToWorld(new Vector3(i + 0.5f, -row - 0.5f, 0)), Quaternion.identity);
    36.                         break;
    37.                     case 'G':
    38.                         Instantiate(greenCube, levelGrid.GridToWorld(new Vector3(i + 0.5f, -row - 0.5f, 0)), Quaternion.identity);
    39.                         break;
    40.                     case 'B':
    41.                         Instantiate(blueCube, levelGrid.GridToWorld(new Vector3(i + 0.5f, -row - 0.5f, 0)), Quaternion.identity);
    42.                         break;
    43.                     default:
    44.                         break;
    45.                 }
    46.             }
    47.             row++;
    48.         }
    49.     }
    50. }
    51.  
    It's in C# because C# is my language of choice, but it can be done in javaScript as well. It needs little more polish before I include it in as an example with Grid Framework, but it works fine. There are six variables: reader is what oes the reading, levelData is the plain text file that contains our level information, levelGrid is the grid we want to use as a reference and the other three are just prefabs for a red, green and blue cube. Since they are prefabs they can be anything.
    BuildLevel() takes two arguments, the text file and the grid we position things on. Then the reader reads a line and analyzes that lien character by character. If the charcter is R it places a red cube, if it's G, then a green cube, if it's B then it's a blue cube and in any other case nothing happens, there is a hole in the level. After each row we increase the row counter to keep track of where in the text file we are. The level is built in the same order in which it's written, from left to right and top to bottom. That's why the row counter moves from 0 to negative numbers.

    here is an example, if I take this text file
    Code (csharp):
    1.  
    2. RGBGBGBRRG
    3. BRGR0GRGBR
    4. G0BG0R0RGB
    5. BR00GBRGBR
    6. G0BGBGBRGB
    7.  
    I get this level:
    [​IMG]
     
  19. markpollard1

    markpollard1

    Joined:
    Apr 1, 2010
    Posts:
    68
    HI,

    I have been playing with your Grid Framework plugin.

    I have managed to get a sphere to move around the grid parameters, but i want to put a wall (the block in the center) in the way so that the player cannot pass this.

    How do i detect when the player will hit this?

    Thanks

    [​IMG]
     
  20. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    That's easy, I can think of two ways off the top of my head.

    Using linecasting:
    Instead of moving the sphere to its traget position use a linecast from the sphere's current position to its target position. If the linecast doesn't return anything the way is clear and you can proceed. If it returns something the path is blocked and your are done. More information on linecasting is found here:
    http://docs.unity3d.com/Documentation/ScriptReference/Physics.Linecast.html

    Using a matrix:
    Linecasting uses physics, which might or might not be a concern to you. This approach uses a matrix of type bool, you create this matrix when your game starts and then every time you want to move to a tile you have your sphere check if that tile is forbidden or allowed. The matrix should be public static so any object can access it without need to search for it or store a reference. How do you know which tiles are forbidden? One way would be to have everything allowed and then when the game starts all blocks mark their square as forbidden
    Code (csharp):
    1.  
    2. function Start(){
    3.      allowedMatrix[Mathf.RoundToInt(myGrid.WorldToGrid(transform.position).x), Mathf.RoundToInt(myGrid.WorldToGrid(transform.position).y)] = false;
    4. }
    5.  
    Then when you want to move your sphere you perform a check:
    Code (csharp):
    1.  
    2. if(allowedMatrix[Mathf.RoundToInt(targetSquare.x, TargetSquare.y] == false)
    3.      return;
    4.  
    This approach is more work but it works without physics. In addition the information whether a square is forbidden is accessible to any object at any time from any location.
     
  21. michelm

    michelm

    Joined:
    Jul 2, 2012
    Posts:
    8
    I bought this yesterday and am loving it so far, but am having a hell of a time trying to figure out something that I know is really simple.

    For some reason, when I make the grid flat (and rotate/tilt the camera to make an isometric view) run-time dragging and grid snapping completely breaks. I'm using the included script SnappingUnits.cs. I spent hours trying to debug it and didn't really get anywhere. I noticed the world point Y value seems to be resetting, which I thought might have something to do with camera tilt, but I'm stumped.

    Any ideas about what I'm missing?
     
  22. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    Hello, the problem lies here:
    Code (csharp):
    1.  
    2. //handle mouse input to convert it to world coordinates
    3. var cursorScreenPoint: Vector3 = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);
    4. var cursorWorldPoint: Vector3 = Camera.main.ScreenToWorldPoint(cursorScreenPoint);
    5.  
    This works only properly if the camera is not rotated because the result depends on the camera view's rotation. When I wrote that example I wanted to show off Grid Framework's flexibility and reliability instead of writing a complex mouse input handler.
    You will need a better way to handle mouse input, like a ray shooting from the cursor and then seeing where it hits the plane and use that point as your world point. I haven't done anything with cursor input yet, but I came across this when doing a quick Google search, it looks like what you would need:
    http://answers.unity3d.com/questions/200500/get-mouse-positon-in-world-coordinates-on-a-plane.html
     
  23. michelm

    michelm

    Joined:
    Jul 2, 2012
    Posts:
    8
    Wonderful, got it working. Thank you!

    For reference here are the changes I made.

    Instead of those cursorWorldPoint and cursorScreenPoint lines:
    Code (csharp):
    1.  
    2. RaycastHit hitWorld;
    3. Vector3 cursorWorldPoint = new Vector3();
    4. if(Physics.Raycast(ray, out hitWorld, layerMask)){
    5.         cursorWorldPoint = hitWorld.point;
    6. }
    7.  
    Changed z to y here:
    Code (csharp):
    1.  
    2. //we want to keep the Z coordinate, so apply it directly to the new position
    3. cursorWorldPoint.y = cachedTransform.position.y;
    4.  
     
  24. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    Glad to hear that. The downside to this approach is that it will only work if there is something for the ray to hit (like a plane), but for most games that should be no problem.
     
  25. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    I've written two new examples, one that takes a plain text file and parses it to create a breakout-style level based on a grid without changing the scene, the other is a continuation of my grid-based movement exmple where I can place obstacles on the grid and the sphere will not step on those squares (without using any physics like collision and raycasts). Sadly I can't update Grid Framework because I can't log into my account via Package Manager. My account still works, I can log into the forums and my Publisher Administration, so the problem must lie within the editor. I've submitted a bug report, but until then I cannot publish updates. If you are interested in one of those two examples please contact me over the Unity forums and I'll send you the examples, provided that you already own Grid Framework. On a related note, it appears that Grid Framework's product page in the Asset Store doesn't have any screenshots. I did submit screenshots, but they don't appear for me, I don't know if other people can't see them either.
     
  26. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    Version 1.1.7 has been approved by the Asset Store team. I fixed a small typo that prevented the menu item for adding the GFGridRenderCamera component from working and I added two more examples, video tutorials will follow soon. I also redid the screenshots because the Asset Store ate my old ones somehow.
    The first example shows you how you can use a plain text file and Grid Framework to build levels outside the editor. If you have a game like breakout that's heavily based around grid-based design it would be tedious to design each level via Drag&Drop in the editor. Another disadvantage is that changing the level would mean switching the scene and it would be harder for players to create their own levels as mods. In my example we design the level as a plain text file where each character corresponds to one predefined prefab. Then we need to set up only one scene and the text parser script will, along with the grid, take the text file, read it and then place blocks accordingly. You can even switch levels on the fly without changing the scene.
    The second example continues the grid-based movement example by placing obstacles on the grid. One way to avoid them would be to attach colliders to the obstacles and then have the walker perform a line cast in the direction of its movement and see if the line cast hits anything. However, since this is Grid Framework we can do better than that. In this example I create a matrix that stores whether a tile is forbidden or not and then the walker checks if its next target square is alowed or not. There are no colliders or physics used.
     
  27. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    I made another example video for Grid Framework, this time for the recently introduced text parsing example. Now building new levels is as easy as writing a few lines of plain text and you get perfect clockwork-like precision. This opens up new possibilities for faster development, easier maintenance, easier level editors and support for user-made content. Just take a look at how simle, yet effective it is:
     
  28. choi

    choi

    Joined:
    Oct 11, 2012
    Posts:
    6
    Bumpy terrain, a mesh on the surface, so id you draw?
    Is very necessary.
     
  29. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    I'm sorry, I'm not sure I understand what you are trying to tell me.
     
  30. vag_liv

    vag_liv

    Joined:
    Oct 24, 2012
    Posts:
    3
    Hi,

    I just bought your Grid Framework. It all works well, I have a grid drawn on screen as I need to, but with 2 issues:
    a) When I reload the level from inside the game (on Gameover), the grid dissapears, on pc and on my Android tablet. It only reappears if i stop the game, and restart
    b) The grid is drawn over all objects in the scene, and the line width is 1. I need the grid to appear under the level geometry, is that possible?

    Thanks!
     
  31. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    I'll need more information about your setup... when you reload the level during runtime does the main camera have a GridRenderCamera component attached? Without that it won't do anything, that component is responsible for taking the grid points and rendering thmem on the screen. For your second question, what line width are you using and what camera mode (perspective or orthogonal)? A screenshot would be helpful. Also, are you sure it's the rendered grid you see and not the gizmos? Gizmos will always be drawn on to of everything. You can set a flag to hide the drawing of the grid during runtime (drawing=gizmos, rendering=GL class).
     
  32. vag_liv

    vag_liv

    Joined:
    Oct 24, 2012
    Posts:
    3
    Hi,

    thanks for the quick reply man!

    1) On reload, I get the following error:
    (Filename: Assets/Plugins/Grid Framework/GFTransformExtensions.cs Line: 11)

    MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    at (wrapper managed-to-native) UnityEngine.Transform:INTERNAL_CALL_TransformDirection (UnityEngine.Transform,UnityEngine.Vector3)

    at UnityEngine.Transform.TransformDirection (Vector3 direction) [0x00000] in C:\BuildAgent\work\14194e8ce88cdf47\Runtime\ExportGenerated\Editor\UnityEngineTransform.cs:193

    at GFTransformExtensions.GFTransformPointFixed (UnityEngine.Transform theTransform, Vector3 position) [0x00000] in D:\seashepherd\SeaShepherd_unity\Assets\Plugins\Grid Framework\GFTransformExtensions.cs:11

    at GFRectGrid.CalculateDrawPoints (Vector3 from, Vector3 to) [0x00090] in D:\seashepherd\SeaShepherd_unity\Assets\Plugins\Grid Framework\GFRectGrid.cs:433

    at GFRectGrid.RenderGrid (Vector3 from, Vector3 to, Int32 width, UnityEngine.Camera cam, UnityEngine.Transform camTransform) [0x0006f] in D:\seashepherd\SeaShepherd_unity\Assets\Plugins\Grid Framework\GFRectGrid.cs:341

    at GFRectGrid.RenderGrid (Int32 width, UnityEngine.Camera cam, UnityEngine.Transform camTransform) [0x00000] in D:\seashepherd\SeaShepherd_unity\Assets\Plugins\Grid Framework\GFRectGrid.cs:327

    at GFGridRenderCamera.OnPostRender () [0x0006d] in D:\seashepherd\SeaShepherd_unity\Assets\Plugins\Grid Framework\Grid Rendering\GFGridRenderCamera.cs:21
    UnityEditor.EditorGUIUtility:INTERNAL_CALL_RenderGameViewCameras(Rect, Rect, Boolean, Boolean)
    UnityEditor.EditorGUI


    Does that mean anything to you?

    2) I use line width 1, and an Orthographic camera. Yeah I ve set Hide_Drawing, but the behavior is the same. I can send you some high def screenshots, give me an email adress.

    Thanks again!!

    V
     
  33. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    OK, the first one does make sense:
    OK, I got it! What happens is that there is a class in the background that stores references to all grids and when the camera wants to render them it asks that class for a list of all grids. When you load another level the old grids get destroyed (or just their Transform components, I'm not sure but it doesn't matter), but their references remain in the list. Then the camera tries to get information from something that doesn't exist and everything crashes. I've fixed it now, when a grid is destroyed it will delete itself from the list. I'll publish an update but it will take some time until it gets approved. If you want to patch it on your own in the meantime open up the script GFGrid.cs and find the lines 81 and 82, swap them so it says
    Code (csharp):
    1.  
    2. cachedTransform = transform;
    3. GFGridRenderManager.AddGrid(GetComponent<GFGrid>());
    4.  
    That will make sure no grid is registered in the list before it has cached its Transform component. Next, below the Awake function after the curly brackets add the following lines:
    Code (csharp):
    1.  
    2. void OnDestroy(){
    3.     GFGridRenderManager.RemoveGrid(GetComponent<GFGrid>());
    4. }
    5.  
    This will automatically remove the grid from the list.


    As for your second problem, I can't replicate it. I've created a minimal example and the rendering appears behind the cube as it should, no matter the size of the rendered line:
    http://tinypic.com/r/28vu59s/6
    Please don't snd my high-res screenshots via email, my internet connections doesn't like large files in my mail. You can send me a PN if you don't want them to be visible publicly. Please make your screenshot look like mine, I need to be able to see your scene view and your game view.
     
  34. vag_liv

    vag_liv

    Joined:
    Oct 24, 2012
    Posts:
    3
    Coool the problem is solved, the gid stays on, thanks a lot!!

    As far as the second issue goes, i ll live with it for now

    Thanks again!

    V
     
  35. tezer86

    tezer86

    Joined:
    Jul 19, 2010
    Posts:
    90
    Hey, just bought this last night and it looks like a great tool. I was wondering how you can actually limit the grid, for example on the runtime snap scene, the grid size is limited but you can still move objects off of it.

    So for a real game example, In my 2D game, I want the player to be able to place buildings in a limited area on the grid (like the rendered section of the runtime example) and only on the very bottom layer of the grid (also like runtime example). I also dont want building to overlap, so when the player tries to move or place a building on a grid already occupied it wont let them

    Cheers
    Terry
     
  36. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    Hello, what you want can be done pretty simply if you look at my included Grid Movement example. By their nature all grids are infinite in size, so I need to manually perform a check to see if a position is within the limits. In the example I perform a simple if check:
    Code (csharp):
    1.  
    2. //if we would wander off beyond the size of the grid turn the other way around
    3. for(int j = 0; j < 2; j++){
    4.     if(Mathf.Abs(newPosition[j]) > grid.size[j])
    5.         newPosition[j] -= Mathf.Sign(newPosition[j]) * 2.0f;
    6. }
    7.  
    newPosition is in grid space coordinates and size is the size of the grid you set in the inspector. If the position is outside the range I just set the sphere to move the other way, but in your case you'd want to just do nothing, then the position of the object the player is dragging won't change. The exact implementation depends on how your game works, but it's all just simple math.

    The second question is something that could be handled by triggers. Most RTS games let you drag buildings anywhere but they will be tinted red if they are intersecting other buildings and you won't be able to position them. Here is my idea: have a trigger on the building while it is being dragged, then check if the trigger is interecting any building colliders (OnTriggerStay), if so prevent the player from positioning the building. When the player positions it turn off the trigger and turn on the collider. If you don't want to use triggers and colliders things get a little more complicated. You'll need to store a matrix where each entry represents a grid tile. When a building is placed mark that tile as occupied. If the player wants to place a building on a tile check if that tile is occupied, if not, then place the object, if it is, then do something else.

    There is an example included called "Movement With Walls" which is a continuation of the normal Movement example. The sphere roams the grid randomly but now it also avoids obstacles. It works without using any physics, just checking matrix entries. It consits of two steps, first the matix is built, then the obstacles each tell the matrix to mark their fields a occupied. Then witch each step when the sphere wants to move somewhere it checks first if the target field is free or not.
     
  37. tezer86

    tezer86

    Joined:
    Jul 19, 2010
    Posts:
    90
    Thanks for the reply, Im working on this now. Just another quick question, when I build on the iPad the grid renders in black even when its white in the unity editor.

    Cheers
    Terry
     
  38. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    That shouldn't happen. Have you tried building for PC/Mac? If those work fine then it's a bug with Unity, if it doesn't please let me know so I can investigate the issue.
     
  39. tezer86

    tezer86

    Joined:
    Jul 19, 2010
    Posts:
    90
    I have just built for the mac and its fine. Correct white grid, iPad grid is still black though.
     
  40. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    OK, then it's a Unity bug with iPad... I just did some quick Google research. it's indeed a bug with iOS. The workaround for now seems to be setting the colour in the shader itself. I know that Owlchemy Labs have a few unlit shaders hosted on their site, you could try out one of those:
    http://owlchemylabs.com/content/
    The UnlitColored one seems to work fine for me. Import it into your project, create a new material, apply the UnlitColored shader to it and set your colour. Now drop the new material into the material field of the grid (if you don't specify any material manually GridFramwork will fall back to a default material on its own)

    Also, don't forget to file a bug report to Unity. I hope this helps.
     
  41. tezer86

    tezer86

    Joined:
    Jul 19, 2010
    Posts:
    90
    Thanks! Worked like a charm, I actually have zero knowledge of shaders so I would never have found that from my own research.

    Cheers
    Terry
     
  42. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    Surprise update! Version 1.1.9 just got approved and it contains quite a few changes:
    • NEW METHOD AlignVector3: lets you align a single point represented as a Vector3 instead of a Transform to a grid
    • added the ability to lock a certain axis when calling AlignTransform and AlignVector3
    • added a new constructor to both GFBoolVector3 and GFColorVector3 that lets you pass one parameter that gets applied to all components
    • you can now lock axes in the Grid Align Panel as well
    • aligning objects via the Grid Align Panel which already are in place won't do anything, meaning they won't create redundant Undo entries anymore
    • fixed an issue in GetVectrosityPointsSeperate
    • renamed the classes BoolVector3 and ColorVector3 to GFBoolVector3 and GFColorVector3 to avoid name collision
    • size has always been a member of GFGrid, not GFRectGrid, I fixed that mistake in the documentation
    • minor clode cleanup and removing redundant code
    The first two are based on a user's suggestions, thank you for bringing those up. Previously when you wanted to align a Transform it would be aligned along all the axes, but now you can set certain axes to be left as they are (relative to the grid's local space). Also, instead of aligning a Transform you can also just align a Vector3 now, this is useful when you only need to calculate a position. You need to specify a scale, which was previously taken straight from the Transform, but I've set it to default to (1, 1, 1) so in most cases you won't have to think about it. Of course the Grid Align Panel lets you lock axes as well now. Since the option is passed as a GFBoolVector3 I added a new convenient constructor to the class that takes only one parameter and sets all entries to that. The same goes for GFColorVector3.

    Another improvement is that objects which are already in place in the editor will be ignored by the Grid Align Panel when you try to align them. The reason for this is that before, if you had set the Autosnapping flag and clicked on an object that was already in place it would create an Undo entry even though you didn't see anything happening. Now there will be an Undo only if something happened.

    The function GetVectorsityPointSeperate had been broken due to a few typos since release and I've only noticed it a few days ago. I guess no one was using it yet, so it went unnoticed for quite a while. It definitely works now.

    The rest is just some under the hoods maintenance, moving code around, removing redundant parts, updating the documentation, the usual stuff. None of it has any impact on stability or performance, but it is important to keep things clean when I finally release the Hex Grids.

    That's it for now, please enjoy the new features.
    HiPhish
     
  43. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    The 1.1.10 update brings in a new function, ScaleVector3(Vector scl) : Vector3 which takes in a vector and then scales it so it fits inside the grid. This is similar to AlignVector3, which was introduced in the last update, to allow performing the aligning and scaling without having to provide an actual Transform.

    In other news, the hex grids are almost done. All the functionality has been written, now I need to clean everything up and write the documentation. Hex grids will be officially introduced in the 1.2.0 update, which I expect to release within the next week or, if something goes wrong, the week after. Unfortunately, due to all the work I have put into Grid Framework since the first release I cannot charge 15$ anymore, starting with 1.2.0 the price will be raised to 20$, so if you want a copy of Grid Framework, now is the time to get it. When I originally released Grid Framework there were still many loose ends and it was not integrated well into the workflow. When you downloaded it from the Asset Store you had to move files manually in place, there were no menu entries, you had to drag a script manually onto objects, there was no custom inspector panel, there was no rendering, no Vectrosity support and less examples included. Over the time I have been adressing all these shortcomings and improving, but none on its own felt like they were justifying a price increase. With hex grids I'm bringing in a major functionality update and I believe the 20$ price tag is still well justified. Of course anyone who has already purchased Grid Framework will get this and all future updates for free, that was the deal when I first launched it and nothing is going to change about that.
     
  44. ibps13

    ibps13

    Joined:
    Oct 6, 2012
    Posts:
    94
    Hi hiphish,

    I'm trying the runtime snapping demo include in your framework and I would like to know, how I can rotate object and how prevent an object of this overlay to another ?

    It's possible with framework ? do you have simple example ?

    Thanks
     
  45. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    I answered the overlapping question a few posts above, so I'll just copy-paste my answer:
    As for you second question, are you having a specific problem? You rotate objects the same way you always rotate them in Unity. You can use
    Code (csharp):
    1.  
    2. var myGrid : GFGrid // that's the grid you want to use
    3. transform.roation = myGrid.transform.rotation
    4.  
    the first time when you spawn an object to set the initial rotation and then when you want to rotate objects you just do it as it is always done in Unity:
    Code (csharp):
    1.  
    2. transform.rotate(Vector3(0,90,0)); //rotate 90° around the local Y-axis
    3.  
    Here is more information:
    http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html
     
  46. ibps13

    ibps13

    Joined:
    Oct 6, 2012
    Posts:
    94
    Hi hiphish,

    Thx for reply trying trigger now ! :))
     
  47. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    Just a quick update, version 1.2.0 has been submitted. This is your last chance to buy the package for 15$, once it has been approved the price will be raised to 20$.
     
  48. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    The wait is over, version 1.2.0 is out, bringing you the long promised hex grids. I'll soon make a video demonstrating the new grid, in the meantime let me explain it in words. My implementation brings you all the features you knew from rectangular grids, except on a hex grid, and both grids inherit from the same base class. This means the API for both is the same and you can write one script for both grids with little to no need to make special adjustments for differentgrid classes. Currently there is only one coordinate system and hex grids have "only" as much functionality as rectangular grids. I whish to improve upon this in the future.

    Phew, this has really exhaused me. Often times I was wondering what I had gotten myself into and it was not uncommon for me to work beyond midnight, pondering above pencil-drawings, deriving formulae and thinking how to make everything work nice. The last stretch has been especially tiresome, getting the computer to do something is one thing, but then you start putting together the manual and you notice that the way it *how* it works doesn't feel right. It's those little thing no one notices when they are done right but everyone notices them when they are done wrong. What kept me pushing forward are you guys and your support. Many of you are silent, and that's fine, but I know you are there. Thank you.
     
  49. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    I made a short video giving you an overview of hex grids, so you can see them right in action. I'll make a video on how to extend Grid Framework with your own methods yourself next.
     
  50. hiphish

    hiphish

    Joined:
    Nov 13, 2010
    Posts:
    548
    Let's say you just bought Grid Framework, wrote some game logic and now you want to reuse it. Wouldn't it be great if it was a class method in Grid Framework so you could simply call it with one line of code? Even better, what if you could have one method that has the same syntax for both rectangular and hexagonal grids but different implementation based on the type of grid, so you would have to write just one script for any type of grid? Luckily this is no problem in Unity thanks to extension methods and if you have the code, then wrapping it up into an extension method can de done in a few minutes. Take a look at my latest video tutorial:


    Extension methods are only available in C#, but once you've written the method you can use it in any of Unity's scripting languages. Aside from keeping your code cleaner, extension methods have the advantage that if you need to make adjustments to your game logic you only need to do it in one place and every call of the method benefits from it.