Exemplo n.º 1
0
    void LoadLocalDLL()
    {
        Logger.Log("LoadLocalDLL " + DLLLoaclPath);
        Type t;

        if (ApplicationEx.platform == RuntimePlatform.WindowsEditor || ApplicationEx.platform == RuntimePlatform.IPhonePlayer)
        {
            t = GetTypeFromAssembly();
            Logger.Log("WindowsEditor Temp ");
            EnterGame(t);
            return;
        }
        SetupUI.instance.SetHint("载入资源中");
        StartCoroutine(LoadFileForm(URLs.FILE_PROTOCOL + DLLLoaclPath,
                                    (p) =>
        {
        },
                                    (www, errorInfo) =>
        {
            if (!string.IsNullOrEmpty(errorInfo))
            {
                Logger.Error("LoadLocalDLL Error " + errorInfo);
                return;
            }
            //Logger.Assert(www != null, "download file bytes empty error:" + errorInfo);
            byte[] dllData = www.assetBundle.LoadAllAssets <TextAsset>()[0].bytes;
            www.assetBundle.Unload(false);
            Action enter = () =>
            {
                t = GetTypeFromAssembly(dllData);
                EnterGame(t);
            };
            GameStart.Invoke(enter);
        }));
    }
Exemplo n.º 2
0
    public static void ExportFile(string path, Action <float> loading, Action <byte[], string> loaded)
    {
        var    lowerPath = path.ToLower();
        string apkPath   = URLs.streamingAssetsPath + lowerPath;
        string savePath  = URLs.persistentDataPath + lowerPath;

        Logger.Log("[ExportFile]" + apkPath + " " + savePath);
        instance.StartCoroutine(instance.LoadFileForm(apkPath, loading,
                                                      (www, errorInfo) =>
        {
            if (!string.IsNullOrEmpty(errorInfo))
            {
                GameStart.Invoke(() =>
                {
                    loaded(null, errorInfo);
                });
                return;
            }

            byte[] bytes = www.bytes;
            GameStart.Invoke(() =>
            {
                if (bytes != null && bytes.Length != 0)
                {
                    errorInfo = SaveFile(bytes, savePath, false);
                }
                loaded(bytes, errorInfo);
            });
        }));
    }
Exemplo n.º 3
0
 void StartHotUpdate()
 {
     GetApkRootCfg(() =>
     {
         GameStart.Invoke(FirstExport);
     });
 }
Exemplo n.º 4
0
    private void GetApkRootCfg(Action callback)
    {
        Logger.Log("GetApkRootCfg: " + APKRootCfgPath);

        StartCoroutine(LoadFileForm(APKRootCfgPath,
                                    (p) =>
                                    {     },
                                    (www, errorInfo) =>
        {
            if (www == null || !string.IsNullOrEmpty(errorInfo))
            {
                Logger.Error("get ApkRootCfg file empty error:" + errorInfo);
                PluginMsgAction.Instance.ShowMsgBox("ApkRootCfg :" + errorInfo, "重试", "退出", () =>
                {
                    PluginMsgAction.Instance.HideMsgBox();
                    Logger.Log("get ApkRootCfg file retry");
                    GameStart.Invoke(StartHotUpdate);
                },
                                                    () =>
                {
                    Application.Quit();
                });
                return;
            }
            string content = Encoding.Default.GetString(www.bytes);
            _apkRootXML.LoadXml(content);
            GameStart.Invoke(callback);
        }));
    }
Exemplo n.º 5
0
    void GetNewestMD5Version()
    {
        _serverMD5Version = GetMD5Version(_serverRootXML);
        Logger.Log("[CheckMD5Version] version local:" + _localMD5Version + " vs server:" + _serverMD5Version);
        if (_serverMD5Version == _localMD5Version && File.Exists(ServerMD5ZipFilePath))
        {
            GameStart.Invoke(CheckDllVersion);
            return;
        }

        Action <string> downloadResult = (error) =>
        {
            if (string.IsNullOrEmpty(error))
            {
                if (File.Exists(ServerMD5FilePath))
                {
                    File.Delete(ServerMD5FilePath);
                }
                SetMD5Version(_localRootXML, _serverMD5Version);
                SaveLocalRootXML();
                _localMD5Version = _serverMD5Version;
                GameStart.Invoke(CheckDllVersion);
            }
        };

        Action downloadDll = () =>
        {
            string fileName = _serverRootXML.SelectSingleNode("/root/Version").Attributes["md5url"].Value;
            DownloadFileFromServer(_serverMD5Version, fileName, ServerMD5ZipFilePath, downloadResult);
        };

        GameStart.Invoke(downloadDll);
    }
