Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: djaydino on July 08, 2015, 05:07:22 PM
-
Hi,
I am trying to figure out how to do this.
i got my xml setup like this :
<?xml version="1.0" encoding="ISO-8859-1"?>
<upgrades>
<prefab>
<category>Cat1</category>
<prefabName>Prefab 1</prefabName>
<status>Locked</status>
<required>1</required>
<price>20</price>
</prefab>
<prefab>
<category>Cat1</category>
<prefabName>Prefab 2</prefabName>
<status>Locked</status>
<required>5</required>
<price>50</price>
</prefab>
<prefab>
<category>Cat1</category>
<prefabName>Prefab 3</prefabName>
<status>Locked</status>
<required>10</required>
<price>30</price>
</prefab>
<prefab>
<category>Cat1</category>
<prefabName>Prefab 3</prefabName>
<status>Unlocked</status>
<required>10</required>
<price>25</price>
</prefab>
</upgrades>
and i use the action xml Select Nodes to get the Locked items with this xpath query : //prefab[status="Unlocked"]/prefabName
after this i want to get the prefab names sorted by price.
but i can't figure it out yet.
-
Hello,
I have a solution if this was a Ui prefab in ngui using uiGird.cs sort alphabetically
If you have figured how to get the info from inside xml to your game and assigned each prefab there atturbites [ name , price ,...]
If so you can make a sort manger that have a int variable [how to sort] ( 1 Name 2 Price .. )
The prefab get this int and compares it [ it should already have string variables name , price ]
If sort manger int is 1 Then set owner(theprefab) name to the variable string name
If it was 2 Set owner name to variable string price
In sort manger wait a short while then invoke or call UiGrid.cs to sort accordingly to there gameobjects names .
This will work I have tried it own other thing similar.
I hope it helps. :)
-
Hi,
isn't it possible with xpath Functions?
-
Hi,
yep, xpath has comparision operators:
http://www.w3schools.com/xpath/xpath_operators.asp
Bye,
Jean
-
i am a bit lost on how to set this up to get the prefab name (unlocked) sorted by price
-
bump
-
Hi,
yeah, please let me go trhough monday and tuesday, else, bump me on tuesday, ok? I'll come up with a working sample.
Bye,
Jean
-
thx jean,
if i get the hang of it i will try if i can make some tutorials for datamaker.
-
Bump, just a reminder :)
-
another bump :)
i am kinda stuck in my project until i can get this made :)
-
Hi,
Sorry for the wait, trying to keep up :)
Please find attached a working sample working on Unity 4.
-- you have a book list with prices
-- the PlayMaker inspector shows min and max price and a search button, click on search
-- the fsm deselect all books ( all children, and send the event "DESELECT")
-- the fsm filters the books given that price range
-- then it goes trhough each filtered book and select them ( send event "SELECT)
so with this you have everything to start building a listing that you can enable or disable.
IF you plan on disabling gameobject, make sure you keep them into an Array ( using ArrayMaker), cause disabled gameobject can't be searched withint he hierarchy.
one possible improvment here is to populate the books using xml, here I went to the point and created them by hand with just their id, but really they should be popluated with an fsm that feature all the xml data as fsm variables.
Let me know if this helps.
I don't put this on the ecosystem, I want PlayMaker 1.8 to be out first and clean up the existing samples.
Bye,
Jean
-
Hi,
no problem, i understand.
thank you for the sample.
i understand more now how it works,
but is it possible to loop trough from lowest price to highest price?
because i have a canvas with a panel and a vertical layout group where i will set my buttons as child inside. (they come from a different off screen object)
they will be shown from top to bottom depending on what position they are as a child.
i got everything working as i want to, only not yet sorted.
-
Hi,
sorting is not possible with xpath, you would have to do the sorting yourself. Typically, one way if you don't want to script would be using arrayMaker.
have two arrays, where indexes matches, that is the book id at index x has it's price also at index x
first array lists book id
second array lists prices
make a third array as a copy of prices but you sort it.
then you can take the prices from the sorted array, find the index from the price list, and with that index, you get the book id from the first array.
that's how you can do it with arrayMaker.
another way would be to rearrange childs if you are on the latests version of Unity, you can set the child index, so all your books would be iterated, and based on price of the sibling would be moved up or down the child stack. It's tricky to get this done right but that's another solution.
Bye,
Jean
then
-
hi,
I went for a HashTable and use hashtable add to add the gameobject name to a key and price as value.
hashtable seems sorts them automatically by value.
and this works for me :)
but having issues on beta,
i made a video so you can see whats going on.
please check beta forum.
greetings,
Dino
-
Hi,
one more question to change properties in the xml file @ runtime,
i need to use xml set node properties right?
and then use xml save in proxy?
lets say for example i want to change the genre "Computer" to "Mac" from bk101,
and save it so the next time i play it, it has the Genre Mac.
-
Hi,
yep, xml set node properties is what you need.
then if you want to save data in editor ( to overwrite your xml text asset), yes you have the option right within the proxy component interface, but that only works inside Unity.
in your game you'll have to extract the string, and save it somehow, either in playerprefs or online.
Bye,
Jean
-
ah, so i can save this also encrypted in easy save?
-
Hi,
yep :)
Bye,
Jean