Пример #1
0
    void OnCollisionEnter2D(Collision2D col)
    {
        //Debug.Log ("collide");
        rb.velocity = new Vector2(0, 0);
        NotificationCenter.GetInstance().PostNotification("GameOver");

        // 若撞柱而死,则旋转90度下落
        if (col.collider.tag == "Tube")
        {
            Vector3 rotation = this.transform.localEulerAngles;
            this.transform.localEulerAngles = new Vector3(rotation.x, rotation.y, -90f);
        }

        this.enabled = false;
        Animator animator = GetComponent <Animator>();

        animator.enabled = false;
        //BoxCollider2D collider = GetComponent<BoxCollider2D>();
        //collider.enabled = false;
        int birdLayer  = LayerMask.NameToLayer("Bird");
        int layerMask  = Physics2D.GetLayerCollisionMask(birdLayer);
        int tubeLayer  = LayerMask.NameToLayer("Tube");
        int maskChange = ~(1 << tubeLayer);

        Physics2D.SetLayerCollisionMask(birdLayer, layerMask & maskChange);
    }
Пример #2
0
        // Use this for initialization
        void Start()
        {
            MainMediator mainMediator = new MainMediator();
            UserMediator userMediator = new UserMediator();

            NotificationCenter nc = NotificationCenter.GetInstance();

            // 测试AddObserver
            nc.AddObserver(mainMediator, "ShowSkillPanel");
            nc.AddObserver(userMediator, "LoginSucess");
            nc.AddObserver(userMediator, "Register");
            nc.AddObserver(mainMediator, "LoginSucess");
            // 查看Observers
            nc.ViewObserver();
            // 测试RemoveObserver
            //nc.RemoveObserver( userMediator , "LoginSucess" );
            //nc.RemoveObserver( mainMediator, "LoginSucess" );
            // 查看Observers
            return;

            nc.ViewObserver();
            print("SendNotification( Register  )");
            nc.SendNotification("Register2");
            print("SendNotification( LoginSucess)");
            nc.SendNotification("LoginSucess");
            mainMediator = null;
            nc.RemoveObserver(userMediator, "LoginSucess");
            nc.ViewObserver();
            print("SendNotification( LoginSucess)");
            nc.SendNotification("LoginSucess");
        }
Пример #3
0
    private void Start()
    {
        NotificationCenter.GetInstance().Add(NotificationCenter.E_SUBJECT.E_PLAYER_DATA, UpdatePlayerData);

        m_objPopup.SetActive(false);

        UpdatePlayerData();
    }
Пример #4
0
 void Update()
 {
     if (restartRenderer.enabled &&
         Input.GetButtonDown("Jump"))
     {
         SceneManager.LoadScene("Game");
         NotificationCenter.GetInstance().PostNotification("GameReset");
     }
 }
Пример #5
0
    void Start()
    {
        Notifier n = new Notifier();

        n.Execute(this, EventArgs.Empty);

        NotificationCenter.GetInstance().SendNotification("GameStart");
        Debug.Log("Send 'GameStart' but is not any hanlder!");
    }
Пример #6
0
 void OnCollisionEnter2D(Collision2D col)
 {
     if (this.enabled)
     {
         GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0);
         NotificationCenter.GetInstance().PostNotification("GameOver");
         Singleton <ContextManager> .Instance.Push(new RestartContext());
     }
     this.enabled = false;
 }
Пример #7
0
    // 추후 if문을 없애고 보다 효율적으로 개선해야함.
    private void UpgradeDelegate(WWW www)
    {
        if (www.text == "")
        {
            Debug.Log("서버에서 업그레이드 정보를 전달하는 중 문제가 발생했습니다.");
            return;
        }

        int             nResultCode = 0;
        JSONObject      jsonResult  = null;
        DialogDataAlert dialogAlert = null;

        jsonResult  = JSONObject.Parse(www.text);
        nResultCode = (int)jsonResult["ResultCode"].Number;

        if (nResultCode == 1) // Success_Code
        {
            UserSingleton.GetInstance().Refresh
            (
                delegate()
            {
                NotificationCenter.GetInstance().Notify(NotificationCenter.E_SUBJECT.E_PLAYER_DATA);
            }
            );

            dialogAlert = new DialogDataAlert
                          (
                Language.GetInstance().GetLanguage("Upgrade Success"),
                Language.GetInstance().GetLanguage("Success"),
                delegate() { }
                          );
        }
        else if (nResultCode == 4) // Player_is_MaxLevel
        {
            dialogAlert = new DialogDataAlert
                          (
                Language.GetInstance().GetLanguage("Upgrade Failed"),
                Language.GetInstance().GetLanguage("Max Level"),
                delegate() { }
                          );
        }
        else if (nResultCode == 5) // Not_Enough_Diamond
        {
            dialogAlert = new DialogDataAlert
                          (
                Language.GetInstance().GetLanguage("Upgrade Failed"),
                Language.GetInstance().GetLanguage("Not Enough Diamond"),
                delegate() { }
                          );
        }

        m_objAlertDialog.SetActive(true);

        DialogManager.GetInstance().Push(dialogAlert);
    }