Exemplo n.º 6
0
    private void DownloadDllAndEnterGame()
    {
        _serverDLLVersion = GetDLLVersion(_serverRootXML);
        Action <WWW, string> downloadResult = (www, error) =>
        {
            if (!string.IsNullOrEmpty(error))
            {
                Logger.Error("Download Dll Error " + error);
                return;
            }
            //Logger.Assert(www != null, "download file bytes empty error:" + error);

            byte[] dllData = www.bytes;
            Action enter   = () =>
            {
                Type t = GetTypeFromAssembly(dllData);
                EnterGame(t);
            };
            GameStart.Invoke(enter);
        };

        Action downloadDll = () =>
        {
            string fileName = _serverRootXML.SelectSingleNode("/root/Version").Attributes["url"].Value;
            StartCoroutine(LoadFileForm(DownloadMgr.Instance.GetRandomParasUrl(fileName), null, downloadResult));
        };

        GameStart.Invoke(downloadDll);
    }
Exemplo n.º 7
0
    void CheckDllVersion()
    {
        //iphone 依然有dll版本,dll版本为基包值。
        _serverDLLVersion = GetDLLVersion(_serverRootXML);
        Logger.Log("[CheckDllVersion] version local:" + _localDLLVersion + " vs server:" + _serverDLLVersion);
        if (_serverDLLVersion <= _localDLLVersion)
        {
            GameStart.Invoke(LoadLocalDLL);
            return;
        }

        Action <string> downloadResult = (error) =>
        {
            if (string.IsNullOrEmpty(error))
            {
                SetDLLVersion(_localRootXML, _serverDLLVersion);
                SaveLocalRootXML();
                _localDLLVersion = _serverDLLVersion;
                GameStart.Invoke(LoadLocalDLL);
            }
        };

        Action downloadDll = () =>
        {
            var t = new Thread(LogIpAddressAndMobileIP);
            t.Start();
            string fileName = _serverRootXML.SelectSingleNode("/root/Version").Attributes["dllurl"].Value;
            DownloadFileFromServer(_serverDLLVersion, fileName, DLLLoaclPath, downloadResult);
        };

        GameStart.Invoke(downloadDll);
    }
Exemplo n.º 8
0
    void LoadStreamingDllAndEnterGame()
    {
        SetupUI.instance.SetHint("LoadStreamingDllAndEnterGame");
        var streamingDllPath = URLs.streamingAssetsPath + DLLFileName;

        Logger.Error("LoadStreamingDllAndEnterGame:" + URLs.FILE_PROTOCOL + streamingDllPath);
        StartCoroutine(LoadFileForm(URLs.FILE_PROTOCOL + streamingDllPath, (p) => {
            SetupUI.instance.SetHint("LoadStreamingDllAndEnterGame:" + p);
        },
                                    (www, errorInfo) => {
            Logger.Log("LoadStreamingDllAndEnterGame final");
            if (!string.IsNullOrEmpty(errorInfo))
            {
                Logger.Error("LoadStreamingDll Error " + errorInfo);
                return;
            }
            SetupUI.instance.SetHint("UnLoadDLL:");
            //Logger.Assert(www != null, "download file bytes empty error:" + errorInfo);
            byte[] dllData = www.assetBundle.LoadAllAssets <TextAsset>()[0].bytes;
            www.assetBundle.Unload(false);
            Action enter = () =>
            {
                SetupUI.instance.SetHint("GetTypeFromAssembly:");
                Type t = GetTypeFromAssembly(dllData);
                EnterGame(t);
            };
            GameStart.Invoke(enter);
        }));
    }
