public static void ClearReferences() { _playerMonoGo = null; _playerMono = null; _playerCharacter = null; _rpgCamera = null; _playerSave = null; _sceneMasterGameObject = null; _lootSpawner = null; _audioPlayer = null; _playerController = null; _eventHandler = null; _uiHandler = null; _rpgMinimapCamera = null; }
/// <summary> /// 建立3个成员的关联 /// </summary> public void Initialize() { PlayerMono = Player.GameObjectInScene.GetComponent <IPlayerMono>(); if (PlayerMono) { PlayerMono.PlayerMedi = this; PlayerMono.Rgbd = Player.Rgbd; PlayerMono.AnimatorComponent = Player.animator; PlayerWeapon = PlayerMono.iPlayerWeapon; PlayerMono.Initialize(); if (PlayerWeapon != null) { PlayerWeapon.PlayerMedi = this; // 引用 PlayerWeapon.Initialize(); PlayerMono.WeaponCollider = PlayerWeapon.WeaponCollider; } else { Debug.LogWarning("iPlayerWeapon未赋值"); } } }
void InitEnv() { CallBackEvents.Add(Conf.USER_FACADE + "#" + Conf.LOGIN_ACCOUNT, data => { var vo = data as SysUserVO; //var vo = JObject.FromObject(data).ToObject<SysUserVO>(); if (vo != null) { Debug.Log("login success"); SessionInfo._currentSysUserVO = vo; } else { Debug.Log("login failed"); } }); //CallBackEvents.Add(Conf.PK_MATCH_FACADE + "#" + Conf.AUTO_MATCH, // data => // { // }); NotifyEvents.Add(Conf.BATTLE_MATCH_SUCCESS, data => { Debug.Log("Match success"); //切换到战斗界面 //然后发送UIReady NetCtrl.SocketClient.Send(Conf.PK_MATCH_FACADE, Conf.UI_READY, null); }); NotifyEvents.Add(Conf.BATTLE_INIT_DONE, data => { var bro = data as BattleResultBo; if (bro != null) { Debug.Log("BattleInitDone..."); _currentBRB = bro; _todoQue.Enqueue(Conf.BATTLE_INIT_DONE); } }); NotifyEvents.Add(Conf.BATTLE_TIME_IN, data => { _todoQue.Enqueue(Conf.BATTLE_TIME_IN); }); NotifyEvents.Add(Conf.BATTLE_OPT_DONE, data => { var bro = data as BattleResultBo; if (bro != null) { _currentBRB = bro; //播放操作... _todoQue.Enqueue(Conf.BATTLE_OPT_DONE); } }); NotifyEvents.Add(Conf.BATTLE_OVER_TIME, data => { _todoQue.Enqueue(Conf.BATTLE_OVER_TIME); }); _todoQue = new Queue<string>(); _todoDic = new Dictionary<string, Action>(); //战斗初始化 _todoDic.Add(Conf.BATTLE_INIT_DONE, () => { for (int i = 0; i < _currentBRB.halfRound.boardPokers.Count; i++) { //_boardPokers[i].Poker = _currentBRB.halfRound.boardPokers[i]; _boardPokers[_currentBRB.halfRound.boardPokers[i].pos - 1].Poker = _currentBRB.halfRound.boardPokers[i]; } if (IsMe()) { _self.Player = _currentBRB.halfRound.atk; _opponent.Player = _currentBRB.halfRound.def; } else { _self.Player = _currentBRB.halfRound.def; _opponent.Player = _currentBRB.halfRound.atk; } _self.NameLabel.text = _self.Player.pName; _opponent.NameLabel.text = _opponent.Player.pName; _self.HPLable.text = _self.Player.pHp + "/" + _self.Player.pHpMax; _opponent.HPLable.text = _opponent.Player.pHp + "/" + _opponent.Player.pHpMax; //完成后发送AnimReady NetCtrl.SocketClient.Send(Conf.PK_MATCH_FACADE, Conf.ANIM_READY, null); }); //战斗主消息 _todoDic.Add(Conf.BATTLE_OPT_DONE, () => { //_currentBRB.halfRound.detailMfs[0].opt for (int i = 0; i < _currentBRB.halfRound.detailMfs.Count; i++) { var op = _currentBRB.halfRound.detailMfs[i].opt; //Debug.Log(1); var itsyou = op.optOr.pType == 0 && op.optOr.pId == SessionInfo._currentSysUserVO.suId; Debug.Log("odMfs Count" + _currentBRB.halfRound.detailMfs[i].odMfs.Count); for (int j = 0; j < _currentBRB.halfRound.detailMfs[i].odMfs.Count; j++) { var odmf = _currentBRB.halfRound.detailMfs[i].odMfs[j]; if (itsyou) { _self.Player.pHp += odmf.hpMf; _self.HPLable.text = _self.Player.pHp + "/" + _self.Player.pHpMax; } else { _opponent.Player.pHp += odmf.hpMf; _opponent.HPLable.text = _opponent.Player.pHp + "/" + _opponent.Player.pHpMax; } } switch (op.optType) { case OptType.NONE: Debug.Log("飘窗"); if (_currentBRB.halfRound.round == 1) { //第一回合重置棋盘 _boardPokers[_currentBRB.halfRound.boardPokers[i].pos - 1].Poker = _currentBRB.halfRound.boardPokers[i]; } break; case OptType.SKIP: Debug.Log("跳过"); break; case OptType.MAJORSKILL: Debug.Log("武将技"); break; case OptType.PLAYAHAND: if (itsyou) { } else { Debug.Log("敌方出牌"); for (int j = 0; j < op.lineOpt.pokerLines.Count; j++) { //Debug.Log("from: " + op.lineOpt.pokerLines[j].from + " to: " + op.lineOpt.pokerLines[j].to); } for (int j = 0; j < op.lineOpt.pokerMfs.Count; j++) { //Debug.Log("handpos: " + op.lineOpt.pokerMfs[j].handPoker.pos + " etype: " + op.lineOpt.pokerMfs[j].handPoker.elementType); var ophp = _opponent.HandPokers[op.lineOpt.pokerMfs[j].handPoker.pos - 1]; var bdp = _boardPokers[op.lineOpt.pokerMfs[j].boardPos - 1]; //bdp.gameObject.SetActive(false); //ophp.transform.parent = _board.transform; //ophp.transform.localPosition = bdp.transform.localPosition; bdp.Poker = ophp.Poker; ophp.Poker = null; } } break; case OptType.FILLHAND: if (itsyou) { Debug.Log("玩家补牌"); for (int j = 0; j < op.lineOpt.pokerMfs.Count; j++) { //Debug.Log( op.lineOpt.pokerMfs[j].handPoker.pos); //Debug.Log(_self.HandPokers[op.lineOpt.pokerMfs[j].handPoker.pos - 1].transform.parent.name); var shp = _self.HandPokers[op.lineOpt.pokerMfs[j].handPoker.pos - 1]; shp.Reset(); shp.Poker = op.lineOpt.pokerMfs[j].handPoker; shp.gameObject.SetActive(true); } } else { Debug.Log("敌方补牌"); for (int j = 0; j < op.lineOpt.pokerMfs.Count; j++) { //Debug.Log(op.lineOpt.pokerMfs[j].handPoker.pos); var shp = _opponent.HandPokers[op.lineOpt.pokerMfs[j].handPoker.pos - 1]; shp.Reset(); shp.Poker = op.lineOpt.pokerMfs[j].handPoker; shp.gameObject.SetActive(true); } } break; default: break; } } if (_currentBRB.halfRound.gameOver) { Debug.Log("Game Over"); } else { //完成后发送AnimReady NetCtrl.SocketClient.Send(Conf.PK_MATCH_FACADE, Conf.ANIM_READY, null); } }); //战斗计时开始 _todoDic.Add(Conf.BATTLE_TIME_IN, () => { if (IsMe()) { Debug.Log("玩家回合开始"); _self.HandPokers.ForEach(d => { if (d.Poker != null) { d.collider2D.enabled = true; } //d.GetComponent<DragItem>().Reset(); }); } else { Debug.Log("敌方回合开始"); } }); //战斗超时 _todoDic.Add(Conf.BATTLE_OVER_TIME, () => { _canOpt = false; _self.HandPokers.ForEach(d => d.collider2D.enabled = false); }); _board = NGUITools.AddChild(gameObject); _board.name = "board"; //初始化棋盘 _boardPokers = new List<PokerMono>(); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { var go = CreateTestCommponent(_board, "空", new Vector3(Screen.width * -0.2f + Screen.width * j * 0.1f, Screen.height * 0.24f - Screen.height * i * 0.12f), true); var pm = go.AddComponent<PokerMono>(); pm.Label = go.GetComponent<UILabel>(); _boardPokers.Add(pm); } } //初始化玩家 var p = NGUITools.AddChild(gameObject); p.name = "player"; _self = p.AddComponent<PlayerMono>(); var name = CreateTestCommponent(p, "P1", Vector3.zero, false); var hp = CreateTestCommponent(p, "100", new Vector3(0, -Screen.height * 0.12f), false); _self.NameLabel = name.GetComponent<UILabel>(); _self.HPLable = hp.GetComponent<UILabel>(); _self.HandPokers = new List<PokerMono>(); for (int i = 0; i < 5; i++) { var oriPos = new Vector3(-Screen.width * 0.1f + Screen.width * i * 0.05f, -Screen.height * 0.24f); var handp = CreateTestCommponent(p, "空", oriPos, true); var pkm = handp.AddComponent<PokerMono>(); pkm.Label = handp.GetComponent<UILabel>(); pkm.OriPos = oriPos; pkm.OriParent = p.transform; var ut = GetComponent<UIRoot>(); var di = handp.AddComponent<DragItem>(); di.UT = ut; di.PM = pkm; di.OnDragStart = () => { //Debug.Log("drag start"); //取出第一张 if (_self.FirstP != null) { //确定是否在牌桌上 if (di.transform.parent != pkm.OriParent) { //_self.FirstP.gameObject.SetActive(true); _boardPokers[_self.FirstP.InTablePos - 1].gameObject.SetActive(true); _self.FirstP = null; } } }; //var posT1 = new int[] { 1, 5, 21, 25 }; var posT2 = new int[] { 2, 3, 4, 22, 23, 24 }; var posT3 = new int[] { 6, 10, 11, 15, 16, 20, }; di.OnDropOnTable = go => { //牌桌上的牌 var pt = go.GetComponent<PokerMono>(); //手牌 var ph = di.GetComponent<PokerMono>(); if (pt.Poker.valid) { pkm.Reset(); } else { //放第一张 if (_self.FirstP == null) { _self.FirstP = ph; _self.FirstP.InTablePos = pt.Poker.pos; Debug.Log("FirstP in Table:" + _self.FirstP.InTablePos); go.SetActive(false); di.transform.parent = go.transform.parent; di.transform.localPosition = go.transform.localPosition; di.collider2D.enabled = true; } //放第二张 else { //Debug.Log("lololo"); //Debug.Log(_self.FirstP.Poker.pos); var p1 = _self.FirstP.InTablePos; var p2 = pt.Poker.pos; var ok = false; if ((p1 == 1 && p2 == 25) || (p1 == 25 && p2 == 1) || (p1 == 5 && p2 == 21) || (p1 == 21 && p2 == 5)) { //Debug.Log("T1 OK"); ok = true; } else if (posT2.Contains(p1) && (p2 == p1 + 20 || p2 == p1 - 20)) { //Debug.Log("T2 OK"); ok = true; } else if (posT3.Contains(p1) && ((p2 < p1 && p2 == p1 - 4) || (p2 > p1 && p2 == p1 + 4))) { ok = true; if (p1 == 6 && p2 == 2) { ok = false; } //if (ok) Debug.Log("T3 OK"); } if (ok) { _self.SecondP = ph; _self.SecondP.InTablePos = pt.Poker.pos; var bp1 = _boardPokers[_self.FirstP.InTablePos - 1]; bp1.Poker = _self.FirstP.Poker; bp1.gameObject.SetActive(true); var bp2 = _boardPokers[_self.SecondP.InTablePos - 1]; bp2.Poker = _self.SecondP.Poker; //Debug.Log("lasdoasd: " + _self.HandPokers.Any(g => !g.gameObject.activeSelf)); ArrayCollection pokers = new ArrayCollection(); pokers.Add(new PokerMf() { boardPos = p1, handPoker = _self.FirstP.Poker }); pokers.Add(new PokerMf() { boardPos = p2, handPoker = ph.Poker }); Hashtable ht = new Hashtable() { {Conf.OPT_TOKEN, _currentBRB.halfRound.lastOpt.optToken}, {Conf.OPT_TYPE,(int)OptType.PLAYAHAND}, {Conf.HAND_POKERS,pokers} }; NetCtrl.SocketClient.Send(Conf.PK_MATCH_FACADE, Conf.DO_OPT, ht); //重置 _self.FirstP.Reset(); _self.SecondP.Reset(); _self.FirstP.Poker = _self.SecondP.Poker = null; _self.FirstP = _self.SecondP = null; _canOpt = false; _self.HandPokers.ForEach(d => d.collider2D.enabled = false); } else { Debug.Log("wrong put"); pkm.Reset(); } } } }; handp.collider2D.enabled = false; _self.HandPokers.Add(pkm); } p.transform.localPosition = new Vector3(-Screen.width * 0.38f, 0); //对手 p = NGUITools.AddChild(gameObject); p.name = "opponent"; _opponent = p.AddComponent<PlayerMono>(); name = CreateTestCommponent(p, "P2", Vector3.zero, false); hp = CreateTestCommponent(p, "100", new Vector3(0, -Screen.height * 0.12f), false); _opponent.NameLabel = name.GetComponent<UILabel>(); _opponent.HPLable = hp.GetComponent<UILabel>(); _opponent.HandPokers = new List<PokerMono>(); for (int i = 0; i < 5; i++) { var oriPos = new Vector3(-Screen.width * 0.1f + Screen.width * i * 0.05f, -Screen.height * 0.24f); var handp = CreateTestCommponent(p, "空", oriPos, true); var pkm = handp.AddComponent<PokerMono>(); pkm.Label = handp.GetComponent<UILabel>(); handp.collider2D.enabled = false; _opponent.HandPokers.Add(pkm); } p.transform.localPosition = new Vector3(Screen.width * 0.38f, 0); _canOpt = false; }