Esempio n. 1
0
    IEnumerator CheckServerInitialized()
    {
        bool isCheck = true;

        while (isCheck)
        {
            yield return(new WaitForSeconds(0.1f));

            if (Application.loadedLevel != (int)GameLeve.WaterwheelNet || Network.peerType == NetworkPeerType.Disconnected)
            {
                if (Toubi.GetInstance() != null &&
                    !Toubi.GetInstance().IsIntoPlayGame)
                {
                    Toubi.GetInstance().IsIntoPlayGame = true;
                }
                continue;
            }
            isCheck = false;
        }

        if (NetworkRpcMsgCtrl.GetInstance() != null)
        {
            NetworkRpcMsgCtrl.GetInstance().RemoveSelf();
        }

        GameObject obj    = GameNetCtrlXK.GetInstance().PlayerObj[0];
        Transform  tran   = GameNetCtrlXK.GetInstance().PlayerPos[0].transform;
        GameObject player = (GameObject)Network.Instantiate(obj, tran.position, tran.rotation, GlobalData.NetWorkGroup);
        WaterwheelPlayerNetCtrl playerScript = player.GetComponent <WaterwheelPlayerNetCtrl>();

        playerScript.SetIsHandlePlayer();

        //create AiPlayer
        CreateAiPlayer();
    }
    // Use this for initialization
    void Start()
    {
        _Instance         = this;
        IsChangeGameMode  = true;
        IsChangeGameLevel = true;
        GlobalData.GetInstance().gameMode = GameMode.None;
        if (TouBiObj != null)
        {
            TouBiScript = TouBiObj.GetComponent <Toubi>();
        }
        SelectObj.SetActive(false);
        ChangeLeve.SetInstance(Leve);

        if (GlobalData.GetInstance().IsFreeMode)
        {
            timer = 1;
            Starts.SetActive(false);
            pcvr.StartLightStateP1 = LedState.Mie;
        }
        else
        {
            Starts.SetActive(true);
            pcvr.StartLightStateP1 = LedState.Shan;
        }

        if (!GlobalData.GetInstance().IsFreeMode)
        {
            Mode.SetActive(false);
        }
        else
        {
            SelectObj.SetActive(true);
            Mode.SetActive(true);
        }
        Leve.SetActive(false);
        StartCoroutine("Timer");

        if (NetCtrlScript == null)
        {
            GameObject netCtrl = GameObject.Find(GlobalData.netCtrl);
            if (netCtrl != null)
            {
                NetCtrlScript = netCtrl.GetComponent <NetCtrl>();
            }
        }

        //单机游戏,跳过联机或单机选择界面.
        if (GlobalData.GetInstance().LinkModeState == 1)
        {
            Starts.SetActive(true);
            Mode.SetActive(true);
            GlobalData.GetInstance().gameMode = GameMode.SoloMode;
            ClickStartBtEvent(ButtonState.UP);
        }

        InputEventCtrl.GetInstance().ClickStartBtEvent += ClickStartBtEvent;
    }
Esempio n. 3
0
    void SendLoadLevelMsgToOthers(int levelVal)
    {
        if (GlobalData.GetInstance().gameLeve == (GameLeve)levelVal)
        {
            return;
        }
        Debug.Log("SendLoadLevelMsgToOthers *********** levelVal " + (GameLeve)levelVal);
        MaxLinkServerCount = Network.connections.Length;
        RequestMasterServer.GetInstance().ResetIsClickConnect();
        Toubi.GetInstance().MakeGameIntoWaterwheelNet();

        GlobalData.GetInstance().gameLeve = (GameLeve)levelVal;
    }