Exemplo n.º 9
0
        public async Task ConnectAsync()
        {
            connection = new HubConnection(url);
            hubProxy   = connection.CreateHubProxy("ChatHub");
            hubProxy.On <User>("ParticipantLogin", (u) => ParticipantLoggedIn?.Invoke(u));
            hubProxy.On <string>("ParticipantLogout", (n) => ParticipantLoggedOut?.Invoke(n));
            hubProxy.On <string>("ParticipantDisconnection", (n) => ParticipantDisconnected?.Invoke(n));
            hubProxy.On <string>("ParticipantReconnection", (n) => ParticipantReconnected?.Invoke(n));
            hubProxy.On <string>("BroadcastGameStart", (n) => GameStart?.Invoke(n, MessageType.Broadcast));
            hubProxy.On <string>("BroadcastGameEnd", (n) => GameEnd?.Invoke(n, MessageType.Broadcast));
            hubProxy.On <string, string>("BroadcastSetHost", (n, m) => SetNewHost?.Invoke(n, m, MessageType.Broadcast));
            hubProxy.On <string, string>("BroadcastTextMessage", (n, m) => NewTextMessage?.Invoke(n, m, MessageType.Broadcast));
            hubProxy.On <string, byte[]>("BroadcastPictureMessage", (n, m) => NewImageMessage?.Invoke(n, m, MessageType.Broadcast));
            hubProxy.On <string, byte[]>("BroadcastStrokes", (n, m) => NewStrokesCollected?.Invoke(n, m, MessageType.Broadcast));
            hubProxy.On <string, string>("BraodcastAnswerIsRight", (n, m) => Correct?.Invoke(n, m));
            hubProxy.On <string, string>("UnicastTextMessage", (n, m) => NewTextMessage?.Invoke(n, m, MessageType.Unicast));
            hubProxy.On <string, byte[]>("UnicastPictureMessage", (n, m) => NewImageMessage?.Invoke(n, m, MessageType.Unicast));
            hubProxy.On <string>("ParticipantTyping", (p) => ParticipantTyping?.Invoke(p));

            connection.Reconnecting += Reconnecting;
            connection.Reconnected  += Reconnected;
            connection.Closed       += Disconnected;

            ServicePointManager.DefaultConnectionLimit = 10;
            await connection.Start();
        }
Exemplo n.º 10
0
    void Progress(float p)
    {
        DownloadTask currentTask = _task;

        GameStart.Invoke(() =>
        {
            currentTask.OnProgress(p);
        });
    }
Exemplo n.º 11
0
    private void OnDownloadServerRootFailed()
    {
        Logger.Error("CheckServerVersion Download serverCfg Failed");
        Action errorCallback = () =>
        {
            ShowErrorInfo("检查服务器版本出错", WebPlayerCheckServerVersion);
        };

        GameStart.Invoke(errorCallback);
    }
Exemplo n.º 12
0
 public static void StartGame()
 {
     GameStart?.Invoke();
     GameStartOrRestart?.Invoke();
     CurrentGameState = GameState.Playing;
     if (Instance.debug)
     {
         Debug.Log("Start Game");
     }
 }
Exemplo n.º 13
0
    /// <summary>
    /// Start the game
    /// </summary>
    private void StartGameRunning()
    {
        gameState = GAME_STATE.Playing;

        //Send chat message
        TwitchChatClient.Instance.SendChatMessageTargeted(playerList.GetJoinedUsernames(), "The game is now starting!");

        //Start Game
        GameStart?.Invoke();
    }
Exemplo n.º 14
0
 public void Start()
 {
     EnemySpawner  = new EnemySpawner(width, height);
     Player        = new Player(width, height);
     BulletsFolder = new BulletsFolder();
     level         = 5;
     Score         = 0;
     GameStart?.Invoke();
     EnemySpawner.CreateAsteroidWave(level);
 }
Exemplo n.º 15
0
        private void InteractFieldUnopened(Field field)
        {
            if (!_isFirstFieldRevealed)
            {
                _isFirstFieldRevealed = true;
                PlaceMines(field);
                GameStart?.Invoke();
            }

            OpenField(field);
        }
