Skip to content

Commit 9f6e6ff

Browse files
authored
Add files via upload
1 parent f5cc455 commit 9f6e6ff

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

StreamingAssetsAndroid.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine.UI;
4+
using UnityEngine;
5+
using UnityEngine.Networking; // for UnityWebRequest
6+
using System.IO; // SUPPORTS FOR READING AND WRITING OF FILES
7+
8+
public class GameControl : MonoBehaviour
9+
{
10+
public Image BG;
11+
public Text Name;
12+
13+
void Awake(){
14+
BetterStreamingAssets.Initialize();
15+
}
16+
17+
void Start()
18+
{
19+
string[] allfiles = BetterStreamingAssets.GetFiles("/","*.*");
20+
21+
foreach(string files in allfiles){
22+
if(files.Contains("sea")){ // checking of whether name matches or not
23+
StartCoroutine("Process",files);
24+
}
25+
}
26+
27+
}
28+
29+
void Update()
30+
{
31+
32+
}
33+
34+
IEnumerator Process(string file){
35+
36+
if(file.Contains("meta")){ // if file contains meta it means it is UnityBuilt-in file
37+
yield break;
38+
}
39+
else{
40+
string namewithoutextention = Path.GetFileNameWithoutExtension(file.ToString()); //to get the filename without any extention
41+
string[] individualwords = namewithoutextention.Split(' '); // split individual words with space
42+
string tempname = "";
43+
int i = 0;
44+
foreach(string a in individualwords){
45+
if(i!=0){ // to exclude first part in filename and get only the original name from it which is to be printed
46+
tempname = tempname + a + " "; // concatenate the name to be displayed only
47+
}
48+
i++;
49+
}
50+
51+
//get url to the file
52+
string url = "jar:file://"+Application.dataPath +"!/assets/"+file;
53+
UnityWebRequest www = UnityWebRequest.Get(url);
54+
DownloadHandlerTexture dht = new DownloadHandlerTexture ();
55+
www.downloadHandler = dht;
56+
yield return www.SendWebRequest();
57+
while (!www.isDone)
58+
{
59+
yield return www;
60+
}
61+
BG.sprite = Sprite.Create (((DownloadHandlerTexture)www.downloadHandler).texture , new Rect (0,0, ((DownloadHandlerTexture)www.downloadHandler).texture.width, ((DownloadHandlerTexture)www.downloadHandler).texture.height), new Vector2(0.5f, 0.5f));
62+
Name.text = tempname;
63+
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)