Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by Om3n · Apr 06, 2010 at 08:55 PM · gameobjectwwwspawningdynamicparsing

(solved)Pasing WWW data post/get to load gameobjects?

I cannot seem any reference on how to go about spawning gameobjects from a sql/php backend using data retrieved using the WWW set. I cant seem to find any kind of reference in regards to this anywhere. Im trying to pull x,y,z from the sql using php and the spawning the prefab for the player at the position. I need to be able ot parse the data out of the returned data and then spawn the gameobject based on the data. Any thoughts/references on this would be greatly appreciated. Thank you!

Comment
Add comment · Show 2
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 Lucas Meijer 1 ♦♦ · May 10, 2010 at 08:31 PM 1
Share

ins$$anonymous$$d of rena$$anonymous$$g your question (solved), please click the accept button on the answer that sovled your question. Thanks! Lucas

avatar image grey · Jul 22, 2010 at 05:31 AM 0
Share

Ditto. Let's try to keep it tidy.

4 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by StephanK · Apr 06, 2010 at 09:19 PM

You can use WWW to open any url you want, including your typical get parameters (e.g. http://myserver.com/?action=getData) www.data will contain the received data as a string. So you can write you own php code, that will return the reqired data in a format that you can easily parse. To parse the returned data you can use the standard .net string features, or you return xml and use .net's xml parsing functions.

Comment
Add comment · Show 3 · 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 Om3n · Apr 06, 2010 at 09:49 PM 0
Share

Thank you very much for a prompt reply. It has put me in the right direction. Would you have to have any links to spawning dynamic gameobjects based on the data received from the database?

avatar image StephanK · Apr 07, 2010 at 07:24 AM 0
Share

Do you mean loading the gameobjects from a distant server, or just spawning a prefab? For loadin look up asset strea$$anonymous$$g in the manual. For spawning prefabs look at GameObject.Instantiate() and Resources.Load

avatar image Om3n · Apr 07, 2010 at 02:45 PM 0
Share

I meant loading the gameobjects with data received with info from the www data stream. ie: client logs in & queries the db then spawns objects based on that query. I will start with asset strea$$anonymous$$g to see if it leads me anywhere, Thank you again.

avatar image
1

Answer by Om3n · May 07, 2010 at 05:52 PM

This is how i ended up doing it, hopefully it can serve as an example for somone else =)

function Start() 

{ // show the progress window showProgress=true;

var w = WWW(URL); yield w; planetData = w.data; //here we return the data our PHP told us

var singlecoords = planetData.Split("\n"[0]); //line splitting php outut

curLine=0; maxLines=singlecoords.Length;

for (line in singlecoords) { // advance progress indicator ++curLine; var coords = line.Split(","[0]); //taking xyz & other data from singlecoords if (line.Length >= 8) { // makes sure we only instantiate valid planet records and // not any blanks the PHP/web exchanger added to the end planetID = parseInt(coords[0]); planetName = coords[6]; planetOwner = coords[4]; planetSector = coords[5]; objectType = parseInt(coords[7]);

     var pos = Vector3(parseInt(coords[1]),parseInt(coords[2]),parseInt(coords[3]));

     if (ObjectFactories.Length>objectType && ObjectFactories[objectType] != null) {
         var planetInstance = Instantiate(ObjectFactories[objectType], pos, Quaternion.identity);
         planetInstance.name = planetName;

     switch (objectType) {
         case 0: /* Planet */
             pInfo=planetInstance.GetComponent(PlanetClick);
             pInfo.planetName=planetName;
             pInfo.planetSector=planetSector;
             pInfo.planetOwner=planetOwner;
             pInfo.planetID=planetID;
             pInfo.objectType=objectType;
             break;

         case 1: /* Asteroid Belt */
         print(objectType);
             pInfo=planetInstance.GetComponent(PlanetClick);
             pInfo.planetName=planetName;
             pInfo.planetSector=planetSector;
             pInfo.planetOwner=planetOwner;
             pInfo.planetID=planetID;
             pInfo.objectType=objectType;
             break;

         default:
             print("No initializer for object type "+objectType);
     }

     } else {
         print("No prefab template in objectType slot "+objectType);
     }
 }

}

Comment
Add comment · 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
-1

Answer by Jens T · Jul 13, 2010 at 07:58 AM

Please note. This might fail strangely and silently. Check if there is difference between receiving hard coded and dynamic data using this php code:

this is hard coded text and will usually appear <?php

print "This is dynamic text, should appear, but might disappear";

?>

Comment
Add comment · 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
0

Answer by sandeep · May 10, 2010 at 06:46 PM

Question: Can i use this way to read fetched data from php/MYSQL Db.

code in my unity .js file.

var hs_get : WWW = new WWW (url); yield hs_get; var newdata = hs_data.data; . . .

does this mean , "newdata" has all the attributes as in the database table fetched from DB using PHP?

reply to me : sandeepsebol@gmail.com

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Get components of multiple instantiated objects? 2 Answers

Moving different objects with randomized value 0 Answers

Emptying and filling Arrays on command? C# 1 Answer

How to select a gameobject by script dynamically 1 Answer

Fastest way to instantiate thousands of objects at runtime? 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