Ejemplo n.º 1
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.SetRenderTarget(RenderTarget);
            GraphicsDevice.RasterizerState  = RasterizerState.CullCounterClockwise;
            GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;
            GraphicsDevice.SamplerStates[1] = SamplerState.PointClamp;

            Mesh.ResetStats();

            SkyModule.Draw(gameTime);
            ChunkModule.Draw(gameTime);
            HighlightModule.Draw(gameTime);
            HudModule.Draw(gameTime);
            ChatModule.Draw(gameTime);
            WindowModule.Draw(gameTime);
            DebugInfoModule.Draw(gameTime);

            _imgui.BeforeLayout(gameTime);
            ImGuiLayout();
            _imgui.AfterLayout();

            GraphicsDevice.SetRenderTarget(null);
            SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);
            SpriteBatch.Draw(RenderTarget, Vector2.Zero, Color.White);
            SpriteBatch.End();

            base.Draw(gameTime);
        }
Ejemplo n.º 2
0
    private void Awake()
    {
        VRView.viewerPivot.parent = transform;         // Parent the camera pivot under EditorVR
        if (VRSettings.loadedDeviceName == "OpenVR")
        {
            // Steam's reference position should be at the feet and not at the head as we do with Oculus
            VRView.viewerPivot.localPosition = Vector3.zero;
        }
        InitializePlayerHandle();
        CreateDefaultActionMapInputs();
        CreateAllProxies();
        CreateDeviceDataForInputDevices();
        CreateEventSystem();

        m_PixelRaycastModule            = U.Object.AddComponent <PixelRaycastModule>(gameObject);
        m_PixelRaycastModule.ignoreRoot = transform;
        m_HighlightModule       = U.Object.AddComponent <HighlightModule>(gameObject);
        m_ObjectPlacementModule = U.Object.AddComponent <ObjectPlacementModule>(gameObject);

        m_AllTools          = U.Object.GetImplementationsOfInterface(typeof(ITool));
        m_AllWorkspaceTypes = U.Object.GetExtensionsOfClass(typeof(Workspace));

        // TODO: Only show tools in the menu for the input devices in the action map that match the devices present in the system.
        // This is why we're collecting all the action maps. Additionally, if the action map only has a single hand specified,
        // then only show it in that hand's menu.
        // CollectToolActionMaps(m_AllTools);
    }
Ejemplo n.º 3
0
        void Awake()
        {
            ClearDeveloperConsoleIfNecessary();

            UpdateProjectFolders();
            UpdateHierarchyData();

            VRView.viewerPivot.parent = transform;             // Parent the camera pivot under EditorVR
            if (VRSettings.loadedDeviceName == "OpenVR")
            {
                // Steam's reference position should be at the feet and not at the head as we do with Oculus
                VRView.viewerPivot.localPosition = Vector3.zero;
            }

            var hmdOnlyLayerMask = 0;

            if (m_PreviewCameraPrefab)
            {
                var go = U.Object.Instantiate(m_PreviewCameraPrefab);
                m_CustomPreviewCamera = go.GetComponentInChildren <IPreviewCamera>();
                if (m_CustomPreviewCamera != null)
                {
                    VRView.customPreviewCamera     = m_CustomPreviewCamera.previewCamera;
                    m_CustomPreviewCamera.vrCamera = VRView.viewerCamera;
                    hmdOnlyLayerMask = m_CustomPreviewCamera.hmdOnlyLayerMask;
                }
            }
            VRView.cullingMask = UnityEditor.Tools.visibleLayers | hmdOnlyLayerMask;

            InitializePlayerHandle();
            CreateDefaultActionMapInputs();
            CreateAllProxies();
            CreateDeviceDataForInputDevices();

            m_DragAndDropModule = U.Object.AddComponent <DragAndDropModule>(gameObject);

            CreateEventSystem();

            m_PixelRaycastModule            = U.Object.AddComponent <PixelRaycastModule>(gameObject);
            m_PixelRaycastModule.ignoreRoot = transform;
            m_HighlightModule = U.Object.AddComponent <HighlightModule>(gameObject);
            m_LockModule      = U.Object.AddComponent <LockModule>(gameObject);
            m_LockModule.updateAlternateMenu = (rayOrigin, o) => SetAlternateMenuVisibility(rayOrigin, o != null);
            ConnectInterfaces(m_LockModule);

            m_SelectionModule              = U.Object.AddComponent <SelectionModule>(gameObject);
            m_SelectionModule.selected    += SetLastSelectionRayOrigin;          // when a selection occurs in the selection tool, call show in the alternate menu, allowing it to show/hide itself.
            m_SelectionModule.getGroupRoot = GetGroupRoot;
            ConnectInterfaces(m_SelectionModule);

            m_AllTools          = U.Object.GetImplementationsOfInterface(typeof(ITool)).ToList();
            m_MainMenuTools     = m_AllTools.Where(t => !IsPermanentTool(t)).ToList();         // Don't show tools that can't be selected/toggled
            m_AllWorkspaceTypes = U.Object.GetImplementationsOfInterface(typeof(IWorkspace)).ToList();

            UnityBrandColorScheme.sessionGradient = UnityBrandColorScheme.GetRandomGradient();
        }