Esempio n. 4
0
    //private List<UISpriteData> spriteList;
    // Use this for initialization
    void Start()
    {
        _Instance = this;
        InitSprite();
        //spriteList=yi_gewei.atlas.spriteList;
//		if(GlobalData.GetInstance().xutoubi==0)
//		{
//		GlobalData.GetInstance().xutoubi=xutoubi;
//		}
        GlobalData.GetInstance().IconCountChange += IconCountChange;
        ConvertNumToImg("xu", GlobalData.GetInstance().XUTOUBI);
        ConvertNumToImg("yi", GlobalData.GetInstance().Icon);

        //Toubi.PlayerPushCoin( 10 ); //test
    }
    IEnumerator CheckConnectToServer()
    {
        if (GlobalData.GetInstance().gameLeve != GameLeve.WaterwheelNet)
        {
            yield break;
        }

        while (true)
        {
            Debug.Log("***************loadedLevel " + Application.loadedLevel
                      + ", IsIntoPlayGame " + Toubi.GetInstance().IsIntoPlayGame);
            if (Application.loadedLevel == (int)GameLeve.WaterwheelNet)
            {
                break;
            }

            if (Application.loadedLevel == (int)GameLeve.Movie)
            {
                if (!Toubi.GetInstance().IsIntoPlayGame)
                {
                    Toubi.GetInstance().StartIntoGame();
                    Toubi.GetInstance().IsIntoPlayGame = true;
                }
                yield return(new WaitForSeconds(0.5f));
            }
        }

        GlobalData.GetInstance().RemoveNetworkRpc();
        int playerIndex = IndexSpawnClient;

        Debug.Log("CheckConnectToServer::playerIndex " + playerIndex);

        GameObject obj    = GameNetCtrlXK.GetInstance().PlayerObj[playerIndex];
        Transform  tran   = GameNetCtrlXK.GetInstance().PlayerPos[playerIndex].transform;
        GameObject player = (GameObject)Network.Instantiate(obj, tran.position, tran.rotation, GlobalData.NetWorkGroup);
        WaterwheelPlayerNetCtrl playerScript = player.GetComponent <WaterwheelPlayerNetCtrl>();

        //playerScript.SetPlayerNetworkPlayer(playerNet);
        playerScript.SetIsHandlePlayer();

        //GameNetCtrlXK.GetInstance().SetPlayerList(player, playerIndex);

        Spawner.SpawnerScript.SpawnNetObj();
    }
    void Start()
    {
        _Instance = this;

        LinkPlayerObj.SetActive(false);
        backgroudSprite        = BackgroudObj.GetComponent <UISprite>();
        backgroudScl           = BackgroudObj.GetComponent <TweenScale>();
        backgroudColor         = BackgroudObj.GetComponent <TweenColor>();
        backgroudScl.enabled   = false;
        backgroudColor.enabled = false;

        ModeObj.transform.localPosition = new Vector3(-1258f, 0f, 0f);
        ModeObj.SetActive(false);

        StartBtObj.SetActive(false);
        ActiveJiaShi.SetActive(false);
        CenterObj.SetActive(false);

        LinkTScl_0  = LinkObj.GetComponents <TweenScale>()[0];
        LinkTScl_1  = LinkObj.GetComponents <TweenScale>()[1];
        DanJiTScl_0 = DanJiObj.GetComponents <TweenScale>()[0];
        DanJiTScl_1 = DanJiObj.GetComponents <TweenScale>()[1];

        LinkSprite  = LinkObj.GetComponent <UISprite>();
        DanJiSprite = DanJiObj.GetComponent <UISprite>();

        MovieObj.SetActive(true);
        InitSprite();

        //GlobalData.GetInstance().IcoinCountChange += IcoinCountChange;
        ConvertNumToImg("xu", GlobalData.GetInstance().XUTOUBI);
        ConvertNumToImg("yi", GlobalData.GetInstance().Icoin);
        audioTouBiStatic = AudioListCtrl.GetInstance().AudioTouBi;

        ShowInsertCoinImg();

        //Toubi.PlayerPushCoin( 10 ); //test
        InputEventCtrl.GetInstance().ClickStartBtOneEvent += clickStartBtOneEvent;
        InputEventCtrl.GetInstance().ClickStartBtTwoEvent += clickStartBtTwoEvent;

        SetPanelCtrl.GetInstance();
        FinishPanelCtrl.IsCanLoadSetPanel = true;         //reset IsCanLoadSetPanel
    }
    void SendLoadLevelMsgToOthers(int levelVal)
    {
        if (GlobalData.GetInstance().gameLeve == (GameLeve)levelVal)
        {
            return;
        }
        Debug.Log("SendLoadLevelMsgToOthers*********** levelVal " + (GameLeve)levelVal);
        MaxLinkServerCount = Network.connections.Length;
        RequestMasterServer.GetInstance().ResetIsClickConnect();
        Toubi.GetInstance().MakeGameIntoWaterwheelNet();

        GlobalData.GetInstance().gameLeve = (GameLeve)levelVal;

        /*if (Network.peerType == NetworkPeerType.Server) {
         *      NetworkServerNet.GetInstance().RemoveMasterServerHost();
         * }*/
        //Application.LoadLevel(levelVal);
        //Application.LoadLevelAsync(levelVal);
        //Debug.Log("SendLoadLevelMsgToOthers -> levelVal = " + levelVal);
    }
