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); }
// 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"); }
private void Start() { NotificationCenter.GetInstance().Add(NotificationCenter.E_SUBJECT.E_PLAYER_DATA, UpdatePlayerData); m_objPopup.SetActive(false); UpdatePlayerData(); }
void Update() { if (restartRenderer.enabled && Input.GetButtonDown("Jump")) { SceneManager.LoadScene("Game"); NotificationCenter.GetInstance().PostNotification("GameReset"); } }
void Start() { Notifier n = new Notifier(); n.Execute(this, EventArgs.Empty); NotificationCenter.GetInstance().SendNotification("GameStart"); Debug.Log("Send 'GameStart' but is not any hanlder!"); }
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; }
// 추후 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); }
// 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); } }
//参数是边框的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); }
/// <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); }
/// <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]); // } } }
void OnDestroy() { NotificationCenter.GetInstance().RemoveNotificationHandler("MoveY", MoveYHandler); }
void OnTriggerExit2D(Collider2D col) { NotificationCenter.GetInstance().PostNotification("ScoreAdd"); }
public void SendNotification(string name, object data = null) { NotificationCenter.GetInstance().SendNotification(name, data); }
// Start is called before the first frame update protected override void OnStart() { //添加观察者以及对应的处理函数 NotificationCenter.GetInstance().AddObserver("HeroChange", IndexChanged); }
void OnMouseDown() { SceneManager.LoadScene("Game"); NotificationCenter.GetInstance().PostNotification("GameReset"); }
void OnCollisionEnter2D(Collision2D col) { rigidbody2D.velocity = new Vector2(0, 0); NotificationCenter.GetInstance().PostNotification("GameOver"); this.enabled = false; }
void Awake() { handlers = new Dictionary <string, EventHandler>(); center = NotificationCenter.GetInstance(); }
private void Start() { NotificationCenter.GetInstance().Add(NotificationCenter.E_SUBJECT.E_PLAYER_DATA, UpdatePlayerData); UpdatePlayerData(); }
void Start() { NotificationCenter.GetInstance().AddNotificationHandler("MoveY", MoveYHandler); }
public void SendMoveY() { NotificationCenter.GetInstance().SendNotification("MoveY", this, new MoveYEventArgs(1.5f)); }