Ejemplo n.º 4
0
        protected override void Update(GameTime gameTime)
        {
            GameTime = gameTime;

            if (PendingMainThreadActions.TryTake(out var action))
            {
                action();
            }

            var adjusted = Client.World.World.FindBlockPosition(
                new Coordinates3D((int)Client.Position.X, 0, (int)Client.Position.Z), out var chunk);

            if (chunk != null && Client.LoggedIn)
            {
                if (chunk.GetHeight((byte)adjusted.X, (byte)adjusted.Z) != 0)
                {
                    Client.Physics.Update(gameTime.ElapsedGameTime);
                }
            }

            if (NextPhysicsUpdate < DateTime.UtcNow && Client.LoggedIn)
            {
                // NOTE: This is to make the vanilla server send us chunk packets
                // We should eventually make some means of detecting that we're on a vanilla server to enable this
                // It's a waste of bandwidth to do it on a TrueCraft server
                Client.QueuePacket(new PlayerGroundedPacket {
                    OnGround = true
                });
                NextPhysicsUpdate = DateTime.UtcNow.AddMilliseconds(50);
            }

            if (IsActive)
            {
                foreach (var module in InputModules)
                {
                    module.Update(gameTime);
                }
            }

            SkyModule.Update(gameTime);
            ChunkModule.Update(gameTime);
            HighlightModule.Update(gameTime);
            HudModule.Update(gameTime);
            ChatModule.Update(gameTime);
            WindowModule.Update(gameTime);
            DebugInfoModule.Update(gameTime);

            UpdateCamera();

            base.Update(gameTime);
        }
Ejemplo n.º 5
0
        protected override void Initialize()
        {
            base.Initialize();             // (calls LoadContent)

            _imgui = new ImGuiRenderer(this);
            _imgui.RebuildFontAtlas();

            InputModules = new List <IGameplayModule>();

            if (GraphicsDevice.Viewport.Width < 640 || GraphicsDevice.Viewport.Height < 480)
            {
                ScaleFactor = 0.5f;
            }
            else if (GraphicsDevice.Viewport.Width < 978 || GraphicsDevice.Viewport.Height < 720)
            {
                ScaleFactor = 1.0f;
            }
            else
            {
                ScaleFactor = 1.5f;
            }

            Camera = new Camera(GraphicsDevice.Viewport.AspectRatio, 70.0f, 0.1f, 1000.0f);
            UpdateCamera();

            WhitePixel = new Texture2D(GraphicsDevice, 1, 1);
            WhitePixel.SetData(new[] { Color.White });

            Audio = new AudioManager();
            Audio.LoadDefaultPacks(Content);

            SkyModule       = new SkyModule(this);
            ChunkModule     = new ChunkModule(this);
            HighlightModule = new HighlightModule(this);
            DebugInfoModule = new DebugInfoModule(this, Pixel);
            ChatModule      = new ChatModule(this, Pixel);
            HudModule       = new HUDModule(this, Pixel);
            WindowModule    = new WindowModule(this, Pixel);
            ControlModule   = new PlayerControlModule(this);

            InputModules.Add(WindowModule);
            InputModules.Add(DebugInfoModule);
            InputModules.Add(ChatModule);
            InputModules.Add(HudModule);
            InputModules.Add(ControlModule);

            Client.PropertyChanged += HandleClientPropertyChanged;
            Client.Connect(EndPoint);

            BlockProvider.BlockRepository = BlockRepository;
            var itemRepository = new ItemRepository();

            itemRepository.DiscoverItemProviders();
            ItemRepository = itemRepository;
            BlockProvider.ItemRepository = ItemRepository;

            IconRenderer.CreateBlocks(this, BlockRepository);

            var centerX = GraphicsDevice.Viewport.Width / 2;
            var centerY = GraphicsDevice.Viewport.Height / 2;

            Mouse.SetPosition(centerX, centerY);

            MouseComponent.Scroll       += OnMouseComponentScroll;
            MouseComponent.Move         += OnMouseComponentMove;
            MouseComponent.ButtonDown   += OnMouseComponentButtonDown;
            MouseComponent.ButtonUp     += OnMouseComponentButtonUp;
            KeyboardComponent.KeyDown   += OnKeyboardKeyDown;
            KeyboardComponent.KeyUp     += OnKeyboardKeyUp;
            GamePadComponent.ButtonDown += OnGamePadButtonDown;
            GamePadComponent.ButtonUp   += OnGamePadButtonUp;

            CreateRenderTarget();
            SpriteBatch = new SpriteBatch(GraphicsDevice);
            ThreadId    = Thread.CurrentThread.ManagedThreadId;
        }
