private void OnGUI()
        {
            if (null == Backend)
            {
                EditorGUILayout.LabelField($"Backend not supported for backend type '{m_BackendType.ToString()}'");
                return;
            }

            try
            {
                Backend.Targets = m_Targets;
                Backend.Mode    = m_Mode;

                Backend.OnGUI();

                m_Targets = Backend.Targets;
            }
            catch (ExitGUIException)
            {
                throw;
            }
            catch (Exception e)
            {
                TinyEditorAnalytics.SendExceptionOnce("Inspector.OnGUI", e);
                throw;
            }
        }
Ejemplo n.º 2
0
 public static Process RunNoWait(string executable, string arguments, ShellProcessArgs processArgs, DataReceivedEventHandler outputReceived = null, DataReceivedEventHandler errorReceived = null)
 {
     try
     {
         var exeDir = Where(executable, processArgs.ExtraPaths);
         if (exeDir == null)
         {
             if (processArgs.ThrowOnError)
             {
                 throw new FileNotFoundException($"Could not find command '{executable}' in the given search locations.");
             }
             return(null);
         }
         return(StartProcess(Path.Combine(exeDir.FullName, executable), arguments, processArgs.WorkingDirectory, outputReceived, errorReceived));
     }
     catch (Exception e)
     {
         TinyEditorAnalytics.SendException("Shell.RunNoWait", e);
         throw;
     }
 }
Ejemplo n.º 3
0
        private void OnGUI()
        {
            try
            {
                if (s_GuiContents == null)
                {
                    s_GuiContents = new GUIContents(UTinyEditorApplication.ContextType);
                }

                GUI.enabled = !EditorApplication.isPlayingOrWillChangePlaymode;

                DoLayout();
                GUI.enabled = true;
            }
            catch (ExitGUIException)
            {
                throw;
            }
            catch (Exception e)
            {
                TinyEditorAnalytics.SendExceptionOnce("Editor.OnGUI", e);
                throw;
            }
        }
Ejemplo n.º 4
0
        public static ShellProcessOutput RunInShell(string command, ShellProcessArgs args)
        {
            Assert.IsFalse(string.IsNullOrEmpty(command));
            Assert.IsNotNull(args);

            try
            {
                var extraPaths       = args.ExtraPaths;
                var workingDirectory = args.WorkingDirectory;
                var throwOnError     = args.ThrowOnError;

                var runOutput = new ShellProcessOutput();

                var hasErrors   = false;
                var output      = new StringBuilder();
                var logOutput   = new StringBuilder();
                var errorOutput = new StringBuilder();

                // Setup shell command
                if (extraPaths != null)
                {
                    var sb = new StringBuilder(128);
                    foreach (var part in extraPaths)
                    {
                        if (string.IsNullOrEmpty(part))
                        {
                            continue;
                        }

                        if (sb.Length > 0)
                        {
                            sb.Append(s_PathSeparator);
                        }

#if UNITY_EDITOR_WIN
                        sb.Append(part.Trim('"'));
#else
                        sb.Append(part[0] == '"' ? part : part.DoubleQuoted());
#endif
                    }

#if UNITY_EDITOR_WIN
                    command = $"SET PATH={sb}{s_PathSeparator}%PATH%{Environment.NewLine}{command}";
#else
                    command = $"export PATH={sb}{s_PathSeparator}$PATH{Environment.NewLine}{command}";
#endif
                }

                LogProcessData($"TINY SHELL> {(workingDirectory?.FullName ?? new DirectoryInfo(".").FullName)}",
                               logOutput);
                LogProcessData(command, logOutput);

                // Setup temporary command file
                var tmpCommandFile = Path.GetTempPath() + Guid.NewGuid().ToString();
#if UNITY_EDITOR_WIN
                tmpCommandFile += ".bat";
#else
                tmpCommandFile += ".sh";
#endif
                File.WriteAllText(tmpCommandFile, command);

                // Prepare data received handlers
                DataReceivedEventHandler outputReceived = (sender, e) =>
                {
                    LogProcessData(e.Data, output);
                    logOutput.Append(e.Data);
                };
                DataReceivedEventHandler errorReceived = (sender, e) =>
                {
                    LogProcessData(e.Data, output);
                    errorOutput.Append(e.Data);
                    logOutput.Append(e.Data);
                    if (!string.IsNullOrEmpty(e.Data))
                    {
                        hasErrors = true;
                    }
                };

                // Run command in shell and wait for exit
                try
                {
#if UNITY_EDITOR_WIN
                    using (var process = StartProcess("cmd.exe", $"/Q /C \"{tmpCommandFile}\"", workingDirectory, outputReceived, errorReceived))
#else
                    using (var process = StartProcess("bash", $"\"{tmpCommandFile}\"", workingDirectory, outputReceived,
                                                      errorReceived))
#endif
                    {
                        var exitCode = WaitForProcess(process, output, args.MaxIdleTimeInMilliseconds);
                        runOutput.ExitCode      = exitCode;
                        runOutput.Command       = command;
                        runOutput.CommandOutput = output.ToString();
                        runOutput.FullOutput    = logOutput.ToString();
                        runOutput.ErrorOutput   = errorOutput.ToString();
                        LogProcessData($"Process exited with code '{exitCode}'", logOutput);
                        hasErrors |= (exitCode != 0);
                    }
                }
                finally
                {
                    File.Delete(tmpCommandFile);
                }

                if (hasErrors && throwOnError)
                {
                    throw new Exception($"{UTinyConstants.ApplicationName}: " + errorOutput.ToString());
                }

                runOutput.Succeeded = !hasErrors;

                return(runOutput);
            }
            catch (Exception e)
            {
                TinyEditorAnalytics.SendException("Shell.RunInShell", e);
                throw;
            }
        }
