コード例 #1
0
ファイル: Story.cs プロジェクト: ittimGame1/G8Mao
    public void PlayOnePage(RectTransform root)
    {
        currentPageIndex += 1;
        if (currentPageIndex < items.Length)
        {
            GameObject go = new GameObject("PageItem<" + currentPageIndex + ">");
            go.transform.SetParent(root.transform);
            go.transform.localPosition = Vector3.zero;
            RectTransform rectTrans   = go.AddComponent <RectTransform>();
            Vector2       defaultVec2 = new Vector2(0.5f, 0.5f);
            rectTrans.anchorMin = defaultVec2;
            rectTrans.anchorMax = defaultVec2;
            rectTrans.offsetMin = defaultVec2;
            rectTrans.offsetMax = defaultVec2;
            Image img = go.AddComponent <Image>();
            img.raycastTarget = false;
            img.sprite        = items[currentPageIndex].sprite;

            CanvasScaler cs = root.GetComponentInParent <CanvasScaler>();
            rectTrans.sizeDelta = new Vector2(
                img.sprite.rect.width * cs.transform.localScale.x,
                img.sprite.rect.height * cs.transform.localScale.x);
            rectTrans.anchoredPosition = new Vector2(items[currentPageIndex].position.x, items[currentPageIndex].position.y);

            if (items[currentPageIndex].aniDuration > 0f)
            {
                img.color = new Color(img.color.r, img.color.g, img.color.b, 0f);
                img.DOFade(1.0f, items[currentPageIndex].aniDuration);
            }
        }
        else if (OnCompleteEvent != null)
        {
            OnCompleteEvent.Invoke();
        }
    }
コード例 #2
0
    public void Update()
    {
        if (!running)
        {
            return;
        }
        OnUpdateEvent?.Invoke();

        if (IsComplete())
        {
            running = false;
            OnCompleteEvent?.Invoke();
        }
    }
コード例 #3
0
ファイル: PathMover.cs プロジェクト: Taikatou/GameFrame
        public void Update(GameTime gameTime)
        {
            var position = ToMove.Position.ToPoint();

            Path.Update(position);
            if (Path.ToMove && ToMove.Position.ToPoint() != Path.NextPosition)
            {
                var direction = Path.NextPosition - ToMove.Position.ToPoint();
                NextPosition           = Path.NextPosition;
                ToMove.Moving          = true;
                ToMove.MovingDirection = direction.ToVector2();
            }
            else if (MovementComplete.Complete)
            {
                ToMove.OnMoveCompleteEvent += (sender, args) =>
                {
                    ToMove.Moving = false;
                    OnCompleteEvent?.Invoke(this, null);
                };
            }
        }
コード例 #4
0
        public override void Tick()
        {
            if (!_isRun || TargetRenderer == null)
            {
                return;
            }

            _timeCounter += Application.DeltaTime;
            if (!(_timeCounter >= _frameDuration))
            {
                return;
            }
            _timeCounter = 0f;
            _currentFrame++;
            if (_currentFrame > _animationData.GetRange().y)
            {
                // --------------------------------------------------------------------------------
                // Animation Complete - Loop ?
                // --------------------------------------------------------------------------------
                OnCompleteEvent?.Invoke(this._animationData);
                if (_animationData.loop)
                {
                    _isRun        = false;
                    _timeCounter  = 0f;
                    _timeCounter  = 0f;
                    _currentFrame = _animationData.GetRange().x;
                    var tmpData = _animationData;
                    _animationData = null;
                    PLay(tmpData);
                }
                else
                {
                    Stop();
                }
            }
            else
            {
                DrawFrame();
            }
        }