Exemplo n.º 16
0
    //添加一个网络异常处理的功能,mycontinue跳过当前这个下载下一个
    public static void Handle(string fileName, Exception e, Action giveup, Action again, Action finished = null)
    {
        Logger.Error(e.Message + "\n[Track]" + e.StackTrace);
        Action action = () =>
        {
            //Logger.Log("webclient error:" + e.Message);
            if (e.Message.Contains("ConnectFailure") || //连接失败
                e.Message.Contains("NameResolutionFailure") || //域名解析失败
                e.Message.Contains("No route to host"))    //找不到主机
            {
                Logger.Error("-----------------Webclient ConnectFailure-------------");
                //异常时弹出网络设置对话框
                ShowMsgBoxForNetworkDisconnect(again, ":" + e.Message);
            }
            else
            //(404) Not Found
            if (e.Message.Contains("(404) Not Found") || e.Message.Contains("403"))
            {
                Logger.Error("-----------------WebClient NotFount-------------");
                //抛出一个error,并且继续下载下一个
                //mycontinue();
                //服务器维护中,请稍后再试
                ShowMsgForServerMaintenance(again, ":" + e.Message);
            }
            else
            //Disk full
            if (e.Message.Contains("Disk full"))
            {
                Logger.Error("-----------------WebClient Disk full-------------");
                ShowMsgBoxForDiskFull(fileName, again, ":" + e.Message);
            }
            else
            //timed out
            if (e.Message.Contains("timed out") || e.Message.Contains("Error getting response stream"))
            {
                Logger.Error("-----------------WebClient timed out-------------");
                //again();
                ShowMsgForTimeout(again, ":" + e.Message);
            }
            else
            //Sharing violation on path
            if (e.Message.Contains("Sharing violation on path"))
            {
                Logger.Error("-----------------WebClient Sharing violation on path-------------");
                again();
            }
            else
            {
                ShowMsgForUnknown(again, ":" + e.Message);
            }
        };

        GameStart.Invoke(action);
    }
Exemplo n.º 17
0
        private void AddLevelsList(Panel levelPanel, KeyValuePair <string, List <string> > serie)
        {
            SelectList levelsList = new SelectList(new Vector2(0, 300));

            foreach (var level in serie.Value)
            {
                levelsList.AddItem(level);
            }

            levelsList.OnValueChange = (Entity entity) =>
            {
                var loader    = new LevelLoader();
                var serieName = serie.Key;
                var levelName = levelsList.SelectedValue;
                loader.Load(new Level(serieName, levelName));
                var data = new HashSet <GameObject>();
                data.UnionWith(loader.Walls);
                data.UnionWith(loader.Boxes);
                data.UnionWith(loader.CellsForBoxes);
                data.Add(loader.Storekeeper);

                previewLevel = new Field(data, loader.Size, content.BlocksTextures);
                var startPoint  = new Point(graphics.PreferredBackBufferWidth / 2 - 100, graphics.PreferredBackBufferHeight / 4);
                var sizeOfField = new Point(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2);
                previewLevel.Init(startPoint, sizeOfField);
            };
            levelPanel.AddChild(levelsList);
            AddButton(levelPanel, "Start",
                      (Entity btn) =>
            {
                if (levelsList.SelectedValue == null)
                {
                    return;
                }
                seriesPanel.Visible = false;
                levelPanel.Visible  = false;
                var serieName       = serie.Key;
                var levelName       = levelsList.SelectedValue;
                gameModel.LoadLevel(new Level(serieName, levelName));
                GameStart?.Invoke();
                previewLevel = null;
            });
            levelPanel.AddChild(new HorizontalLine());
            AddButton(levelPanel, "Back",
                      (Entity btn) =>
            {
                seriesPanel.Visible = true;
                levelPanel.Visible  = false;
                previewLevel        = null;
            });
        }
Exemplo n.º 18
0
    public static void ShowMsgBoxForWWWError(Action again, string msg = "")
    {
        Logger.Log("ShowMsgBoxForWWWError " + msg);
        Action act = () =>
        {
            PluginMsgAction.Instance.ShowMsgBox("下载失败:" + msg, "重试", "退出", () =>
            {
                PluginMsgAction.Instance.HideMsgBox();
                again();
            },
                                                () =>
            {
                Application.Quit();
            });
        };

        GameStart.Invoke(act);
    }