Esempio n. 8
0
 void OnDisconnectedFromServer(NetworkDisconnection info)
 {
     if (Network.isServer)
     {
         Debug.Log("Local server connection disconnected");
     }
     else if (info == NetworkDisconnection.LostConnection)
     {
         Debug.Log("Lost connection to the server");
     }
     else
     {
         Debug.Log("Successfully diconnected from the server");
         RequestMasterServer.TimeConnectServer = Time.realtimeSinceStartup;
         if (GlobalData.GetInstance().gameMode == GameMode.OnlineMode &&
             Toubi.GetInstance() != null && !Toubi.GetInstance().IsIntoPlayGame)
         {
             Toubi.GetInstance().IsIntoPlayGame = true;
         }
     }
 }
//	public void InitPlayer()
//	{
//		player=new Player();
//		player.Energy = 100f;
//		player.Speed = 0;
//		player.Score = 0;
//		player.Life = 30;
//		player.LotteryCount = 0;
//		player.FinalRank = 8;
//	}
    public static GlobalData GetInstance()
    {
        if (Instance == null)
        {
            Instance = new GlobalData();
            Instance.InitInfo();
            if (!Directory.Exists(FilePath))
            {
                Directory.CreateDirectory(FilePath);
            }

            //init gameMode
            Instance.gameMode = GameMode.OnlineMode;
            if (Application.loadedLevel == (int)GameLeve.Waterwheel)
            {
                Instance.gameMode = GameMode.SoloMode;
            }

            if (handleJsonObj == null)
            {
                handleJsonObj = HandleJson.GetInstance();
            }

            //start coin info
            startCoinInfo = handleJsonObj.ReadFromFileXml(fileName, "START_COIN");
            if (startCoinInfo == null || startCoinInfo == "")
            {
                startCoinInfo = "1";
                handleJsonObj.WriteToFileXml(fileName, "START_COIN", startCoinInfo);
            }
            Instance.XUTOUBI = Convert.ToInt32(startCoinInfo);
            //Instance.XUTOUBI = 3; //test

            //free mode
            bool   isFreeModeTmp = false;
            string modeGame      = handleJsonObj.ReadFromFileXml(fileName, "GAME_MODE");
            if (modeGame == null || modeGame == "")
            {
                modeGame = "1";
                handleJsonObj.WriteToFileXml(fileName, "GAME_MODE", modeGame);
            }

            if (modeGame == "0")
            {
                isFreeModeTmp = true;
            }
            //isFreeModeTmp = true; //test
            Instance.IsFreeMode = isFreeModeTmp;

            if (Application.loadedLevel == (int)GameLeve.Movie && Application.loadedLevelName == GameLeve.Movie.ToString())
            {
                Toubi.GetInstance().ShowInsertCoinImg();
            }

            //output caiPiao

            /*bool isOutput = true;
             * string outputStr = handleJsonObj.ReadFromFileXml(fileName, "GAME_OUTPUT_TICKET");
             * if(outputStr == null || outputStr == "")
             * {
             *      outputStr = "1";
             *      handleJsonObj.WriteToFileXml(fileName, "GAME_OUTPUT_TICKET", outputStr);
             * }
             *
             * if(outputStr == "0")
             * {
             *      isOutput = false;
             * }
             * Instance.IsOutputCaiPiao = isOutput;*/

            //coin to card num

            /*string ticketNumStr = handleJsonObj.ReadFromFileXml(fileName, "GAME_TICKET_NUM");
             * if(ticketNumStr == null || ticketNumStr == "")
             * {
             *      ticketNumStr = "10";
             *      handleJsonObj.WriteToFileXml(fileName, "GAME_TICKET_NUM", ticketNumStr);
             * }
             * float ticketNum = (float)Convert.ToInt32( ticketNumStr );
             * Instance.CointToTicket = ticketNum;*/

            //ticket rate

            /*string ticketRateStr = handleJsonObj.ReadFromFileXml(fileName, "GAME_TICKET_RATE");
             * if(ticketRateStr == null || ticketRateStr == "")
             * {
             *      ticketRateStr = "1";
             *      handleJsonObj.WriteToFileXml(fileName, "GAME_TICKET_RATE", ticketRateStr);
             * }
             * Instance.TicketRate = ticketRateStr;*/

            //game diff
            string diffStr = handleJsonObj.ReadFromFileXml(fileName, "GAME_DIFFICULTY");
            if (diffStr == null || diffStr == "")
            {
                diffStr = "1";
                handleJsonObj.WriteToFileXml(fileName, "GAME_DIFFICULTY", diffStr);
            }
            Instance.GameDiff = diffStr;

            string val = handleJsonObj.ReadFromFileXml(fileName, "GameAudioVolume");
            if (val == null || val == "")
            {
                val = "7";
                handleJsonObj.WriteToFileXml(fileName, "GameAudioVolume", val);
            }
            GameAudioVolume = Convert.ToInt32(val);

            //SetPanelCtrl.GetInstance();
        }
        return(Instance);
    }
