Exemplo n.º 1
0
    /// <summary>
    /// 下载版本文件
    /// </summary>
    /// <returns></returns>
    IEnumerator LoadVersion()
    {
        Logger.Log("LoadVersion url:" + PathUtils.versionUrl);
        WWW www = new WWW(PathUtils.versionUrl);

        yield return(www);

        if (string.IsNullOrEmpty(www.error) && www.isDone)
        {
            JArray jsonArr = (JArray)JsonConvert.DeserializeObject(www.text);
            foreach (JObject json in jsonArr)
            {
                string webVersion = json["localversion"].ToString();

                if (int.Parse(webVersion) == Version)
                {
                    url     = json["url"].ToString();
                    mapName = json["map"].ToString();
                    if (!string.IsNullOrEmpty(mapName))
                    {
                        Coroutiner.Start(DownMap());
                    }
                    else
                    {
                        Logger.LogError("LoadVersion error: mapName null!");
                    }
                    break;
                }
            }
        }
        else
        {
            Logger.LogError("LoadVersion error:" + www.error);
        }
    }
Exemplo n.º 2
0
        /// <summary> Plays the currently active animation </summary>
        /// <param name="button"> The button reference </param>
        /// <param name="withSound"> If set to <c>true</c> [with sound] </param>
        /// <param name="onStartCallback"> Callback fired when the animation starts playing </param>
        /// <param name="onCompleteCallback"> Callback fired when the animation completed playing </param>
        public void PlayAnimation(UIButton button, bool withSound = true, UnityAction onStartCallback = null, UnityAction onCompleteCallback = null)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (ButtonAnimationType)
            {
            case ButtonAnimationType.Punch:
                if (PunchAnimation == null)
                {
                    return;
                }
                UIAnimator.StopAnimations(button.RectTransform, AnimationType.Punch);
                if (PunchAnimation.Move.Enabled)
                {
                    button.ResetPosition();
                }
                if (PunchAnimation.Rotate.Enabled)
                {
                    button.ResetRotation();
                }
                if (PunchAnimation.Scale.Enabled)
                {
                    button.ResetScale();
                }
                UIAnimator.MovePunch(button.RectTransform, PunchAnimation, button.StartPosition);       //play the move punch animation
                UIAnimator.RotatePunch(button.RectTransform, PunchAnimation, button.StartRotation);     //play the rotate punch animation
                UIAnimator.ScalePunch(button.RectTransform, PunchAnimation, button.StartScale);         //play the scale punch animation
                Coroutiner.Start(InvokeCallbacks(PunchAnimation, onStartCallback, onCompleteCallback));
                break;

            case ButtonAnimationType.State:
                if (StateAnimation == null)
                {
                    return;
                }
                UIAnimator.StopAnimations(button.RectTransform, AnimationType.State);
                UIAnimator.MoveState(button.RectTransform, StateAnimation, button.StartPosition);
                UIAnimator.RotateState(button.RectTransform, StateAnimation, button.StartRotation);
                UIAnimator.ScaleState(button.RectTransform, StateAnimation, button.StartScale);
                UIAnimator.FadeState(button.RectTransform, StateAnimation, button.StartAlpha);
                Coroutiner.Start(InvokeCallbacks(StateAnimation, onStartCallback, onCompleteCallback));
                break;

            case ButtonAnimationType.Animator:
                if (Animators == null || Animators.Count == 0)
                {
                    return;
                }
                foreach (AnimatorEvent animatorEvent in Animators)
                {
                    animatorEvent.Invoke();
                }
                break;
            }

            if (withSound)
            {
                OnTrigger.PlaySound();
            }
        }
Exemplo n.º 3
0
 public void TakeDamage(int value)
 {
     if (_Shield.IsDestroyed)
     {
         Coroutiner.Start(Explode());
     }
     _Shield.DecreaseEnergy(value);
 }
    public void CallGC()
    {
        if (_GCing)
        {
            return;
        }

        Coroutiner.Start(_ResourcesGC());
    }
Exemplo n.º 5
0
    public static void GetItems(string uid)
    {
        Debug.Log($"#Firebase# Getting items from {LocalDataProvider.Instance.localManager.name} {uid}");
        string json     = LocalDataProvider.Instance.localManager.GetItemsJson();
        var    firebase = GameObject.Find("Firebase");

        Debug.Log($"#Firebase# Received items");
        Coroutiner.Start(SendMessageDelayed(firebase, "ReceiveItems", json));
    }