Ejemplo n.º 5
0
        private void OnGUI()
        {
            if (null == EditorContext)
            {
                EditorGUILayout.LabelField("No project loaded.");
                return;
            }

            try
            {
                VerifyEntityGroups();

                using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar, GUILayout.ExpandWidth(true)))
                {
                    if (GUILayout.Button("Create", EditorStyles.toolbarDropDown, GUILayout.Width(75)))
                    {
                        var menu = new GenericMenu();
                        menu.AddItem(new GUIContent("Create EntityGroup"), false, () =>
                        {
                            EntityGroupManager.CreateNewEntityGroup();
                        });

                        menu.AddSeparator("");

                        if (LoadedEntityGroups.Count > 0)
                        {
                            // Entity
                            menu.AddItem(new GUIContent("Create Entity"), false, () =>
                            {
                                m_TreeView.CreateEntity(ActiveScene);
                                InvalidateSceneGraph();
                            });
                            menu.AddItem(new GUIContent("Create Static Entity"), false, () =>
                            {
                                m_TreeView.CreateStaticEntity(ActiveScene);
                                InvalidateSceneGraph();
                            });
                        }

                        menu.ShowAsContext();
                    }

                    if (GUILayout.Button("Load", EditorStyles.toolbarDropDown, GUILayout.Width(75)))
                    {
                        EntityGroupManager.ShowOpenEntityGroupMenu();
                    }

                    // HACK For some reason flexible space does not work here...
                    GUILayout.Space(position.width - 50);
                }

                var searchRect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
                m_TreeView.FilterString = m_Filter.OnGUI(searchRect, m_TreeView.FilterString);

                if (LoadedEntityGroupCount == 0)
                {
                    EditorGUILayout.LabelField("No EntityGroups are loaded.");
                    return;
                }

                m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition);
                {
                    var rect = EditorGUILayout.GetControlRect(false, position.height - 42.0f);
                    rect.width = Screen.width + 1;
                    rect.x     = 0;
                    m_TreeView.OnGUI(rect);

                    // Check for a click on empty space.
                    rect.height = rect.height - m_TreeView.totalHeight;
                    rect.y     += m_TreeView.totalHeight;
                    if (rect.height > 0 && Event.current.type == EventType.MouseDown &&
                        rect.Contains(Event.current.mousePosition))
                    {
                        Selection.instanceIDs = new int[0];
                    }
                }
                EditorGUILayout.EndScrollView();

                ExecuteCommands();
            }
            catch (ExitGUIException)
            {
                throw;
            }
            catch (Exception e)
            {
                TinyEditorAnalytics.SendExceptionOnce("Hierarchy.OnGUI", e);
                throw;
            }
        }
        public static UTinyBuildResults Build(UTinyBuildOptions options)
        {
            if (options?.Project == null || options.Destination == null)
            {
                throw new ArgumentException($"{UTinyConstants.ApplicationName}: invalid build options provided", nameof(options));
            }

            var buildStart = DateTime.Now;

            var           results = new UTinyBuildResults();
            IUTinyBuilder builder = null;

            switch (options.Platform)
            {
            case UTinyPlatform.HTML5:
                builder = new UTinyHTML5Builder();
                break;

            default:
                throw new ArgumentException($"{UTinyConstants.ApplicationName}: build platform not supported", nameof(options));
            }

            try
            {
                EditorUtility.DisplayProgressBar(ProgressBarTitle, "Build started for " + options.Platform.ToString(),
                                                 0.0f);

                var destFolder = options.Destination;
                destFolder.Create();

                // BUILD = <DEST>/PLATFORM/CONFIG
                var buildFolder = new DirectoryInfo(GetBuildDirectory(options.Project, options.Platform, options.Configuration));

                results.OutputFolder = buildFolder;

                UTinyBuildUtilities.PurgeDirectory(buildFolder);
                buildFolder.Create();

                options.Destination = results.BinaryFolder = buildFolder;

                var idlFile = new FileInfo(Path.Combine(buildFolder.FullName, "generated.cs"));
                UTinyIDLGenerator.GenerateIDL(options.Project, idlFile);

                var distFolder = GetRuntimeDistFolder();

                var bindGem = new FileInfo(Path.Combine(
                                               distFolder.FullName, "bindgem/BindGem/bin/Release/BindGem.exe"));

                var exeName = "\"" + bindGem.FullName + "\"";

                // always call bindgem with mono for consistency
                exeName = "mono " + exeName;

                // reference the core runtime file
                var bindReferences = $"-r \"{RuntimeDefsAssemblyPath}\"";

                UTinyBuildUtilities.RunInShell(
                    $"{exeName} -j {bindReferences} -o bind-generated {idlFile.Name}",
                    new ShellProcessArgs()
                {
                    WorkingDirectory = buildFolder,
                    ExtraPaths       = TinyPreferences.MonoDirectory.AsEnumerable()
                });

                // @TODO Perform a full refresh before building

                builder.Build(options, results);

                results.BuildReport.Update();

                Debug.Log($"{UTinyConstants.ApplicationName} project generated at: {results.BinaryFolder.FullName}");

                TinyEditorAnalytics.SendBuildEvent(options.Project, results, DateTime.Now - buildStart);
                return(results);
            }
            catch (Exception ex)
            {
                TinyEditorAnalytics.SendException("BuildPipeline.Build", ex);
                throw;
            }
            finally
            {
                EditorUtility.ClearProgressBar();
                UTinyEditorUtility.RepaintAllWindows();
            }
        }