public override void OnInspectorGUI()
 {
     if (GUILayout.Button("Open Editor"))
     {
         GameDataEditorWindow.Open((GameDataObject)target);
     }
 }
Beispiel #2
0
        private static void ResetPreferences()
        {
            var userDataDirectory = Settings.GetLocalUserDataPath();

            if (Directory.Exists(userDataDirectory) == false)
            {
                return;
            }

            GameDataEditorWindow.FindAllAndClose();

            Directory.Delete(userDataDirectory, recursive: true);
        }
    public static bool OpenEditor(int instanceId, int line)
    {
        // Check if the double clicked asset is an asset of type GameDataObject
        GameDataObject obj = EditorUtility.InstanceIDToObject(instanceId) as GameDataObject;

        // If it is Open the Editor Window
        if (obj != null)
        {
            GameDataEditorWindow.Open(obj);
            return(true);
        }

        return(false);
    }
        // -------------------------------------------------------------------
        // Public
        // -------------------------------------------------------------------
        public void Configure()
        {
            GameDataBuilder.TargetFile = Constants.GameDataDataFile;

            GameDataEditorWindow.ClearWorkspaces();
            GameDataEditorWindow.ClearContent();

            foreach (DataWorkspace workspace in EnumCache <DataWorkspace> .Values)
            {
                GameDataEditorWindow.AddWorkSpace((int)workspace, workspace.ToString());
            }

            GameDataEditorWindow.AddContent <GameDataAudio>("Audio", (int)DataWorkspace.Visual);
            GameDataEditorWindow.AddContent <GameDataVFX>("VFX", (int)DataWorkspace.Visual);
            GameDataEditorWindow.AddContent <GameDataFaction>("Faction", (int)DataWorkspace.Gameplay);
            GameDataEditorWindow.AddContent <GameDataRace>("Race", (int)DataWorkspace.Gameplay);
            GameDataEditorWindow.AddContent <GameDataClass>("Class", (int)DataWorkspace.Gameplay);
            GameDataEditorWindow.AddContent <GameDataTag>("Tag", (int)DataWorkspace.Gameplay);
            GameDataEditorWindow.AddContent <GameDataRarity>("Rarity", (int)DataWorkspace.Items, (int)DataWorkspace.Gameplay);
        }
Beispiel #5
0
    public static void Open(GameDataObject dataObject)
    {
        GameDataEditorWindow window = GetWindow <GameDataEditorWindow>("Game Data Editor");

        window.serializedObject = new SerializedObject(dataObject);
    }
