• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
Question by Irich · Dec 24, 2012 at 12:13 AM · webplayerserversaveloadshare

Save and share from Web Player

Hi I wonder what is the easiest and best way to save changes in web player and share with others. For example if I have a cube and I change the color of the cube. Playerprefs can save changes on my local mac$$anonymous$$ne, but I want to send the changes to others trough email or the automatic update on their mac$$anonymous$$nes when they do refresh page or similar.

Many car configurator generates a unique code that you can send to others who can open your configurator using your code and read up on the web.

Thanks in advance

Comment
Statement
MarkFinn

People who like this

2 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Statement · Dec 24, 2012 at 12:35 AM

There are several ways you can do it. Either you can send the saved preferences as a Base 64 encoded string (suitable when you don't have too many bytes of info). Otherwise you could set up a server that stores preferences in a database and provides keys to look them up later.

Base64 encoding is just taking any binary blob of data and transforming it into a string containing safe and normal characters.

  • http://tedgustaf.com/blog/2010/10/convert-string-to-from-base64-encoding-dotnet/

Example to encode/decode a color:

 using UnityEngine;
 using System.Collections;
 
 public class ColorBase64 : MonoBehaviour
 {    
     public Color color = Color.cyan;
     
     void Start () {        
         Debug.Log ("Color to store as Base64: " + color);
         string base64 = ColorToBase64 (color);
         Debug.Log ("Color stored as Base64 string: " + base64);
         Color color2 = Base64ToColor (base64);
         Debug.Log ("Color loaded from Base64: " + color2);
     }
 
     string ColorToBase64 (Color color) {
         return System.Convert.ToBase64String (ToBytes (color));
     }
 
     Color Base64ToColor (string base64) {
         return ToColor (System.Convert.FromBase64String (base64));
     }
 
     static byte[] ToBytes (Color color) {
         byte[] colorAsBytes = new byte[4];        
         colorAsBytes [0] = (byte)(color.a * 255);
         colorAsBytes [1] = (byte)(color.r * 255);
         colorAsBytes [2] = (byte)(color.g * 255);
         colorAsBytes [3] = (byte)(color.b * 255);
         return colorAsBytes;
     }
 
     static Color ToColor (byte[] bytes) {
         float a = bytes [0];
         float r = bytes [1];
         float g = bytes [2];
         float b = bytes [3];
         return new Color (r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
     }
 }

Example output:

 Color to store as Base64: RGBA(0.443, 0.761, 0.548, 1.000)
 Color stored as Base64 string: /3DCiw==
 Color loaded from Base64: RGBA(0.439, 0.761, 0.545, 1.000)

If you want to talk with a web server to send and retrieve info:

  • http://docs.unity3d.com/Documentation/ScriptReference/WWWForm.html

  • http://wiki.unity3d.com/index.php/WWWForm_PHP_Example

Hope t$$anonymous$$s helps you find a solution that works for you.

Comment
MarkFinn

People who like this

1 Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Dec 24, 2012 at 12:36 AM 0
Share

(And naturally there are many other ways to do it, but I think these are probably some of the easiest ways to go about)

avatar image Irich · Dec 24, 2012 at 12:44 AM 0
Share

Ok so it needs to communicate with the server and database via WWWForm and ex. PHP. Thank you for your answers

avatar image Statement · Dec 24, 2012 at 12:46 AM 0
Share

Yeah, well, not if you do the base64 approach. You'd generate a piece of text that the user can copy/paste.

avatar image Irich · Dec 24, 2012 at 01:05 AM 0
Share

Do you have maybe an example of using base64 approach in action, and what is the limit of bytes?

avatar image Irich · Dec 24, 2012 at 03:12 AM 1
Share

Ok I understand now how this works. So the next user can simply paste / 3DCiw == and get the same color as me by decoding it back to color. Thanks

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is it possible to add a specific prefab and custom user text in in a multiuser web player? 0 Answers

Saving a text file to a server and accessing it again? 0 Answers

How to save data with the webplayer avaiable to all users? 1 Answer

Save/Load game using XML on Browser/Web Player 2 Answers

How do I create/load/save Highscores? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges