I'm using unity and I'm trying to handle an exception.
I have CloudStuff class which is part of monobehaviour and I have UnityCallBack class in the same script.
I have another class on the same object, but in another script called MainMenu. I succesfully accessing values of MainMenu in CloudStuff class, but I can't access neither MainMenu class nor CloudStuff class from UnityCallBack class. I think it is just my poor knowledge of C#, but I'm not sure. Can anybody help me? So my goal is to access other classes from UnityCallBack.
When I print cloud object it is equal null, but I assign it new CloudStuff, maybe problem is here.
Here is the code.
using UnityEngine;
using UnityEngine.SocialPlatforms;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System;
using com.shephertz.app42.paas.sdk.csharp;
using com.shephertz.app42.paas.sdk.csharp.user;
using com.shephertz.app42.paas.sdk.csharp.game;
using com.shephertz.app42.paas.sdk.csharp.social;
using com.shephertz.app42.paas.sdk.csharp.abTest;
using com.shephertz.app42.paas.sdk.csharp.achievement;
using com.shephertz.app42.paas.sdk.csharp.avatar;
using com.shephertz.app42.paas.sdk.csharp.buddy;
using com.shephertz.app42.paas.sdk.csharp.connection;
using com.shephertz.app42.paas.sdk.csharp.customcode;
using com.shephertz.app42.paas.sdk.csharp.email;
using com.shephertz.app42.paas.sdk.csharp.geo;
using com.shephertz.app42.paas.sdk.csharp.log;
using com.shephertz.app42.paas.sdk.csharp.message;
using com.shephertz.app42.paas.sdk.csharp.pushNotification;
using com.shephertz.app42.paas.sdk.csharp.recommend;
using com.shephertz.app42.paas.sdk.csharp.review;
using com.shephertz.app42.paas.sdk.csharp.reward;
using com.shephertz.app42.paas.sdk.csharp.session;
using com.shephertz.app42.paas.sdk.csharp.shopping;
using com.shephertz.app42.paas.sdk.csharp.storage;
using com.shephertz.app42.paas.sdk.csharp.upload;
using AssemblyCSharp;
public class CloudStuff : MonoBehaviour
{
ServiceAPI api;
public UserService userService; // Initializing User Service.
ScoreBoardService scoreBoardService;
ScoreService scoreService;
GameService gameService;
public UnityCallBack callback;
public string gameName;
public MainMenu mainMenu;
#if UNITY_EDITOR
public static bool Validator (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{return true;}
#endif
void Start ()
{
#if UNITY_EDITOR
ServicePointManager.ServerCertificateValidationCallback = Validator;
#endif
api = new ServiceAPI("421bd5f87fdfd68a9d70d521014fa4cbad478502cab02c0862135d64e02738ba","78a2e8e9af3f6d5e00cfe9b11a876f702ddcbe6e3a6e2354ee6f2a60e03c90e6");
callback= new UnityCallBack();
userService = api.BuildUserService ();
scoreBoardService = api.BuildScoreBoardService();
scoreService = api.BuildScoreService();
gameService = api.BuildGameService();
gameName = "CarGame";
mainMenu=this.gameObject.GetComponent<MainMenu>();
App42Log.SetDebug(true); // to avoid printing Json into command line we will comment it
gameService.GetGameByName(gameName, callback);
}
public void CreateUser(string userName, string password, string email)
{
userService.CreateUser(userName,password,email,callback);
}
public void AuthentificateUser(string userName, string password)
{
userService.Authenticate(userName, password,callback);
}
public void setMenuFalse()
{
mainMenu.AuthentificationFailed=true;
}
}
public class UnityCallBack : App42CallBack
{
CloudStuff cloud=new CloudStuff();
public void OnSuccess(object response)
{
if(response is User)
{
User user=(User) response;
Debug.Log(user.GetUserName());
App42Log.Console("userName is " + user.GetUserName());
App42Log.Console("emailId is " + user.GetEmail());
}
}
public void OnException(Exception e)
{
App42Exception exception = (App42Exception)e;
int appErrorCode = exception.GetAppErrorCode();
if(appErrorCode == 2005)
{
Debug.Log("Email already exists.");
}
if(appErrorCode == 2002)
{
Debug.Log("Authentification Failed");
cloud.mainMenu.AuthentificationFailed=true;
}
App42Log.Console("Exception : " + e);
}
}