Beispiel #6
0
        private static IEnumerable DownloadCharonAsync(Action <string, float> progressCallback = null)
        {
            var checkRequirements = CharonCli.CheckRequirementsAsync();

            yield return(checkRequirements);

            var checkResult = checkRequirements.GetResult();

            if (checkResult == RequirementsCheckResult.MissingRuntime)
            {
                yield return(UpdateRuntimeWindow.ShowAsync());
            }

            var currentVersion = default(Version);
            var charonPath     = Path.GetFullPath(Settings.CharonPath);
            var toolName       = Path.GetFileNameWithoutExtension(Path.GetFileName(charonPath));

            if (File.Exists(charonPath))
            {
                if (progressCallback != null)
                {
                    progressCallback(Resources.UI_UNITYPLUGIN_PROGRESS_CHECKING_TOOLS_VERSION, 0.05f);
                }

                var checkToolsVersion = CharonCli.GetVersionAsync();
                yield return(checkToolsVersion.IgnoreFault());

                currentVersion = checkToolsVersion.HasErrors ? default(Version) : checkToolsVersion.GetResult();
            }

            if (progressCallback != null)
            {
                progressCallback(Resources.UI_UNITYPLUGIN_PROGRESS_GETTING_AVAILABLE_BUILDS, 0.10f);
            }

            var getBuildsAsync = UpdateServerCli.GetBuilds(UpdateServerCli.PRODUCT_CHARON);

            yield return(getBuildsAsync.IgnoreFault());

            if (getBuildsAsync.HasErrors)
            {
                if (progressCallback != null)
                {
                    progressCallback(Resources.UI_UNITYPLUGIN_PROGRESS_DONE, 1.0f);
                }

                Debug.LogError(string.Format("Failed to get builds list from server. Error: {0}", getBuildsAsync.Error.Unwrap().Message));
                yield break;
            }

            var builds          = getBuildsAsync.GetResult();
            var buildsByVersion = builds.ToDictionary(b => b.Version);
            var lastBuild       = builds.OrderByDescending(b => b.Version).FirstOrDefault();

            if (lastBuild == null)
            {
                if (progressCallback != null)
                {
                    progressCallback(Resources.UI_UNITYPLUGIN_PROGRESS_DONE, 1.0f);
                }

                if (Settings.Current.Verbose)
                {
                    Debug.Log(string.Format("No builds of {0} are available.", toolName));
                }
                yield break;
            }

            var currentBuild = currentVersion != null?builds.FirstOrDefault(b => b.Version == currentVersion) : null;

            var lastVersion     = lastBuild.Version;
            var isMissing       = File.Exists(charonPath);
            var actualHash      = isMissing || currentBuild == null ? null : FileAndPathUtils.ComputeHash(charonPath, currentBuild.HashAlgorithm);
            var isCorrupted     = currentBuild != null && string.Equals(currentBuild.Hash, actualHash, StringComparison.OrdinalIgnoreCase) == false;
            var expectedVersion = string.IsNullOrEmpty(Settings.Current.EditorVersion) ? default(Version) : new Version(Settings.Current.EditorVersion);

            if (!isMissing && !isCorrupted && expectedVersion == currentVersion && currentVersion != null)
            {
                if (progressCallback != null)
                {
                    progressCallback(Resources.UI_UNITYPLUGIN_PROGRESS_DONE, 1.0f);
                }

                if (Settings.Current.Verbose)
                {
                    Debug.Log(string.Format("{0} version '{1}' is expected and file is not corrupted.", toolName, currentVersion));
                }
                yield break;
            }

            var versionToDownload = expectedVersion ?? lastVersion;

            if (buildsByVersion.ContainsKey(versionToDownload) == false)
            {
                if (progressCallback != null)
                {
                    progressCallback(Resources.UI_UNITYPLUGIN_PROGRESS_DONE, 1.0f);
                }

                Debug.LogError(string.Format("Build of {0} with version '{1}' is not available to download.", toolName, versionToDownload));
                yield break;
            }

            if (progressCallback != null)
            {
                progressCallback(string.Format(Resources.UI_UNITYPLUGIN_PROGRESS_DOWNLOADINGS, 0, 0), 0.10f);
            }

            var downloadPath  = Path.GetTempFileName();
            var downloadAsync = UpdateServerCli.DownloadBuild(UpdateServerCli.PRODUCT_CHARON, versionToDownload, downloadPath, progressCallback);

            yield return(downloadAsync.IgnoreFault());

            if (downloadAsync.HasErrors)
            {
                if (progressCallback != null)
                {
                    progressCallback(Resources.UI_UNITYPLUGIN_PROGRESS_DONE, 1.0f);
                }

                Debug.LogError(string.Format("Failed to download build of {0} with version '{1}'.{2}{3}", toolName, versionToDownload, Environment.NewLine, downloadAsync.Error.Unwrap()));
                yield break;
            }

            GameDataEditorWindow.FindAllAndClose();

            try
            {
                if (File.Exists(charonPath))
                {
                    File.Delete(charonPath);
                }
                if (Directory.Exists(charonPath))
                {
                    Directory.Delete(charonPath);
                }

                var toolsDirectory = Path.GetDirectoryName(charonPath) ?? "";
                if (Directory.Exists(toolsDirectory) == false)
                {
                    Directory.CreateDirectory(toolsDirectory);
                }

                File.Move(downloadPath, charonPath);

                // ensure config file
                var charonConfigPath = charonPath + ".config";
                if (File.Exists(charonConfigPath) == false)
                {
                    var embeddedConfigStream = typeof(Menu).Assembly.GetManifestResourceStream("GameDevWare.Charon.Charon.exe.config");
                    if (embeddedConfigStream != null)
                    {
                        using (embeddedConfigStream)
                            using (var configFileStream = File.Create(charonConfigPath, 8 * 1024, FileOptions.SequentialScan))
                            {
                                var buffer = new byte[8 * 1024];
                                var read   = 0;
                                while ((read = embeddedConfigStream.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    configFileStream.Write(buffer, 0, read);
                                }
                            }
                    }
                }
            }
            catch (Exception moveError)
            {
                Debug.LogWarning(string.Format("Failed to move downloaded file from '{0}' to {1}. {2}.", downloadPath, charonPath, moveError.Message));
                Debug.LogError(moveError);
            }
            finally
            {
                try { if (File.Exists(downloadPath))
                      {
                          File.Delete(downloadPath);
                      }
                }
                catch { /* ignore */ }
            }

            if (File.Exists(charonPath))
            {
                if (progressCallback != null)
                {
                    progressCallback(Resources.UI_UNITYPLUGIN_PROGRESS_CHECKING_TOOLS_VERSION, 0.95f);
                }

                var checkToolsVersion = CharonCli.GetVersionAsync();
                yield return(checkToolsVersion.IgnoreFault());

                currentVersion = checkToolsVersion.HasErrors ? default(Version) : checkToolsVersion.GetResult();
            }

            Settings.Current.EditorVersion = currentVersion != null?currentVersion.ToString() : null;

            Settings.Current.Save();

            Debug.Log(string.Format("{1} version is '{0}'. Download is complete.", currentVersion, Path.GetFileName(charonPath)));

            if (progressCallback != null)
            {
                progressCallback(Resources.UI_UNITYPLUGIN_PROGRESS_DONE, 1.0f);
            }
        }
        private IEnumerable CompleteAsync()
        {
            GameDataEditorWindow.FindAllAndClose();

            this.versionDirectory.Refresh();
            if (this.versionDirectory.Exists == false)
            {
                Debug.LogError(string.Format("Unable to complete deployment because directory '{0}' with '{1}' product doesn't exists.", this.versionDirectory.Name, ProductInformation.PRODUCT_CHARON));
                yield break;
            }

            var extensionsToClean = new[] { ".exe", ".dll", ".config", ".xml", ".pdb", ".mdb", ".sha1" };

            foreach (var fileToClean in this.baseDirectory.GetFiles().Where(file => extensionsToClean.Contains(file.Extension, StringComparer.OrdinalIgnoreCase)))
            {
                try
                {
                    if (Settings.Current.Verbose)
                    {
                        Debug.Log(string.Format("Removing old file '{0}' of '{1}' product.", fileToClean.FullName, ProductInformation.PRODUCT_CHARON));
                    }

                    fileToClean.Delete();
                }
                catch (Exception error)
                {
                    Debug.LogWarning(error);
                }
            }

            this.versionDirectory.Refresh();
            foreach (var file in this.versionDirectory.GetFiles())
            {
                if (Settings.Current.Verbose)
                {
                    Debug.Log(string.Format("Copying target file '{0}' for product '{1}'.", file, ProductInformation.PRODUCT_CHARON));
                }

                try
                {
                    file.CopyTo(Path.Combine(Settings.ToolBasePath, file.Name), overwrite: true);
                }
                catch (Exception error)
                {
                    Debug.LogWarning(error);
                }
            }

            // ensure config file
            var charonConfigPath = new FileInfo(Settings.CharonExecutablePath + ".config");

            if (charonConfigPath.Exists)
            {
                try
                {
                    charonConfigPath.Delete();
                }
                catch (Exception error)
                {
                    Debug.LogWarning(error);
                }
            }
            var embeddedConfigStream = typeof(Menu).Assembly.GetManifestResourceStream("GameDevWare.Charon.Unity.Charon.exe.config");

            if (embeddedConfigStream != null)
            {
                using (embeddedConfigStream)
                    using (var configFileStream = charonConfigPath.Create())
                    {
                        var buffer = new byte[8 * 1024];
                        var read   = 0;
                        while ((read = embeddedConfigStream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            configFileStream.Write(buffer, 0, read);
                        }
                    }
            }

            var currentVersion = default(SemanticVersion);

            if (File.Exists(Settings.CharonExecutablePath))
            {
                if (this.progressCallback != null)
                {
                    this.progressCallback(Resources.UI_UNITYPLUGIN_PROGRESS_CHECKING_TOOLS_VERSION, 0.95f);
                }

                var checkToolsVersion = CharonCli.GetVersionAsync();
                yield return(checkToolsVersion.IgnoreFault());

                currentVersion = checkToolsVersion.HasErrors ? default(SemanticVersion) : checkToolsVersion.GetResult();
            }

            Settings.Current.EditorVersion = currentVersion != null?currentVersion.ToString() : null;

            Settings.Current.Save();
        }