first ,Hi and pardon me for bad English writing!
i want to browse a picture form my hard disk and use it (e.g for texture of an object) when my game is running, then save it in assets. can anyone help me ?
first ,Hi and pardon me for bad English writing!
i want to browse a picture form my hard disk and use it (e.g for texture of an object) when my game is running, then save it in assets. can anyone help me ?
I can’t really explain this right now but I hope it helps. I made this to read a configuration file at runtime and use the variables in the file to setup the game.
I use this so that the user can setup the environment as they need. I make serious game environments.
using UnityEngine;
using System;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;
public class EnvironmentSetup : MonoBehaviour {
private string documentsPath = Application.dataPath +"/Documents/Configurations/";
private string fileText;
private string[] dataLines;
private string[][] dataPairs;
//currently the Environment Setup is hardcoded
//TODO: make this dynamic and selectable?
private string evSetup = "envSetup.txt";
private string dataPairName;
private string dataPairValue;
private GameObject goButtonDissableAvatar;
void Start()
{
SetupWorld();
}
void Update()
{
}
public void SetupWorld()
{
fileText = File.ReadAllText(documentsPath+evSetup);
dataLines = fileText.Split('\n');
dataPairs = new string[dataLines.Length][];
char[] del = new char[]
{
':',
','
};
int lineNum = 0;
foreach (string line in dataLines)
{
dataPairs[lineNum++] = line.Split(del);
}
for (int i = 0; i < dataPairs.Length; i++)
{
string[] innerArray = dataPairs[i];
dataPairName = "";
dataPairValue = "";
for (int j = 0; j < innerArray.Length; j++)
{
if (j == 0)
{
dataPairName = innerArray[j];
}
else if (j == 1)
{
dataPairValue = innerArray[j];
}
}
if (dataPairName != "")
{
if (GameObject.Find(dataPairName).GetComponent<Valve>())
{
GameObject.Find(dataPairName).GetComponent<Valve>().SetSelected(Convert.ToBoolean(dataPairValue));
}
}
}
}
}