Пример #8
0
    // Update is called once per frame
    void Update()
    {
        if (!isStart)
        {
            // 准备阶段做上下缓动
            radian += perRadian;
            float dy = Mathf.Cos(radian) * radius;
            //Debug.Log ("dy=" + dy);
            transform.localPosition += new Vector3(0, dy, 0);


            if (Input.GetButtonDown("Jump"))
            {
                NotificationCenter.GetInstance().PostNotification("GameStart");
            }
        }
        else
        {
            if (Input.GetButtonDown("Jump"))
            {
                rb.velocity = new Vector2(0, speed);
                //Animator animator = GetComponent<Animator>();
                //animator.SetTrigger("jump");
            }

            // 处理下降和上升过程中的旋转
            Vector3 rotation  = this.transform.localEulerAngles;
            float   rotationZ = rotation.z;
            if (rotationZ >= 180)
            {
                rotationZ -= 360;
            }
            if (rb.velocity.y > 0)
            {
                rotationZ += rb.velocity.y * rb.velocity.y * 5f;
            }
            else if (rb.velocity.y <= -2.5f)
            {
                rotationZ -= rb.velocity.y * rb.velocity.y * 0.5f;
            }
            rotationZ = Math.Min(rotationMax, rotationZ);
            rotationZ = Math.Max(rotationMin, rotationZ);
            this.transform.localEulerAngles = new Vector3(rotation.x, rotation.y, rotationZ);
            //Debug.Log ("rotationZ=" + rotationZ);
        }
    }
Пример #9
0
 //参数是边框的Transfrom和下标
 private void BtnClicked(int index)
 {
     //尽量使用transfrom.Find 而少使用 gameObject.Find 因为一个是查找当前,一个是查找全局
     for (int i = 0; i < btnList.Length; i++)
     {
         if (i == index)
         {
             btnList[i].transform.Find("Border").gameObject.SetActive(true);
         }
         else
         {
             btnList[i].transform.Find("Border").gameObject.SetActive(false);
         }
     }
     //发数据:通知名字, 发送的对象, 下标
     NotificationCenter.GetInstance().PostNotification("HeroChange", this, index);
 }
Пример #10
0
        /// <summary>
        /// 移除Mediator
        /// </summary>
        /// <param name="mediatorName"></param>
        /// <returns></returns>
        public IMediator RemoveMediator(string mediatorName)
        {
            IMediator mediator = HasMediator(mediatorName) ? mediatorMap[mediatorName] : null;

            if (mediator != null)                                              // 如果不为空
            {
                string[] notifications = mediator.ListNotificationInterests(); // 找到所有的消息
                if (notifications.Length > 0)                                  // 如果有
                {
                    for (int i = 0; i < notifications.Length; i++)             // 则遍历一遍 从NotificationCenter里面移除
                    {
                        NotificationCenter.GetInstance().RemoveObserver(mediator, notifications[i]);
                    }
                }
                mediator.OnRemove();              // 调用OnRemove方法
                mediatorMap[mediatorName] = null; // 置为空
            }
            return(mediator);
        }
Пример #11
0
 /// <summary>
 /// 注册Mediator
 /// </summary>
 /// <param name="mediator"></param>
 public void RegisterMediator(IMediator mediator)
 {
     if (HasMediator(mediator.mediatorName))
     {
         return;                                                    // 不重复注册同一个Mediator
     }
     mediatorMap[mediator.mediatorName] = mediator;                 // 放到map里面
     mediator.OnRegister();                                         // 执行OnRegiser方法
     Debug.Log("RegisterMediator:: " + mediator.mediatorName);
     string[] notifications = mediator.ListNotificationInterests(); // 找到所有的消息
     if (notifications.Length > 0)                                  // 如果有
     {
         for (int i = 0; i < notifications.Length; i++)             // 则遍历一遍 添加到NotificationCenter里面
         {
             Debug.Log("AddObserver " + i + " " + notifications[i]);
             NotificationCenter.GetInstance().AddObserver(mediator, notifications[i]);   //
         }
     }
 }
Пример #12
0
 void OnDestroy()
 {
     NotificationCenter.GetInstance().RemoveNotificationHandler("MoveY", MoveYHandler);
 }
Пример #13
0
 void OnTriggerExit2D(Collider2D col)
 {
     NotificationCenter.GetInstance().PostNotification("ScoreAdd");
 }
Пример #14
0
 public void SendNotification(string name, object data = null)
 {
     NotificationCenter.GetInstance().SendNotification(name, data);
 }
Пример #15
0
 // Start is called before the first frame update
 protected override void OnStart()
 {
     //添加观察者以及对应的处理函数
     NotificationCenter.GetInstance().AddObserver("HeroChange", IndexChanged);
 }
Пример #16
0
 void OnMouseDown()
 {
     SceneManager.LoadScene("Game");
     NotificationCenter.GetInstance().PostNotification("GameReset");
 }
Пример #17
0
 void OnCollisionEnter2D(Collision2D col)
 {
     rigidbody2D.velocity = new Vector2(0, 0);
     NotificationCenter.GetInstance().PostNotification("GameOver");
     this.enabled = false;
 }
Пример #18
0
 void Awake()
 {
     handlers = new Dictionary <string, EventHandler>();
     center   = NotificationCenter.GetInstance();
 }
Пример #19
0
    private void Start()
    {
        NotificationCenter.GetInstance().Add(NotificationCenter.E_SUBJECT.E_PLAYER_DATA, UpdatePlayerData);

        UpdatePlayerData();
    }
Пример #20
0
 void Start()
 {
     NotificationCenter.GetInstance().AddNotificationHandler("MoveY", MoveYHandler);
 }
 public void SendMoveY()
 {
     NotificationCenter.GetInstance().SendNotification("MoveY", this, new MoveYEventArgs(1.5f));
 }