Exemplo n.º 19
0
    //服务器维护中,下载文件404/403时使用
    private static void ShowMsgForServerMaintenance(Action again, string msg = "")
    {
        Logger.Log("ShowMsgForServerMaintenance");
        Action act = () =>
        {
            PluginMsgAction.Instance.ShowMsgBox("服务器维护中,请稍后再试", "重试", "退出", () =>
            {
                PluginMsgAction.Instance.HideMsgBox();
                again();
            },
                                                () =>
            {
                Application.Quit();
            });
        };

        GameStart.Invoke(act);
    }
Exemplo n.º 20
0
    //超时,采用倒计时对话框
    private static void ShowMsgForTimeout(Action again, string msg = "")
    {
        Logger.Log("ShowMsgForTimeout");
        Action act = () =>
        {
            PluginMsgAction.Instance.ShowMsgBox("网络异常", "重试", "退出", () =>
            {
                PluginMsgAction.Instance.HideMsgBox();
                again();
            },
                                                () =>
            {
                Application.Quit();
            });
        };

        GameStart.Invoke(act);
    }
Exemplo n.º 21
0
 void CheckNetwork(Action callback)
 {
     GameStart.Invoke(callback);
     //
     //        if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork) //wifi
     //        {
     //            GameStart.Invoke(callback);
     //            return;
     //        }
     //
     //        if (Application.internetReachability == NetworkReachability.NotReachable) //无网络
     //        {
     //            PluginMsgAction.Instance.ShowMsgBox("网络异常,未找到可用网络", "设置网络", "重试", () =>
     //            {
     //                PlatformSDKPlugin.instance.OpenNetworkSetting();
     //            }, () =>
     //            {
     //                PluginMsgAction.Instance.HideMsgBox();
     //                CheckNetwork(callback);
     //            });
     //            return;
     //        }
     //
     //        if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork) //移动数据
     //        {
     //            if (allowDownloadBy3G)
     //            {
     //                GameStart.Invoke(callback);
     //            }
     //            else
     //            {
     //                PluginMsgAction.Instance.ShowMsgBox("检测到当前在使用移动数据,可能会产生一些流量消耗,是否继续使用?", "设置网络", "继续", () =>
     //                {
     //                    PlatformSDKPlugin.instance.OpenNetworkSetting();
     //                }, () =>
     //                {
     //                    allowDownloadBy3G = true;
     //                    PluginMsgAction.Instance.HideMsgBox();
     //                    GameStart.Invoke(callback);
     //                });
     //            }
     //            return;
     //        }
 }
Exemplo n.º 22
0
    void Finished(WWW www, string error)
    {
        DownloadTask currentTask = _task;

        if (www == null)
        {
            isLoading = false;
            NetworkErrorHandle.ShowMsgBoxForWWWError(() =>
            {
                //跳过当前这个下载下一个
                currentTask.state = DownloadTaskState.Retry;
                _mgr.CheckDownLoadList();
            }, error);
            return;
        }
        Exception ex = CheckMd5(www, currentTask);

        if (ex != null)
        {
            isLoading = false;
            NetworkErrorHandle.Handle(currentTask.itemPath, ex,
                                      () =>
            {
                //跳过当前这个下载下一个
                currentTask.state = DownloadTaskState.Failed;
                _mgr.CheckDownLoadList();
            },
                                      () =>
            {
                //从新下载这个
                currentTask.state = DownloadTaskState.Retry;
                _mgr.CheckDownLoadList();
            });
            www.Dispose();
            return;
        }
        //Logger.Assert(currentTask.state == DownloadTaskState.Success, " task state must be Success " + currentTask.state);
        isLoading       = false;
        currentTask.www = www;
        GameStart.Invoke(() =>
        {
            _mgr.CheckDownLoadList();
        });
    }
Exemplo n.º 23
0
        private void OnPlayerCountSelected(object sender, EventArgs e)
        {
            var control = (Control)sender;

            if (!int.TryParse(control.Text, out int playerCount))
            {
                playerCount = 1;
            }

            var players = new Player[playerCount];

            for (int i = 0; i < playerCount; i++)
            {
                players[i] = new Player("Giocatore " + (i + 1));
            }
            _gameMode.Players = players;

            GameStart?.Invoke(this, new GameStartArgs(_gameMode));
        }