Ejemplo n.º 6
0
 public void ConnectDependency(HighlightModule dependency)
 {
     m_HighlightModule = dependency;
 }
Ejemplo n.º 7
0
        void Awake()
        {
            Nested.evr = this;             // Set this once for the convenience of all nested classes

            ClearDeveloperConsoleIfNecessary();

            m_DirectSelection = new DirectSelection();
            m_Interfaces      = new Interfaces();
            m_Menus           = new Menus();
            m_MiniWorlds      = new MiniWorlds();
            m_Rays            = new Rays();
            m_Tools           = new Tools();
            m_UI          = new UI();
            m_Viewer      = new Viewer();
            m_Vacuumables = new Vacuumables();

            m_HierarchyModule     = AddModule <HierarchyModule>();
            m_ProjectFolderModule = AddModule <ProjectFolderModule>();

            VRView.cameraRig.parent    = transform;          // Parent the camera rig under EditorVR
            VRView.cameraRig.hideFlags = defaultHideFlags;
            if (VRSettings.loadedDeviceName == "OpenVR")
            {
                // Steam's reference position should be at the feet and not at the head as we do with Oculus
                VRView.cameraRig.localPosition = Vector3.zero;
            }

            var hmdOnlyLayerMask = 0;

            if (m_PreviewCameraPrefab)
            {
                var go = ObjectUtils.Instantiate(m_PreviewCameraPrefab);
                m_CustomPreviewCamera = go.GetComponentInChildren <IPreviewCamera>();
                if (m_CustomPreviewCamera != null)
                {
                    VRView.customPreviewCamera     = m_CustomPreviewCamera.previewCamera;
                    m_CustomPreviewCamera.vrCamera = VRView.viewerCamera;
                    hmdOnlyLayerMask = m_CustomPreviewCamera.hmdOnlyLayerMask;
                    m_Interfaces.ConnectInterfaces(m_CustomPreviewCamera);
                }
            }
            VRView.cullingMask = UnityEditor.Tools.visibleLayers | hmdOnlyLayerMask;

            m_DeviceInputModule = AddModule <DeviceInputModule>();
            m_DeviceInputModule.InitializePlayerHandle();
            m_DeviceInputModule.CreateDefaultActionMapInputs();
            m_DeviceInputModule.processInput           = ProcessInput;
            m_DeviceInputModule.updatePlayerHandleMaps = m_Tools.UpdatePlayerHandleMaps;

            m_UI.Initialize();

            m_KeyboardModule = AddModule <KeyboardModule>();

            m_DragAndDropModule        = AddModule <DragAndDropModule>();
            m_InputModule.rayEntered  += m_DragAndDropModule.OnRayEntered;
            m_InputModule.rayExited   += m_DragAndDropModule.OnRayExited;
            m_InputModule.dragStarted += m_DragAndDropModule.OnDragStarted;
            m_InputModule.dragEnded   += m_DragAndDropModule.OnDragEnded;

            m_TooltipModule = AddModule <TooltipModule>();
            m_Interfaces.ConnectInterfaces(m_TooltipModule);
            m_InputModule.rayEntered += m_TooltipModule.OnRayEntered;
            m_InputModule.rayExited  += m_TooltipModule.OnRayExited;

            m_PixelRaycastModule               = AddModule <PixelRaycastModule>();
            m_PixelRaycastModule.ignoreRoot    = transform;
            m_PixelRaycastModule.raycastCamera = m_UI.eventCamera;

            m_HighlightModule = AddModule <HighlightModule>();
            m_ActionsModule   = AddModule <ActionsModule>();

            m_LockModule = AddModule <LockModule>();
            m_LockModule.updateAlternateMenu = (rayOrigin, o) => m_Menus.SetAlternateMenuVisibility(rayOrigin, o != null);

            m_SelectionModule              = AddModule <SelectionModule>();
            m_SelectionModule.selected    += m_Rays.SetLastSelectionRayOrigin;          // when a selection occurs in the selection tool, call show in the alternate menu, allowing it to show/hide itself.
            m_SelectionModule.getGroupRoot = GetGroupRoot;

            m_SpatialHashModule = AddModule <SpatialHashModule>();
            m_SpatialHashModule.shouldExcludeObject = go => go.GetComponentInParent <EditorVR>();
            m_SpatialHashModule.Setup();

            m_IntersectionModule = AddModule <IntersectionModule>();
            m_Interfaces.ConnectInterfaces(m_IntersectionModule);
            m_IntersectionModule.Setup(m_SpatialHashModule.spatialHash);

            m_Menus.mainMenuTools = m_Tools.allTools.Where(t => !m_Tools.IsPermanentTool(t)).ToList();             // Don't show tools that can't be selected/toggled

            m_WorkspaceModule = AddModule <WorkspaceModule>();
            m_WorkspaceModule.workspaceCreated   += m_Vacuumables.OnWorkspaceCreated;
            m_WorkspaceModule.workspaceCreated   += m_MiniWorlds.OnWorkspaceCreated;
            m_WorkspaceModule.workspaceCreated   += (workspace) => { m_DeviceInputModule.UpdatePlayerHandleMaps(); };
            m_WorkspaceModule.workspaceDestroyed += m_Vacuumables.OnWorkspaceDestroyed;
            m_WorkspaceModule.workspaceDestroyed += (workspace) => { m_Interfaces.DisconnectInterfaces(workspace); };
            m_WorkspaceModule.workspaceDestroyed += m_MiniWorlds.OnWorkspaceDestroyed;

            UnityBrandColorScheme.sessionGradient = UnityBrandColorScheme.GetRandomGradient();

            m_SceneObjectModule = AddModule <SceneObjectModule>();
            m_SceneObjectModule.shouldPlaceObject = (obj, targetScale) =>
            {
                foreach (var miniWorld in m_MiniWorlds.worlds)
                {
                    if (!miniWorld.Contains(obj.position))
                    {
                        continue;
                    }

                    var referenceTransform = miniWorld.referenceTransform;
                    obj.transform.parent = null;
                    obj.position         = referenceTransform.position + Vector3.Scale(miniWorld.miniWorldTransform.InverseTransformPoint(obj.position), miniWorld.referenceTransform.localScale);
                    obj.rotation         = referenceTransform.rotation * Quaternion.Inverse(miniWorld.miniWorldTransform.rotation) * obj.rotation;
                    obj.localScale       = Vector3.Scale(Vector3.Scale(obj.localScale, referenceTransform.localScale), miniWorld.miniWorldTransform.lossyScale);
                    return(false);
                }

                return(true);
            };

            m_Viewer.AddPlayerModel();

            m_Rays.CreateAllProxies();

            // In case we have anything selected at start, set up manipulators, inspector, etc.
            EditorApplication.delayCall += OnSelectionChanged;
        }