├── Images ├── BotInstruction.JPG ├── ChatbotScene.JPG ├── MediaFile.JPG ├── NewUI.JPG ├── ScreenShot1.JPG ├── ScreenShot2.JPG ├── ScreenShot3.JPG ├── ScreenShot4.JPG ├── ScreenShot5.JPG ├── ScreenShot6.JPG ├── ScreenShot7.JPG ├── ScreenShot8.JPG └── SkyScene.JPG ├── LICENSE ├── README.md └── UnityAndGeminiPackageV3.2.unitypackage /Images/BotInstruction.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnityGameStudio/Gemini-Unity-Package/fb729c33773e5a812d765ab5d4e191e43de76d18/Images/BotInstruction.JPG -------------------------------------------------------------------------------- /Images/ChatbotScene.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnityGameStudio/Gemini-Unity-Package/fb729c33773e5a812d765ab5d4e191e43de76d18/Images/ChatbotScene.JPG -------------------------------------------------------------------------------- /Images/MediaFile.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnityGameStudio/Gemini-Unity-Package/fb729c33773e5a812d765ab5d4e191e43de76d18/Images/MediaFile.JPG -------------------------------------------------------------------------------- /Images/NewUI.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnityGameStudio/Gemini-Unity-Package/fb729c33773e5a812d765ab5d4e191e43de76d18/Images/NewUI.JPG -------------------------------------------------------------------------------- /Images/ScreenShot1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnityGameStudio/Gemini-Unity-Package/fb729c33773e5a812d765ab5d4e191e43de76d18/Images/ScreenShot1.JPG -------------------------------------------------------------------------------- /Images/ScreenShot2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnityGameStudio/Gemini-Unity-Package/fb729c33773e5a812d765ab5d4e191e43de76d18/Images/ScreenShot2.JPG -------------------------------------------------------------------------------- /Images/ScreenShot3.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnityGameStudio/Gemini-Unity-Package/fb729c33773e5a812d765ab5d4e191e43de76d18/Images/ScreenShot3.JPG -------------------------------------------------------------------------------- /Images/ScreenShot4.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnityGameStudio/Gemini-Unity-Package/fb729c33773e5a812d765ab5d4e191e43de76d18/Images/ScreenShot4.JPG -------------------------------------------------------------------------------- /Images/ScreenShot5.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnityGameStudio/Gemini-Unity-Package/fb729c33773e5a812d765ab5d4e191e43de76d18/Images/ScreenShot5.JPG -------------------------------------------------------------------------------- /Images/ScreenShot6.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnityGameStudio/Gemini-Unity-Package/fb729c33773e5a812d765ab5d4e191e43de76d18/Images/ScreenShot6.JPG -------------------------------------------------------------------------------- /Images/ScreenShot7.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnityGameStudio/Gemini-Unity-Package/fb729c33773e5a812d765ab5d4e191e43de76d18/Images/ScreenShot7.JPG -------------------------------------------------------------------------------- /Images/ScreenShot8.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnityGameStudio/Gemini-Unity-Package/fb729c33773e5a812d765ab5d4e191e43de76d18/Images/ScreenShot8.JPG -------------------------------------------------------------------------------- /Images/SkyScene.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnityGameStudio/Gemini-Unity-Package/fb729c33773e5a812d765ab5d4e191e43de76d18/Images/SkyScene.JPG -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 UnityGameStudio 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gemini-Unity-Package 2 | > Currently, this plugin is only suported on versions of Unity 2021.x and above 3 | 4 | # Installation 5 | 6 | This plugin is provided as a custom Unity package that you can import into any existing project with the Unity version 2021.x and above. 7 | 8 | Once you've downloaded the Unity package, you can import the package into your scene through the `Gemini_Manager_V3` prefab. 9 | 10 | --- 11 | 12 | # Setup 13 | 14 | Gemini provides an alternative to ChatGPT for Unity developers. Here's a quick guide to setting up the latest release (V3) and previous release (V2): 15 | 16 | - **V3 Setup Guide (Latest Release)**: [Watch the YouTube tutorial](https://www.youtube.com/watch?v=J-6bymbjT_M&ab_channel=UnityGameStudio) 17 | - **V2 Setup Guide (Previous Release)**: [Watch the YouTube tutorial](https://www.youtube.com/watch?v=Z6MFqIzOHK0&ab_channel=UnityGameStudio) 18 | 19 | 20 | ### Step 1: Login to your Google account and copy your secret key 21 | To get started you will first need to fetch your Google API key, which can be found in your Google AI Studio account under `Get API Key` (or through [this direct link](https://aistudio.google.com/app/apikey)). Here, you can create a new secret key and copy the value (you will need to your secret key for the next step). 22 | 23 | ![](/Images/ScreenShot4.JPG) 24 | 25 | ### Step 2: Open the Unity Editor, configure the package, and start using Gemini 26 | Inside the package, you will find a `GeminiManager` prefab. Drag the prefab into your scene, and add your API Gemini Secret Key inside the `JSONTemplate.json`. We recommend doing that, so you can git ignore your JSON file when working with github. 27 | 28 | ![](/Images/NewUI.JPG) 29 | 30 | In the component bar you will see a `JsonApi` option where you will attach the `JSONTemplate.json` text Asset. When starting the script, it will set your API_Key, and send your `prompt`, then you will receive an answer from the LLM at the beginning of the scene. 31 | 32 | ![](/Images/ScreenShot8.JPG) 33 | 34 | 35 | # Functions 36 | 37 | This plugin provides two public functions. One function to send a prompt, and receive a text reply from the Gemini API. And another function to send a chat history, and receive a reply from the Gemini API based on the chat. 38 | 39 | Prompt Function: 40 | 41 | The script contains an IEnumerator function that sends your prompt to the Gemini API and prints the response to the console by calling Debug.Log(). 42 | 43 | `private IEnumerator SendPromptRequestToGemini(string promptText)` 44 | 45 | Chatbot Function: 46 | 47 | The script contains an IEnumerator function that stores the user and Gemini responses, then sends the chat history to the Gemini API and prints the response to the console by calling Debug.Log(). 48 | There is a sample scene called `Chatbot` in the `Example` folder. 49 | 50 | The chatbot function now possess a `Bot Instructions` field, where you can add a behaviour, a knowdlege base or a background story to your chatbot. 51 | 52 | ![](/Images/BotInstruction.JPG) 53 | 54 | `private IEnumerator SendChatRequestToGemini(string newMessage)` 55 | 56 | ![](/Images/ChatbotScene.JPG) 57 | 58 | Image Prompt Function: 59 | 60 | The script contains an IEnumerator function that sends your prompt to the Gemini API `gemini-2.0-flash-exp-image-generation`, then it receives a generated image, and saves it inside your device. 61 | There is a sample scene called `SkyGeneration` in the `Example` folder. 62 | 63 | `private IEnumerator SendPromptRequestToGeminiImageGenerator(string promptText)` 64 | 65 | ![](/Images/SkyScene.JPG) 66 | 67 | Multimodal Prompt Function: 68 | 69 | The script contains an IEnumerator function that reads a Media File through its File Path, then sends the bytes to the Gemini API along with your prompt. After, it prints the response to the console by calling Debug.Log(). 70 | 71 | There is a `Media` folder with sample files inside the `Example` folder. 72 | 73 | `private IEnumerator SendPromptMediaRequestToGemini(string promptText, string mediaPath)` 74 | 75 | ![](/Images/MediaFile.JPG) 76 | 77 | # Usage 78 | The unity package was made to directly use the prompt function. When you enter a prompt and send it (click on play), Unity will send the prompt to the Gemini API, then it will receive the response, and make a `Debug.Log` of the reply. 79 | 80 | > Note that each time you send a prompt, a new chat request is sent to Gemini API. If you want to keep a chat history, I recommend using the `SendChatRequestToGemini(string newMessage)` function instead. 81 | 82 | -------------------------------------------------------------------------------- /UnityAndGeminiPackageV3.2.unitypackage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnityGameStudio/Gemini-Unity-Package/fb729c33773e5a812d765ab5d4e191e43de76d18/UnityAndGeminiPackageV3.2.unitypackage --------------------------------------------------------------------------------