Exemple #1
0
        internal bool ScreenToPanel(Vector2 screenPosition, out Vector2 panelPosition)
        {
            // if no target texture is set, screen space overlay is assumed
            if (targetTexture == null)
            {
                panelPosition = screenPosition * m_Scale;
                return(true);
            }

            // can we delegate to worldtransform?
            if (m_PanelTransform == null)
            {
                if (m_ShouldWarnWorldTransformMissing)
                {
                    m_ShouldWarnWorldTransformMissing = false;
                    Logger.Log("PanelRenderer needs an IWorldTransform implementation for world-space rendering", LogLevel.Error);
                }
                panelPosition = Vector2.zero;
                return(false);
            }

            Vector2 panelUVPosition;
            var     hit = m_PanelTransform.ScreenToPanelUV(screenPosition, out panelUVPosition);

            if (!hit)
            {
                panelPosition = Vector2.zero;
                return(false);
            }

            var panelSize = panel.visualTree.layout.size;

            panelPosition = new Vector2(panelUVPosition.x * panelSize.x, panelUVPosition.y * panelSize.y);
            return(true);
        }
Exemple #2
0
        private void RerouteConsoleOutput()
        {
            var writer = new StreamWriter(_newConsoleStream);

            Console.SetOut(writer);

            var  reader   = new StreamReader(_newConsoleStream);
            bool firstUse = true;

            Task.Run(() =>
            {
                while (Application.isPlaying)
                {
                    if (_newConsoleStream.Position != _lastConsoleStreamPos)
                    {
                        if (firstUse)
                        {
                            Logger.Log("Please use ApiProvider.Log intsead of Console.WriteLine", LogLevel.Warning);
                            firstUse = false;
                        }
                        writer.Flush();
                        var pos = _newConsoleStream.Position;
                        _newConsoleStream.Position = _lastConsoleStreamPos;

                        Logger.Log(reader.ReadToEnd());

                        _lastConsoleStreamPos      = pos;
                        _newConsoleStream.Position = pos;
                    }
                }
            });
        }
Exemple #3
0
 public T CreateUnityType <T>(params object[] args) where T : class
 {
     if (!IsMainThread)
     {
         EnqueueTaskForMainThread(() =>
         {
             Logger.Log("Cannot make VisualElement outside of main thread", LogLevel.Error);
         });
         return(null);
     }
     return((T)Activator.CreateInstance(typeof(T), args));
 }
Exemple #4
0
        private void SetupApplication()
        {
            mainThreadId = Thread.CurrentThread.ManagedThreadId;

            Application.logMessageReceivedThreaded +=
                (condition, stackTrace, type) =>
            {
                if (type == LogType.Exception)
                {
                    Logger.Log($"Unhandled exception: {condition}\n{stackTrace}", LogLevel.Error);

                    /*
                     * if (!ModuleManager.IsFinishedLoading)
                     * {
                     *      Task.Run(() =>
                     *      {
                     *              while (Application.isPlaying) // Wait until module manager loads
                     *              {
                     *                      Thread.Sleep(250);
                     *                      if (ModuleManager.IsFinishedLoading)
                     *                      {
                     *                              // TODO show some module-independent error screen
                     *                              break;
                     *                      }
                     *              }
                     *      });
                     * }
                     */
                }
            };
            Screen.fullScreen = false;

            GameObject.Find("Screen").GetComponent <PanelScaler>().scaleMode = PanelScaler.ScaleMode.ConstantPhysicalSize;

            Task.Run(() =>
            {
                SynthesisAPI.UIManager.VisualElements.VisualElement root = null;
                while (root == null)
                {
                    root = UIManager.RootElement;
                    Thread.Sleep(200);
                }

                UIManager.Setup();
            });
        }
Exemple #5
0
    private void Start()
    {
        var   selectionPanel = AssetManager.GetAsset <VisualElementAsset>("/modules/synthesis_core/SelectionList.uxml");
        Panel p = new Panel("SelectionPanel", selectionPanel, (ve) =>
        {
            var closeButton = ve.Get(name: "close-button") as Button;
            if (closeButton != null)
            {
                closeButton.Subscribe(e => UIManager.ClosePanel("SelectionPanel"));
            }

            var list = ve.Get(name: "selections") as ListView;
            if (list != null)
            {
                var teamNames = new List <string>()
                {
                    "Mean Machine", "Spartan Robotics", "Shockwave"
                };
                list.Populate(teamNames,
                              () =>
                {
                    var a = new Label();
                    a.SetStyleProperty("height", "30px");
                    return(a);
                },
                              (element, index) =>
                {
                    (element as Label).Color = (1.0f, 1.0f, 1.0f, 1.0f);
                    (element as Label).Name  = $"sel-{teamNames[index]}";
                    (element as Label).Text  = teamNames[index];
                    // element.SetStyleProperty("width", "30px");
                }
                              );

                var selectButton = ve.Get(name: "select-button") as Button;
                if (selectButton != null)
                {
                    selectButton.Subscribe(
                        e => Logger.Log($"You've selected team \"{teamNames[list.SelectedIndex]}\"")
                        );
                }
            }