Search Unity

  1. 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. MottoFun

    MottoFun

    Joined:
    Jul 29, 2022
    Posts:
    8
    Does anyone know how to deactivate the UI in the template? I want to disable the "Continue" button.
     
  2. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    The UI used the standard Unity UI system. Each button is a game-object. If you want to disable a particular button, just deactivate it the game-object.
     
  3. Marc0101

    Marc0101

    Joined:
    Apr 20, 2017
    Posts:
    7

    Thanks a lot! I now understand the dynamics of placement, size, and unity of your asset and I really think it is an excellent job!
    Now I would like to understand if it is a convertible project in VR, with the implementation of unity XR for Oculus Quest.
    The conversion is mainly about the selection and click mechanism of the elements. Basically, the mouse input should be replaced with controller input.
    I've tried looking at the various scripts, but I can't figure out where the instructions are so that, for example, a selectable box lights up when the mouse is passed.
    Can you give me some instructions about this? Thanks!
     
  4. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    Thank you!

    All the code for user input and interaction are located in the folder 'Scripts/UI'. The mouse input in particular is in the script UIInput.cs. I'm not sure what you mean about selectable box. If it's a node on the grid, then the code you are looking for is in UIInput, where code detect a new node has been hovered over by the cursor and put a highlight indicator on that node. If you are referring to the buttons, then it's just default unity UI animation state. I've the animation automatically highlight the button when the cursor hover over it. There's no code involve.
     
  5. MottoFun

    MottoFun

    Joined:
    Jul 29, 2022
    Posts:
    8
    Thanks!
     
  6. MottoFun

    MottoFun

    Joined:
    Jul 29, 2022
    Posts:
    8
    Hello! I am studying the enemy's AI. How does the unit select targets and execute actions under AI operation?
     
  7. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    The AI units uses a series of scripted logic and calculation to determine the next action and target. It's all in AI.cs. You can look it up yourself. Once and action or target is determined, it just call the appropriate function like when the player has issued a command.
     
  8. MottoFun

    MottoFun

    Joined:
    Jul 29, 2022
    Posts:
    8
    Hello!Could you tell mehow to close battlefield air?
     
  9. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    I don't understand. What do you mean?
     
  10. MottoFun

    MottoFun

    Joined:
    Jul 29, 2022
    Posts:
    8
    Sorry!Could you please tell me how to turn off the fog of battlefield?I found that some enemies could not be displayed in the battlefield.
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    The fog of war setting is on GameControl. It's just a simple check box 'Enable Fog-of-War'.
     
  12. MottoFun

    MottoFun

    Joined:
    Jul 29, 2022
    Posts:
    8
    I found it! thank you!
     
  13. chaosmonger

    chaosmonger

    Joined:
    Jan 23, 2019
    Posts:
    71
    I'm having a weird bug...
    The premise is that I manipulated the grid a bit, especially removing part of it to fit my environment... so from a rectangular generated grid, I deleted some hexes where my buildings were. Nevertheless, the bug is rather strange.
    Basically the selected/highlighted grid cell, it's always a few cells away from my mouse cursor, as you can see on the screenshot:

    What could be the cause of it and how can I solve it?
    The bug seems related with GridIndicator somehow, but I've no idea... The Hex_Select under GridIndicators is placed correctly in the unit, but Hex_Cursor is always at that distance/direction far away from my mouse cursor.
    Any guidance would be very helpful! Thanks
    N.
     
    Last edited: Mar 16, 2023
  14. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    It's hard to say what could have cause this.

    Are you using multiple cameras in your scene? If yes, make sure only one camera is given the tag 'MainCamera'. It has to be the one looking the grid.

    If the camera is not the issue, check the grid collider and make sure it's aligned with the visible grid.. By default, it's the 'collider' object under the hierarchy of GRID_MANAGER_GENERATOR. And make sure there are no other collider in the scene with the layer 'Node' (layer-29) that could intersect with the camera pov to the grid.

    That's the two potential reason that I can think of on top of my head.
     
  15. chaosmonger

    chaosmonger

    Joined:
    Jan 23, 2019
    Posts:
    71
    So, I've double checked and there are no other cameras with the tag "Main Camera", besides my main camera. I've tried to manipulate the "collider" at runtime (which is correctly aligned with everything), and I noticed some changes if I raise the "Y" position value. I cannot make it work, but somehow it seems related with that "collider" and how my camera returns the image... Maybe something related with the camera projection alignment with the collider, I'm not sure (I've tried with other camers, though, and the problem is still there... feels like the highlighted node is always two hexes away in the same direction, no matter the angle of the camera)... Can you point me out which script is handling this thing? The other Grid Indicators are placed nicely, also the units move properly... The problem seems related only with the mouse cursor and the GRID_MANAGER_GENERATOR collider.

    EDIT: I think I've found the problem, even if I don't understand why... but basically all the parents elements of TBTK must be in "0,0,0" position, otherwise it doesn't work...
     
    Last edited: Mar 16, 2023
  16. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    You are right. It's all about camera projection alignment with the collider. The detection is based on the cursor position projected from the camera to the collider. If you offset the collider or somehow the use the wrong camera for the projection, you end up with a misaligned position.

    You can find out all this work in UIInput.cs, GetNodeFromCursor(), and GridManager.cs, GetNode(). GetNode() do the raycasting and pass the position to GetNode() to retrieve a node nearest to that position. Of course there are some assumption in how the calculation is made so it's possible that if you move the wrong things around in the scene, it could mess up the calculation.
     
  17. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    Just updated from Unity 2019 to 2021 and having some minor issues with TBTK's UI. Specifically, right clicking on a unit to get the stats no longer works and the pause menu / settings pop-up is heavily off-centered. Any idea what might be causing that?

    Our version of TBTK is a bit behind due to all the modifications we've made to it and simply updating directly isn't very easy. Unsure if it has anything to do with fixes you made in the last few patches.
     
  18. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    I just test it myself and everything seems to be working correctly. Honestly I can't remember what I did in the last few updates. But I doubt it has anything to do with pause menu. If it's off centred, it's probably has to do with the settings on the UI elements. Also, there isn't a setting menu/popup.

    As for the unit info, check UIControl on the game-object UI_TBTK. Make sure 'Enable Unit Info' is checked. Other than that, I can't see why it isn't working. I would dig into the code, specifically UIUnitInfo.Show() to see where that is called from and why it isn't working.
     
    Stexe likes this.
  19. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    Looks like most of the issues were due to UI layers changing or something. We did run into an issue with " GetNodeFromCursor() " in UIInput.cs ... we're having trouble getting the raycast working that will open the unit's info. Any idea on what might be causing that problem?
     
  20. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    If you are sure that the issue is about raycasting, look in GetNodeFromCursor() in UIInput.cs. It boils down to the camera and the target collider (any collider with layer-29). I would add some debug code in so see what the raycast hits, if it hits anything at all.
     
    Stexe likes this.
  21. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    Layer-29? Looks like that's the issue.

    Code (CSharp):
    1.         public static int GetLayerUnit(){ return 31; }
    2.         public static int GetLayerInvisible(){ return 30; }
    3.        
    4.         public static int GetLayerNode(){ return 29; }
    5.         public static int GetLayerObsFullCover(){ return 28; }
    6.         public static int GetLayerObsHalfCover(){ return 27; }    //obstacleHalfCover
    7.         public static int GetLayerTerrain(){ return 25; }
    8.        
    9.         public static int LayerUI(){ return 5; }    //layer5 is named UI by Unity's default
    Looks like a lot of these layers didn't have a name in Unity and when we updated from 2019 to 2021 and validated any warnings / potential problems it changed the objects to Default if it was on an unnamed layer. By fixing the layer numbers it fixed basically all of the issues. Thanks!
     
  22. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    What layer are the units supposed to be on? It seems I can only get info for a unit by right clicking if it is set to layer 29 (Node) instead of layer 31 (Unit).

    Not sure why that's the case. Is layer 31 normally for controllable units vs AI controlled units or what?

    Besides that it seems like it fixed almost everything else going on.
     
  23. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    You can find all the layers in _TBTK.cs. That's how the framework knows which layer is what, regardless how you name the layers in LayerSetting. You are right that layer-31 is set to unit and layer-29 is set to node. However the right-clicking is intend to detects the node on the grid instead of the unit. If your right-clicking for unit info doesn't work if the unit is not set to layer-29, I think your node is not set to layer-29 as it should be.
     
  24. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    Yeah, I've been using _TBTK.cs to guide it. I have the nodes set to Layer29 and the unit set to Layer31, but right clicking on the unit doesn't work. It only works if the unit is set to Layer31 itself. Not a huge deal and I'll just set the units to that -- it just seems odd that the unit has to be set to that layer instead of being set to Layer31 for Unit and working that way.
     
  25. Luckylionel

    Luckylionel

    Joined:
    Jun 15, 2023
    Posts:
    1
    Please help i cant Add models to make units the tool kit doesnt recognite any of them
     
  26. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    You can simply replace the model of any unit and it will work as the logic is on the unit script itself and not on the model. Simply change the model component to whatever you want and it should work fine.
     
  27. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    @Luckylionel, I suggest you to read the documentation. There's a section explaining how you can add new unit with your custom model to the framework.
     
    Stexe likes this.
  28. RadicalRavens

    RadicalRavens

    Joined:
    Aug 8, 2023
    Posts:
    1
    Ahoj!

    Uvažujem o kúpe TBTK. Hral som dostupné demo a nastavenie "X-Com" vyzerá z technického hľadiska naozaj pekne.

    Zaujímalo by ma, ako je TBTK pripravený implementovať animácie natáčania krytu. V plánovanom prototype je použitie krytu dôležitou súčasťou boja a bolo by skvelé, keby postava mohla vystúpiť z krytu (Full Cover) alebo sa postaviť (Half Cover).

    Hodnota útoku je teda rovnaká, treba však vyhodnotiť, či je postava v úplnom alebo polovičnom kryte a hrať danú animáciu.

    Tu je príklad situácie:

     
  29. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    @radicalraven, I'm afraid the cover system doesn't support animation but you should be able to add that yourself. I've briefly explain it in the email I've sent you.
     
    Stexe likes this.
  30. Cdy0774

    Cdy0774

    Joined:
    Dec 29, 2014
    Posts:
    9
    It seems that the feature to display the movement and attack ranges of all units is missing. This functionality is crucial in tactical strategy games
     
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    Sorry for the slow response. I've been away for the past 2 weeks.

    Unless you are experiencing some kind of bug, it's definitely there. When you select a unit, the tile within the movement range are all highlighted. As for the attacking range, there isn't a range display per se. But all the targets within the selected unit attack range are highlighted. When you are trying to move the unit (by hovering over any movable tiles), the attackable target highlights will be updated based on the tile you are hovering over.
     
    Stexe likes this.
  32. chaosmonger

    chaosmonger

    Joined:
    Jan 23, 2019
    Posts:
    71
    Hello, I've been using the toolkit for a while, but now I want to use it for a JRPG style combat. I don't have much experience with this style, and I've checked the demo within the asset. I have a question though... Is it possible to have melee attacks with the default toolkit in this mode? Meaning, specifically, can I move my character to go in the proximity of the enemy, do the melee attack, then return to my position? In the demo there are only range attacks, so I'd love to have some guidance in that sense... thanks!
     
  33. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    Unfortunately not. The toolkit is designed with unit playing in grid in mind. So while it support unit with melee and range attack (it uses melee attack automatically when the target is close enough), the unit will still always stay in its tile when performing the attack.

    That said, you can add a snippet of code to get the unit to move in on its target to do an attack, then return back to its position. I can give you a sample code that show you how it can be done.
     
    Stexe likes this.
  34. chaosmonger

    chaosmonger

    Joined:
    Jan 23, 2019
    Posts:
    71
    Thanks, a sample code would be very much appreciated. What I'm not so sure about, is when the Unit has both melee and range attack. I mean, in the standard TBTK one of the two is chosen based on the proximity with the enemy, but on a JRPG combat, they'll always be from afar. I can also somehow transform the melee into an "ability" (and keep range only when clicking directly with the right-mouse-button above an enemy), but in that case, the Unit should move from its grid cell, go in front of the enemy, do the melee attack (which only at that point is triggered in terms of animations, damage, etc.), then return to its grid node and orientation. Also, will AI handle "melee abilities" in that case?
     
    Stexe likes this.
  35. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    That's one way to do it. Otherwise you will have to add additional code for user to determine what kind of attack to use. Unfortunately the AI won't use melee because they don't use ability and they will always be out of range for melee. If you don't need a lot of precision in how AI works, you can have the AI randomize between melee and range attack instead of checking the range.

    Now to the code, you can add something like this in Unit.cs:
    Code (csharp):
    1. IEnumerator LerpToPos(Vector3 targetPosition){
    2.     Vector3 startingPosition=GetPos();
    3.  
    4.     float duration=0;
    5.     while(duration<1){
    6.         transform.position=Vector3.Lerp(startingPosition, targetPosition, duration);
    7.         duration+=Time.deltaTime*2;
    8.         yield return null;
    9.     }
    10. }
    Then you can add this in AttackRoutine() in Unit.cs, just before the aim animation:
    Code (csharp):
    1. //have the unit stop at half a node length before the target instead of landing on top of the target
    2. Vector3 attackPosition=targetNode.GetPos()+(GetPos()-targetNode.GetPos()).normalized*GridManager.GetNodeSize()*0.5f;
    3. yield return StartCoroutine(LerpToPos(attackPosition));
    Then after the attack is done:
    Code (csharp):
    1. yield return StartCoroutine(LerpToPos(node.GetPos()));
    Make sense?
     
    Stexe likes this.
  36. chaosmonger

    chaosmonger

    Joined:
    Jan 23, 2019
    Posts:
    71
    Thanks, yes, makes sense.
    I guess for player units I'll go for range attack as default attack (if it has a range attack, otherwise it'll be a melee attack), and for the units that has both melee and range attacks, then the melee one is treated as an ability. For AI, I'd go for a random value, but I'll need to code that as an attribute, like % of melee attack (the other % will return a range attack), so that some units are more often using melee attacks than others.
     
  37. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    Any ideas on ways to possibly have two combats being shown at once (in different scenes)? It seems like simply duplicating the scene and running two instances of it you run into issues with static variables in relation to the grid.

    We're trying to have a split screen of two different combats happening at once automatically. I assume that isn't easy to do without a lot of refactoring but maybe there's something we missed and I figured I'd ask.
     
  38. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    I'm afraid the framework is not designed to support that. Hence the static variable of various singleton class like GameControl and UnitManager. You can change that of course but it will be a lot of work. All those static variables have to be removed. All the components will need a way to get reference to the other component in their specific instance of game. You get the idea.

    It's not terribly complicated. It's just a lot of ground to cover and you will need to make lots of changes to almost every script in the framework.
     
    Stexe likes this.
  39. Stexe

    Stexe

    Joined:
    Feb 2, 2014
    Posts:
    217
    Okay, thanks. That's what we were afraid of and it looks like there isn't an easier way to do it. Shame you can't have static variables that are only static inside their own individual scenes instead of across the entire Unity project.
     
  40. guihaoh

    guihaoh

    Joined:
    Oct 4, 2021
    Posts:
    13
    Hello, I am a beginner with Unity, and I would like to ask how I can add a new type of node. Alternatively, I want units to be affected by certain effects when they reach a specific area's node. For example, when a unit is on this node, its attack damage, accuracy, and movement speed decrease until the unit leaves this node. The unit will receive a certain amount of damage each turn, or if they use an attack skill on this area, the damage will change from single-target to area-of-effect. I would like to try applying the effects from the effect editor directly to the node, as it would be easier to manage. However, I have not found an option or anything similar to add a new type of node.
     
  41. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    Unfortunately that is not supported by default. You will have to do your own code modification for it. To do that, you will need to start looking into the Node class in Node&Wall.cs to allow an effect to be assigned to it. Then Unit.cs so the unit can modify its stats accordingly based on the node it's on. You will also need a way to assign and visualize the effects being assigned to the nodes. It's not a trivial modification if I'm honest.
     
  42. guihaoh

    guihaoh

    Joined:
    Oct 4, 2021
    Posts:
    13
    Thank you, it seems I need to try it myself to achieve the effect.
     
  43. guihaoh

    guihaoh

    Joined:
    Oct 4, 2021
    Posts:
    13
    Currently, I have managed to add new node types in the grid editor. Now, I want to try adding effects to my newly created nodes. For instance, when a unit enters a flame node, they would receive damage at the start of each turn. Inside a water node, their move range would be reduced. I have tagged these nodes and attempted to use collision detection to check if a unit is in the corresponding node. Next, I want to try using the effect editor to implement this, but after adding these effects in the effect editor, I'm unsure how to make my new nodes automatically apply these effects to the units on them at the start of each turn. In other words, I don't know how to enable these nodes to automatically cast abilities with effects on the units standing on them each turn. Is there a way to achieve this? I apologize, my coding skills are not very good.
     
    Stexe likes this.
  44. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    Well it seems like you have done the hard part. Now there's two parts for this, when the unit moves and when the game first starts.

    For the first part, if you look in Unit.cs, MoveRoutine() (around line800), this is the code that get executed when a unit moves. You can see how each node is assigned to the unit when it reach a new node (node=path[0]). Now I'm not sure how you specify the effect on each node, but you can add the code to apply the node effect here.

    For the start of the game, I suggest you check StartGame() in UnitManager. By that time, each unit in allUnitList (or unitList in the respective faction instance) would have got their node assigned. So you can just do what you have done in Unit.cs
     
    Stexe likes this.
  45. guihaoh

    guihaoh

    Joined:
    Oct 4, 2021
    Posts:
    13

    Before this, I have another question, I don't know how to give an effect to a node by using the effect editor....
     
  46. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    Ah I see. Well I'm afraid you will have to dig a bit for this one.

    You can't 'give' an effect to a node using EffectEditor. That's just for creating different type of effects and then storing them in EffectDB. Now you will need to look at the Node class in NodeNWall.cs and add a way to identify which the node type and from there. Once you have that, you can pull the corresponding effect in EffectDB for the node based on the type specified. Something like this:
    Code (csharp):
    1.  
    2. public class Node{
    3.     public type nodeTypeEffectID;  //this value can correspond to the prefabID of the effect in EffectEditor
    4.  
    5.     public Effect GetEffect(){
    6.         return EffectDB.GetItem(nodeTypeEffectID);
    7.     }
    8.  
    9.     //rest if the code
    10. }
    11.  
     
  47. guihaoh

    guihaoh

    Joined:
    Oct 4, 2021
    Posts:
    13
    Thank you!
    That's helped me out
     
  48. midnight_dragon_knight

    midnight_dragon_knight

    Joined:
    Feb 4, 2023
    Posts:
    2
    Does this toolkit work for 2.5d?
     
  49. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,978
    It should. The base framework works independently from the camera. So you can work the camera however you want. Give the scene a 3D environment and allow the camera to rotate and pan around, you will have a 3D scene. Fix the camera from a certain angle and just use a 2D image as the background and you will get a 2D scene. It's up to you.
     
  50. guihaoh

    guihaoh

    Joined:
    Oct 4, 2021
    Posts:
    13
    Question regarding editing curFaction.deployingList

    Hi, I had question regarding how to edit the deployingList for the current faction, by directly edit the deployingList, it will require to instantiate a unitObj before adding to the deployingList. But through the UIDeployment, the arrow, button, and deployment clicking the grid are also changing the deployingList.
    So if we are adding all units back to the deployingList before we proceeds to a scene that could allow the player to edit the team
    while (curFaction.unitList.Count != 0)
    {
    curFaction.deployingList.Add(curFaction.unitList[0]);
    curFaction.unitList.RemoveAt(0);

    } //Then proceed to a screen that change deployingList

    Then reload the scene with changed deployingList (All unit instantiated before added to the deployingList)
    It will gives out error:
    MissingReferenceException: The object of type 'GameObject' 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.
    TBTK.UIUnitControl.OnSelectUnit (TBTK.Unit unit) (at Assets/UIUnitControl.cs:64)
    TBTK.TBTK.OnSelectUnit (TBTK.Unit unit) (at Assets/TBTK/Scripts/_TBTK.cs:64)
    TBTK.UnitManager._SelectUnit (TBTK.Unit unit) (at Assets/TBTK/Scripts/UnitManager.cs:380)
    TBTK.UnitManager.TBSelectUnit (TBTK.Unit unit) (at Assets/TBTK/Scripts/UnitManager.cs:352)
    TBTK.UnitManager.EndTurn_FactionPerTurn (System.Int32 turnIdx) (at Assets/TBTK/Scripts/UnitManager.cs:293)
    TBTK.TurnControl+<_EndTurn>d__26.MoveNext () (at Assets/TBTK/Scripts/TurnControl.cs:94)
    UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <3b24cc7fa9794ed8ab04312c53e6dedd>:0

    So which list should I actually change to change deployingList without this bug and allow deployment to happen also have units that already deployed on the grid to be removed when editing team.