Esempio n. 10
0
    void OnGUI()
    {
        GameScene levelVal = (GameScene)Application.loadedLevel;

        HostData[] data = MasterServer.PollHostList();

        // Go through all the hosts in the host list
        foreach (var element in data)
        {
#if SHOW_NET_INFO
            var name = element.gameName + " " + element.connectedPlayers + " / " + element.playerLimit;
            GUILayout.BeginHorizontal();
            GUILayout.Box(name);
            GUILayout.Space(5);

            var hostInfo = "[";
            foreach (var host in element.ip)
            {
                hostInfo = hostInfo + host + ":" + element.port + " ";
            }
            hostInfo = hostInfo + "]";
            GUILayout.Box(hostInfo);
            GUILayout.Space(5);
            GUILayout.Box(element.comment);
            GUILayout.Space(5);
            GUILayout.FlexibleSpace();
#endif

            if (element.comment == MasterServerGameNetComment &&
                ServerIp == element.ip[0] &&
                Toubi.GetInstance() != null &&
                !Toubi.GetInstance().IsIntoPlayGame)
            {
                Toubi.GetInstance().IsIntoPlayGame = true;
            }

            if (Network.peerType == NetworkPeerType.Disconnected)
            {
                if (!IsClickConnect)
                {
                    bool isConnectServer = false;
                    if (levelVal == GameScene.Scene01_Net &&
                        element.comment == MasterServerGameNetComment &&
                        element.ip[0] != Network.player.ipAddress &&
                        ServerIp == element.ip[0])
                    {
                        if (Time.realtimeSinceStartup - TimeConnectServer > RandConnectTime)
                        {
                            isConnectServer   = true;
                            TimeConnectServer = Time.realtimeSinceStartup;
                            RandConnectTime   = Random.Range(3f, 10f);
                        }
                    }
                    else if (levelVal == GameScene.Movie &&
                             element.comment == MasterServerMovieComment &&
                             element.ip[0] != Network.player.ipAddress &&
                             element.connectedPlayers < element.playerLimit &&
                             Toubi.GetInstance() != null &&
                             Toubi.GetInstance().CheckIsLoopWait())
                    {
                        if (Time.realtimeSinceStartup - TimeConnectServer > RandConnectTime)
                        {
                            isConnectServer   = true;
                            TimeConnectServer = Time.realtimeSinceStartup;
                            RandConnectTime   = Random.Range(3f, 10f);
                        }
                    }

                    if (isConnectServer)
                    {
                        // Connect to HostData struct, internally the correct method is used (GUID when using NAT).
                        Network.RemoveRPCs(Network.player);
                        Network.DestroyPlayerObjects(Network.player);

                        MasterServer.dedicatedServer = false;
                        Network.Connect(element);
                        IsClickConnect = true;
                        if (levelVal == GameScene.Movie)
                        {
                            ServerIp    = element.ip[0];
                            TimeConnect = 0f;
                        }
                        Debug.Log("Connect element.ip -> " + element.ip[0]
                                  + ", element.comment " + element.comment
                                  + ", gameLeve " + levelVal
                                  + ", time " + Time.realtimeSinceStartup.ToString("f2"));
                    }
                }
                else
                {
                    if (levelVal == GameScene.Scene01_Net)
                    {
                        if (element.comment == MasterServerGameNetComment && ServerIp == element.ip[0])
                        {
                            TimeConnect += Time.deltaTime;
                            if (TimeConnect >= 2f)
                            {
                                TimeConnect    = 0f;
                                IsClickConnect = false;
                            }
                        }
                    }
                    else if (levelVal == GameScene.Movie)
                    {
                        TimeConnect += Time.deltaTime;
                        if (TimeConnect >= 2f)
                        {
                            TimeConnect    = 0f;
                            IsClickConnect = false;
                            Debug.Log("reconnect masterServer...");
                        }
                    }
                }
            }
#if SHOW_NET_INFO
            GUILayout.EndHorizontal();
#endif
        }
    }