コード例 #5
0
 public void UploadImage(string imagePath, string caption, bool crop = false, bool withBorder = false)
 {
     if (crop)
     {
         imagePath = Crop(imagePath, withBorder);
     }
     try
     {
         string guid;
         string deviceId;
         //save our device/guid so we look like we're always uploading from the same phone
         if (!string.IsNullOrEmpty(Properties.Settings.Default.deviceId))
         {
             guid     = Properties.Settings.Default.guid;
             deviceId = Properties.Settings.Default.deviceId;
         }
         else
         {
             guid     = GenerateGuid();
             deviceId = $"android-{guid}";
             Properties.Settings.Default.deviceId = deviceId;
             Properties.Settings.Default.guid     = guid;
             Properties.Settings.Default.Save();
         }
         var data = new Dictionary <string, string>
         {
             { "device_id", deviceId },
             { "guid", guid },
             { "username", _username },
             { "password", StringUtilities.SecureStringToString(_password) },
             { "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8" }
         };
         var loginData       = serializer.Serialize(data);
         var signature       = GenerateSignature(loginData);
         var signedLoginData =
             $"signed_body={signature}.{HttpUtility.UrlEncode(loginData)}&ig_sig_key_version=6";
         OnLoginEvent?.Invoke(this, new NormalResponse {
             Status = "ok", Message = "Logging in please wait."
         });
         var loginResponse = instagramApi.PostData("accounts/login/", signedLoginData, _userAgent);
         if (string.IsNullOrEmpty(loginResponse))
         {
             ErrorEvent?.Invoke(this,
                                new ErrorResponse
             {
                 Status  = "fail",
                 Message = "Empty response received from the server while trying to login"
             });
         }
         else
         {
             try
             {
                 var loginJson = JObject.Parse(loginResponse);
                 var status    = (string)loginJson["status"];
                 if (status.Equals("ok"))
                 {
                     var username = (string)loginJson["logged_in_user"]["username"];
                     var hasAnonymousProfilePicture =
                         (bool)loginJson["logged_in_user"]["has_anonymous_profile_picture"];
                     var profilePicUrl = (string)loginJson["logged_in_user"]["profile_pic_url"];
                     var fullName      = (string)loginJson["logged_in_user"]["full_name"];
                     var isPrivate     = (bool)loginJson["logged_in_user"]["is_private"];
                     SuccessfulLoginEvent?.Invoke(this,
                                                  new LoggedInUserResponse
                     {
                         Username = username,
                         HasAnonymousProfilePicture = hasAnonymousProfilePicture,
                         ProfilePicUrl = profilePicUrl,
                         FullName      = fullName,
                         IsPrivate     = isPrivate
                     });
                     OnMediaUploadStartedEvent?.Invoke(this, EventArgs.Empty);
                     var uploadResponse = instagramApi.PostImage(imagePath, _userAgent);
                     if (string.IsNullOrEmpty(uploadResponse))
                     {
                         ErrorEvent?.Invoke(this,
                                            new ErrorResponse
                         {
                             Status  = "fail",
                             Message =
                                 "Empty response received from the server while trying to post the image"
                         });
                     }
                     else
                     {
                         try
                         {
                             var uploadJson   = JObject.Parse(uploadResponse);
                             var uploadStatus = (string)uploadJson["status"];
                             if (uploadStatus.Equals("ok"))
                             {
                                 OnMediaUploadeComplete?.Invoke(this, EventArgs.Empty);
                                 OnMediaConfigureStarted?.Invoke(this, EventArgs.Empty);
                                 var newLineStripper = new Regex(@"/\r|\n/", RegexOptions.IgnoreCase);
                                 //...
                                 caption = newLineStripper.Replace(caption, "");
                                 var mediaId       = (string)uploadJson["media_id"];
                                 var configureData = new Dictionary <string, string>
                                 {
                                     { "device_id", deviceId },
                                     { "guid", guid },
                                     { "media_id", mediaId },
                                     { "caption", caption.Trim() },
                                     { "device_timestamp", StringUtilities.GenerateTimeStamp() },
                                     { "source_type", "5" },
                                     { "filter_type", "0" },
                                     { "extra", "{}" },
                                     { "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8" }
                                 };
                                 var configureDataString = serializer.Serialize(configureData);
                                 var configureSignature  = GenerateSignature(configureDataString);
                                 var signedConfigureBody =
                                     $"signed_body={configureSignature}.{HttpUtility.UrlEncode(configureDataString)}&ig_sig_key_version=4";
                                 var configureResults = instagramApi.PostData("media/configure/",
                                                                              signedConfigureBody, _userAgent);
                                 if (string.IsNullOrEmpty(configureResults))
                                 {
                                     ErrorEvent?.Invoke(this,
                                                        new ErrorResponse
                                     {
                                         Status  = "fail",
                                         Message =
                                             "Empty response received from the server while trying to configure the image"
                                     });
                                 }
                                 else
                                 {
                                     try
                                     {
                                         var configureJson   = JObject.Parse(configureResults);
                                         var configureStatus = (string)configureJson["status"];
                                         if (configureStatus.Equals("fail"))
                                         {
                                             ErrorEvent?.Invoke(this,
                                                                new ErrorResponse
                                             {
                                                 Status  = "fail",
                                                 Message = (string)configureJson["message"]
                                             });
                                         }
                                         else if (configureStatus.Equals("ok"))
                                         {
                                             var uploadedResponse = new UploadResponse
                                             {
                                                 Images = new List <UploadResponse.InstagramMedia>()
                                             };
                                             foreach (
                                                 var media in
                                                 configureJson["media"]["image_versions2"]["candidates"].Select(
                                                     x => JObject.Parse(x.ToString()))
                                                 .Select(mediaJson => new UploadResponse.InstagramMedia
                                             {
                                                 Url = (string)mediaJson["url"],
                                                 Width = (int)mediaJson["width"],
                                                 Height = (int)mediaJson["height"]
                                             }))
                                             {
                                                 uploadedResponse.Images.Add(media);
                                             }
                                             OnCompleteEvent?.Invoke(this, uploadedResponse);
                                         }
                                     }
                                     catch (Exception ex)
                                     {
                                         ErrorEvent?.Invoke(this,
                                                            new ErrorResponse
                                         {
                                             Status  = "fail",
                                             Message = "Could not decode the configure response"
                                         });
                                     }
                                 }
                             }
                             else
                             {
                                 ErrorEvent?.Invoke(this,
                                                    new ErrorResponse
                                 {
                                     Status  = "fail",
                                     Message =
                                         (string)uploadJson["message"]
                                 });
                             }
                         }
                         catch (Exception)
                         {
                             ErrorEvent?.Invoke(this,
                                                new ErrorResponse
                             {
                                 Status  = "fail",
                                 Message = "Could not decode the upload response"
                             });
                         }
                     }
                 }
                 else
                 {
                     var message = (string)loginJson["message"];
                     InvalidLoginEvent?.Invoke(this, new ErrorResponse {
                         Status = status, Message = message
                     });
                 }
             }
             catch (Exception)
             {
                 ErrorEvent?.Invoke(this,
                                    new ErrorResponse
                 {
                     Status  = "fail",
                     Message = "Could not decode the login response"
                 });
             }
         }
     }
     finally
     {
         //clean up
         if (crop)
         {
             if (File.Exists(imagePath))
             {
                 File.Delete(imagePath);
             }
         }
     }
 }
コード例 #6
0
 private void OnComplete()
 {
     TweenID = null;
     OnCompleteEvent?.Invoke();
 }