diff --git a/Assets/Scripts/UI/UIElementMouseCapturer.cs b/Assets/Scripts/UI/UIElementMouseCapturer.cs index 24e6346..986ae5a 100644 --- a/Assets/Scripts/UI/UIElementMouseCapturer.cs +++ b/Assets/Scripts/UI/UIElementMouseCapturer.cs @@ -22,7 +22,6 @@ public class UIElementMouseCapturer : EventTrigger public void OnDisable() { - Debug.Log("UIElementMouseCapturer OnDisable"); OnPointerExit(null); } diff --git a/README.md b/README.md new file mode 100644 index 0000000..5ad1cd1 --- /dev/null +++ b/README.md @@ -0,0 +1,89 @@ +# micromissiles-unity + +# Getting started **developing** micromissiles-unity + +This guide will help you set up and run the project in development mode. You'll learn how to install Unity Hub, open the project, and navigate the main scene. + +## Table of Contents + +- [Prerequisites](#prerequisites) +- [Installation Steps](#installation-steps) + - [1. Install Unity Hub](#1-install-unity-hub) + - [2. Clone the Project Repository](#2-clone-the-project-repository) + - [3. Launch the Project via Unity Hub](#3-launch-the-project-via-unity-hub) + - [4. Open the Main Scene](#4-open-the-main-scene) +- [Next Steps](#next-steps) +- [Additional Resources](#additional-resources) + +## Prerequisites + +- A computer with internet access. +- Administrative privileges to install software. +- [Git](https://git-scm.com/downloads) installed on your system (optional, for cloning the repository). + +## Installation Steps + +### 1. Install Unity Hub + +Unity Hub is a desktop application that manages your Unity projects and installations. It simplifies the process of installing different Unity versions and launching projects. + +**Steps to Install Unity Hub:** + +1. Visit the [Unity Download Page](https://unity3d.com/get-unity/download). +2. Click on **"Download Unity Hub"**. +3. Run the downloaded installer and follow the on-screen instructions to complete the installation. + +### 2. Clone the Project Repository + +Obtain the project source code by cloning the repository from GitHub. + +```bash +git clone https://github.com/PisterLab/micromissiles-unity.git +``` +Alternatively, you can download the repository as a ZIP file and extract it to a preferred location. + +### 3. Launch the Project via Unity Hub + +1. **Open Unity Hub**. + +2. **Add the Project to Unity Hub**: + - Navigate to the **"Projects"** tab. + - Click on the **"ADD"** button. + - Browse to the folder where you cloned or extracted the project. + - Select the folder containing the `Assets` folder and click **"Select Folder"**. + +3. **Install the Required Unity Version**: + - Unity Hub will detect if the project requires a Unity version that is not currently installed. + - A notification or warning icon may appear next to the project name. + - Click on the notification and select **"Install Unity **[version]**"**. + - Unity Hub will download and install the required Unity version automatically. + +4. **Open the Project**: + - Once the required Unity version is installed, click on the project name in Unity Hub to open it. + + +### 4. Open the Main Scene + +After the project opens in Unity: + +1. In the **Project** window (usually located at the bottom), navigate to: + + ``` + Assets/Scenes/ + ``` + +2. Find the main scene file, usually named `MainScene.unity`. + +3. Double-click on `MainScene.unity` to open it. + +4. The scene will load in the **Scene** view. You can now run the simulation by clicking the **Play** button at the top of the Unity Editor. + +## Next Steps + +- Familiarize yourself with the [**Keybinds and Controls**](docs/Keybinds_and_Controls.md) to navigate and interact with the simulation. +- Learn how to configure the simulation settings by reading the [**Simulation Configuration Guide**](docs/Simulation_Config_Guide.md). + +## Additional Resources + +- [Keybinds and Controls](docs/Keybinds_and_Controls.md) +- [Simulation Configuration Guide](docs/Simulation_Config_Guide.md) \ No newline at end of file diff --git a/docs/Keybinds_and_Controls.md b/docs/Keybinds_and_Controls.md new file mode 100644 index 0000000..2dc2d16 --- /dev/null +++ b/docs/Keybinds_and_Controls.md @@ -0,0 +1,88 @@ +# Keybinds and Controls + +Welcome to the simulation! This guide will help you navigate and interact with the environment using your mouse and keyboard. Below are the keybindings organized into easy-to-read tables, along with detailed descriptions to enhance your experience. + +## Table of Contents +- [Mouse Controls](#mouse-controls) +- [Keyboard Controls](#keyboard-controls) + - [Camera Movement](#camera-movement) + - [Camera Speed](#camera-speed) + - [Simulation Controls](#simulation-controls) + - [Additional Controls](#additional-controls) + - [Preset Views](#preset-views) + +## Mouse Controls + +Use your mouse to control the camera's orientation and zoom level. + +| **Action** | **Keybind** | **Description** | +|---------------------------|-----------------------------|-----------------------------------------------------------| +| **Orbit Camera** | Left Mouse Button (Hold) | Rotate the camera around a focal point by holding the left mouse button and moving the mouse. | +| **Rotate Camera** | Right Mouse Button (Hold) | Adjust the camera's rotation by holding the right mouse button and moving the mouse. | +| **Zoom In/Out** | Mouse Scroll Wheel | Scroll the wheel up to zoom in and scroll down to zoom out. | + +## Keyboard Controls + +### Camera Movement + +Navigate the camera through the simulation using the following keys: + +| **Action** | **Keys** | **Description** | +|----------------------|------------------------------------|-----------------------------------------------------------| +| **Move Forward** | **W** or **Up Arrow** | Moves the camera forward in the simulation space. | +| **Move Left** | **A** or **Left Arrow** | Moves the camera to the left side. | +| **Move Backward** | **S** or **Down Arrow** | Moves the camera backward. | +| **Move Right** | **D** or **Right Arrow** | Moves the camera to the right side. | +| **Move Upward** | **Q** | Raises the camera upward. | +| **Move Downward** | **E** | Lowers the camera downward. | + +### Camera Speed + +Adjust the speed of the camera movement to suit your preference: + +| **Action** | **Keybind** | **Description** | +|----------------------|-------------------|-----------------------------------------------------------| +| **Increase Speed** | **Left Shift (Hold)** | Hold down the Left Shift key to move the camera faster. | +| **Normal Speed** | *Release Left Shift* | Releases the Left Shift key to return to normal movement speed. | + +### Simulation Controls + +Manage the simulation state with these keybinds: + +| **Action** | **Keybind** | **Description** | +|----------------------|-------------------|-----------------------------------------------------------| +| **Pause/Resume** | **Spacebar** | Toggles between pausing and resuming the simulation. | +| **Restart Simulation** | **R** | Restarts the simulation from the beginning. | +| **Toggle Configuration Panel** | **L** | Opens or closes the configuration selector panel for adjusting simulation settings. | + +### Additional Controls + +Enhance your interaction with the simulation using these additional keybinds: + +| **Action** | **Keybind** | **Description** | +|----------------------|-------------------|-----------------------------------------------------------| +| **Toggle Auto-Rotate** | **P** | Enables or disables the camera's auto-rotate feature. | +| **Quit Application** | **Esc** | Exits the simulation application. | + +### Preset Views + +Quickly switch to predefined camera angles for different perspectives: + +| **Action** | **Keybind** | **Description** | +|----------------------|-------------------|-----------------------------------------------------------| +| **Preset View 1** | **1** | Switches to the first predefined camera view. | +| **Preset View 2** | **2** | Switches to the second predefined camera view. | +| **Preset View 3** | **3** | Switches to the third predefined camera view. | +| **Preset View 4** | **4** | Switches to the fourth predefined camera view. | +| **Preset View 5** | **5** | Switches to the fifth predefined camera view. | +| **Preset View 6** | **6** | Switches to the sixth predefined camera view. | + +*Note: The implementation for preset views may be added in future updates.* + +## Tips for Effective Navigation + +- **Combining Controls**: Feel free to combine mouse and keyboard controls for a more dynamic navigation experience. For example, hold the **Left Shift** key while moving the camera forward with the **W** key for faster traversal. +- **Pausing for Adjustments**: Use the **Spacebar** to pause the simulation, allowing you to adjust camera angles or settings without interruption. +- **Exploring Views**: Utilize the preset views to quickly jump to different perspectives, making it easier to explore various aspects of the simulation. + +We hope this guide enhances your experience. Happy simming! \ No newline at end of file diff --git a/docs/Simulation_Config_Guide.md b/docs/Simulation_Config_Guide.md new file mode 100644 index 0000000..9c3815d --- /dev/null +++ b/docs/Simulation_Config_Guide.md @@ -0,0 +1,207 @@ +# Simulation Configuration Guide + +This guide provides instructions on how to configure the simulation by editing the configuration files. You can customize missile and target behaviors, simulation parameters, and more to suit your research needs. + +## Configuration Files + +The main configuration files you will work with are: + +- **Simulation Configurations**: + - JSON File: [`1_salvo_1_hydra_7_drones.json`](Assets/StreamingAssets/Configs/1_salvo_1_hydra_7_drones.json) + - C# Script: [`SimulationConfig.cs`](Assets/Scripts/Config/SimulationConfig.cs) + +- **Model Configurations**: + - JSON File: [`micromissile.json`](Assets/StreamingAssets/Configs/Models/micromissile.json) + - C# Script: [`StaticConfig.cs`](Assets/Scripts/Config/StaticConfig.cs) + +### File Locations + +- **Simulation Configurations** are found in `Assets/StreamingAssets/Configs/`. +- **Model Configurations** are located in `Assets/StreamingAssets/Configs/Models/`. + +## Simulation Configurations + +### Editing Simulation Configurations + +#### `1_salvo_1_hydra_7_drones.json` + +This JSON file outlines the initial setup for missiles and targets. + +```json:Assets/StreamingAssets/Configs/1_salvo_1_hydra_7_drones.json +{ + "timeScale": 1, + "missile_swarm_configs": [ + { + "num_agents": 1, + "agent_config": { + "missile_type": "HYDRA_70", + // Additional configurations... + } + } + ], + "target_swarm_configs": [ + { + "num_agents": 7, + "agent_config": { + "target_type": "DRONE", + // Additional configurations... + } + } + ] +} +``` + +- **`timeScale`**: Adjusts the speed of the simulation. +- **`missile_swarm_configs`**: Contains settings for missile swarms. +- **`target_swarm_configs`**: Contains settings for target swarms. + +#### Key Configuration Parameters + +- **`num_agents`**: Specifies how many agents (missiles or targets) are involved. +- **`agent_config`**: Contains settings for each agent, including: + - **`missile_type`** / **`target_type`**: Defines the type of missile or target. + - **`initial_state`**: Sets the starting position, rotation, and velocity. + - **`standard_deviation`**: Adds random noise to initial states. + - **`dynamic_config`**: Includes time-dependent settings like launch times and sensor configurations. + - **`submunitions_config`**: Details for any submunitions used. + +### Adding or Modifying Agents + +1. **Add a New Swarm Configuration**: + + To introduce a new missile or target swarm, create a new entry in `missile_swarm_configs` or `target_swarm_configs`. + + ```json + { + "num_agents": 5, + "agent_config": { + "missile_type": "MICROMISSILE", + // Additional configurations... + } + } + ``` + +2. **Modify Existing Configurations**: + + Change parameters like `num_agents`, `initial_state`, or `dynamic_config` to adjust the behavior of existing agents. + +### `SimulationConfig.cs` + +This script defines the data structures used to interpret the JSON configuration files. + +```csharp:Assets/Scripts/Config/SimulationConfig.cs +using System; +using System.Collections.Generic; +using UnityEngine; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +[Serializable] +public class SimulationConfig { + [Header("Simulation Settings")] + public float timeScale = 0.05f; + + [Header("Missile Swarm Configurations")] + public List missile_swarm_configs = new List(); + + [Header("Target Swarm Configurations")] + public List target_swarm_configs = new List(); +} + +// Additional classes and enums... +``` + +- **Classes**: + - `SimulationConfig`: Contains all simulation settings. + - `SwarmConfig`: Represents a group of agents. + - `AgentConfig`: Configuration for individual agents. + +- **Enums**: + - `MissileType`, `TargetType`, and `SensorType` define available types. + +#### Editing Enums + +To add new missile or target types, update the enums accordingly. + +```csharp:Assets/Scripts/Config/SimulationConfig.cs +[JsonConverter(typeof(StringEnumConverter))] +public enum MissileType { HYDRA_70, MICROMISSILE, NEW_MISSILE_TYPE } +``` + +## Model Configurations + +### Editing Model Configurations + +#### `micromissile.json` + +This file defines the physical and performance characteristics of the missile models. + +```json:Assets/StreamingAssets/Configs/Models/micromissile.json +{ + "accelerationConfig": { + "maxReferenceAcceleration": 300, + "referenceSpeed": 1000 + }, + "boostConfig": { + "boostTime": 0.3, + "boostAcceleration": 350 + }, + // Additional configurations... +} +``` + +- **`accelerationConfig`**: Parameters for acceleration. +- **`boostConfig`**: Settings for the boost phase. +- **`liftDragConfig`**: Aerodynamic properties. +- **`bodyConfig`**: Physical properties like mass and area. +- **`hitConfig`**: Collision and hit detection properties. + +### Modifying Parameters + +Adjust values to change the missile's behavior, such as increasing acceleration or changing mass. + +### Adding New Models + +To define a new missile or target model: + +1. **Create a New JSON File** in `Assets/StreamingAssets/Configs/Models/`. +2. **Define Model Parameters** similar to `micromissile.json`. +3. **Update the Code** to recognize and load the new model. + +### `StaticConfig.cs` + +This file defines classes corresponding to the model configuration JSON structure. + +```csharp:Assets/Scripts/Config/StaticConfig.cs +using System; + +[Serializable] +public class StaticConfig { + // Nested classes for configuration parameters... +} +``` + +#### Updating Classes + +If you add new parameters to the JSON model files, ensure the corresponding classes in `StaticConfig.cs` are updated. + +## Using the Deployment Build + +When using the deployment build: + +- Ensure all required configuration files are included. +- Place simulation configuration files in the appropriate directory (`StreamingAssets/Configs/`). +- Modify the JSON files to adjust the simulation without needing to rebuild the application. + +--- + +**Note**: Always back up configuration files before making significant changes. Incorrect configurations can lead to simulation errors. + +For further assistance, refer to the comments and documentation within the code files: + +- [`SimManager.cs`](Assets/Scripts/SimManager.cs): Manages simulation state and agent creation. +- [`InputManager.cs`](Assets/Scripts/Managers/InputManager.cs): Handles user input and interactions. + +--- + +*This guide aims to help you set up and customize the simulation project effectively. If you encounter any issues or have questions, please reach out to the project maintainers.* \ No newline at end of file