Esempio n. 11
0
    //float TestDVal;
    void CheckMasterServerList()
    {
        int masterServerNum = 0;
        //int masterServerGameNetNum = 0;
        bool isCreatMasterServer = true;

        HostData[] data = MasterServer.PollHostList();

        // Go through all the hosts in the host list
        foreach (var element in data)
        {
            if (element.comment == MasterServerMovieComment)
            {
                masterServerNum++;
                if (Network.peerType == NetworkPeerType.Disconnected)
                {
                    if (masterServerNum > 0)
                    {
                        isCreatMasterServer = false;
                    }
                }
                else if (Network.peerType == NetworkPeerType.Server)
                {
                    if (masterServerNum > 1 && Random.Range(0, 100) % 2 == 1)
                    {
                        //随机删除1个循环动画场景的masterServer.
                        isCreatMasterServer = false;
                        Debug.Log("random remove masterServer...");
                    }
                }
            }
            else if (element.comment == MasterServerGameNetComment && element.ip[0] == ServerIp)
            {
                //masterServerGameNetNum++;
            }
        }

        GameScene levelVal = (GameScene)Application.loadedLevel;

        if (levelVal == GameScene.Scene01 || levelVal == GameScene.SetPanel)
        {
            isCreatMasterServer = false;
        }

        switch (Network.peerType)
        {
        case NetworkPeerType.Disconnected:
            if (isCreatMasterServer)
            {
                if (levelVal == GameScene.Movie)
                {
                    if ((Toubi.GetInstance() != null && !Toubi.GetInstance().CheckIsLoopWait()) ||
                        Toubi.GetInstance() == null)
                    {
                        return;
                    }
                    ServerIp = "";
                }
                NetworkServerNet.GetInstance().InitCreateServer();
                //MasterServerTime = Time.realtimeSinceStartup;
            }
            break;

        case NetworkPeerType.Server:
            if (!isCreatMasterServer)
            {
                NetworkServerNet.GetInstance().RemoveMasterServerHost();
            }
            else
            {
                if (levelVal == GameScene.Movie)
                {
                    //MasterServerTime = Time.realtimeSinceStartup;
                    if (Toubi.GetInstance() != null && !Toubi.GetInstance().CheckIsLoopWait())
                    {
                        NetworkServerNet.GetInstance().ResetMasterServerHost();
                    }
                }

                /*else if (levelVal == GameLeve.WaterwheelNet) {
                 *
                 *  if (masterServerGameNetNum == 0) {
                 *      TestDVal = Time.realtimeSinceStartup - MasterServerTime;
                 *      if (Time.realtimeSinceStartup - MasterServerTime > 10f) {
                 *          Debug.Log("no masterServer...");
                 *          NetworkServerNet.GetInstance().RemoveMasterServerHost();
                 *          MasterServerTime = Time.realtimeSinceStartup;
                 *      }
                 *  }
                 * }*/
            }
            break;
        }
    }
    void clickStartBt(int key)
    {
        if (!bIsClickStartBt)
        {
            return;
        }

        if (bIsSelectLeve)
        {
            return;
        }
        bIsClickStartBt     = false;
        bIsSelectLeve       = true;
        IsCanActiveSetPanel = false;

        //reset IsSelectGameMode
        StartSenceChangeUI.IsSelectGameMode = false;
        if ((Starts.activeSelf && key == 0) || key == 1)
        {
            Starts.SetActive(false);
            if (GlobalData.GetInstance().LinkModeState != 0 &&
                !GlobalData.GetInstance().IsFreeMode)
            {
                Toubi.GetInstance().subPlayerCoin();
            }

            pcvr.StartLightStateP1 = LedState.Mie;
            if (GlobalData.GetInstance().gameMode == GameMode.OnlineMode)
            {
                LinkPlayerNameCtrl.GetInstance().HiddenPlayerInfo();
                if (key == 0)
                {
                    NetCtrlScript.handleSelectLevel((int)GlobalData.GetInstance().gameLeve);
                }
                else
                {
                    SelectObj.SetActive(false);
                    GlobalData.GetInstance().gameLeve = NetCtrlScript.GetSelectGameLevel();
                    NetCtrlScript.handleResetLinkCount();
                    //ScreenLog.Log("********** level " + GlobalData.GetInstance().gameLeve);
                }
            }

            if (GlobalData.GetInstance().gameMode == GameMode.OnlineMode && key == 0)
            {
                NetCtrlScript.handleLoadLevel();
            }

            if (GlobalData.GetInstance().gameLeve == GameLeve.Leve1)
            {
                Leve2.SetActive(false);
                StopAllCoroutines();
                Leve1.GetComponent <TweenPosition>().enabled = false;
                Leve1Hover.enabled   = false;
                Leve1Unhover.enabled = false;
                //Leve1UI.spriteName="diYiGuanDaTu";
                //Leve1UITexture.mainTexture = Leve1Texture[2];
                Leve1.transform.position    = Vector3.zero;
                Leve1.transform.eulerAngles = Vector3.zero;
                TweenScale scale = Leve1.GetComponent <TweenScale>();
                scale.PlayForward();
                EventDelegate.Add(scale.onFinished, delegate {
                    //AudioManager.Instance.PlayBGM(BackgroundAudio,true);
                    AudioSourceObj      = AudioManager.Instance.audio;
                    AudioSourceObj.clip = BackgroundAudio;
                    AudioSourceObj.loop = true;
                    AudioSourceObj.Play();

                    InvokeRepeating("changeBackgroundSdVol", 0f, 1.5f);
                    StartCoroutine("ColorCorrection");
                });
            }
            else if (GlobalData.GetInstance().gameLeve == GameLeve.Leve2)
            {
                Leve1.SetActive(false);
                StopAllCoroutines();
                Leve2.GetComponent <TweenPosition>().enabled = false;
                Leve2Hover.enabled   = false;
                Leve2UnHover.enabled = false;
                //Leve2UITexture.mainTexture = Leve2Texture[2];
                //Leve2UI.spriteName="diErGuanDaTu";
                Leve2.transform.position    = Vector3.zero;
                Leve2.transform.eulerAngles = Vector3.zero;
                TweenScale scale = Leve2.GetComponent <TweenScale>();
                scale.PlayForward();
                EventDelegate.Add(scale.onFinished, delegate {
                    AudioSourceObj      = AudioManager.Instance.audio;
                    AudioSourceObj.clip = BackgroundAudio;
                    AudioSourceObj.loop = true;
                    AudioSourceObj.Play();

                    InvokeRepeating("changeBackgroundSdVol", 0f, 1.5f);
                    StartCoroutine("ColorCorrection");
                });
            }
        }
    }