Exemplo n.º 24
0
    void CheckServerVersion()
    {
        SetupUI.instance.SetHint("检查服务器版本");
        SetupUI.instance.SetProgress(0.3f);
        string serverCfgURL = GetServerCfgURL();

        Logger.Log("CheckServerVersion Download " + serverCfgURL);
        DownloadMgr.Instance.AsynDownLoadText(serverCfgURL, (text) =>
        {
            _serverRootXML.LoadXml(text);
            URLs.versionRootPath = _serverRootXML.SelectSingleNode("/root/VersionPath").Attributes["url"].Value;

            bool needReInstall = IsNeedReInstall();
            if (needReInstall)
            {
                Action errorCallback = () =>
                {
                    Logger.Log("IsNeedReInstall ");
                    PluginMsgAction.Instance.ShowMsgBox("发现新版本, 请下载新版本后覆盖安装", "确定", "退出", () =>
                    {
                        Application.Quit();
                    }, () =>
                    {
                        Application.Quit();
                    });
                };
                GameStart.Invoke(errorCallback);
                return;
            }
            GetNewestMD5Version();
        },
                                              () =>
        {
            Logger.Error("CheckServerVersion Download serverCfg Failed");
            Action errorCallback = () =>
            {
                ShowErrorInfo("检查服务器版本出错", CheckServerVersion);
            };
            GameStart.Invoke(errorCallback);
        }
                                              );
    }
Exemplo n.º 25
0
    private static void ShowMsgBoxForNetworkDisconnect(Action again, string msg = "")
    {
        Logger.Log("ShowMsgBoxForNetworkDisconnect");
        Action act = () =>
        {
            PluginMsgAction.Instance.ShowMsgBox("网络异常", "重试", "设置网络", () =>
            {
                PluginMsgAction.Instance.HideMsgBox();
                again();
            },
                                                () =>
            {
#if UNITY_ANDROID
                var jc            = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
                var mMainActivity = jc.GetStatic <AndroidJavaObject>("currentActivity");
                mMainActivity.Call("gotoNetworkSetting");
#endif
            });
        };

        GameStart.Invoke(act);
    }
Exemplo n.º 26
0
    private static void ShowMsgBoxForDiskFull(string fileName, Action again, string msg = "")
    {
        Logger.Log("ShowMsgBoxForDiskFull:" + fileName);
        if (File.Exists(fileName))
        {
            Logger.Log("Delete:" + fileName);
            File.Delete(fileName);
        }
        Action act = () =>
        {
            PluginMsgAction.Instance.ShowMsgBox("SD卡空间不足", "重试", "退出", () =>
            {
                PluginMsgAction.Instance.HideMsgBox();
                again();
            },
                                                () =>
            {
                Application.Quit();
            });
        };

        GameStart.Invoke(act);
    }
Exemplo n.º 27
0
    void Start()
    {
        Countdown.onCountdownEnd.AddListener(EnableBoard);
        onGameReset.AddListener(Reset);
        onGameStart.AddListener(StartGame);
        difficultySettingsData = new DifficultySettingsData();
        InitialiseStatPlayerPrefs();
        onGameReset.Invoke();

        customSettingInfo = difficultySettingsData.Difficulties.CustomPlayerPref;
        if (!PlayerPrefs.HasKey(customSettingInfo.Col.Name))
        {
            PlayerPrefs.SetInt(customSettingInfo.Col.Name, customSettingInfo.Col.InitialValue);
        }
        if (!PlayerPrefs.HasKey(customSettingInfo.Row.Name))
        {
            PlayerPrefs.SetInt(customSettingInfo.Row.Name, customSettingInfo.Row.InitialValue);
        }

        Difficulty currentGameDifficulty = GameDifficulty.gameDifficulty.GetCurrentGameDifficulty();

        onGameStart.Invoke(GetDifficultyInfo(currentGameDifficulty));
        DontDestroyOnLoadManager.RemoveObj(GameDifficulty.gameDifficulty.gameObject);
    }
Exemplo n.º 28
0
 public void Begin()
 {
     GameStart?.Invoke();
     _coroutineRunner.RunCoroutine(GameRoutine());
 }
 protected virtual void OnGameStart()
 {
     GameStart?.Invoke(this, new GameStartEventArgs());
 }
Exemplo n.º 30
0
 protected virtual void OnGameStart(LeagueEventArgs args) => GameStart?.Invoke(this, args);