void OnLevelLoadingComplete(EventArgs <ILevelInfo> arg) { // Debug.Log("Level load complete"); // Test HUD Hud = SceneObject.Instantiate <UiHud>(Root); var resources = new Resources(); resources.OnResourcesChanged += OnResourcesChanged; // Create object placer var host = GameObject.Instantiate <GameObject>(); host.AddComponent <Inventory>().Setup(resources); // Display gameobject counter SceneObject.Instantiate <UiDebug>(Parent); // Player mouse interaction WorldMouse = new WorldMouse(); // Create grid new Grid(16, 16, 2); LevelSystem.LoadingComplete -= OnLevelLoadingComplete; }
public void removeWorldMouse(WorldMouse m) { int index = worldMice.IndexOf(m); worldMice.RemoveAt(index); eventData.RemoveAt(index); lastPressed.RemoveAt(index); }
public void addWorldMouse(WorldMouse m) { if (!worldMice.Contains(m)) { worldMice.Add(m); } eventData.Add(new PointerEventData(base.eventSystem)); lastPressed.Add(null); }
// Process is called by UI system to process events. public override void Process() { //the currently selected object may want to update something each frame BaseEventData data = GetBaseEventData(); ExecuteEvents.Execute(base.eventSystem.currentSelectedGameObject, data, ExecuteEvents.updateSelectedHandler); //we process each world mouse separately, which encapsulates the concept of a mouse within a camera space that will raycast into the world for (int i = 0; i < eventData.Count && i < worldMice.Count; i++) { WorldMouse wm = worldMice[i]; wm.rayDistance = Mathf.Infinity; //assume nothing was hit to start //this makes the event system camera align with the world mouse worldMouseCam.transform.position = wm.transform.position; worldMouseCam.transform.forward = wm.transform.forward; //we reset the event data for the current frame. Since the cursor doesn't actuall move, these are constant //this may cause some problems down the road...in which case we would probably create a camera for each canvas //and then move the cursor to the raycast intersection with the quad encapsulating the GUI, updating these deltas PointerEventData currentEventData = eventData[i]; currentEventData.Reset(); currentEventData.delta = Vector2.zero; currentEventData.position = new Vector2(worldMouseCam.pixelWidth / 2.0f, worldMouseCam.pixelHeight / 2.0f); currentEventData.scrollDelta = Vector2.zero; //this is where all the magic actually happens //the event system takes care of raycasting from all cameras at all cursor locations into the world base.eventSystem.RaycastAll(currentEventData, m_RaycastResultCache); currentEventData.pointerCurrentRaycast = FindFirstRaycast(m_RaycastResultCache); if (wm.worldRayDistance < currentEventData.pointerCurrentRaycast.distance) { continue; //don't process anything if a world object was hit } //if we hit something this will not be null if (currentEventData.pointerCurrentRaycast.gameObject != null) { //this is useful to know where the object was hit (to draw a point or limit the lenght of a laser) wm.rayDistance = currentEventData.pointerCurrentRaycast.distance; //we can think of the object we hit as what we are hovering above (the simplest type) GameObject hoverObject = currentEventData.pointerCurrentRaycast.gameObject; // handle enter and exit events (highlight) base.HandlePointerExitAndEnter(currentEventData, hoverObject); //if the user clicks, other events may need to be handled if (wm.pressDown()) { //if we click, we want to clear the current selection //and fire associated events if (base.eventSystem.currentSelectedGameObject) { base.eventSystem.SetSelectedGameObject(null); } //these are important for those handling a click event currentEventData.pressPosition = currentEventData.position; currentEventData.pointerPressRaycast = currentEventData.pointerCurrentRaycast; //execute both the pointer down handler GameObject handledPointerDown = ExecuteEvents.ExecuteHierarchy(hoverObject, currentEventData, ExecuteEvents.pointerDownHandler); //execute the click handler, either on the hoverObject if nothing handled pointerdown or on whatever handled it GameObject handledClick = ExecuteEvents.ExecuteHierarchy(handledPointerDown == null?hoverObject:handledPointerDown, currentEventData, ExecuteEvents.pointerClickHandler); //something handled the click or pressed, so save a reference to it, needed later GameObject newPressed = handledClick != null ? handledClick : handledPointerDown; //we need to deal with a new selection if the press/click was handled if (newPressed != null) { currentEventData.pointerPress = newPressed; if (ExecuteEvents.GetEventHandler <ISelectHandler>(newPressed)) { base.eventSystem.SetSelectedGameObject(newPressed); } } //execute a drag start event on the currently pressed object and save it ExecuteEvents.Execute(newPressed, currentEventData, ExecuteEvents.beginDragHandler); currentEventData.pointerDrag = newPressed; //we save what was currently pressed for when we release lastPressed[i] = newPressed == null ? hoverObject : newPressed; } //handle releasing the "click" if (wm.pressUp()) { if (lastPressed[i] != null) { ExecuteEvents.Execute(lastPressed[i], currentEventData, ExecuteEvents.endDragHandler); ExecuteEvents.ExecuteHierarchy(lastPressed[i], currentEventData, ExecuteEvents.dropHandler); ExecuteEvents.Execute(lastPressed[i], currentEventData, ExecuteEvents.pointerUpHandler); currentEventData.pointerDrag = null; currentEventData.rawPointerPress = null; currentEventData.pointerPress = null; lastPressed[i] = null; } } // drag handling if (lastPressed[i] != null) { ExecuteEvents.Execute(lastPressed[i], currentEventData, ExecuteEvents.dragHandler); } } m_RaycastResultCache.Clear(); } }
private void InputHandler() { renderer.ActiveScene.CurrentCamera.TranslateRelativly(Vector3.Forward * (Mouse.GetState().ScrollWheelValue - scrollWheelValue) * .1f); scrollWheelValue = Mouse.GetState().ScrollWheelValue; renderer.ActiveScene.CurrentCamera.LockRotation = true; if (Mouse.GetState().RightButton == Microsoft.Xna.Framework.Input.ButtonState.Released) { WorldMouse.Update(); mouseReferencePosition.X = WorldMouse.Position.X; mouseReferencePosition.Y = WorldMouse.Position.Y; } if (Mouse.GetState().RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { Vector3 translation; WorldMouse.Update(); translation.X = mouseReferencePosition.X - WorldMouse.Position.X; translation.Y = mouseReferencePosition.Y - WorldMouse.Position.Y; mouseReferencePosition.X = WorldMouse.Position.X; mouseReferencePosition.Y = WorldMouse.Position.Y; translation.Z = 0; renderer.ActiveScene.CurrentCamera.Translate(translation / 100); } if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } if (Keyboard.GetState().IsKeyDown(Keys.E)) { if (!exploding) { exploding = true; } } if (Keyboard.GetState().IsKeyDown(Keys.F)) { exploding = false; } if (Keyboard.GetState().IsKeyDown(Keys.Right)) { renderer.ActiveScene.Access(mod1).Translate(Vector3.Right); } if (Keyboard.GetState().IsKeyDown(Keys.Left)) { renderer.ActiveScene.Access(mod1).Translate(Vector3.Left); } if (Keyboard.GetState().IsKeyDown(Keys.Up)) { renderer.ActiveScene.Access(mod1).Translate(Vector3.Up); } if (Keyboard.GetState().IsKeyDown(Keys.Down)) { renderer.ActiveScene.Access(mod1).Translate(Vector3.Down); } if (Keyboard.GetState().IsKeyDown(Keys.F)) { renderer.ActiveScene.Access(mod).Translate(Vector3.Forward); } if (Keyboard.GetState().IsKeyDown(Keys.B)) { renderer.ActiveScene.Access(mod).Translate(Vector3.Backward); } if (Keyboard.GetState().IsKeyDown(Keys.X)) { renderer.ActiveScene.Access(mod).RotateZ(.1f); //No Longer used } if (Keyboard.GetState().IsKeyDown(Keys.Y)) { renderer.ActiveScene.Access(mod).RotateY(.1f);// No Longer used } if (Keyboard.GetState().IsKeyDown(Keys.Z)) { renderer.ActiveScene.Access(mod).Aim(renderer.ActiveScene.Access(mod).Right, .1f); } if (Keyboard.GetState().IsKeyDown(Keys.D)) { renderer.ActiveScene.Access(mod).TranslateRelativly(Vector3.Right); } if (Keyboard.GetState().IsKeyDown(Keys.S)) { renderer.ActiveScene.Access(mod).TranslateRelativly(Vector3.Down); } if (Keyboard.GetState().IsKeyDown(Keys.W)) { renderer.ActiveScene.Access(mod).TranslateRelativly(Vector3.Up); } if (Keyboard.GetState().IsKeyDown(Keys.A)) { renderer.ActiveScene.Access(mod).TranslateRelativly(Vector3.Left); } //if (Keyboard.GetState().IsKeyDown(Keys.A)) // { // renderer.ActiveScene.Access3D(tur).Attach(renderer.ActiveScene.Access3D(mod), "Mount"); // renderer.ActiveScene.Access3D(tur1).Attach(renderer.ActiveScene.Access3D(mod1), "Mount"); // } if (Keyboard.GetState().IsKeyDown(Keys.T)) { renderer.ActiveScene.Access3D(tur).TrackToCursor(); renderer.ActiveScene.Access3D(tur1).TrackToCursor(); } if (Keyboard.GetState().IsKeyDown(Keys.P)) { renderer.ActiveScene.Access3D(tur).Animate(animations.GetAnimation("Cannon0_Fire")); } if (Keyboard.GetState().IsKeyDown(Keys.O)) { renderer.ActiveScene.Access3D(tur).Animate(animations.GetAnimation("Cannon0_Cooldown")); } if (Keyboard.GetState().IsKeyDown(Keys.L)) { System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog(); // Default to the directory which contains our content files. string assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location; string relativePath = System.IO.Path.Combine(assemblyLocation, "../../../../Content"); string contentPath = System.IO.Path.GetFullPath(relativePath); fileDialog.InitialDirectory = contentPath; fileDialog.Title = "Load Model"; fileDialog.Filter = "Model Files (*.fbx;*.x)|*.fbx;*.x|" + "FBX Files (*.fbx)|*.fbx|" + "X Files (*.x)|*.x|" + "All Files (*.*)|*.*"; if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { LoadModel(fileDialog.FileName); } } }
/// <summary> /// Calls Update on the active scene /// </summary> public void Update() { WorldMouse.Update(); activeScene.Update(); }