Exemplo n.º 6
0
 public static void CheckLoginStatus()
 {
     if (LocalDataProvider.Instance.alreadyLogin)
     {
         var firebase = GameObject.Find("Firebase");
         var result   = new LoginResult {
             Id = "123", FormFilled = LocalDataProvider.Instance.FormFilled
         };
         Coroutiner.Start(SendMessageDelayed(firebase, "LoginSuccess", LitJson.JsonMapper.ToJson(result)));
     }
 }
        /// <summary> Triggers this behavior by executing its actions </summary>
        /// <param name="toggle"> UIToggle that triggered this behavior </param>
        public void Invoke(UIToggle toggle)
        {
            PlayAnimation(toggle);

            if (toggle.IsOn)
            {
                OnToggleOn.ExecuteEffect(OnToggleOn.GetCanvas(toggle.gameObject));
                OnToggleOn.InvokeAnimatorEvents();
                if (!TriggerEventsAfterAnimation)
                {
                    OnToggleOn.SendGameEvents(toggle.gameObject);
                    OnToggleOn.InvokeAction(toggle.gameObject);
                    OnToggleOn.InvokeUnityEvent();
                    return;
                }

                Coroutiner.Start(InvokeCallbackAfterDelay(() =>
                {
                    if (toggle == null)
                    {
                        return;
                    }
                    OnToggleOn.SendGameEvents(toggle.gameObject);
                    OnToggleOn.InvokeAction(toggle.gameObject);
                    OnToggleOn.InvokeUnityEvent();
                },
                                                          GetAnimationTotalDuration()));
            }
            else
            {
                OnToggleOff.ExecuteEffect(OnToggleOff.GetCanvas(toggle.gameObject));
                OnToggleOff.InvokeAnimatorEvents();
                if (!TriggerEventsAfterAnimation)
                {
                    OnToggleOff.SendGameEvents(toggle.gameObject);
                    OnToggleOff.InvokeAction(toggle.gameObject);
                    OnToggleOff.InvokeUnityEvent();
                    return;
                }

                Coroutiner.Start(InvokeCallbackAfterDelay(() =>
                {
                    if (toggle == null)
                    {
                        return;
                    }
                    OnToggleOff.SendGameEvents(toggle.gameObject);
                    OnToggleOff.InvokeAction(toggle.gameObject);
                    OnToggleOff.InvokeUnityEvent();
                },
                                                          GetAnimationTotalDuration()));
            }
        }
Exemplo n.º 8
0
 public void HideViews(List <UIViewCategoryName> views)
 {
     foreach (UIViewCategoryName view in views)
     {
         if (DebugMode)
         {
             DDebug.Log("Hide UIView: " + view.Category + " / " + view.Name);
         }
         Coroutiner.Start(UIView.HideViewNextFrame(view.Category, view.Name, view.InstantAction));
         //                UIView.HideView(view.Category, view.Name, view.InstantAction);
     }
 }
 public override void OnEnter()
 {
     if (DebugMode.Value)
     {
         DDebug.Log("Playmaker - State Name [" + State.Name + "] - Show UIView");
     }
     Coroutiner.Start(ShowView());
     if (FinishImmediately.Value)
     {
         Finish();
     }
 }
Exemplo n.º 10
0
        private void Update()
        {
//            if (!m_loadInProgress) return;
//            Debug.Log("CurrentAsyncOperation == null? " + (CurrentAsyncOperation == null));
            if (CurrentAsyncOperation == null)
            {
                return;
            }
            Progress = Mathf.Clamp01(CurrentAsyncOperation.progress / 0.9f); //update load progress [0, 0.9] > [0, 1]
            if (DebugComponent && !m_activatingScene)
            {
                DDebug.Log("[" + name + "] Load progress: " + Mathf.Round(Progress * 100) + "%", this);
            }
            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (!m_sceneLoadedAndReady && CurrentAsyncOperation.progress == 0.9f) // Loading completed
            {
                if (DebugComponent)
                {
                    DDebug.Log("[" + name + "] Scene is ready to be activated.", this);
                }
                LoadBehavior.OnSceneLoaded.Invoke(gameObject);
                m_sceneLoadedAndReady     = true; //mark that the scene has been loaded and is now ready to be activated (bool needed to stop LoadBehavior.OnSceneLoaded.Invoke(gameObject) from executing more than once)
                m_sceneLoadedAndReadyTime = Time.realtimeSinceStartup;
            }

            if (m_sceneLoadedAndReady && !m_activatingScene && AllowSceneActivation)
            {
                if (SceneActivationDelay < 0)
                {
                    SceneActivationDelay = 0;                           //sanity check
                }
                if (SceneActivationDelay >= 0 && Time.realtimeSinceStartup - m_sceneLoadedAndReadyTime > SceneActivationDelay)
                {
                    ActivateLoadedScene();
                    m_activatingScene = true;
                }
            }

            if (!CurrentAsyncOperation.isDone)
            {
                return;
            }
            if (DebugComponent)
            {
                DDebug.Log("[" + name + "] Scene has been activated.", this);
            }
            m_loadInProgress      = false;
            CurrentAsyncOperation = null;
            if (SelfDestructAfterSceneLoaded)
            {
                Coroutiner.Start(SelfDestruct());
            }
        }
