Search Unity

TurnBased-Toolkit (TBTK)

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

  1. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
  2. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
  3. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
    Thank you
     
    Last edited: Jul 18, 2015
  4. Pedro-Oliveira

    Pedro-Oliveira

    Joined:
    Aug 1, 2013
    Posts:
    25
    @Rajmahal looks incredible, i hope it succeeds (^_^)/

    It is possible to remove an ability from an unit via perks? i mean you can add abilities to an unit with perks but can you remove or replace an that already exist?
    I want to make abilities level up via perks if possible.
     
  5. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Unfortunately you cant remove ability from unit using perk as of current version. But I see how this maybe useful in some case. I'll see if I can add that in the next update.

    However that might take some time so if you want to do it yourself you are welcome to try. A good place to start would be _PurchasePerk() in PerkManager.cs, under condition if(perk.type==_PerkType.NewUnitAbility). From there you can see how a new ability is added to the units. That should give you an indication how to reverse the process.
     
  6. Pedro-Oliveira

    Pedro-Oliveira

    Joined:
    Aug 1, 2013
    Posts:
    25
    @songtan I see, since this is not my top priority right now i hope the update will be ready by the time, nonetheless this information already saves a lot of search time if not.Thx
     
  7. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
    I have the UI elements set up for this using a level select screen. My level select screen has 4 level buttons with 3 of them being covered up by a raw image preventing click. I set up a simple java script that disables the raw image per level based on if(PlayerPrefs.GetInt("savedgame1")==1) with savedgame being changed per rawimage to be deleted. Now I need to figure out where to put the key in your script ie. PlayerPrefs.SetInt("savedgame1",1); and to add the variable to allow me to select which scene and key is saved ie savedgame1 to scene 1,savedgame2 to scene 2. I just lack the knowledge of C# to know how to add that in. I believe I should put it here gamecontrol.cs
    Code (CSharp):
    1. public static void GameOver(int factionID){
    2.             if(FactionManager.IsPlayerFaction(factionID)){
    3.                 PerkManager.GainPerkCurrencyOnVictory();
    4.             }
    5.    
    6.             if(onGameMessageE!=null) onGameMessageE("GameOver");
    7.    
    8.             gamePhase=_GamePhase.Over;
    9.    
    10.             FactionManager.GameOver();
    11.    
    12.             if(onGameOverE!=null) onGameOverE(factionID);
    13.         }
    14.        
    But I am unsure how to go about it. Could you maybe give me an example? Also adding this into the code would be great for an extra feature having it under the game control menu to be able to set playerpref key to whatever the user decides so they can call that from there level select screen to enable disable levels. I know I would pay extra for a feature like that.

    Edit: I got it working by doing this but still I need to learn how to set it up so its different for each scene since all scenes share this script.
    Code (CSharp):
    1. public static void GameOver(int factionID){
    2.             if(FactionManager.IsPlayerFaction(factionID)){
    3.                 PerkManager.GainPerkCurrencyOnVictory();
    4.             }
    5.        
    6.             if(onGameMessageE!=null) onGameMessageE("GameOver");
    7.        
    8.             gamePhase=_GamePhase.Over;
    9.        
    10.             FactionManager.GameOver();
    11.        
    12.             if(onGameOverE!=null) onGameOverE(factionID);
    13.  
    14.             if (FactionManager.IsPlayerFaction (factionID)) {
    15.                 PlayerPrefs.SetInt ("savedgame1", 1);
     
    Last edited: Jul 19, 2015
  8. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You are almost there. Like I said in earlier post, you can create a variable that carries unique value for each scene. A simple int type will do. Let's call that variable sceneID. so the code would look like this:
    Code (csharp):
    1.      public int sceneID=0;
    2.  
    3.      public static void GameOver(int factionID){
    4.        //the existing code
    5.    
    6.        if(FactionManager.IsPlayerFaction(factionID)){
    7.          if(sceneID==0) PlayerPrefs.SetInt ("savedgame0", 1);
    8.          else if(sceneID==1) PlayerPrefs.SetInt ("savedgame1", 1);
    9.          else if(sceneID==2) PlayerPrefs.SetInt ("savedgame2", 1);
    10.          //and so on
    11.        }
    12.      }
    Or something more elegant like this:
    Code (csharp):
    1.      public int sceneID=0;
    2.  
    3.      public static void GameOver(int factionID){
    4.        //the existing code
    5.    
    6.        if(FactionManager.IsPlayerFaction(factionID)){
    7.          PlayerPrefs.SetInt ("savedgame"+sceneID.ToString(), 1);
    8.        }
    9.      }
    Of course you will have to manually assign the value of the sceneID for each scene and make sure it match the what you have in the loading.
     
  9. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
    Thanks for the help I was able to fit it in but had to change public int scene to public static int scene. My only question is how do I manually assign a scene ID seeing as how all scenes use the same gamecontroller.cs script so If I change it there and hit save all of my levels will then be changed to that scene ID.
     
  10. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry my bad there. There something wrong with my code. You should definitely keep sceneID as it's, NOT making static. Static variable shared common value across all instance of the script so every scene will have the same value, which is exact opposite of what we need. Keeping it as a non-static variable will open it up for editing in Inspector, and each instance can have it's own value. Meaning you can give it different value in difference scene.

    So back to the mistake in my code, you need to add instance. in front of sceneID in the function. For example:
    Code (csharp):
    1. PlayerPrefs.SetInt ("savedgame"+instance.sceneID.ToString(), 1);
    To understand why, I would suggest you to go through this video - https://unity3d.com/learn/tutorials/modules/intermediate/scripting/statics
     
  11. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
    You sir are amazing thank you so much I now have a fully functional level progression system. You should add that to the kit as a feature.
     
    Last edited: Jul 19, 2015
  12. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You are welcome. :)
     
  13. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
    I found a bug with inserting animation clips into the unit editor. For some reason the idle animation overrides the move animation so no matter what is put in the idle animation slot even entering none the unit will always perform the idile animation during movement (slides across ground while doing idle animation). All other animations are operating properly.
     
  14. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You are right. There's a small bug in the code that it never triggers the move animation. It's quite easy to fix it. Simply change line705 in Unit.cs from:

    if(path.Count==0){
    to

    if(path.Count!=0){
     
  15. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
    Once again thanks for the quick support
     
  16. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
    I get a "unexpected symbol error <internal>" when I update that line of code. Tried it a couple times only get the same error code.
     
  17. deskicio

    deskicio

    Joined:
    Apr 28, 2015
    Posts:
    1
    Hi,

    Is a fantastic assest. Im thinking use in my next game, but I have one question:
    Is 100% compatible with Unity 5 or higher ?

    Thanks in advance!!
     
  18. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
    It is I am am using it in the latest unity version
     
  19. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28


    My game is coming along nicely just need to get that movement animation bug fixed
     
  20. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
    Also one more question while I wait on a new set of code. When my char transitions from the idle animation to the attack animation its very slow is there a way to speed up the transition?
     
  21. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
    Is there anyway to get this working in the current version?
     
  22. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    Don't know. I haven't played around with it since I released my game on the previous version. I'm starting a new project with it so I'll let you know what I find out.
     
  23. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
    Also wanted to note that the movement audio animation wont work either along with the standard movement animation. Do not know if the problems are linked.
     
  24. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry for the slow repsond guys I've been away for the past 2 days.

    @cbell77, you probably have modified the wrong line of code or done something wrong. Changing "==" to "!=" shouldn't cause any error. And yes the same is preventing the audio from working as well. Please email me so I can just send you all fixed file instead. For your information, the work around used by @drewradley wouldn't work in current version. That was for the previous version of TBTK (v1.x) where legacy animation is used. The current version used mecanim. Not sure if this has been changed or not but the last time I checked, you can't really just add in new animation on the fly nor can you change the animation speed. To accommodate additional animation for different action, you will have to change the animation controller's state machine to reflect that, and then add the code to play it..
     
  25. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    So I noticed. Still digging through the code to see what's changed since I last checked.
     
  26. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
    Thanks for your response I was able to get the animations all aligned using the state machine.
     
  27. Rajmahal

    Rajmahal

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

    I'm noticing something odd in my older version. On a touch device (IOS in this case), if you have an ability that requires a target, clicking on a tile occupied by a friendly unit triggers the ability immediately while clicking on an empty tile or tile with a hostile requires a subsequent click to trigger. This is kind of annoying as it is inconsistent and confusing the for the player. I tried to dig through the code to figure out why this was different but got lost in the code. Do you know where this would be decided in the code and how I might be able to fix it?
     
  28. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Did you release your first game?

    Also, do you mind sharing how you added overwatch in your earlier version?
     
  29. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @Rajmahal, I'll check and let you know. It would be helpful if I can have your code in case mine doesn't have the same issue. Just to be sure, are you using v2 or v1?
     
    Last edited: Jul 26, 2015
    Rajmahal likes this.
  30. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    Yep. Released a game using TBTK (in signature). It's actually only mostly finished but what I haven't done is almost all cosmetic such as audio. But you can play the entire game and it's about 8 to 9 hours long.

    I never managed to get overwatch to work. What I did instead was to give them a "wait" button that moved them to the end of the turn. If you want to try OW, what I tried was to set up a raycast from any units on OW to the current enemy unit. If during the enemy's move phase, the ray hits it, the player unit attacks. I got everything to work except if you killed the unit when attacking from OW. Then the whole thing fell apart and I never could quite figure it out.
     
    Rajmahal likes this.
  31. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    I'm using version 1.0.6f3. It's possible it's something I've added or caused due to the many changes I've made but I can't think what it might be. If you aren't able to reproduce it, if you could give me some tips on where to look in the code, that would be great. I looked at the "OnMouseEnter()" function in Tile.cs and went from there and got to the point where it should be only highlighting the tiles as red or green but can't understand why it would then be triggering the effect on friendly units and not on empty or hostile tiles.

    I'll happily send you my code if you are sure which .cs file you think it might be in.
     
  32. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    1.0.6 eh? That's really old... I don't even have a running copy of that anymore.

    But I look at the code and I think I know what is the problem now. You need to modify Update() in GridManager.cs. That's where the touch input code is. The reason is in default mode (when not selecting ability target), you can select your unit in a single tap but you need to double tap to initiate an attack. The code doesn't take into account of the ability target select mode hence you only need one tap to initiate ability on a friendly target but two to initiate target on a hostile unit. So what you need to is check if the system is waiting for a target for an ability. You can do that easily by calling GridManager.IsInTargetTileSelectMode(), which will return a boolean indicate if you are in target selection phase for ability. Make sense?
     
  33. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Thanks Song ... I'll give that a shot.

    By the way, I should be submitting the game to Apple this today. I'm putting you in the credits as "Developers: Song Tan". Is there any other way you would like to be credited?
     
  34. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    @drewradley Just played your game. Pretty cool though it took me a while to figure out how to leave the first room. How did you build your camera control function to have it move to the active unit during a fight scene?
     
  35. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    One more thing ... I've noticed that in my version, the toggle on a shoot object that says "Show hit effect on miss" doesn't seem to work. It always shows the hit effect on a miss regardless of whether this box is checked or not. The strange thing is that I've gone to the code where this is used and the logic should work. I can't figure out why it doesn't seem to work. Was this something you fixed in a later release?
     
  36. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    Thanks for playing! That's one of the cosmetic things... plan to put an effect there so people know where to go. I don't recall off the top of my head how I reset the camera. I'll look through the code some time this week and get back to you on that.
     
  37. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    @songtan Actually I have a very old version ... Grid manager.cs doesn't even have an update function. The touch update cycle is in GameControlTB.cs instead:

    Here is the code:

    Code (CSharp):
    1. //UI & input related code
    2.  
    3.     // Update is called once per frame
    4.     void Update () {
    5.         //for touch input on mobile device
    6.         #if UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_EDITOR
    7.             if(Input.touchCount==1){
    8.                 Touch touch=Input.touches[0];
    9.                 //if(touch.phase == TouchPhase.Ended){
    10.              
    11.            
    12.                  if(touch.phase == TouchPhase.Began){  // Raj debug comment
    13.                     if(!IsCursorOnUI(Input.mousePosition)){
    14.                         Ray ray = Camera.main.ScreenPointToRay(touch.position);
    15.                         RaycastHit hit;
    16.                         LayerMask mask=1<<LayerManager.GetLayerTile();
    17.                         if(Physics.Raycast(ray, out hit, Mathf.Infinity, mask)){
    18.                             Tile tile=hit.collider.gameObject.GetComponent<Tile>();
    19.                             /**/
    20.                             //if this is the second tap on the tile
    21.                             if(tile==lastTileTouched){
    22.                                 lastTileTouched=null;
    23.                                 tile.OnTouchMouseDown();
    24.                             }
    25.                             //if the tile is a new one
    26.                             else{
    27.                                 //clear any effect off previously selected tile
    28.                                 if(lastTileTouched!=null) lastTileTouched.OnTouchMouseExit();
    29.                                 //if the tile contain friendly unit, select it directly
    30.                                 if(tile.unit!=null && tile.unit.factionID==0){
    31.                                     lastTileTouched=tile;
    32.                                     tile.OnTouchMouseEnter();
    33.                                     tile.OnTouchMouseDown();
    34.                                 }
    35.                                 //a new tile with no friendly unit,  just call mouse tnter
    36.                                 else{
    37.                                     lastTileTouched=tile;
    38.                                     tile.OnTouchMouseEnter();
    39.                                 }
    40.                             }
    41.                             //*/
    42.                         }
    43.                         else{
    44.                             if(lastTileTouched!=null){
    45.                                 lastTileTouched.OnTouchMouseExit();
    46.                                 lastTileTouched=null;
    47.                             }
    48.                         }
    49.                      
    50.                         if(onUnitInfoE!=null) onUnitInfoE(lastTileTouched);
    51.                     }
    52.                  } // Raj Touch.phase == touch.began
    53.             }
    Any thoughts on what should change?
     
    Last edited: Jul 26, 2015
  38. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Okay, I think I figured it out ... probably add the check for target mode in the if statement on line 30 above. I'll give that a shot.
     
  39. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @Rajmahal, I'm not sure about 'showHitEffectWhenMissed'. I can't remember if there's ever been a bug or I have fixed it. It seems fine to me from what I see. You are on the right path there about the touch input. Just add if(!GridManager.IsInTargetTileSelectMode()) before line33 and that should be it.
     
  40. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Cool ... thanks. It's weird, I haven't changed anything on my end on the shoot object code but for me ... if a shoot object doesn't have that flag checked, it still shows the hit effect particle on a miss. Not a huge issue.
     
  41. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
    I am trying to code a simple (if a certain unit gets destroyed=game over) script so I can add a hero unit (player unit) to the field of battle but if he dies the game is over and must be restarted. I am digging through the code looking for some pieces I can use to put it together but I am lost.
     
  42. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    Here is how it looks like I did the tracking but it's been a long time so I might be missing something and I have no idea if it will work in the new version. Also, have no idea how much of this is my edits and how much was already in there.
    Changes to CameraControl.cs
    It uses three variables
    Code (CSharp):
    1. public bool trackUnit=false;
    2.     private UnitTB lastSelectedUnit;
    3.     private bool tracking=true;
    then in the update:

    Code (CSharp):
    1.     if(trackUnit && UnitControl.selectedUnit!=null){
    2.             if(lastSelectedUnit!=UnitControl.selectedUnit){
    3.                 lastSelectedUnit=UnitControl.selectedUnit;
    4.                 tracking=true;
    5.             }
    6.          
    7.             if(tracking){
    8.                 float dist=Vector3.Distance(thisT.position, lastSelectedUnit.thisT.position)*.025f;
    9.                 dist=Mathf.Max(1, dist);
    10.                 thisT.position=Vector3.Lerp(thisT.position, lastSelectedUnit.thisT.position, Time.deltaTime*zoomSpeed*dist);
    11.             }
    12.         }
    lastly, I set "tracking=false" in several places where the camera is moved so you can actually move the camera if you want. For instance:
    • if(Input.touchCount==1){tracking=false;
    • if(Input.GetButton("Horizontal")) { tracking=false;

    Make no promises that I didn't miss something, but if you have any problems, let me know and I'll try to help.
     
    Rajmahal likes this.
  43. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @cbell77, try OnUnitDestroyed() in FactionManager.cs. Any destroyed unit will fire the onUnitDestroyedE event passing its own reference (calling OnUnitDestroyed() in doing so). In fact, there's a code in there for something like that in the first few lines of OnUnitDestroyed(). That's a hidden (not shown in editor) public variable in Unit.cs, isObjectUnit. It's intended to be used as level objective - destroy the target unit and player wins. So you can add another variable that is used for opposite effect.
     
    Rajmahal likes this.
  44. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
    That was super simple thank you very much.
     
  45. cbell77

    cbell77

    Joined:
    Aug 25, 2013
    Posts:
    28
    I found a small bug. The cover Icon which I assume is supposed to pop up next to the units health/ap bar is not showing when in cover.
     
  46. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Noted. I'll try to fix that asap. Thanks for letting me know.
     
  47. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    I couldn't get the move animations to play and had to add the "unitAnim.Move()" command at line 711 to make it play. Is there something I missed that doesn't require it to be moved? I'm using sprites if that makes a difference. I don't see how it could really since it the same command.
     
  48. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm not sure. Tbh animation has always been a finicky subject to me. I take it at line711 it's in the while(path.Count>0) loop? In that case probably some setting in the AnimatorController is stopping the move state is being looped. Are you using the default controller? Have you modified it in anyway?
     
  49. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    Oh wait, 711 is where is currently is and I added it to 658. I put it right before the "moving" debug statement. The line around 711 seems to not work because it's inside if(path.Count==0).

    Same thing with the unitAudio.Move. Doesn't work where it is but does around line 658.
     
  50. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I see what's the problem now. There's a bug that I've just fixed recent. It should have been if(path.Count!=0){ instead of if(path.Count==0){.