Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TurnBased-Toolkit (TBTK)

Discussion in 'Assets and Asset Store' started by Song_Tan, Aug 11, 2013.

  1. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Do you mind looking into the code and seeing if there's someway to maintain the current persistant load / save functionality without loading a prefab with all units? It's a really big memory hog and a tough issue for mobile development. I'm going to try on my end as well but if you could give me your thoughts too .. that would be great.
     
  2. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Right, please give me some time. I'll see what I can do.
     
  3. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    @Rajmahal, I've just made some modification that remove the need of loading the prefab list, assuming you are using the default UI or NGUI that is. Please email me so I can sent your the code.

    If you are not using any of the default UI, I can talk you through the change so you can apply the solution yourself.
     
    Rajmahal likes this.
  4. Exeneva

    Exeneva

    Joined:
    Dec 7, 2013
    Posts:
    432
    Will you be updating the kit to use the new UGUI?
     
  5. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Yes, definitely. In fact I've already started on it. However it could take sometime as I need to get use to it. Also I dont expect it to be really ready until Unity4.6 is fully released.
     
  6. Thoreandon

    Thoreandon

    Joined:
    Aug 21, 2014
    Posts:
    37
    How can i enable a right mouseclick on a unit, so that a menu or something appears, like in the Single Basic Demo. Cannot find the code for that Example.
    Only left-click call UnitTB.Select() but not right-click.
     
  7. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    If I remember correctly, right mouse click on unit to show unit info is enabled all the time. The code you are looking for is actually in Tile.cs, starting from OnMouseEnter(). There, the right mouse button click event is checked.
     
    Last edited: Aug 25, 2014
  8. Exeneva

    Exeneva

    Joined:
    Dec 7, 2013
    Posts:
    432
    How many AIs does this kit have support for?

    I tried to have 3 AIs and it seems like only 2 are working.
     
  9. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    It supports as many as you specified/placed on the grid. When you say 3 AI, do you mean 3 units or 3 factions? And how exactly are they 'not working'? I would check the setting AI-Stance on AIManager. If you have set it to passive or trigger, the AI unit wont be actively seek out and attack you. So it might be that.
     
  10. Exeneva

    Exeneva

    Joined:
    Dec 7, 2013
    Posts:
    432
    I'm not sure, it just seemed like one faction wasn't working.

    Regardless, my team developed an entry for ludum dare 30 using the TBTK, although it's a heavily modified version of TBTK now. I present to you Cohack, a turn-based tactical game inspired by an old shockwave game called Spybot: The Nightfall Incident.
    Cohack - Ludum Dare



    Also, the performance of TBTK could be greatly improved performance on mobile by setting the tile material to the shared material property by default, this way each tile doesn't have to use its own material instance.
     
    Last edited: Aug 26, 2014
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    First of all, congratulation on your game. Pretty neat concept.

    About the AI, it's hard to say why that happen. Personally I have never come across any problem like that. It could be a setting error or due to the heavy modification you made that the AI algorithm no longer able to comprehend the extra logic required. It will take a careful debug on the AI code to find out why. Since you are using "all unit per turn" turn mode, you can easily find out how many AI faction are there in the game to start with. You can do this in InitFaction() of UnitControl.cs. Just add this chunk of code at the very end of the function and check the log when you start the game.

    Code (csharp):
    1.  
    2.     int AIFaction=0;
    3.      int playerFaction=0;
    4.      for(int i=0; i<allFactionList.Count; i++){
    5.        if(allFactionList[i].isPlayerControl) playerFaction+=1;
    6.        else AIFaction+=1;
    7.      }
    8.      Debug.Log("Total Faction in game: "+allFactionList.Count+"  ("+playerFaction+" player's and "+AIFaction+" AI's)");
    9.  
    Finally thanks for the tip on the shared material, I'll see what I can do.
     
  12. Assassin101

    Assassin101

    Joined:
    Aug 27, 2014
    Posts:
    1
    Hello songtan, I'm planning on purchasing the TBTK, but I have a few question regarding what can I do with it (sorry if you have answered this questions before and I didn't notice...):

    1: Can I use sprites instead of 3D models for my characters? And if possible, is there animation support for movement, attack, etc of my sprites?
    2: Is it necessary to purchase NGUI to use this framework? I'm starting using Unity, so I don't have many packages, and NGUI seems a little bit expensive (especially if I have to buy both TBTK and NGUI at the same time).
    3: Is it possible to use this framework to play with 2 o more human players instead of the AI in a multiplayer match? (with an multiplayer system included in TBTK, Unity Networking System or perhaps a 3rd party system like Photon Server).
    4: Can I make Stats of units, leveling up information and other kinds of information in a Database (say MySQL or Posgres) and access it via TBTK or via normal Unity methods? (I haven't used databases with Unity before, so I'm sorry if this is a dump question).
    5: Some documentation of how to use the framework would be nice, if you don't have any problem with that.

    Sorry for bothering you, and hope you can answer me soon... And thanks.
     
    Last edited: Aug 27, 2014
  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Hi Assassin, to answer your question:

    1. Yes you can use sprite however there will be no animation suppport for sprites. You will have to write some additional code to do that.
    2. No, NGUI is optional. TBTK comes with 2 UI, one uses NGUI and there other one uses Unity UI.
    3. It's possible I guess but I'm afraid it's not supported by default. You will have to make your own modification.
    4. Leveling of unit is not supported. If you ask me, it's not too difficult to add provided you are some what profficient in coding. As for database integration, have to say I have no prior experience either.
    5. There's a pdf documentation that comes with the package that explain most of the basic stuff. And then there's these videos:


    Hope this answer your question.
     
  14. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    That's awesome, Songtan ... really appreciate it. I sent you a PM as I'm not sure if I have your email. Please send me the details on how you accomplished this. I am using the NGUI version of the UI.
     
  15. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Can you provide some more details on this? Do you mean using mobile friendly versions of the Shader on the material for the hex tiles or something else? Working on optimizing my game for mobile so would really appreciate any guidance.
     
  16. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    Hi!
    Just bought it, really awesome!
    Controls work on mobile but not on my Mac. Is there an option somewhere to enable mouse controls?
    Thx!
     
  17. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Thanks for your purshase. Hope you enjoy the package. Fyi, mouse control are suppose to be enabled all the time, unless you have set the build platform to mobile (iOS or Android). I would suggest you to check and switch your build platform to stand-alone when working on desktop.
     
  18. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    Thanks for the fast answer!
    So if I do iOS development but want to check gameplay changes quickly, I have to switch platforms all the time?
     
  19. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    What you can do in this case is to remove the platform dependent compilation code in Tile.cs. Find the set of function for mouse input namedly onMouseEnter(), OnMouseExit, etc which should be around line450. You will notice there are 2 lines of code at the start and the end of them:
    Code (csharp):
    1.  
    2. #if !UNITY_IPHONE && !UNITY_ANDROID
    3.     //onMouseEnter and so on....
    4. #endif
    5.  
    Just remove this 2 line should do the trick. However please note that Unity does emulate touch input as mouse input, so in some case you end up having some duplicate input.
     
  20. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    Awesome thanks! Will try asap.
     
  21. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Hi Songtan,

    I tried the code changes you mentioned to get around how the system loads all units in the Unit Manager in the unit selection screen but it didn't work. Looking at the profiler, I'm still seeing units that exist in the Unit Manager and not in the Unit Selection window as being loaded into memory. Removing the units from the Unit Manager does remove them from memory but then I run into Null reference exceptions during gameplay. I guess I could get around the issue by having two versions of my game ... one with only a small number of units in the Unit Manager window for low memory devices but it would be great if I wouldn't have to go that route. Any ideas on what's causing it?
     
  22. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Just noticed that PerkManagerTB also has a similar Resources.Load line that loads the UnitListPrefab object. I'll try to apply the same changes on PerkManagerTB as well.
     
  23. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Sorry that I couldn't respond earlier

    Here's something that might help: the reason this prefab loading are needed is because of the way all the system in TBTK ties together. ie PerkManager needs to know how many unit are there so it can setup the bonus modifier for all the possible unit properly.

    In your case, there are two solution depending on the circumstance. if you are pretty certain that your game doesnt use any perk that concern any unit at all, you can just safely remove that section of code. Or if you are sure that which unit has a corresponding perk or not, you can strip away the loading the unitList (which is the list to be load into original) a public variable which you can assign manually.
     
  24. fmarkus

    fmarkus

    Joined:
    May 22, 2010
    Posts:
    181
    It worked awesome. Thanks!
     
  25. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Does Perkmanager need a list of all units in the whole game or just the player's available units? Right now, I've changed it so that it loads only a list of the player's available units but I'm not using Perks yet so I don't know if this is fine or not.

    I have a situation where the player can choose up to 6 units from a list of 18 and will use those 6 for the entire game. Can I change the TBStats unit list to then only include the 6 that the player chose rather than all 18 of his available choices?
     
  26. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Yes you can try that. It should cause any error. The way PerkManager work is it loads the unit and create a corresponding list of UnitStatModifier. The list contains any stat that might have been modified from unlocked perk. Considering perks only affects player's unit, as long as all the player unit in the scene is in the unit list, you shouldn't run into any error since you wont be access the statModifier for the unit anyway.
     
  27. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Cool .. will give that a shot.

    Regarding the earlier posters comment about improving performance on mobile by sharing a material on the Tile, I'm still unclear as to what it means. At the moment, I see that a hex or square tile has a script that includes a list of several materials. The materials all have different colour shades and the code applies the appropriate material on the tile when the tile needs to be shown with a particular colour.

    So would it optimize things to have it only have one material and then have the code adjust the colour of that one material rather than switching to another material with that colour preset? Is that what was implied or would it be something else?
     
  28. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Please refer to this link - http://docs.unity3d.com/Manual/DrawCallBatching.html
    Specifically in the material section

    Materials
    Only objects sharing the same material can be batched together. Therefore, if you want to achieve good batching, you need to share as many materials among different objects as possible.

    If you have two identical materials which differ only in textures, you can combine those textures into a single big texture - a process often called texture atlasing. Once textures are in the same atlas, you can use a single material instead.

    If you need to access shared material properties from the scripts, then it is important to note that modifying Renderer.material will create a copy of the material. Instead, you should use Renderer.sharedMaterial to keep material shared.​

    In the script Tile.cs, I've overlooked this and use renderer.material to change the material, hence break the dynamic batching. You can modify the script accordingly so it wont break the dynamic batching.
     
  29. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Great ... thanks, I'll take a look.
     
  30. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    I took a quick look and I think all that's necessary is to change the calls to renderer.material to renderer.sharedmaterial. No change in gameplay but I'm pretty sure draw calls dropped by 20 or 30. Not sure though as I didn't check the numbers before making the changes. Do you think that's all that's needed?
     
  31. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Hi Songtan,

    I've made all of the changes you suggested in order to stop the game loading all units in the unitprefablist into memory. Unfortunately, it still seems to load all units (including their animations, textures, etc.) into memory. Is there anything else that might be causing it? I looked in the code for all Resource.Load("PrefabList") instructions and updated them but there's still something else causing the loading of all units in the unitmanager into memory. Any ideas?
     
  32. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    As far as I'm aware GlobalStatTB and PerkManagerTB are the only two runtime components that load the prefabList from Resources. Anything other than these two are could be an editor component. I would suggest you close Unity, start again and run the scene without open any editor and see if that makes any different. Some of the editors may have store the list as a static variable so just just closing them wont help. Also you can try remove/relocate the prefabList object (or just rename it) to see if it throws up any error. Then from the error you can know if some component is trying to load it and which component is that.
     
  33. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Great ideas ... thanks, I'll give that a shot.
     
  34. rayfigs

    rayfigs

    Joined:
    Feb 8, 2009
    Posts:
    41
  35. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Hi Ray, I'm sorry to say that without any modification, it won't be able to do what you need.
     
  36. Thoreandon

    Thoreandon

    Joined:
    Aug 21, 2014
    Posts:
    37
    Is it better to delete Tiles that i dont need with the DEL Key (remove them completely) or mark them in the GridManager as empty ?
    Does it have sideeffects using DEL ? (Maybe neighbour Tiles are wrong or something?)

    Does the Max Size of the Grid (40*40), that you mentioned somewhere here, means 1600 Tiles ?
    I mean, if i make a Grid 100*100 and delete 9000 of it, would be be ok? (Just example)

    Actually i have scenes where most of the space is occupied. It would be much easier for me to place Tiles step by step. It seems like the GridPainter cannot do this.
    It would be cool if i could make a small grid, like 5*5 and then add single tiles step by step by clicking at the Terrain.
     
    Last edited: Sep 8, 2014
  37. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Good question ... I'd like to know as well. So far I've just been marking them as empty / invisible but not sure if that's the best approach or not from a performance perspective.
     
  38. rayfigs

    rayfigs

    Joined:
    Feb 8, 2009
    Posts:
    41
    @songtan- thanks for the reply. What sort of modifications would I need? Could you recommend what sort of skills or assets that would be needed to hire someone to mod your kit?

    Many thanks,
    Ray
     
  39. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    @Thoreadon, @ Rajmahal, you can delete it if you want. It shouldn't break anything. The reason I leave it in the scene is so that the user can re-enable it using GridPainter when needed. As you aware, it's not possible to just click on an empty space and place a tile there. However, knowing my careless nature, there could be one or two null exception error if you delete the unwanted tile. But it should be an easy fix by just adding a simple condition check to avoid the error where it occur.

    @rayfigs, honestly, the only common things with your game and TBTK are the hex-grid and the path-finding component. Albeit yours is a lot more simpler. Assuming that you already have TBTK, you dont really need any additional asset, as I dont think there's anything out there that can do specifically what you need. The major modification/addition required would be the basic game logic and the algorithm for the cat to look for nearest exit and move towards it.
     
  40. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Thanks Songtan ... I'll give that a shot. Do you think that leaving the unused tiles as empty / invisible has much of a performance impact?
     
  41. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I dont think they will have too much of a performance impact. For a start there's no rendering required since they are not visible. Furthermore the tile themself doesnt have any active code running unless call upon. Another alternative (if deleting them throws up a lot of error) is to deactivate them. I'm pretty sure inactive object has almost no performance impact. You can have loads of them in the scene without any problem.
     
  42. Thoreandon

    Thoreandon

    Joined:
    Aug 21, 2014
    Posts:
    37
    Strange behaviour:
    I placed a unit with Gridpainter and start the game, then the mesh ist placed correct but the tiles are placed wrong??

    If i click somewhere, the unit moves out of the scene.
     
    Last edited: Sep 8, 2014
  43. Thoreandon

    Thoreandon

    Joined:
    Aug 21, 2014
    Posts:
    37
    Forget the question, after generating the grid again it was gone.
     
  44. UnluckyPhil

    UnluckyPhil

    Joined:
    Feb 27, 2014
    Posts:
    3
    Hi

    Really enjoying the TBTK, would it be possible to get a copy of code as well?

    Thanks
    Phil
     
  45. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I don't really have the code. But if you can pm/email me I could sent the modding instruction I sent to Rajmahal too.
     
  46. Thoreandon

    Thoreandon

    Joined:
    Aug 21, 2014
    Posts:
    37
    I use 3D Assets for 'decoration', like walls, stone etc.
    Of course, the units and tiles dont care about that, so units drive through or shot through them.

    I can mark the tiles as unwalkable but when i have to regenerate the grid, everything is gone and i have to do it again.
    How can a system be implemented that care about these Problem ?
    >Dont drive/walk/shot through other , non TBTK gameobjects in the scene

    Perhaps someone has a solution allready and share it.
    I think about giving these objects a script that, at start, automatically iterate through all tiles, and comparing coordinates.
    If the gameobject touches the tile, it will be set to unwalkable.
    Or doint this with a collider ?
    Any tipps?
     
  47. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    You can set up some objects as "obstacles" with the obstacle creator window, if I recall. That's how I'm doing it. Haven't played around yet with walls yet ... not sure exactly how they work.
     
  48. Thoreandon

    Thoreandon

    Joined:
    Aug 21, 2014
    Posts:
    37
    Yes i saw this but havent figured it out either.
    What i need is a invisible Wall that the player cannot see, but Units cannot pass and shot through.
    I dont want to set up everything myself by hand coz my map has many non-tbtk objects, so i need something that set the obstacles automatically. Sometimes, the grid has to be regenerate, and then i dont want to set up the stuff over and over again until the scene is finally finished.
     
  49. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Can't really help you then ... I do everything by hand in my game.
     
  50. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    You can place those any object however you want. After that, just use the grid painter to set blocked tile to unwalkable. You can setup walls between any two tile as well. It dont really need to be visible to the player.

    The tricky bit is the "dont shoot through them" bit. As far as I can tell, you will need additional coding to do that. First you will need to place some collider on those blocked tile. Then in the code where possible target is checked, you need to add a raycast to check if there's any of these placed collider is in the way.