Exemplo n.º 11
0
    public static void SaveLoginData(string uid, string name, int age, int avatarId, int textSize, float volume)
    {
        var firebase = GameObject.Find("Firebase");

        LocalDataProvider.Instance.registrationData = new RegistrationData {
            AvatarID = avatarId,
            Name     = name,
            Age      = age,
            Volume   = volume,
            FontSize = textSize
        };
        Coroutiner.Start(SendMessageDelayed(firebase, "OnRegisterDataSave"));
    }
Exemplo n.º 12
0
        /*protected virtual void BeginShoot()
         * {
         *
         * }
         *
         * protected virtual void CountinueShoot()
         * {
         *
         * }
         *
         * protected virtual void EndShoot()
         * {
         *
         * }*/

        public void Shoot(int pressureTime)
        {
            if (_CanShoot && Ammo > 0)
            {
                LeanPool.Spawn(Shell, transform.position, Shell.transform.rotation);
                LeanPool.Despawn(LeanPool.Spawn(MuzzleFlash.gameObject, transform.position, transform.rotation, transform), MuzzleFlash.main.duration);
                SoundManager.PlaySound(ShootSound);
                Ammo--;
                _CanShoot = false;

                Coroutiner.Start(Reload());

                OnAmmoChangedEvent?.Invoke();
            }
        }
Exemplo n.º 13
0
    public static void SignIn(string phoneNumber)
    {
        string message  = phoneNumber.Equals("+525512345678") ? "SMSSent" : "SMSError";
        var    firebase = GameObject.Find("Firebase");

        Debug.Log($"#Firebase#Sign in result {message} to gameobject {firebase}", firebase);
        if (message.Equals("SMSError"))
        {
            Coroutiner.Start(SendMessageDelayed(firebase, message, LitJson.JsonMapper.ToJson(new ErrorData {
                message = "Invalid phone", code = ""
            })));
        }
        else
        {
            Coroutiner.Start(SendMessageDelayed(firebase, message));
        }
    }
Exemplo n.º 14
0
    public void PlayAnimation(BBUIButton _bBButton, UnityEvent onStartCallback = null, UnityEvent onCompleteCallback = null)
    {
        bBButton = _bBButton;
        switch (ButtonAnimationType)
        {
        case ButtonAnimationType.Punch:
            PunchAnimation = uiAnimationData.Animation.Copy();
            if (PunchAnimation == null)
            {
                return;
            }
            UIAnimator.StopAnimations(bBButton.RectTransform, AnimationType.Punch);
            if (PunchAnimation.Move.Enabled)
            {
                bBButton.ResetPosition();
            }
            if (PunchAnimation.Rotate.Enabled)
            {
                bBButton.ResetRotation();
            }
            if (PunchAnimation.Scale.Enabled)
            {
                bBButton.ResetScale();
            }
            UIAnimator.MovePunch(bBButton.RectTransform, PunchAnimation, bBButton.StartPosition);
            UIAnimator.RotatePunch(bBButton.RectTransform, PunchAnimation, bBButton.StartRotation);
            UIAnimator.ScalePunch(bBButton.RectTransform, PunchAnimation, bBButton.StartScale);
            Coroutiner.Start(InvokeCallbacks(PunchAnimation, onStartCallback, onCompleteCallback));
            break;

        case ButtonAnimationType.State:
            StateAnimation = uiAnimationData.Animation.Copy();
            if (StateAnimation == null)
            {
                return;
            }
            UIAnimator.StopAnimations(bBButton.RectTransform, AnimationType.State);
            UIAnimator.MoveState(bBButton.RectTransform, StateAnimation, bBButton.StartPosition);
            UIAnimator.RotateState(bBButton.RectTransform, StateAnimation, bBButton.StartRotation);
            UIAnimator.ScaleState(bBButton.RectTransform, StateAnimation, bBButton.StartScale);
            UIAnimator.FadeState(bBButton.RectTransform, StateAnimation, bBButton.StartAlpha);
            Coroutiner.Start(InvokeCallbacks(StateAnimation, onStartCallback, onCompleteCallback));
            break;
        }
    }
