public void useSkillsBlink(MGNotification notification) { if (notification.objc == null) { skillsBlink(); } }
void roleDeadAnimController(MGNotification notification) { //if (GameObject.Find("role1").GetComponent<RoleAnimController>().isKillRoadblock) return; if (notification.objc.Equals("role")) { Debug.Log("roleDeadAnimController:" + notification.objc); setAllAnimStateToFalse(); animStateToDead(); } else if (notification.objc.Equals("role1")) { Debug.Log("roleDeadAnimController:" + notification.objc); setAllAnimStateToFalse(); animStateToDead(); } Debug.Log("set role trigger"); if (downOrUp) { rigidbody2D.gravityScale = 0.5f; } else { rigidbody2D.gravityScale = 0f; } rigidbody2D.velocity = Vector3.zero; collider2D.isTrigger = true; isDead = true; MGNotificationCenter.defaultCenter().postNotification(uiEvent.enableAllUIButton, false); }
public void continueNotification(MGNotification notification) { if (notification.objc != null) { continueGame(null); } }
public void stopNotification(MGNotification notification) { if (notification.objc != null) { clickStop(null); } }
void loadLevelWay(MGNotification notification) { if (notification.objc != null && notification.objc is string) { Application.LoadLevel(notification.objc as string); } }
public void useSkillsRoadblock(MGNotification notification) { if (notification.objc == null) { skillsRoadblock(); } }
public void useSkillsDart(MGNotification notification) { if (notification.objc == null) { skillsDart(); } }
public void useSkillsBones(MGNotification notification) { Vector3 pos = new Vector3(transform.position.x + 3 * renderer.bounds.size.x / 16, transform.position.y + (transform.localScale.y > 0 ? 1 : -1) * renderer.bounds.size.y / 2, transform.position.z); MGSkillBones skillObjc = bones as MGSkillBones; if (notification.objc == null)//需要在对方客户端同步的 { if (Network.peerType != NetworkPeerType.Disconnected) { skillObjc = mgNetWorking.Instantiate(bones, pos, new Quaternion(), 0) as MGSkillBones; } else { skillObjc = bones.createSkillSprite(pos) as MGSkillBones; } } else//不需要再对方客户端同步的,短时间的bones { skillObjc = bones.createSkillSprite(pos) as MGSkillBones; skillObjc.name = notification.objc as string; } if (skillObjc) { skillObjc.releaseSkillObjcName = this.gameObject.name; skillObjc.transform.parent = this.transform; } }
public void downButtonClick(MGNotification notification) { if (!isRoll && !isPressDown && transform.localScale.y < 0) { return; } //Debug.Log(this.gameObject.name + " downButtonClick"); collider2D.isTrigger = true; if (isFirstJump)//在空中 { //Debug.Log("在空中"); isPressDown = true; isPressDownToGround = false; downOrUp = true; rigidbody2D.gravityScale = 10f; rigidbody2D.velocity = new Vector3(0, -10, 0); setAllAnimStateToFalse(); animStateToRoll(); } else//在绳子上 { //Debug.Log("在绳子上"); if (isRoll && !downOrUp) { isChangeDownOrUp = true; } isRoll = true; downOrUp = true; rigidbody2D.gravityScale = 0f; music.play("Sound/updown_roll"); setAllAnimStateToFalse(); animStateToRoll(); } }
void triggerFunc(MGNotification notification) { Debug.Log("triggerFunc"); if (notification.objc is Collider2D)//自己要做的 { Collider2D other = notification.objc as Collider2D; danDart(); GameObject objc = GameObject.Find(other.name); if (objc) { int boneMask = objc.GetComponent <Jump>().stateMask & roleState.bone; int sprintMask = objc.GetComponent <Jump>().stateMask & roleState.sprint; if (boneMask != 0 || sprintMask != 0) { return; } } MGMsgModel skillModel = new MGMsgModel(); skillModel.eventId = SkillEffectEnum.dart; skillModel.gameobjectName = other.name; //发送给自己 MGNotificationCenter.defaultCenter().postNotification(SkillEffectEnum.dart, skillModel); } else if (notification.objc is MGMsgModel)//对面要做的 { //MGMsgModel other = notification.objc as MGMsgModel; danDart(); } }
public void enableAllUIButton(MGNotification notification) { GameObject[] buttons = GameObject.FindGameObjectsWithTag("UIButton"); for (int i = 0; i < buttons.Length; ++i) { buttons[i].GetComponent <UIButton>().enabled = (bool)notification.objc; } }
public void downToLine(MGNotification notification) { //角色会根据下按钮,翻转到线下 MGNotificationCenter.defaultCenter().postNotification(buttonEventId(RoleButtonEvent.downFormerEventId), null); if (notification.objc == null) { mgNetWorking.sendMessageToPeer(objcToJson(RoleActEventEnum.downToLineFormerEventId)); } }
void sprintEffect(MGNotification notification) { if (notification != null) { sprintSwitch = notification; MGMsgModel skillModel = (MGMsgModel)notification.objc; GameObject objc = GameObject.Find(skillModel.gameobjectName); if (objc) { if (tempObjcet == null) { tempObjcet = GameObject.Find("sprint(Clone)"); } float dis = MGGlobalDataCenter.defaultCenter().roleFrontPos.x - MGGlobalDataCenter.defaultCenter().roleLaterPos.x; objc.transform.Translate(speedSwitch * Vector3.right * MGSkillSprintInfo.SkillEffectSpeed * dis * Time.deltaTime / MGSkillSprintInfo.durationTime); if (tempObjcet) { int fx = objc.transform.localScale.y > 0?1:-1; tempObjcet.transform.position = new Vector3(objc.transform.position.x + 0.25f, objc.transform.position.y + fx * objc.GetComponent <SpriteRenderer>().bounds.size.y / 2f, objc.transform.position.z); } } sprintTimer += Time.deltaTime; if (sprintTimer > MGSkillSprintInfo.durationTime) { //修改背景的移动速度 GameObject[] backgroundList = GameObject.FindGameObjectsWithTag("Background"); for (int i = 0; i < backgroundList.Length; ++i) { backgroundList[i].GetComponent <bgnear>().speed -= 20; } backgroundList = GameObject.FindGameObjectsWithTag("Road"); for (int i = 0; i < backgroundList.Length; ++i) { backgroundList[i].GetComponent <bgnear>().speed -= 20; } objc.GetComponent <RoleAnimController>().isSprint = false; objc.GetComponent <Animator>().SetBool("sprint", false); objc.GetComponent <SpriteRenderer>().material = new Material(Shader.Find("Sprites/Default")); UILabel label = GameObject.Find("log").GetComponent <UIInput>().label; Vector3 pos1 = GameObject.Find("role1").transform.position; Vector3 pos = GameObject.Find("role").transform.position; label.text += "\r\nrole.x=" + pos.x + ";role1.x=" + pos1.x; sprintTimer = 0; sprintSwitch = null; tempObjcet = null; GameObject sprint = GameObject.Find("sprint(Clone)"); if (sprint != null) { Destroy(sprint); } objc.GetComponent <Jump>().stateMask &= ~roleState.sprint; } } }
void roleKillAnimController(MGNotification notification) { if (notification.objc.Equals("role1")) { Debug.Log("roleKillAnimController"); setAllAnimStateToFalse(); animStateToKill(); } isKillRoadblock = false; MGNotificationCenter.defaultCenter().postNotification(uiEvent.enableAllUIButton, false); }
void dartEffect(MGNotification notification) { if (notification != null) { MGMsgModel skillModel = (MGMsgModel)notification.objc; GameObject objc = GameObject.Find(skillModel.gameobjectName); float dis = MGGlobalDataCenter.defaultCenter().roleFrontPos.x - MGGlobalDataCenter.defaultCenter().roleLaterPos.x; if (objc && (objc.GetComponent <Jump>().stateMask & roleState.wudi) == 0) { objc.transform.Translate(Vector3.left * MGSkillDartInfo.SkillEffectSpeed * dis); } } }
void roleKillRoadblockAnimController(MGNotification notification) { if (isKillRoadblock) { return; } if (notification.objc.Equals("role1")) { Debug.Log("roleKillRoadblockAnimController"); setAllAnimStateToFalse(); animStateToKillRoadblock(); } isKillRoadblock = true; }
// Use this for initialization void Start() { sprintTimer = 0; beatbackTimer = 0; blinkSkillBonesTimer = 1; sprintSwitch = null; tempObjcet = null; roadblockSwitch = null; shortBonesName = "bones_short"; MGNotificationCenter.defaultCenter().addObserver(this, dartEffect, SkillEffectEnum.dart); MGNotificationCenter.defaultCenter().addObserver(this, blinkEffect, SkillEffectEnum.blink); MGNotificationCenter.defaultCenter().addObserver(this, sprintEffect, SkillEffectEnum.sprint); MGNotificationCenter.defaultCenter().addObserver(this, beatbackEffect, SkillEffectEnum.beatback); MGNotificationCenter.defaultCenter().addObserver(this, roadblockEffect, SkillEffectEnum.roadblock); }
public void jump(MGNotification notification) { MGNotificationCenter.defaultCenter().postNotification(buttonEventId(RoleButtonEvent.upFormerEventId), notification); //if (roleAnimaController.isRoll || roleAnimaController.isPressDown) return; if (transform.localScale.y < 0 || roleAnimaController.isRoll) { Debug.Log("jump"); if (notification.objc == null) { mgNetWorking.sendMessageToPeer(objcToJson(RoleActEventEnum.jumpFormerEventId)); } return; } if (roleAnimaController.isFirstJump && !roleAnimaController.isSecondJump && jumpCount == 0) { Debug.Log("一段跳"); isGround = false; Vector3 velocity = rigidbody2D.velocity; velocity.y = jumpVelocity; rigidbody2D.velocity = velocity; jumpCount = 1; //如果没有发送给对方,则发送消息 if (notification.objc == null) { mgNetWorking.sendMessageToPeer(objcToJson(RoleActEventEnum.jumpFormerEventId)); } } //如果不在地面上,且一段跳了,则二段跳 else if (roleAnimaController.isFirstJump && roleAnimaController.isSecondJump && jumpCount == 1) { Debug.Log("二段跳"); Vector3 velocity = rigidbody2D.velocity; if (velocity.y < -1.0f) { velocity.y = jumpSecond + 3; } else { velocity.y = jumpSecond; } rigidbody2D.velocity = velocity; jumpCount = 2; if (notification.objc == null) { mgNetWorking.sendMessageToPeer(objcToJson(RoleActEventEnum.jumpFormerEventId)); } } }
public void upButtonClick(MGNotification notification) { //if (isPressDown && !isPressDownToGround) return; if (isSecondJump) { return; } Debug.Log(this.gameObject.name + " upButtonClick"); if (transform.localScale.y < 0 || (isRoll && downOrUp))//上翻 { //Debug.Log("上翻"); if (isRoll && downOrUp == true) { isChangeDownOrUp = true; } isRoll = true; downOrUp = false; rigidbody2D.gravityScale = 0f; collider2D.isTrigger = true; music.play("Sound/updown_roll"); setAllAnimStateToFalse(); animStateToRoll(); return; } if (isRoll) { return; } //Debug.Log(this.gameObject.name + " jumpButtonClick"); if (isFirstJump == false)//一段跳 { isFirstJump = true; setAllAnimStateToFalse(); animStateToFirstJump(); music.play("Sound/updown_roll"); } else if (isSecondJump == false)//二段跳 { isSecondJump = true; setAllAnimStateToFalse(); animStateToRoll(); music.play("Sound/updown_roll"); } }
void roadblockEffect(MGNotification notification) { if (notification != null) { roadblockSwitch = notification; MGMsgModel skillModel = (MGMsgModel)notification.objc; GameObject objc = GameObject.Find(skillModel.gameobjectName); float dis = MGGlobalDataCenter.defaultCenter().roleFrontPos.x - MGGlobalDataCenter.defaultCenter().roleLaterPos.x; if (objc && (objc.GetComponent <Jump>().stateMask & roleState.wudi) == 0) { objc.transform.Translate(Vector3.left * MGSkillRoadblockInfo.SkillEffectSpeed * dis * Time.deltaTime / MGSkillRoadblockInfo.durationTime); } roadblockTimer += Time.deltaTime; if (roadblockTimer > MGSkillRoadblockInfo.durationTime * Time.timeScale) { roadblockTimer = 0; roadblockSwitch = null; } } }
void blinkEffect(MGNotification notification) { if (notification != null) { blinkSkillBonesTimer = 0; if (MGGlobalDataCenter.defaultCenter().isFrontRoler == false && MGGlobalDataCenter.defaultCenter().isSingle == false) { MGNotificationCenter.defaultCenter().postNotification(SkillActEventEnum.bones, shortBonesName);//发送bones技能的事件 return; } MGMsgModel skillModel = (MGMsgModel)notification.objc; Debug.Log("skillModel:" + skillModel + ",eventId:" + skillModel.eventId + ",gameobjectName:" + skillModel.gameobjectName); GameObject objc = GameObject.Find(skillModel.gameobjectName); if (objc) { Debug.Log("blinkObjc:" + objc + "name:" + objc.name); float dis = MGGlobalDataCenter.defaultCenter().roleFrontPos.x - MGGlobalDataCenter.defaultCenter().roleLaterPos.x; Vector3 roleLaterPos = MGGlobalDataCenter.defaultCenter().roleLater.transform.position; Vector3 roleFrontPos = MGGlobalDataCenter.defaultCenter().role.transform.position; if (roleFrontPos.x - roleLaterPos.x < MGSkillBlinkInfo.SkillEffectSpeed * dis) { objc.transform.Translate(Vector3.right * (roleFrontPos.x - roleLaterPos.x - 1f)); } else { objc.transform.Translate(Vector3.right * MGSkillBlinkInfo.SkillEffectSpeed * dis); } } MGNotificationCenter.defaultCenter().postNotification(SkillActEventEnum.bones, shortBonesName);//发送bones技能的事件 UILabel label = GameObject.Find("log").GetComponent <UIInput> ().label; Vector3 pos1 = GameObject.Find("role1").transform.position; Vector3 pos = GameObject.Find("role").transform.position; label.text += "\r\nrole.x=" + pos.x + ";role1.x=" + pos1.x + ";shortBonesName:" + shortBonesName; } }
void observerSel3(MGNotification notification) { print("收到通知:" + notification.name + notification); }
public void triggerFunc(MGNotification notification) { string tag = null, name = null; if (notification.objc is Collider2D)//自己要做的 { tag = (notification.objc as Collider2D).tag; name = (notification.objc as Collider2D).name; } else if (notification.objc is MGMsgModel)//对面要做的 { tag = (notification.objc as MGMsgModel).tag; name = (notification.objc as MGMsgModel).name; } //Debug.Log(tag + ";" + name); if (isBreak) { return; } if (name == "bones(Clone)" || name == "sprint(Clone)") { //Debug.Log("roadblock break"); isBreak = true; try { this.GetComponent <Animator>().SetBool("isBreak", true); } catch { } } if (tag != "Player") { return; } if (name != releaseSkillObjectName) { string strrole = "role"; int irole = strrole.Length; if (name.Length >= irole && name.Substring(0, irole) == strrole) { MGGlobalDataCenter.defaultCenter().isRoadBlockHit = true; } else { MGGlobalDataCenter.defaultCenter().isRoadBlockDefence = true; } //print("技能名:路障。被打中的是" + name + ",释放技能的是" + releaseSkillObjectName); isBreak = true; try{ this.GetComponent <Animator>().SetBool("isBreak", true); }catch {} MGNotificationCenter.defaultCenter().postNotification(RoleButtonEvent.killAnimLatterEventId, name); GameObject objc = GameObject.Find(name); if (objc) { int boneMask = objc.GetComponent <Jump>().stateMask & roleState.bone; int sprintMask = objc.GetComponent <Jump>().stateMask & roleState.sprint; if (boneMask != 0 || sprintMask != 0) { return; } } if (notification.objc is Collider2D) { MGMsgModel skillModel = new MGMsgModel(); skillModel.eventId = SkillEffectEnum.roadblock; skillModel.gameobjectName = name; //发送给自己 MGNotificationCenter.defaultCenter().postNotification(SkillEffectEnum.roadblock, skillModel); } } }