playMaker

Author Topic: Converting a material name to a String  (Read 3865 times)

acass64

  • Playmaker Newbie
  • *
  • Posts: 7
Converting a material name to a String
« on: May 18, 2013, 03:22:29 PM »
Basically, I am allowing the game player to choose a favorite photo as a background texture for the game. When they quit and come back I want to bring that photo back up. I want to use PlayerPrefs to store the photo, but am not sure how to convert a material to a string or int.

How do I go about converting the texture to a string or int that can be used in PlayerPrefs?

Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: Converting a material name to a String
« Reply #1 on: May 20, 2013, 01:49:37 AM »
Hi,

 Where is the photo stored? is it a photo that the user choose form his computer? or a preset?

you will not save the material reference, you only need to save the texture reference, BUT if this is a user photo, you will also need to store the texture as well, and that depends very much of your platform target. Can you tell us more about this?

bye,

 Jean

acass64

  • Playmaker Newbie
  • *
  • Posts: 7
Re: Converting a material name to a String
« Reply #2 on: May 22, 2013, 11:30:48 AM »
Thanks much for the feedback.

The images are stored in Unity. The user can select from a predefined set of "texture images".

Once the user selects their preferred texture, I would like to write that to PlayerPrefs so that when they re-enter the game, it will remain constant.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15620
  • Official Playmaker Support
Re: Converting a material name to a String
« Reply #3 on: May 23, 2013, 03:21:56 AM »
Hi,

 ok, use ArrayMaker then.

 when editing, create a new hashtable, and add all your textures, and name each entries properly.

 then when you let the user select a texture, you store the hashtable string key reference. and when coming back you can simply look up the pref and pick it up in that hashtable.

Does that make sense?

bye,

 Jean

nikosurfing

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Converting a material name to a String
« Reply #4 on: June 22, 2016, 05:07:04 AM »
Hi,

 ok, use ArrayMaker then.

 when editing, create a new hashtable, and add all your textures, and name each entries properly.

 then when you let the user select a texture, you store the hashtable string key reference. and when coming back you can simply look up the pref and pick it up in that hashtable.

Does that make sense?

bye,

 Jean

Jean, how to save sprite to variable playerprefabs, so that photo player will remain constant even they closed the app. However a photo user choosed from his device (i sucessfuly load photo from gallery or camera on android device). Any tutorial for this? I stuck from this from a few days ago. Please help me

dudebxl

  • Hero Member
  • *****
  • Posts: 602
Re: Converting a material name to a String
« Reply #5 on: June 22, 2016, 10:48:18 AM »
Ah, check the ecosystem for texture compression action and the result is a string that you can then save in playerpref or playerprefsX or playerprefsQ

Might have to convert sprite to texture if you dont have the original texture somewhere...