Exemplo n.º 15
0
    public static void CheckVerificationCode(string verificationCode)
    {
        string message  = verificationCode.Equals("123456") ? "LoginSuccess" : "LoginError";
        var    firebase = GameObject.Find("Firebase");

        if (verificationCode.Equals("123456"))
        {
            Coroutiner.Start(SendMessageDelayed(firebase, message, LitJson.JsonMapper.ToJson(new LoginResult {
                Id = "1234", FormFilled = LocalDataProvider.Instance.FormFilled
            })));
        }
        else
        {
            Coroutiner.Start(SendMessageDelayed(firebase, message, LitJson.JsonMapper.ToJson(new ErrorData {
                message = "Invalid code", code = ""
            })));
        }
        Debug.Log($"#Firebase#Verification result {message} to gameobject {firebase}", firebase);
    }
Exemplo n.º 16
0
 public void DecreaseEnergy(int value)
 {
     if (!_Indestructible)
     {
         int valueToDecrease = Mathf.Abs(value);
         CurrentEnergy -= valueToDecrease;
         LeanTween.alpha(gameObject, 0.6f, 0.04f).setLoopPingPong(Random.Range(2, 8));
         //LeanTween.alpha(gameObject, 1, 1);
         if (CurrentEnergy <= 0)
         {
             CurrentEnergy = 0;
             gameObject.SetActive(false);
         }
         else
         {
             Coroutiner.Start(Cooldown());
         }
         OnChangeEnergyEvent?.Invoke();
     }
     return;
 }
Exemplo n.º 17
0
    /// <summary>
    /// 发送HTTP请求
    /// </summary>
    /// <returns>HTTP引擎状态</returns>
    /// <param name="type">HTTP请求类型</param>
    /// <param name="url">服务器URL地址</param>
    /// <param name="success">请求成功回调函数</param>
    /// <param name="data">需要传递的数据</param>
    /// <param name="autoMask">是否自动开启操作屏蔽遮罩层</param>
    /// <param name="timeOut">请求超时秒数</param>
    public void SendRequest(HTTP_REQUEST_TYPE type, string url, SuccessCallBack success, string data = "", bool autoMask = true, float timeOut = 5.0f)
    {
        if (type == HTTP_REQUEST_TYPE.Post && data == "")
        {
#if UNITY_EDITOR
            Debug.LogError("使用POST方式请求服务器,data数据不能为空!");
#endif
            return;
        }

        if (_Processing)
        {
#if UNITY_EDITOR
            Debug.LogError("HTTP引擎正在请求服务器!");
#endif
            return;
        }

        Coroutiner.Start(
            _SendRequestCallback(type, url, success, data, autoMask, timeOut)
            );
    }
Exemplo n.º 18
0
        private IEnumerator AsynchronousLoad(int sceneBuildIndex, LoadSceneMode mode)
        {
//            yield return null;
            ResetProgress();
            LoadBehavior.OnLoadScene.Invoke(gameObject);

            CurrentAsyncOperation = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneBuildIndex, mode);

            if (CurrentAsyncOperation == null)
            {
                yield break;
            }
            CurrentAsyncOperation.allowSceneActivation = false; //update the scene activation mode
            m_loadInProgress = true;                            //mark that a scene load process is running
            bool sceneLoadedAndReady = false;                   //mark that the scene has not been loaded (load progress has not reached 90%)
            bool activatingScene     = false;

//            while (!CurrentAsyncOperation.isDone)
            while (m_loadInProgress)
            {
//                if (CurrentAsyncOperation == null) yield break;

                // [0, 0.9] > [0, 1]
                Progress = Mathf.Clamp01(CurrentAsyncOperation.progress / 0.9f); //update load progress
                if (DebugComponent && !activatingScene)
                {
                    DDebug.Log("[" + name + "] Load progress: " + Mathf.Round(Progress * 100) + "%", this);
                }
                DDebug.Log("[" + name + "] Load progress: " + Mathf.Round(Progress * 100) + "%", this);
                // Loading completed
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (!sceneLoadedAndReady && CurrentAsyncOperation.progress == 0.9f)
                {
//                    Progress = 1f;
                    if (DebugComponent)
                    {
                        DDebug.Log("[" + name + "] Scene is ready to be activated.", this);
                    }
                    LoadBehavior.OnSceneLoaded.Invoke(gameObject);

                    sceneLoadedAndReady = true; //mark that the scene has been loaded and is now ready to be activated (bool needed to stop LoadBehavior.OnSceneLoaded.Invoke(gameObject) from executing more than once)
                }

                if (sceneLoadedAndReady && !activatingScene && AllowSceneActivation)
                {
                    if (SceneActivationDelay < 0)
                    {
                        SceneActivationDelay = 0;                           //sanity check
                    }
                    if (SceneActivationDelay > 0)
                    {
                        yield return(new WaitForSecondsRealtime(SceneActivationDelay));
                    }
                    ActivateLoadedScene();
                    activatingScene = true;
                }

                if (CurrentAsyncOperation.isDone)
                {
                    if (DebugComponent)
                    {
                        DDebug.Log("[" + name + "] Scene has been activated.", this);
                    }
                    m_loadInProgress = false;
//                    CurrentAsyncOperation = null;
                    if (SelfDestructAfterSceneLoaded)
                    {
                        Coroutiner.Start(SelfDestruct());
                    }
                }

                yield return(null);
            }
        }
