GithubHelp home page GithubHelp logo

amousqiu / unityassetsapi Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 228 KB

A Restful API in PHP to facilitate uploading, downloading and browsing of various game related assets.

License: Other

PHP 89.16% HTML 10.84%

unityassetsapi's Introduction

UnityAssetsAPI

A general Restful API in PHP woks along with MySQL database as a management system to facilitate uploading, downloading and browsing of various game related assets.

Web Interface

Server Home Page

home page screenshot

Photo Server Home Page

home page screenshot

Music Server Home Page

home page screenshot

How to set it up on your server?

  • You would need to set up these stuff on your server

    - Apache
    - php
    - phpMyadmin
    - mysql    
    

  • Now download the file folder

  • Upload the whole folder to your target server

    • Linux
      scp โ€“r Desktop/UnityAPI/ [email protected]:~/public_html
      Local Repository: Desktop/UnityAPI/
      //change this to your folder
      Server Repository: [email protected]:~/public_html
      //change this to your own
    • Windows

      I'm not suggesting using windows bro.
      But if you insist, just copy and paste this folder to your target place

How it works?

๐Ÿ… Detailed comments in imageServer code

How should I use it for other kind of files?

  • InsertData.php


//change this to your servername for phpMyadmin  
 $servername = null;  
//change this to your username for phpMyAdmin  
$username = "root";
//change this to your password for phpMyAdmin  
$password = null;
//change this to your database name   
$dbName = "Server";
//change 'Table' and 'Name' according to your database  
$sql = "select * from Table where Name='" . $FileName . "'";
//change 'Table' and 'Name' according to your database  
$sql = "INSERT INTO Table (Name) VALUES ('" . $FileName . "')";  



  • itemsData.php


//change this to your serverName for phpMyadmin   
$servername = null;
//change this to your username for phpMyAdmin  
$username = "root";
//change this to your password for phpMyAdmin   
$password = null;
//change this to your database name   
$dbName = "Server";
//change 'Table' according to your database  
$sql="SELECT * FROM 'Table'"; 
//change 'Name' according to your database  
echo "FileName:".$row ['Name'].";"; 



  • UnityUpload.php


//The only thing you need to do is changing ".png" to the file type you want to upload     
$myFile = $file_path.$_REQUEST['Name'].".png";

Now all the server part are all done!

Time to learn how to apply them in Unity


Here is some example codes.

Some projects

  • Download Part

    string GetDataValue(string data, string index)
    {
        Debug.Log("data: " + data + "index" + index);
        string value = data.Substring(data.IndexOf(index) + index.Length);
        if (value.Contains("|"))
        {
            value = value.Remove(value.IndexOf("|"));
        }
        return value;
    }
   WWWForm musicForm = new WWWForm();
   //change this to your url
   WWW wwwMusic = new WWW("Your itemsData.php url");
   yield return wwwMusic;
   string allString = (wwwMusic.text);
   Debug.Log(allString);
   //seperate each tuples
   items = allString.Split(';');
   string filename;
   for (int i = 0; i < items.Length - 1; i++)
   {
      filename = GetDataValue(items[i], "FileName:");
   }

After these part , you would get an array of the filenames, find a specific way for the files you need to load



  • Upload Part

  • Insert into database

    public static string insertIntoDB(string filename, byte[] bytes)
    {
        string result="";
        WWWForm form = new WWWForm();
        form.AddField("fileNamePost", filename);
        //change this to your url
        string insertURL = "Your insertData.php url";
        WWW www = new WWW(insertURL, form);
        if (www.error != null)
        {
            Debug.Log(www.error);
        }

        else
        {
            while (!www.isDone)
            {
            }
            Debug.Log("insertNew wav file: " + www.text);
            if (www.text != "exist")
            {
                result= "success";
                upload(bytes, filename);
            }
            else
            {
                result="fail";
            }
        }
        return result;
    }
  • Upload into server

    public static void upload(byte[] bytes, string filename)
    {
        //change this to your url
        string url = "Your UnityUpload.php url";
        WWWForm form = new WWWForm();
        form.AddField("Name", filename);
        form.AddBinaryData("post", bytes);
        WWW www = new WWW(url, form);
    }

THE END.

unityassetsapi's People

Contributors

amousqiu avatar yifanevawang avatar

Stargazers

 avatar  avatar  avatar

Watchers

James Cloos avatar Rahul Y Gupta avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.