Skip to content

Commit

Permalink
removed userprefs
Browse files Browse the repository at this point in the history
  • Loading branch information
mranoncoder committed Feb 15, 2023
1 parent 2726435 commit d1aa29b
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 103 deletions.
5 changes: 0 additions & 5 deletions Editor/AlturaNFTSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,12 @@ static void GuiLine( int i_height = 1 )

#region ReadWrite UserPrefs

private static AlturaUser.UserPrefs _userPrefs = new AlturaUser.UserPrefs();
private static TextAsset targetFile;
static void ReadFromUserPrefs()
{
targetFile = Resources.Load<TextAsset>("AlturaNFT UserPrefs");
if (targetFile != null)
{
_userPrefs = JsonConvert.DeserializeObject<AlturaUser.UserPrefs>(targetFile.text);
myAPIString = _userPrefs.API_KEY;
AlturaUser.SaveNewApi(myAPIString);
AlturaUser.Initialise();
UserStats();
}
Expand All @@ -338,7 +334,6 @@ static void ReadFromUserPrefs()
}
void WriteToUserPrefs()
{
AlturaUser.SaveNewApi(myAPIString);
base.SaveChanges();
}

Expand Down
2 changes: 0 additions & 2 deletions Runtime/GetCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public class GetCollection : MonoBehaviour

private void Awake()
{
AlturaUser.Initialise();
_apiKey = AlturaUser.GetUserApiKey();

}

Expand Down
97 changes: 1 addition & 96 deletions Runtime/Internal/AlturaUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,97 +17,17 @@ namespace AlturaNFT.Internal

public static class AlturaUser
{
[System.Serializable]
public class UserPrefs {
public string API_KEY;
}

public static bool _initialised = false;
private static UserPrefs _userPrefs = new UserPrefs();

public static void Initialise()
{
if(_initialised == false)
{
_userPrefs = getUserPrefs();
#if UNITY_EDITOR
CheckAlturaPkg.OnListCheckComplete(isUPM => src.UPMImport = isUPM.ToString());
CheckAlturaPkg.CheckPkgList();
#endif
}

}


#region Prefs File Write
#if UNITY_EDITOR
public static void SaveNewApi(string newAPI)
{
_userPrefs.API_KEY = newAPI;
SaveUserPrefs();
}


public static void SaveUserPrefs()
{
if (!AssetDatabase.IsValidFolder("Assets/AlturaNFT/Resources"))
{
CreateFolder();
}

WriteToUserPrefs();
}

static void WriteToUserPrefs()
{
_initialised = false;
string json = JsonUtility.ToJson(_userPrefs);
System.IO.File.WriteAllText("Assets/AlturaNFT/Resources/" + "AlturaNFT UserPrefs.json", json);
AssetDatabase.Refresh();
AlturaUser.Initialise();
}


static void CreateFolder()
{
AssetDatabase.CreateFolder("Assets", "AlturaNFT");
string guid = AssetDatabase.CreateFolder("Assets/AlturaNFT", "Resources");
string newFolderPath = AssetDatabase.GUIDToAssetPath(guid);
}

#endif
#endregion


#region Prefs File Read
static UserPrefs getUserPrefs()
{
string _userfile = LoadUserPrefsTextfile();
if (_userfile.Length != 0)
{
_initialised = true;
return JsonConvert.DeserializeObject<UserPrefs>(_userfile);
}
else
{
_initialised = false;
Debug.LogError("Unable to Initialise, Make sure to input your APIKEYS in AlturaNFT/Home in Unity Editor");
return null;
}
}

private static TextAsset targetFile;

public static string LoadUserPrefsTextfile()
{
targetFile = Resources.Load<TextAsset>("AlturaNFT UserPrefs");;
if (targetFile != null)
return targetFile.text;
else
return string.Empty;
}

#endregion


#region Get Set Gos

Expand Down Expand Up @@ -170,21 +90,6 @@ public static string GetSource()
return json;
}

public static string GetUserApiKey()
{
if (_initialised)
{
return _userPrefs.API_KEY;
}
else if(targetFile==null)
{

return String.Empty;
}
else
return " Make sure to input your APIKEYS in AlturaNFT/Home ";
}

#endregion

}
Expand Down

0 comments on commit d1aa29b

Please sign in to comment.