playMaker

Author Topic: How to create a Simple Touch Button that changes an objects material.[SOLVED]  (Read 5700 times)

mickman

  • Junior Playmaker
  • **
  • Posts: 62
Hi everyone,
 
Scenario:

Each time a  GUI button is tapped, it changes the material on an object. ( iterating through a list of materials )  ie.  tap once = mat1:  tap again = mat 2:   tap third time = mat3  etc...

My 1st attempt:
  
I have created a button that changes the material once... but the button disappears after I touch it. The object material changes back to its original material when I move the object  
 The object also has a collider & finger swipe action on it that operates fine, I really don't want the material to change when I move the object.

My 2nd attempt:

Ok after some PlayMaking around I found a solution.. not so difficult either..

Each time I was adding a new state the Gui button action was not allocated to each new state... so it simply would not be visible.  To fix the missing button problem,  I simply copied and pasted the original State (Idle) and pasted it five times, so the button is now in each state.  

 Since I also had a  " Set Action" material action on my original State,  each time I copied and pasted the State, it simply carried another Set Material action along with it..  & then,  I just allocated a new material in the Set Material Area.  mmm....  copy & paste is my new PlayMaker Friend  ;D

  I'm not sure if this is the most efficient way to create an app but it works... maybe someone can point out a much more efficient approach.


 regards,
            Mick
« Last Edit: October 26, 2012, 01:10:35 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

1:
 are you sure the action is not set to revert back to the original material or something?

2: yes, indeed the GUI within playmaker only persists within its state, it is a shame and renders it pretty much impossible to use on complex ui needs. I would suggest either guitextures or third party 2d frameworks like ngui.

bye,

 Jean

mickman

  • Junior Playmaker
  • **
  • Posts: 62
I have several Set Material actions... so each time you hit the button it simply swaps to the next material.

but because PM does not support GUI buttons that are visible after you click I had to copy the GUI button into each event that holds the set material action.

I was thinking maybe there's a global GUI Holder that keeps all buttons visible in the scene unless you stipulate that the button turns off when tapped. 

 

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 Unfortunatly no. Fortunatly, I have in my drawer a quite large project aiming at doing just this. You define your UI via xml and if you want to have a button, you have an action to do that and it will only disappear if you explicitly delete it, not because you left the state you created it in.

 It's still very alpha, pm me if you are interested, it has a lot in store, multiple ways binding between Fsm Variables and ui components properties, you can even all describe in xml and have a button fire a global or even local event to any fsm or a given fsm, all of this within your xml :) you can show hide groups, parent components to anything you defined with an Id in your xml ( say you have a horyzontal layout view with id 'hello' you can parent y button to 'hello' and it will simply add it to this layout, so hard referencing or difficult pointers to maintains. It has a lot more as well, like in editor preview of the xml description file, etc etc.

 I kind of left that project aside, because it's a beast, and because Unity is working on a better UI system, but since it's not coming any time soon, It might be good that I spend a bit more time on this to release a version to the community.

bye,

 Jean

mickman

  • Junior Playmaker
  • **
  • Posts: 62
I understand... I might even delve a little into NGUI since I have it loaded.  NGUI interfae it fairly straight forward, jut have to pull out the paint brush and get to work creating icons etc...