Search Unity

TurnBased-Toolkit (TBTK)

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

  1. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    It's possible but I wouldn't say it's easy. You can just set them up as unit of a 3rd faction that has no movement available (0 move range, 0 attack range, etc). That will make them attackable by other unit. You can get them to do an aoe damage to all nearby unit by adding the code in DestroyRoutine() in Unit.cs. The tricky bit is make sure the turn sequence to still work correctly if somehow the explosion has took out some of the units.
     
    Stexe likes this.
  2. raszop

    raszop

    Joined:
    Jan 18, 2016
    Posts:
    7
    yeah that's the kind of a hack i was thinking about, but I thought i could avoid creating them as "units". I will try and let you know if i came with any other solution to that.
     
    Stexe likes this.
  3. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    How would you modify the deployment grid based on faction programmatically (as opposed to clicking to have it predefined)? Say you're loading a scene and you want to change the deployment grid from X faction to Y faction when the scene loads. Since there's a coroutine that delays the stuff by 0.5s I assume you could just modify the deployFactID value? I see it would be under GRID_MANAGER_GENERATOR object with the Grid Manager (Script) and then Grid T -> Element # (column) -> List -> Element # (row) -> Deploy Fact ID.

    I could burrow down into the object and modify those values under Grid Manager, but is there an easier way that you can think of? Or maybe I'm completely missing something?
     
  4. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm not sure if I understand your question. Specifically what is this 'deployment grid' that you are referring to? The whole gird itself, or the set of nodes that the unit can be deployed from? My best guess is you have a set of deployment nodes, you want to change what faction they are meant for during runtime? In that case, it's like you said. However it's not as complicated as you think. Just something like this in GridManager.InitGrid() will do the job:

    Code (CSharp):
    1. for(int x=0; x<grid.Count; x++){
    2.     for(int z=0; z<grid[x].Count; z++){
    3.         if(grid[x][z].deployFacID==oldFacID){
    4.             grid[x][z].deployFacID=newFacID;
    5.         }
    6.     }
    7. }
     
    Stexe likes this.
  5. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    The whole grid itself is part of deployment, so in theory all of them. I'll try what you suggested though and see how it goes. Thanks.
     
    mario_code4ever likes this.
  6. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    That did work, thanks.

    What about changing the direction of a faction at runtime?

    Also, what about getting a specific faction's color at runtime to use for things, like loading textures based on player color to color the units that?
     
    Last edited: Feb 22, 2022
  7. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The faction's direction and colour are stored on factionList in UnitManager. factionList[index].direction and factionList[index].color with index being the index of faction in question.
     
    Stexe likes this.
  8. orsilore

    orsilore

    Joined:
    Feb 3, 2022
    Posts:
    1
    HI,
    I saw your asset (TBtk-3) in the Unity asset store and I wanted to ask you some questions?

    Does your tool kit simply create a grid on the ground or individual editable tiles?

    It is posssible to give tiles different functions and characteristics (movement cost, passable only by some units, etc.) and I wanted to know if your toolkit allows you to edit them or not
     
  9. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You can edit individual tile but it's very limited in that regard. By limited I mean you can only edit the unit movement cost to move through them. You can also edit individual tile to be an obstacle, walled in certain direction (so unit can move/shoot through), spawn/deploy area for units, etc. but I'm not sure if those are the editable attributes you are looking for.

    And I should point out that changing the move cost only changes a value, it doesn't change the visual of the tile. That's up to you. In fact that is how many aspects of the toolkit work. You will probably need to use your own asset when it comes to visualization to make the most out of it.
     
  10. xagarth

    xagarth

    Joined:
    Sep 7, 2016
    Posts:
    17
    Hey @songtan ,

    Is this kit compatibile with 2d, 2d renderer, etc?
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Yes. You can make a 2D game or use 2D renderer if you want.

    However the framework is intended for 3D so the unit will rotate and move to face where they are going/attacking. So unless you are going for a top-down 2D view, you will need to do some light code modification to disable these rotation. It mostly involves removing/changing just a couple lines of code, I can show you how.
     
    Stexe likes this.
  12. xagarth

    xagarth

    Joined:
    Sep 7, 2016
    Posts:
    17
    No, that's fair enough. Thanks :) My concern is rather on the grid itself, say I have an isometric view and want to map the grid onto that, also colliders, raycasts, etc, they are not compatible between 2d and 3d if you use them.
     
  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Well, it doesn't really work in 2D space you see. Everything will still work in 3D space. When I say 2D, I meant the game looks 2D as far as the players are concern. In practise, you just use orthogonal camera projection and lock the camera angle.
     
    xagarth likes this.
  14. thebaddie

    thebaddie

    Joined:
    Feb 27, 2016
    Posts:
    7
    Hello, I'm considering buying TBTK3 but I'd like to read the documentation before to understand if it will fit my needs

    is it possibile?
     
  15. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Just sent you the documentation. :)
     
  16. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    Random question, but we're having weird issues with UnitManagerEditor Window. The "Starting Units" drop down list sometimes doesn't populate with the correct names from itemName and when a unit is selected there it only selects the 0 Unit (first unit in the list).

    Is this an issue with Unity's drop down stuff itself? Or TBTK? Any ideas? We have over 50 units which I think might be an issue. We're also on a slightly older Unity version (2019.4.30) and have considered updating to see if it fixes it, but don't want to spend the hours and hours it will take to do that if it isn't related to Unity itself.

    Any thoughts or ideas?
     
  17. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Have you been adding/removing unit from the UnitEditor while you are using the drop down? The list get populated when the editor first initiated. This happen when you first boot up Unity, or when you enter and exit player mode. Or if you have added/removed unit, try close all editor window, play a scene to force the list to reset.
     
  18. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    No, we add units to the UnitDB programmatically since it is a lot of units being created from a spreadsheet, converted to JSON, and then used to make prefabs that are fed into the UnitDB.

    The list isn't the issue -- it shows all the units in the list. The problem is selecting the units as if you click on any of them it just selects the first. I've tried reloading the scene, playing scenes, restarting Unity, and so on. Still selects only the first unit in the list.
     
  19. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I see. When you create the prefabs and fed them into UnitDB, did you assign a unique prefabID to individual prefab? The unique prefabID is what used to identify a particular prefab in various scenario where direct prefab reference is not possible, which is what happen in this case. The popup only accept an index that correspond to a list of string. So if some of your prefabs share the same prefabID, the editor will always end up thinking the first prefab in the list with that ID is the unit you are looking for.

    TLDR: make sure your prefabs has unique prefabID.
     
    Stexe likes this.
  20. Kalibyrx

    Kalibyrx

    Joined:
    Apr 28, 2022
    Posts:
    5
    Hello, first I'd like to say this is a great asset! Very awesome work and I'm glad I purchased it.

    I am having a little trouble getting the Demo_Persistent_PreGame and Demo_PersistentGame running correctly.

    When I open the PreGame scene, I get this error:
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. TBTK.UnitManager.GetFactionWithID (System.Int32 fID) (at Assets/TBTK/Scripts/UnitManager.cs:30)
    3. TBTK.UnitManager.GetAuraDmgHPMinMul (TBTK.Unit unit, TBTK.Node node) (at Assets/TBTK/Scripts/UnitManager.cs:570)
    4. TBTK.Unit.GetMulDmgHPMin () (at Assets/TBTK/Scripts/Unit.cs:390)
    5. TBTK.Unit.GetDmgHPMin () (at Assets/TBTK/Scripts/Unit.cs:389)
    6. Demo_Persistent_PreGame.UpdateUnitDisplay () (at Assets/TBTK/DemoNScenes/Scripts/Demo_Persistent_PreGame.cs:232)
    7. Demo_Persistent_PreGame.OnPoolButton (System.Int32 idx) (at Assets/TBTK/DemoNScenes/Scripts/Demo_Persistent_PreGame.cs:209)
    8. Demo_Persistent_PreGame.Start () (at Assets/TBTK/DemoNScenes/Scripts/Demo_Persistent_PreGame.cs:147)
    9.  
    Is there anything I need to do in order to try and run the PreGame scene and the PersistentGame Scene?

    Thanks,
     
  21. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    Yeah, it looks like that's the issue. They all have the same "fileID" in UnitDB since they are being created from a single template that is then modified. Any suggestions on how to give them different IDs? They all have a different guid though.

    Unless fileID is different than prefabID, in which case I'm unsure how to check what it is or change it.
     
  22. Kalibyrx

    Kalibyrx

    Joined:
    Apr 28, 2022
    Posts:
    5
    I actually got the Demo_Persistent_PreGame scene working by first loading into the XCOM demo and then going back to the Demo_Menu scene. Now when I go back into the "PersistentGame" Demo, instead of the XCOM demo, I get another error.

    Code (CSharp):
    1. ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    2. Parameter name: index
    3. System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <695d1cc93cca45069c528c15c9fdd749>:0)
    4. System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <695d1cc93cca45069c528c15c9fdd749>:0)
    5. TBTK.UnitManager.EndTurn_FactionPerTurn (System.Int32 turnIdx) (at Assets/TBTK/Scripts/UnitManager.cs:303)
    6. TBTK.TurnControl+<_EndTurn>d__26.MoveNext () (at Assets/TBTK/Scripts/TurnControl.cs:94)
    7. UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <d3b66f0ad4e34a55b6ef91ab84878193>:0)
    8.  
    Any ideas on how to work around this? Thanks.
     
  23. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @Stexe, by prefabID I actually meant the variable prefabID in Unit.cs. If you haven't assign any, you can simply reset the prefabID of all the units in DB by using the UnitDB context menu 'Reset PrefabID'. Like so:

    TBTK_ResetPrefabID.png

    It will assign the unit a prefabID corresponds to their index in UnitList.


    @Kalibyrx, That is an oversight from my end. Demo_Persistent_PreGame should work right out of the box. You don't need to run any scene before it. I've sent you a fix. Please check your inbox. Sorry for the trouble.
     
    Stexe likes this.
  24. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    Yep, that did it. Thanks! =)
     
  25. Kalibyrx

    Kalibyrx

    Joined:
    Apr 28, 2022
    Posts:
    5
    @songtan Hey there, I was wondering if there was any documentation on how to add Units to the Demo_Persistent_PreGame Menu scene?

    As in, I have my Main Scene where a Player can recruit new Units. When they recruit new units, I'd like this to pass over to the PreGame Menu Squad list. Also, any documentation on how to create new Units during runtime would be great.

    Thanks!
     
  26. Kalibyrx

    Kalibyrx

    Joined:
    Apr 28, 2022
    Posts:
    5
    Also, it doesn't seem like Attack Ranges are working properly in the Unit Editor Menu. Following the documentation, I made a "Melee Only" Unit, here are the steps I took.
    1. unchecked the has Melee field as the doc said.
    2. reduced the Attack Range for "Attack Range I" to 0 - 0 (also tried 0 - 1) as the min / max.
    3. Melee Only Unit still can attack from default range-attack range.
    Thanks!
     
    Stexe likes this.
  27. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    There is a way since I've been doing it a lot as that's basically half of my game. We store them in a list and then pass them over. We don't create units at runtime, but we do reference the prefabs in the UnitDB and then group them in a list to instantiate.

    I'm curious about this myself as I haven't been able to figure it out.
     
  28. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    @songtan : Haven't heard back in a while. Maybe Unity didn't update you on posts here? Was wondering if there's a way to chain abilities (have one ability chain into another after its use) easily.

    Also, any way to have forced movement (like knockback)?
     
  29. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry for not responding. For some reason I haven't received any notification on new post. Unfortunately I'm currently on holiday and haven't got access to my workstation so I can only answer your question based on what I remember.

    @Kalibyrx, The pregame menu squad selection is all run from a script named Demo_Persistent_Pregame.cs. The pool of unit available is pulled from the prefab list in UnitDB. If you want to add more unit on the fly, I suggest you refer to that. As for how to create new unit in runtime, you will still have to do all the usual steps when you create any unit, except you will have to do all that using script. The attack range settings sounds like a bug. I'll follow it up as soon as I can.

    @Stexe, I'm there's no way to chain ability unless you modify the code to support that. That applies to forced movement as well. The former is probably quite straight forward. You just have the unit to use the next ability (if there's any) after the first one is done. The later however, requires further checks and updates for other condition like overwatch, fog of war, etc.
     
  30. RichardLichten

    RichardLichten

    Joined:
    Jul 20, 2013
    Posts:
    1
    Hello,

    i bought TBK3 and like it! But animation does not work, i use a model with "legacy" i guess animation nad one with separet animations which i added (new controller). I set those in unity manager, but it only shows the model with some animation, not those i set up in the Unity Manager.

    Could you help me? All advice would be welcomed.

    Kindest, Richard
     
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Hi Richard, thanks for your purchase. If you haven't read the documentation, I suggest you do. There's section that explains how to get the animation set up correctly. Being legacy animation should have nothing to do with it.

    If you are still struggling, I can try to take a look a at it but unfortunately I'm currently on holiday so that will have to wait until at least next week.
     
  32. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    What about the melee stuff? Never heard about that. Is it just an entirely separate stat block or something?
     
  33. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I should point out that as far as the framework are concern, there's no distinction between melee and range attack. It's all player perception. If you set the attack range to only 1 (adjacent nodes) and use a melee animation, the player is going to perceive it as a melee attack, despite using the same code. However the framework does support units with 2 separate attacks based on range. I call this hybrid unit and for simplicity sake, I call these 2 attacks melee and range attack. The idea is the unit will use range attack as default, but if the target is close enough, it will switch to melee attack. These 2 attacks has their individual stats block.

    In short, unless you are using hybrid unit. Melee and range attack are the same thing.
     
    Stexe likes this.
  34. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    Gotcha, that's what I thought. But the melee attack stat block has a few weird things like its own HP or something? Is that just ignored, along with all non-attacking stats?
     
  35. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Yes. If you are using the Inspector, you will see those unused stats and they are ignored in the calculation. If you are using the UnitEditor, it will only show you the relevant stats.
     
    Stexe likes this.
  36. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    I think I found a minor UI bug in UIOverlayUnit.cs on line 212ish:

    Code (CSharp):
    1.         void UpdateScreenPos(){
    2.             Vector3 screenPos=Camera.main.WorldToScreenPoint(unit.GetPos());    screenPos.z=0;
    3.             rectT.localPosition=(screenPos+UIOverlayUnit.GetPosOffset())*UI.GetScaleFactor();
    4.         }
    The "GetPosOffset" isn't properly relative to the actual screen space and can move UI elements to very different locations based on the game's resolution.

    I'm not sure what the fix is, but thought I'd mention it as I'm having trouble properly positioning unit health bars for different resolutions.
     
  37. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm sure it's not a bug. But it's a very tricky thing to get right. The problem is not GetPosOffset(), it's UI.GetScaleFactor(). By default, the canvas has a scalar that use a reference resolution width of 1600. UI.GetScaleFactor() gets its value from the 'Scale Reference Width' in UIControl, which is set to 1600 by default. Now these two has to match otherwise the health bar won't be positioned correctly.
     
    Stexe likes this.
  38. Gharowse

    Gharowse

    Joined:
    Sep 15, 2015
    Posts:
    2
    Hi, really loving the package! I just installed the latest version and I'm having trouble getting the generic aoe ability working. On a fresh install, for me, Bombardment doesn't do any damage, nor do other abilities that use generic (circular) aoe damage.
     
  39. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for your purchase and glad you like it. What you are experiencing is a bug. I've sent you a fix. Please check your inbox.
     
  40. Gharowse

    Gharowse

    Joined:
    Sep 15, 2015
    Posts:
    2
    Hey Song, still loving the package. I'm noticing that after I use an ability, the button goes inactive for a second, and then unexpectedly becomes active again (I can click on them to create a checkmark as you can see in the screenshot but they do nothing until I end the turn). How can I keep the ability buttons inactive after they've been used? Thank you!!
    upload_2022-10-29_10-54-16.png
     
  41. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I think I know what happened. I've sent you a fix. Please try that and let me know if that doesn't fix the problem.
     
  42. Marc0101

    Marc0101

    Joined:
    Apr 20, 2017
    Posts:
    7
    Hi! Is there a way to resize the entire board of game (hexagon base + unit)? Thanks!
     
  43. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The only way to adjust the board/grid size is to adjust the 'Node Size' on the Grid_Manager_Generator. You will have to regenerate the grid. For the unit size, you will have to adjust the prefab size individually.
     
  44. Marc0101

    Marc0101

    Joined:
    Apr 20, 2017
    Posts:
    7
    Ok, thanks! Now, I can resize the grid BUT if I resize or scale the unit by prefab (root prefab or graphic element inside), there is this error:

    ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <e38a6d3ee47c43eb9b2e49c63fc0aa48>:0)
    TBTK.UnitManager.EndTurn_UnitPerTurn (System.Int32 turnIdx) (at Assets/TBTK/Scripts/UnitManager.cs:267)
    TBTK.TurnControl+<_EndTurn>d__26.MoveNext () (at Assets/TBTK/Scripts/TurnControl.cs:101)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)

    I resize the node grid from 2 to 1 To have a smaller grid, but the unit don't appears on board. Are there another parameter to change to conform the unit and other games dynamics to the new smallest grid? Thanks a lot!
     
  45. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I don't think that error has anything to do with resizing the unit or grid. It's more likely to do with something went wrong when you regenerate the grid or placing the unit. In indicate there's a unit missing (likely get deleted accidentally) during runtime. Is it the only error you have?
     
  46. Marc0101

    Marc0101

    Joined:
    Apr 20, 2017
    Posts:
    7
    Yes. This is the consolle screenshot

    I try to do that in the Demo Classic scena. This is the first thing I do. Resize node grid from 2 to 1. If I generated units, they don't appear in Editor and in play mode I see this error.

    If I do that in the RJPG scene, I can resize the grid with the node and the unit stay correctly inside his square until a high resize data (from 2 to 0.2). After that, the error appears again
     
  47. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I see. The problem with that two scene is that they rely on the starting unit list from both faction being generated into the scene when the scene first loaded. The requires the grid to have a certain pre-assigned deployment nodes where the unit can be placed on (the crosses on the grid in scene view). When you reduce the grid size and regenerate the grid, you remove all of that. So the units has no where to be deployed on and hence there's no active unit in the game at all.

    You can manually assign some deployment nodes, or manually add some unit to the grid (both using the grid editor) to fix this. The bottom line is, there need to be some units on the grid the when game starts or you get that error. This has nothing to do with the node or unit size itself.
     
  48. MottoFun

    MottoFun

    Joined:
    Jul 29, 2022
    Posts:
    8
    HI!
    Is there any way to customize and edit enemy AI? I didn't find any description about AI editing in the document.
     
  49. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    If you mean changing configurable parameters of the AI. You can find them on the GameControl game-object, on the component 'AI'. There's no documentation on those parameters but all the variables in the inspector has tooltip on them.

    If you mean customize the code itself, then I'm afraid I don't have any instruction for that. But all the code for AI are in AI.cs, feel free to dig into that.
     
  50. MottoFun

    MottoFun

    Joined:
    Jul 29, 2022
    Posts:
    8
    Thank you for your reply! I have found it!