Search Unity

TurnBased-Toolkit (TBTK)

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

  1. Mars91

    Mars91

    Joined:
    Mar 6, 2012
    Posts:
    572
    PM Sent
     
  2. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @Reliique, I have to say I still have no idea how it works after looking at your image. I have to google about it. Sorry I'm not that hardcore of a chess player to know the move by grid coordinate.

    I'm not sure if you need only the move for knights or moves for all the piece or even the other rules. But honestly this wont be a small task. The problem the hex-grid in TBTK is not made for such purpose and thus doesnt use a coordinate system. I'll have to made a system of some kind on the grid to calculate the move.

    Anyway, please email me to discuss the details. I'm not promising anything but we'll see.
     
  3. Reliique

    Reliique

    Joined:
    Apr 11, 2014
    Posts:
    4
    Ok thanks mate, will email you later.
     
  4. 3itg

    3itg

    Joined:
    Jan 22, 2013
    Posts:
    5
    hello @songtan, First things first, TBTK is rad. I really like the tools, and I hope to be able to extend them to meet my needs.
    I have begun to try and extend the framework, based on the "Perks" manager, and editor scripts.
    I am trying to create a "World" outside of battle, where the player will be able to move around the "Party Leader", in a small town scene.
    The town would have vendors for weapons and armor, a tavern to recruit new Party Members and the standard RPG type stuff you do in town.

    I started by taking the PreBattle Scene, and adding to it. I have an additional tab that I called "Map" that I have added.

    Now, I want to make an Editor window, that will allow me to create and place "Map Nodes" on the map.
    I based this part off of the "Perks" source. Seemed to be the most similar.
    I added a "scene" string attribute to MapTB (based on PerkTB) which is where the name of the scene is put.
    I also added attributes for the X Y locations, where I want the Map Locations to be placed in this window. This is all working well.
    I want to implement "Neighbors" for the Map Nodes, to control which locations are available to travel to. and I wanted to have the GUI "draw" the roads or paths for me, and possibly color code them, based on availability.
    I was planning on editing the Perk Pre-requisites to allow me to "Lock" areas until the player has reached a certain point in the game.

    Now that I have explained what Im doing, on to the questions:
    1: Any ideas on how I would create roads on the map (procedurally)?

    2: Where is function of the Perk Button?
    -Since my Map Nodes are based off of these buttons, I want to make so when the Player clicks the Map Node,
    the "scene" attribute that I added, is copied to the game's "NextScene" attribute (in UINGUISetup.cs). Once a scene is selected, the Start Battle Button, will say "Travel", when the player arrives at the Map Node, the Button will return to saying "Start Battle" and when clicked will bring the player to that selected battle.

    3: Any Ideas on how I could implement "Collectables" as weapons, armor and consumable items, using TBTK framework?
    -Ideally, I am looking to give my "Army" an inventory that all units can access, or potentially access based on skills.
    -Also, I would like to Collectables a means to upgrade Units in my Army, By allowing them to equip new weapons and armor.
    -Each Unit would be able to be browsed in an "Equipment" window, and this would allow the player to compare current equipment with armor they have collected in the world.

    3a: I have started looking at extending Editor Menus to create the Weapons Armor. But how would access the individual units and create an inventory / equipment slots that will modify the units stats in battle?

    The easiest way to describe the end goal is by saying the gameplay is something like "Final Fantasy Tactics", though thats still kind of a bad example.

    1 Main Character
    All other units are "Party Members".
    At the Beginning of each Battle, you can select your Units from your available "Party Members".
    Units gain Experience, and Levels. (UsePersistantData)
    After Each Battle, the Player is returned to the Town, where they can modify their army, buy new weapons and armor and select the next battle.

    I can post pictures or video if it helps the explanation at all.
     
    Last edited: Apr 18, 2014
  5. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry for the slow respond and thanks for the explaination. I get the idea of what you are trying to do. To answer your question:

    1. I assume you are refering to drawing lines to implicate the roads between the Map Node (which are clickable button). Using the current UI system of TBTK (either Unity UI or NGUI), I'm afraid I cant think of anyway that this could be done procedurally. Unless they are all just straight line, even then it will be tricky to handle branching. Your best bet would be to hand place them. You could try other 3rd party line drawing plugin, but I'm not sure how well those will work with the current UI.

    2. I dont understand the question. I mean what you want to do is set the next scene which has nothing to do with perks so showing you the perk function wouldnt help. Do you meant to remove the code for perk completely and replace it with your own code? Anyway, the function which is called after the perk button is pressed is line93 96 of UIPerkMenu.cs (if you are using default UI), OnPerkButton() in UINGUIPerkMenu.cs (if you are using NGUI)

    3. You will have to create a new collectible type and effectively have 2 set of code for the Collectible.cs. So when a collectible is collected, you check the type. If the type is custom item type, then your custom code is called instead of the default one. As for how the custom code should go, that will depend on how you design your inventory system

    3a. The stats used for each individual unit are there in UnitTB.cs. They are all public variable so you should be able to just get the UnitTB instance and modify the value directly according to your item system. To create inventory/equipment slots, you can just add the new item variable in UnitTB itself for whatever item equipped on the unit.

    Hope this answer your questions.
     
  6. 3itg

    3itg

    Joined:
    Jan 22, 2013
    Posts:
    5
    @songtan
    thank you very much for the response.
    1: same conclusion I came to.
    2: Thanks, this was more because I wanted to see the code and settings surrounding this, for reference on how to do different things, but similar, within the UI.
    3 3a: Thank you very much, I think this will get me on the right track.
     
  7. deus_duke

    deus_duke

    Joined:
    Mar 12, 2012
    Posts:
    11
    @songtan

    Hello and thanks for posting such a great starter kit. My question is, do you have any examples of how to setup TBTK programmatically at the start of a game? For instance I would want to have TBTK in one scene, transition to this scene from a main scene that allows me to choose my units, and then jump to the TBTK scene and tell TBTK to start with a faction that has the given units. Is this possible with the current setup in TBTK and if so do you have an example?
     
  8. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm not really sure what you mean by programmatically. You mean create the gameObject and add in the script via coding? If you want to create a TBTK scene from scratch via script, you can take a look at TBTK/TBTK(Base)Scripts/Editor/MenuExtension.cs, NewScene().

    If you just want to be able to choose unit before the game start. Take a look at the example scene "ExPreBattleSetup"? It's used for selecting unit before the next TBTK scene. The unit selected will be used as the player unit for the next scene. The next scene are set to be either "ExContBasic", "ExContSpace" or "ExContTropic".
     
  9. deus_duke

    deus_duke

    Joined:
    Mar 12, 2012
    Posts:
    11
    Well the game object and everything is already setup in the new scene, I just need to be able to setup one of the factions programmatically at the start of the round using values from a previous scene. Sorry I probably could have worded my questions a little better. I believe the examples you have provided will be enough information to get me going.

    Thanks!
     
  10. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Very well. Let me know if you need any pointer on this. In most case, the code is already there. You just need to set the unit you want via GlobalStatsTB class. Look for the term in UISetup.
     
  11. TheLurkingDev

    TheLurkingDev

    Joined:
    Nov 16, 2009
    Posts:
    91
    Wow, I did not realize this when I purchased the asset or I would not have done so. I have only played with it for the first time today and I was really liking it until I found this out. Bummed. :(
     
  12. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Just for your info, that was a very old post. As of v1.0.6 (released January2014), support for both NGUI3 and Unity default UI has been added. :)
     
  13. TheLurkingDev

    TheLurkingDev

    Joined:
    Nov 16, 2009
    Posts:
    91
    Awesome - thank you!! I am really looking forward to using this.

    I assume that using the Unity default UI is also detailed in the accompanying pdf?
     
  14. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Not sure what you mean by 'detailed'. I can tell you it's not explained extensively in the documentation as it basically has no configurable variable about it. Just load the package, create a new TBTK scene (via "Tool/SongGameDev/TBTK/NewScene_(DefaultUI)" in the top panel), select gameObject TBTK/UI in the inspector and you'll see.
     
  15. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Just a quick note that I will be on the move starting 26thMay until 13thJune so apologize in advance if I don't respond to any post in a timely manner.
     
  16. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Good luck with the move.

    One request for the next update. Would it be possible for you to add the option to have abilities that modify some "user defined variables" in the same way as the existing abilities modify unit health, unit AP, etc. That way, if a player wanted to create a new component to his game, he could have abilities in the editor that tweak the variables related to that component.

    For example, in the same way that you have the option to create an ability that increases a target's health by 10%, you could also have the option to increase "User Defined Variable 1" by 10%. Obviously, it wouldn't do anything in the standard game but players could then write code to use the "User Defined Variable 1" on the UnitTB for whatever functionality they want.

    I'm trying to add a morale component to my game and it would be really helpful if I could have abilities that boosted morale or reduced morale of a hostile target. If there was a few "User Defined Variables" that I could adjust using the ability editor, I could then write my own scripts that checked the values of the User Defined Variables on each unit and apply appropriate morale effects.

    If it out of scope for what you want to make in this game, can you explain how it can be done? The one area I'm unclear about is how to tweak the editor menu code.
     
  17. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm afraid it doesn't work that way. See with each effect type, the value specified by the user are hard coded to directly modified an existing variable when the ability is activated. For instance, when effect type HPGain is selected, the value specified will be used to modify the HP. When the effect type HitChance is selected, the value will be used to modify the the hit chance. Obviously this wont work for custom variable because the system wouldn't know which variable to modify. The only reliable and easy way to specify this, as far as I know, is via coding. I'm not even sure if there's a way to reference a specific variable of a class. If there is, I'm afraid I dont know.

    Unless I misunderstood your intention and what you really mean is adding a few extra custom effect type which does nothing by default but up to user to code the functionality. If so, that can be done. Although I do wonder how userful would that be. My feeling is if you are proficient enough in coding to code an additional variable and then retrieve the value from the an activated ability, you should be good enough to read the current code and understand what it does and how to further extend it.

    Please dont take this the wrong way tho. I'm perfectly happy to explain to you how you may extend the existing system. It looks complex but the actual principal is pretty simple.
     
  18. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    What I had in mind was the second option with a few custom effect types tied to variables on the UnitTB that currently don't do anything. You're right that I should be able to figure out how to update the editor scripts. I'll take a look and ping you any questions if I'm not able to figure it out.
     
  19. f3mt0

    f3mt0

    Joined:
    Jun 12, 2014
    Posts:
    4
    Does TBTK work with Unity 4.3.4f1 (latest)? I've bought TBTK today, but having various bugs on example scenes. I wanted to make sure I'm running it on proper version of Unity before describing issues.
     
  20. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for your support. As far as I know there shouldnt be any game breaking bug in any version (3.5+) of Unity except some harmless warning message. But truth be told I've never actually test it beyond Unity4.2 so maybe there are complication that I'm not aware of. Can you please let me know what are the bugs you encounter. In the mean time, I'll run some test on my own to make sure.
     
  21. f3mt0

    f3mt0

    Joined:
    Jun 12, 2014
    Posts:
    4
    Hi, thanks for the answer. You're doing great job!

    I'm new to Unity, so maybe I'm doing something wrong.

    Errors I get when trying to run scenes:
    1) ExContBasic
    ArgumentOutOfRangeException: Argument is out of range.
    Parameter name: index
    System.Collections.Generic.List`1[Faction].get_Item (Int32 index) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
    UnitControl.GetFactionInTurn (Int32 turnID) (at Assets/TBTK/TBTK (Base)/Scripts/C#/UnitControl.cs:1260)
    AIManager+<_AIRoutine>c__Iterator2.MoveNext () (at Assets/TBTK/TBTK (Base)/Scripts/C#/AIManager.cs:89)

    2) ExContSpace
    (multiple)
    Failed setting triangles. The number of supplied triangle indices must be a multiple of 3.
    UnityEngine.Mesh:SetTriangles(Int32[], Int32)
    MeshCombineUtility:Combine(MeshInstance[], Boolean) (at Assets/TBTK/TBTK (Base)/Scripts/Standard Assets/Scripts/Utility Scripts/MeshCombineUtility.cs:188)
    CombineChildren:Start() (at Assets/TBTK/TBTK (Base)/Scripts/Standard Assets/Scripts/Utility Scripts/CombineChildren.cs:66)

    Warning: there's no player faction
    UnityEngine.Debug:Log(Object)
    UnitControl:InitFaction() (at Assets/TBTK/TBTK (Base)/Scripts/C#/UnitControl.cs:556)
    UnitControl:OnBattleStart() (at Assets/TBTK/TBTK (Base)/Scripts/C#/UnitControl.cs:276)
    GameControlTB:UnitPlacementCompleted() (at Assets/TBTK/TBTK (Base)/Scripts/C#/GameControlTB.cs:605)
    <UnitPlacementCompleted>c__Iterator1B:MoveNext() (at Assets/TBTK/TBTK (Base)/Scripts/C#/UnitControl.cs:210)

    Warning: only 1 faction exist in this battle
    UnityEngine.Debug:Log(Object)
    UnitControl:InitFaction() (at Assets/TBTK/TBTK (Base)/Scripts/C#/UnitControl.cs:560)
    UnitControl:OnBattleStart() (at Assets/TBTK/TBTK (Base)/Scripts/C#/UnitControl.cs:276)
    GameControlTB:UnitPlacementCompleted() (at Assets/TBTK/TBTK (Base)/Scripts/C#/GameControlTB.cs:605)
    <UnitPlacementCompleted>c__Iterator1B:MoveNext() (at Assets/TBTK/TBTK (Base)/Scripts/C#/UnitControl.cs:210)

    ArgumentOutOfRangeException: Argument is out of range.
    Parameter name: index
    System.Collections.Generic.List`1[Faction].get_Item (Int32 index) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
    UnitControl.GetFactionInTurn (Int32 turnID) (at Assets/TBTK/TBTK (Base)/Scripts/C#/UnitControl.cs:1260)
    AIManager+<_AIRoutine>c__Iterator2.MoveNext () (at Assets/TBTK/TBTK (Base)/Scripts/C#/AIManager.cs:89)

    3) ExContTropic
    3 errors / warings as above - no player faction, only 1 faction exists and then arg out of range

    4) ExSingleSpace
    (multiple)
    Failed setting triangles. The number of supplied triangle indices must be a multiple of 3.
    UnityEngine.Mesh:SetTriangles(Int32[], Int32)
    MeshCombineUtility:Combine(MeshInstance[], Boolean) (at Assets/TBTK/TBTK (Base)/Scripts/Standard Assets/Scripts/Utility Scripts/MeshCombineUtility.cs:188)
    CombineChildren:Start() (at Assets/TBTK/TBTK (Base)/Scripts/Standard Assets/Scripts/Utility Scripts/CombineChildren.cs:83)

    Overall, I guess the best way to find out what's going on would be to test TBTK on the newest Unity. I'm using free version, so you should get similar results (I guess).

    Cheers!
     
  22. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Well, for your information, all ExContBasic, ExContSpace and ExContTropic are not standalone scene. They are intended to be loaded from ExPreBattleSetup scene where the player starting unit and perk can be selected. Hence they have no player units deployed and have to load them from the setup. The error you are getting stated just that, there is only 1 faction with unit in the scene because there are no player units deployed.

    As for ExSingleSpace, this is due to the obsolete unity script. In my defence, I should say that that this is not my script but of Unity standard script used in earlier version of Unity. :) Anyway you can simply remove the script in the scene to get rid of the error. You will find multiple instance of the script, all attached on objects named Tile.

    Hope this help.
     
  23. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Hi Songtan, are you expecting any new updates to this package soon? I've been working on another project for the past couple months but as that is nearing an end, I will be going back to work on my turn-based game. However, I don't want to go through the work of updating the code if you intend to release another update shortly ... would be better to just wait. Thanks,
     
  24. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I dont think I'll be doing any major update anytime soon. At least not in the next 2-3 months. If there is any, it would just be minor bug fixes at most. Hopefully that answer your question.
     
  25. Alarconte

    Alarconte

    Joined:
    Jan 8, 2014
    Posts:
    32
    Hi, thinking to buy your asset, but I need to know some things before:

    As MiniCampaing example shows, you can modify your "persistant data" to add and remove units, that's perfect.
    but, you can have two kinds of persistant memory, let's say, one for land combats, and other for space combats?

    I mean, Outside battle, for example, purchase or remove troops and ships. Then, You can have two kinds of battles, Land and space, and for each battle I need to load a different persistant data (Land Army, or Space Army). The thing is that all combats will be based on data outside the battle scene (what units are on each side, or what background has..), so each battle scene has to be loaded data from Ships Army, OR Land Army.

    And finally, Can a unit name can be changed by runtime? (like Player unit being "playername").

    Thanks!
     
  26. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for the interest. There's no two persistant memory slot for two set of units yet. But the code is there and I think it won't take too much effort to add another, and depends on the scene, load a particular set.

    I'm not sure how you want to change the unit name. Is it for a particular unit or a random unit? But I'm sure with a bit of modification to identify the unit, it can be done.
     
  27. Alarconte

    Alarconte

    Joined:
    Jan 8, 2014
    Posts:
    32
    My idea is for the Land kind of Battle (of my ideas of two kinds of battle), one particular unit is the player (is a RPG game), so when you choose / see the info of the Player unit, you see the name that you have assigned to it in character creation.

    Along with that, change the unit graphics, but that's not neccesary, I can work-around it.
     
  28. Rajmahal

    Rajmahal

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

    Quick question ... is there an easy way to have a faction that is friendly to the player's faction or are all AI factions always enemies to the player? Similarly, is it possible to have two AI factions fight against each other while the player is also controlling his own faction (free for all)?
     
  29. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @Alarconte, I dont think that's too difficult. You just need a slight modification to read the name assigned in the character creation as the unit name.

    @Rajmahal, I'm afraid the system is designed so that a faction will always be hostile to other faction with different factionID. With that said, AI factions will always be hostile to player. On the other end, two AI factions will also be hostile to each other.
     
  30. Exeneva

    Exeneva

    Joined:
    Dec 7, 2013
    Posts:
    432
    Can you explain the damage types that come with the examples? I hovered my mouse over them but didn't get any description so I'm wondering if you can explain.

     
  31. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    I was wondering about that too. Also, how does armor type work exactly?
     
  32. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    ArmorType and DamageType specification work as a way to create a rock-paper-scissor dynamic between the units. For instance, unitA deal double damage to unitB, or unitB partially immuned to unitC and so on. So basically units with a specific armor type will take different amount of damage from attack with different damage type and vice versa. You can define the relation of the armorType and damageType in DamageAmorTable editor.

    Please refer to the video below (at 4:18). It is for another package of mine but the editor interface and concept are the same.

     
  33. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Cool ... sounds very interesting. Will have to play around with that.
     
  34. Exeneva

    Exeneva

    Joined:
    Dec 7, 2013
    Posts:
    432
    For some odd reason, I'm unable to change the models used in TBTK. When I try to drag a prefab over, I get a cancel (circle with a cross through it) sign.



    Any idea on what might cause this? Note that I am using the latest version of Unity.
     
    Last edited: Aug 10, 2014
  35. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The "Add a new unit" slot is meant for UnitTB prefab. That means the prefab must have a UnitTB.cs attach on it otherwise it's not valid. What you need to do is just attach UnitTB.cs on your prefab and you should be able to add it to the UnitManager.
     
  36. Rajmahal

    Rajmahal

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

    I'm moving my project over to mobile and I noticed a few things. Firstly, I recommend you include Windows Phone support if you haven't already in your latest release. It just involves updating the #if UNITY_IPHONE || UNITY_ANDROID to include UNITY_WP8.

    Secondly, is there any way to have the unit info box appear on a mobile device? At the moment, it is tied to the Right Click mouse button. Any way to trigger it on some sort of touch and hold or some other method?

    Lastly, I'm getting some odd behavior where the pinch to zoom is not stopping at the right place. The camera goes straight through the floor. Which parameter controls the maximum zoomed position for touch? It doesn't seem to be limited to the same values as for mouse wheel. Also, I noticed this unusual if statement in the touch to zoom method that I think has to be incorrect:

    Code (CSharp):
    1. if(touch1.phase==TouchPhase.Moved && touch1.phase==TouchPhase.Moved)
    is it supposed to be?

    Code (CSharp):
    1. if(touch1.phase==TouchPhase.Moved && touch2.phase==TouchPhase.Moved)
    You may have fixed this on your latest release ... I'm one release behind. Will be updating it soon. Also, any plans to update the game for uGUI when 4.6 comes out?
     
  37. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for letting me know. I'll do that.

    There's no way to show the unit info box on a mobile device atm. You will have to add that yourself. Basically just detect any gesture you want and then call the function.

    Just done a quick check. It's a bug. Just add these lines to line223 in CameraControl.cs.
    Code (csharp):
    1. float camZ=Mathf.Clamp(camT.localPosition.z, -maxRadius, -minRadius);
    2. camT.localPosition=new Vector3(camT.localPosition.x, camT.localPosition.y, camZ);

    You are absolutely right.

    Yes. I'll definitely give it a go.
     
  38. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Cool .. thanks ... just to clarify since I've added a few lines to my CameraControl script, I should be adding those two lines inside the "if(touch1.phase...) condition, right?
     
  39. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    No, it should be a few lines down. Just after camT.Translate(Vector3.forward*Time.deltaTime*zoomSpeed*touchZoomSpeed);
     
  40. Exeneva

    Exeneva

    Joined:
    Dec 7, 2013
    Posts:
    432
    Hey Song, I have a question. You know the yellow effect that appears when the mouse hovers over a hex tile?


    (In the game view, the tile that has the yellow effect)

    What makes this or where is it? I want to change it to be white instead of yellow. Also, what script causes it to show up on hover?
     
  41. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    That's a ParticleSystem name HexIndicatorCursor (the second object in the HierarchyTab in the image you showed me). The prefab is stored in "TBTK/TBTK(Base)/Resources/HexIndicators" and loaded into IndicatorCursor slot in GridManager. You can either modify the prefab so that it appears white or replace it entirely with your own prefab. You can do that by assigning your own prefab in the GridManager

    The script which contain the function to display the indicator are GridManager.cs, in OnHoverEnter(). The script that initiate the function calling is Tile.cs, OnMouseEnter(). Which is of course called whenever the mouse cursor hovers over a tile.

    Hope this help.
     
  42. Thoreandon

    Thoreandon

    Joined:
    Aug 21, 2014
    Posts:
    37
    Hello.

    I have a question regarding the spawning of Units.

    1) After the players turn and the enemys turn, i want to spawn units.
    2) Sometimes during the the game, i also want to spawn units after a players move.

    I figured out that for 1) i have to edit GameControlTB but i am not sure at what line.
    I called UnitControl.insertUnit() in GameControlTB._OnNewRound(), is that the right spot ?
    Tried it and it seemed to behave a little strange, got some Nullpointer refs.

    Is the call of UnitControl.insertUnit() all i have to do ? I noticed another message in the board where the numbers of indicators have to be increased.
    I did this but still got errors.

    It would help me a lot if you could make a little Best-Practice comment on spawning.
    I also like to know whats the best way to instanciate a unit.
    Thanks.
     
    Last edited: Aug 21, 2014
  43. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    As far as I remember, UnitControl.insertUnit() is all you need to call. But honestly I haven't test this function thoroughly, as in every turn mode so I'm not sure if it's 100% fault proof. Can you show me how you call the function and what are the full NullPointer refs message you are getting? Does it happen right after you call the function?
     
  44. Thoreandon

    Thoreandon

    Joined:
    Aug 21, 2014
    Posts:
    37
    Code (CSharp):
    1.  
    2. Tile[] allTilesInScene=(Tile[])FindObjectsOfType(typeof(Tile));
    3.  
    4. foreach(Tile tile in allTilesInScene){
    5.         if (tile.isSpawn)
    6.                  List<UnitTB> unitPrefabList=new List<UnitTB>();
    7.                 GameObject obj=Resources.Load("PrefabList/UnitListPrefab", typeof(GameObject)) as GameObject;
    8.                  if(obj!=null){
    9.                         UnitListPrefab prefab=obj.GetComponent<UnitListPrefab>();
    10.                          if(prefab!=null){
    11.                                     unitPrefabList=prefab.unitList;
    12.  
    13.                                     UnitTB unit = unitPrefabList[7];        //Hardcoded just for testing
    14.                            
    15.                                     UnitControl.InsertUnit( unit, tile,1,2);
    16.                                     GridManager.hostileList.Add (tile);
    17.  
    18.                                                 }
    19.                                         }
    20.                         }
    21.  
    22.                 }

    Here is the spawn code, i am new to unity so i am not sure if there is a easier way to access the unit prefabs, i know that loading of the prefabs have to move up in the code to prevent loading for each spawn tile but thats not importand right now.
    I added a bool to Tile.cs so i can check specific tiles as spawn areas.
    I spawned 2 units, it worked and they moved, but at the end of the round, 1 of the units died (without getting an attack) , the second one was ok.

    Here is the error, perhaps it has something to do with the unit who dies without a cause.

    MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    UnityEngine.Transform.get_position () (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/UnityEngineTransform.cs:28)
    UIOverlay.OnGUI () (at C:/Users/Jürgen/Documents/New Unity Project 1/Assets/TBTK/TBTK (Base)/Scripts/C#/UI/UIOverlay.cs:118)

    Thanks for your help.
     
    Last edited: Aug 21, 2014
  45. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I found out what is wrong. Please send me an email so I can send you a fix. :)
     
  46. Rajmahal

    Rajmahal

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

    I'm running into an issue with my game as I try to get it to work on mobile devices with 512 MB of RAM. What I'm finding is that when I enter the unit selection screen, the game seems to load every possible unit in the game into memory for some reason. This is very problematic because my game has a small number of units that are usable by the player and many that will never be used (enemies). By loading all of them into memory, it causes crashes on mobile devices with less memory. I'm concerned that as I add more and more enemy units to the game, it will cause memory crashes on devices with even more memory.

    The reaon I think this is happening is because when I use the Unity Profiler and I enter the unit selection screen, I'm seeing animations and meshes in memory for enemy units that I don't actually use anywhere in that screen (or even elsewhere in the game, actually). These are models that only exist because I created them as units in the UnitTBEditor window.

    Is there any way for me to fix this so this doesn't happen?
     
  47. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Not sure where is this coming from but I dont recall pre-loading all prefab. In fact I've just checked, no unit has been instantiated during the unit selection screen. And during battle, only those unit on the grid are instantiated. Do you see any off screen unit that exist in the hierarchy tab? When I run the unit selection screen, there's nothing at all in the hierarchy except the a few base component. The same applies for the game scene, I find no extra hidden unit in game scene. I cant verify with profiler tho since I'm not using UnityPro.
     
  48. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    I don't think anything is in the hierarchy but I'll double check. You never know ... I might have some left over units somewhere in the background of a loading scene or something. I'll do some testing on my end and let you. I might actually load up your base project and run it through the profiler to see if it happens in the base code or if it's something I've introduced.
     
  49. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    I checked and there are no derelict unit's floating around in the hierarchy for any of the scenes.

    The profiler has the memory spike occur in the unit selection screen and in that screen, I noticed that there is this statement in the GlobatStatsTB:

    ********
    public static void LoadUnit(){
    GameObject obj=Resources.Load("UnitPrefabList", typeof(GameObject)) as GameObject;
    if(obj!=null){
    UnitListPrefab prefab=obj.GetComponent<UnitListPrefab>();
    if(prefab!=null){
    //Debug.Log(prefab.unitList.Count);
    unitPrefabList=prefab.unitList;
    }
    }
    ********

    I looked for a gameobject in a Resources folder called "UnitPrefabList" but I couldn't find it. However, I think it's referring to "UnitListPrefab" in your Resources / PrefabList folder. That object has a list of all units in the game, including those that I'm seeing in the profiler memory allocation but that I'm not actually using and would not be selectable as a player unit.

    I removed one of the enemy units I was seeing in the profiler from this prefab list and then reran the scene and that specific enemy was no longer loaded into memory. So I think this is the root object causing that information to be loaded into memory.

    However, what do you think would be the implications of loading only a subset of units into this prefab (the ones that only the player can actually control)? Do you think it would break functionality somewhere else?
     
  50. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Took a look at that, there is an error in that function that should stop it from working properly. It should have been:

    GameObject obj=Resources.Load("PrefabList/UnitListPrefab", typeof(GameObject)) as GameObject;


    So as it's, it shouldn't have loaded the prefab list. Without this function working properly, the persistent unit selection wont work properly either. Not sure you have notice this. If you have select your unit, start the game and quite half way through. The next time you run the game again, your previous selection will be lost even tho it should have been saved.

    That said, if you didn't intend to let the unit selection persist through game session. You can just remove this function all together.

    If you need this, perhaps you can try only loading only certain unit like what you have suggested. The key is to make sure the list contain at least the units available to player. So you can modify the code so that it only stored the unit that match the player's factionID.

    Interesting tho, I didnt think that referencing the prefab would actually consume memory for the meshes and animation.