Exemplo n.º 1
0
        public IEnumerator LoadRemoteTexture(string _avatar, int _size, Texture2D _tex)
        {
            string _url = AvatarUrl(_avatar, _size);

            WWW req = new WWW(_url);

            yield return(req);

            if (!string.IsNullOrEmpty(req.error))
            {
                Debug.LogError("Error loading remote avatar texture");
                yield break;
            }

            if (!Directory.Exists(RaqnStorage.DataPath() + "/cache/avatars"))
            {
                Directory.CreateDirectory(RaqnStorage.DataPath() + "/cache/avatars");
            }
            RaqnStorage.PutBytes("cache/avatars/" + avatar_name + "_" + avatar_size + ".png", req.bytes);

            req.LoadImageIntoTexture(_tex);
            if (av_renderer)
            {
                av_renderer.material.mainTexture = _tex;
            }
            else if (av_image)
            {
                av_image.sprite = GetSprite(_tex);
            }
        }
Exemplo n.º 2
0
 public void _RestoreOfflineSessions()
 {
     string[] _paths = Directory.GetFiles(RaqnStorage.DataPath() + "cache");
     for (int i = 0; i < _paths.Length; ++i)
     {
         string _dir  = Path.GetDirectoryName(_paths[i]);
         string _name = _paths[i].Substring(_dir.Length + 1);
         if (_name.StartsWith(Raqn.Dix.Id + "_L$") && _name.EndsWith(".json"))
         {
             RaqnPlaySession _pl = RaqnPlaySession.Load <RaqnPlaySession>(_name);
             if (_pl == null)
             {
                 File.Delete(_paths[i]);
             }
             else
             {
                 _pl.Sync(() =>
                 {
                     Debug.Log("Playsession synced OK!");
                     File.Delete(_paths[i]);
                 }, (_err) =>
                 {
                     Debug.Log("Error syncing playsession, until next time!");
                 });
             }
         }
     }
 }
Exemplo n.º 3
0
 static public bool StartOfflinePlay()
 {
     if (PlaySession != null || local_login == null || local_license == null || local_license.energy <= local_license.per_session)
     {
         return(false);
     }
     if (ApiSession == null)
     {
         ApiSession = new RaqnApiSession();
         ApiSession.logins.Add(local_login);
     }
     if (PlaySession == null)
     {
         PlaySession         = new RaqnPlaySession();
         PlaySession.dix     = Dix.Id;
         PlaySession.license = local_license.id;
         RaqnPlayer _p = new RaqnPlayer();
         _p.id       = local_login.user.id;
         _p.nickname = local_login.user.profile.nickname;
         _p.avatar   = local_login.user.profile.avatar;
         PlaySession.players.Add(_p);
         PlaySession.InitSessionData(ApiSession.id, Dix.Id, Dix.Package);
         ApiSession.play = PlaySession.id;
     }
     ExpendEnergy(License.per_session);
     RaqnStorage.SaveJson <RaqnLicense>("cache/license.dat", local_license, false, Dix.Secret);
     return(true);
 }
Exemplo n.º 4
0
        protected void OnPlay_Success()
        {
            //ApiSession = Api.GetSession();
            PlaySession = Api.GetPlaySession();
            if (PlaySession == null)
            {
                OnPlay_Error(ResponseStatus.ERR_FORMATTING);
            }
            //init session data for all players
            PlaySession.InitSessionData(ApiSession.id, Dix.Id, Dix.Package);
            RaqnStorage.SaveJson <RaqnLicense>("cache/license.dat", local_license, false, Dix.Secret);

            ExpendEnergy(License.per_session);
            GameData.UpdateStatDelta("RAQN.TotalUses", 1);
            OnSync += () =>
            {
                Api.LicenseCurrent(Dix.Id, (lic) =>
                {
                    local_license = lic;
                });
            };
            SyncJob();
            if (OnPlay != null)
            {
                OnPlay();
            }
        }
Exemplo n.º 5
0
        protected void Initialize()
        {
            Dix = DixInfo.Load();
            try
            {
                GameData = RaqnData.LoadOrCreate <RaqnData>(Dix.Id + ".json", true);
                //GeneralStats = StatContainer.LoadOrDie("General");
            }
            catch (Exception _ex)
            {
                Debug.LogException(_ex);
                Debug.LogError("Could not load DixData. Quitting app! (Exception :" + _ex.Message + ")");
                RealQuit();
            }
            Api = new RaqnApi(Dix.Id, Dix.Secret);
            Api.OnStartSuccess += OnLogin_Success;
            Api.OnStartError   += OnLogin_Error;
            Api.OnLoginSuccess += OnLogin_Success;
            Api.OnLoginError   += OnLogin_Error;
            Api.OnPlaySuccess  += OnPlay_Success;
            Api.OnPlayError    += OnPlay_Error;

            ApiSession = new RaqnApiSession();

            local_login   = RaqnStorage.LoadJson <RaqnLogin>("cache/login.dat", false, Dix.Secret);
            local_license = RaqnStorage.LoadJson <RaqnLicense>("cache/license.dat", false, Dix.Secret);
        }
Exemplo n.º 6
0
        public Texture2D GetLocalTexture(int _size = 100)
        {
            string    _str_size = SizeToImgSize(_size).ToString();
            Texture2D _tex;

            _tex = new Texture2D(_size, _size, TextureFormat.DXT1, false);
            byte[] _img = RaqnStorage.GetBytes("cache/avatars/" + avatar_name + "_" + _str_size + ".png");
            if (_img == null || _img.Length == 0)
            {
                return(null);
            }
            _tex.LoadImage(_img);
            return(_tex);
        }
Exemplo n.º 7
0
 protected void OnLogin_Success()
 {
     ApiSession = Api.GetSession();
     if (ApiUser == null || ApiSession == null)
     {
         OnLogin_Error(ResponseStatus.ERR_FORMATTING);
         return;
     }
     RaqnTime.SetSyncDelta(ApiSession.started);
     local_login = ApiSession.logins[0];
     RaqnStorage.SaveJson <RaqnLogin>("cache/login.dat", local_login, false, Dix.Secret);
     Api.LicenseCurrent(Dix.Id, (lic) =>
     {
         OnLicense_Success(lic);
     }, (_err) =>
     {
         OnLicense_Error(_err);
     });
     if (OnLogin != null)
     {
         OnLogin();
     }
 }
Exemplo n.º 8
0
 new static protected string DataPath(bool _persistent = false)
 {
     return(RaqnStorage.DataPath(_persistent) + "cache/local");
 }