コード例 #1
0
    void Awake()
    {
        _colliders   = GetComponentsInChildren <Collider2D>();
        _rb2D        = GetComponent <Rigidbody2D> ();
        _groundCheck = transform.Find("GroundCheck");

        GameObject eventManagerObj = GameObject.Find("EventManager");

        if (!eventManagerObj)
        {
            Debug.LogError("Scene must contain EventManager and corresponding script");
        }
        _eventManager = eventManagerObj.GetComponent <EventManager> ();
        if (!_eventManager)
        {
            Debug.LogError("EventManager has no attached script");
        }

        GameObject silkManagerObj = GameObject.Find("SilkManager");

        if (!silkManagerObj)
        {
            Debug.LogError("Scene must contain SilkManager and corresponding script");
        }
        _silkManager = silkManagerObj.GetComponent <SilkManager> ();
        if (_silkManager == null)
        {
            Debug.LogError("SilkManager has no attached script");
        }

        _savedParent = transform.parent;
    }
コード例 #2
0
        protected override bool OnStart()
        {
            try
            {
                SilkManager.Register <GLSymbolLoader>(new SymbolLoader());
                _gl = GL.GetApi(new OpenGLNativeContext());
            }
            catch (Exception ex)
            {
                XPlane.Trace.WriteLine(ex.ToString());
                return(false);
            }

            var desktopBounds = Screen.BoundsGlobal;

            _window = new Window(
                new Rect(desktopBounds.Left + 50, desktopBounds.Bottom + 450, desktopBounds.Left + 350, desktopBounds.Bottom + 150),
                decoration: WindowDecoration.RoundRectangle);
            _window.SetPositioningMode(WindowPositioningMode.PositionFree);
            _window.SetGravity(0, 1, 0, 1);
            _window.SetResizingLimits(200, 200, 500, 500);
            _window.Title                 = "Sample Window";
            _window.DrawWindow           += OnDrawWindow;
            _window.MouseLeftButtonEvent += OnMouseLeftButtonEvent;

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Gets the main monitor.
        /// </summary>
        /// <returns>The main monitor.</returns>
        public static IMonitor GetMainMonitor()
        {
            if (!SilkManager.IsRegistered <IWindowPlatform>())
            {
                Window.Init();
            }

            return(SilkManager.Get <IWindowPlatform>().GetMainMonitor());
        }
コード例 #4
0
        /// <summary>
        /// Clears all current contexts for this backend on the current thread.
        /// </summary>
        public static void ClearCurrentContexts()
        {
            if (!SilkManager.IsRegistered <IWindowPlatform>())
            {
                Init();
            }

            SilkManager.Get <IWindowPlatform>().ClearContexts();
        }
コード例 #5
0
        /// <summary>
        /// Gets all monitors present on this window platform.
        /// </summary>
        /// <returns>All monitors present on this window platform</returns>
        public static IEnumerable <IMonitor> GetMonitors()
        {
            if (!SilkManager.IsRegistered <IWindowPlatform>())
            {
                Window.Init();
            }

            return(SilkManager.Get <IWindowPlatform>().GetMonitors());
        }
コード例 #6
0
ファイル: Window.cs プロジェクト: tr002196/Silk.NET
        /// <summary>
        /// Create a window on the current platform.
        /// </summary>
        /// <param name="options">The window to use.</param>
        /// <returns>A Silk.NET window using the current platform.</returns>
        public static IWindow Create(WindowOptions options)
        {
            if (!SilkManager.IsRegistered <IWindowPlatform>())
            {
                Init();
            }

            // We should have a platform now, as Silk.Init would've thrown otherwise.
            // ReSharper disable once PossibleNullReferenceException
            return(SilkManager.Get <IWindowPlatform>().GetWindow(options));
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: Etny/3Dtest
        private unsafe static void Main(string[] args)
        {
            glfw = Glfw.GetApi();

            Console.WriteLine(glfw.GetVersionString());

            glfw.SetErrorCallback(GlfwError);

            //SilkManager.Register<IWindowPlatform>(glfwPlatform);
            SilkManager.Register <GLSymbolLoader>(new Silk.NET.GLFW.GlfwLoader());

            glfw.Init();
            glfw.WindowHint(WindowHintInt.ContextVersionMajor, 3);
            glfw.WindowHint(WindowHintInt.ContextVersionMinor, 3);
            glfw.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Core);

            window = glfw.CreateWindow(800, 600, "3Dtest", null, null);

            if (window == null)
            {
                Console.WriteLine("Window creation failed");
                glfw.Terminate();
                return;
            }


            glfw.MakeContextCurrent(window);
            glfw.SetWindowSizeCallback(window, OnResize);
            glfw.SetCursorPosCallback(window, MouseInput);
            glfw.SetScrollCallback(window, ScrollInput);
            glfw.SetInputMode(window, CursorStateAttribute.Cursor, CursorModeValue.CursorDisabled);
            //glfw.SwapInterval(1);

            OnLoad();

            double currentFrame;

            while (!glfw.WindowShouldClose(window))
            {
                currentFrame = glfw.GetTimerValue();
                deltaTime    = (currentFrame - lastFrame) / glfw.GetTimerFrequency();
                lastFrame    = currentFrame;

                ProcessInput(window);

                //Console.WriteLine($"Fps: {Math.Round(1f/deltaTime)}");

                OnRender();
            }

            glfw.Terminate();
        }
コード例 #8
0
    public new void Start()
    {
        base.Start();

        paused = false;

        descendLimitY     = descendLimitGO.transform.position.y;
        motionCorrectionY = motionCorrectionBarrierGO.transform.position.y;

        rb          = gameObject.GetComponent <Rigidbody>();
        grabHandler = gameObject.GetComponent <SpiderGrabHandler>();
        silkManager = gameObject.GetComponent <SilkManager>();

        descendStage = DescendStage.None;
        ToggleNonTriggerColliders(false);
    }
コード例 #9
0
        /// <summary>
        /// Attempts to resolve an <see cref="IWindowPlatform" />.
        /// </summary>
        /// <exception cref="NotSupportedException">
        /// Thrown if no applicable <see cref="IWindowPlatform" /> was found.
        /// </exception>
        public static void Init()
        {
            var glfwPlatform = new GlfwPlatform();

            if (glfwPlatform.IsApplicable)
            {
                SilkManager.Register <IWindowPlatform>(glfwPlatform);
                SilkManager.Register <IGLSymbolLoader>(new GlfwLoader());
                return;
            }

            // TODO: Mobile

            if (!SilkManager.IsRegistered <IWindowPlatform>())
            {
                throw new NotSupportedException("Couldn't find a suitable windowing platform. Generally, this means that your GLFW library is missing.");
            }
        }
コード例 #10
0
        /// <summary>
        /// Create a window on the current platform.
        /// </summary>
        /// <param name="options">The window to use.</param>
        /// <returns>A Silk.NET window using the current platform.</returns>
        public static IWindow Create(WindowOptions options)
        {
            if (!SilkManager.IsRegistered <IWindowPlatform>())
            {
                Init();
            }

            if (IsViewOnly)
            {
                throw new NotSupportedException
                      (
                          "The currently bound window platform only supports views," +
                          "instead of windows. Use the view APIs instead."
                      );
            }

            // We should have a platform now, as Silk.Init would've thrown otherwise.
            // ReSharper disable once PossibleNullReferenceException
            return(SilkManager.Get <IWindowPlatform>().CreateWindow(options));
        }
コード例 #11
0
ファイル: Window.cs プロジェクト: tr002196/Silk.NET
        /// <summary>
        /// Attempts to resolve an <see cref="IWindowPlatform" />.
        /// </summary>
        /// <exception cref="NotSupportedException">
        /// Thrown if no applicable <see cref="IWindowPlatform" /> was found.
        /// </exception>
        public static void Init()
        {
            var glfwPlatform = new GlfwPlatform();

            if (glfwPlatform.IsApplicable)
            {
                SilkManager.Register <IWindowPlatform>(glfwPlatform);
                SilkManager.Register <IGLSymbolLoader>(new GlfwLoader());
                return;
            }

            // TODO: Mobile

            if (!SilkManager.IsRegistered <IWindowPlatform>())
            {
                throw new NotSupportedException
                      (
                          "Couldn't find a suitable windowing platform. You probably forgot to copy a glfw3 library into " +
                          "your bin/Debug or bin/Release folder (this won't be a problem in Preview 4)"
                      );
            }
        }
コード例 #12
0
        /// <summary>
        /// Attempts to resolve an <see cref="IWindowPlatform" />.
        /// </summary>
        /// <exception cref="NotSupportedException">
        /// Thrown if no applicable <see cref="IWindowPlatform" /> was found.
        /// </exception>
        internal static void Init()
        {
            var glfwPlatform = GlfwPlatform.Instance;

            if (glfwPlatform.IsApplicable)
            {
                SilkManager.Register <IWindowPlatform>(glfwPlatform);
                SilkManager.Register <GLSymbolLoader>(new GlfwLoader());
                return;
            }

            // TODO: Mobile

            if (!SilkManager.IsRegistered <IWindowPlatform>())
            {
                var entAsm = Assembly.GetEntryAssembly()?.Location;
                entAsm = entAsm is null ? "the entry assembly" : Path.GetFileName(entAsm);
                throw new NotSupportedException
                      (
                          "Couldn't find a suitable windowing platform. \n" +
                          $"GLFW: Copy a GLFW 3.3 binary into the same directory as {entAsm}\n"
                      );
            }
        }
コード例 #13
0
        public bool OpenWindow(string name, Size dimensions)
        {
            glfw = Glfw.GetApi();

            glfw.SetErrorCallback(GlfwError);

            SilkManager.Register <GLSymbolLoader>(new Silk.NET.GLFW.GlfwLoader());

            glfw.Init();
            glfw.WindowHint(WindowHintInt.ContextVersionMajor, 3);
            glfw.WindowHint(WindowHintInt.ContextVersionMinor, 3);
            glfw.WindowHint(WindowHintOpenGlProfile.OpenGlProfile, OpenGlProfile.Core);


            window = glfw.CreateWindow(dimensions.Width, dimensions.Height, name, null, null);

            if (window == null)
            {
                Console.WriteLine("Window creation failed");
                glfw.Terminate();
                return(false);
            }


            glfw.MakeContextCurrent(window);
            glfw.SetWindowSizeLimits(window, dimensions.Width, dimensions.Height, dimensions.Width, dimensions.Height);
            //glfw.SetWindowSizeCallback(window, OnWindowResize);
            glfw.SetKeyCallback(window, OnWindowButtonPress);
            glfw.SetCursorEnterCallback(window, OnWindowCursorEnter);
            glfw.SetCursorPosCallback(window, OnWindowCursor);
            glfw.SetMouseButtonCallback(window, OnWindowMouseButton);
            //glfw.SetScrollCallback(window, ScrollInput);
            //glfw.SetInputMode(window, CursorStateAttribute.Cursor, CursorModeValue.CursorDisabled);

            return(true);
        }
コード例 #14
0
 static InputWindowExtensions()
 {
     SilkManager.Register <IInputPlatform>(new GlfwInputPlatform());
 }
コード例 #15
0
 /// <summary>
 /// Creates a window and adds it to this manager.
 /// </summary>
 /// <param name="opts">The options to initialize the new window with.</param>
 /// <param name="platform">
 /// The windowing platform to use. If null, the current windowing platform will be
 /// fetched using the <see cref="SilkManager"/>.
 /// </param>
 public void CreateWindow(WindowOptions opts, IWindowPlatform platform = null)
 => AddWindow((platform ?? SilkManager.Get <IWindowPlatform>()).GetWindow(opts));
コード例 #16
0
 static InputWindowExtensions()
 {
     SilkManager.Register <IInputPlatform>(GlfwInputPlatform.Instance);
 }
コード例 #17
0
 public static IInputContext GetInput(this IWindow window)
 {
     return(SilkManager.GetOrDefault <IInputPlatform>()?.GetInput(window)
            ?? throw new NotSupportedException("Couldn't find a suitable input platform for this window."));
 }
コード例 #18
0
 public static IInputContext CreateInput(this IView view)
 {
     return(SilkManager.GetOrDefault <IInputPlatform>()?.CreateInput(view)
            ?? throw new NotSupportedException("Couldn't find a suitable input platform for this view."));
 }
コード例 #19
0
ファイル: WindowManager.cs プロジェクト: rxcomputers/Silk.NET
 /// <summary>
 /// Creates a window and adds it to this manager.
 /// </summary>
 /// <param name="opts">The options to initialize the new window with.</param>
 /// <param name="host">
 /// The window host to use. If null, the current windowing platform will be
 /// fetched using the <see cref="SilkManager"/>.
 /// </param>
 public void CreateWindow(WindowOptions opts, IWindowHost host = null)
 => AddWindow((host ?? SilkManager.Get <IWindowPlatform>()).CreateWindow(opts));
コード例 #20
0
ファイル: GL.cs プロジェクト: koson/Silk.NET
 public static GL GetApi() => LibraryLoader <GL> .Load
     (new OpenGLESLibraryNameContainer(), SilkManager.Get <GLSymbolLoader>());