Exemplo n.º 19
0
 // ReSharper disable once UnusedMember.Global
 /// <summary> Deselect this button from the EventSystem (if selected), after a set delay </summary>
 /// <param name="delay"> Time to wait before deselecting this button from the EventSystem </param>
 public void DeselectButton(float delay)
 {
     Coroutiner.Start(DeselectButtonEnumerator(delay));
 }
Exemplo n.º 20
0
 // ReSharper disable once UnusedMember.Global
 /// <summary> Deselect this toggle from the EventSystem (if selected), after a set delay </summary>
 /// <param name="delay"> Time to wait before deselecting this toggle from the EventSystem </param>
 public void DeselectToggle(float delay)
 {
     Coroutiner.Start(DeselectToggleEnumerator(delay));
 }
Exemplo n.º 21
0
    public static void LoadLoginData(string uid)
    {
        var firebase = GameObject.Find("Firebase");

        Coroutiner.Start(SendMessageDelayed(firebase, "OnRetrieveLoginData", LocalDataProvider.Instance.RegistrationJson));
    }
Exemplo n.º 22
0
        /// <summary> Triggers this behavior by executing its actions </summary>
        /// <param name="toggle"> UIToggle that triggered this behavior </param>
        /// <param name="playAnimation"> Play the set animation </param>
        /// <param name="playSound"> Play the set sound </param>
        /// <param name="executeEffect"> Run the effect </param>
        /// <param name="executeAnimatorEvents"> Trigger all the animator events </param>
        /// <param name="sendGameEvents"> Send all the game events </param>
        /// <param name="executeUnityEvent"> Execute the Action and the UnityEvent </param>
        public void Invoke(UIToggle toggle, bool playAnimation = true, bool playSound = true, bool executeEffect = true, bool executeAnimatorEvents = true, bool sendGameEvents = true, bool executeUnityEvent = true)
        {
            if (toggle == null)
            {
                return;
            }
            UIAction uiAction = toggle.IsOn ? OnToggleOn : OnToggleOff;

            if (playAnimation)
            {
                PlayAnimation(toggle, false);                                                 //Animation
            }
            if (playSound)
            {
                uiAction.PlaySound();                                                         //Sound
            }
            if (executeEffect)
            {
                uiAction.ExecuteEffect(uiAction.GetCanvas(toggle.gameObject));                //Effect
            }
            if (executeAnimatorEvents)
            {
                uiAction.InvokeAnimatorEvents();                                              //Animator Events
            }
            if (!sendGameEvents && !executeUnityEvent)
            {
                return;
            }
            if (!TriggerEventsAfterAnimation)
            {
                if (sendGameEvents)
                {
                    uiAction.SendGameEvents(toggle.gameObject);                 //Game Events
                }
                if (!executeUnityEvent)
                {
                    return;
                }
                uiAction.InvokeAction(toggle.gameObject); //Action
                uiAction.InvokeUnityEvent();              //UnityEvent
            }
            else
            {
                Coroutiner.Start(InvokeCallbackAfterDelay(() =>
                {
                    if (toggle == null)
                    {
                        return;
                    }
                    if (sendGameEvents)
                    {
                        uiAction.SendGameEvents(toggle.gameObject);                                                           //Game Events
                    }
                    if (!executeUnityEvent)
                    {
                        return;
                    }
                    uiAction.InvokeAction(toggle.gameObject);                                           //Action
                    uiAction.InvokeUnityEvent();                                                        //UnityEvent
                },
                                                          GetAnimationTotalDuration()));
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// 检测版本更新
 /// </summary>
 public void Update(int ver, Utils.VoidDelegate callback)
 {
     version      = ver;
     LoadCallback = callback;
     Coroutiner.Start(LoadVersion());
 }