Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
✅
‏‏‎

mika unitycoder

✅
‏‏‎
View GitHub Profile
@unitycoder
unitycoder / basic-inventory.md
Created January 11, 2023 16:02
unity, how to make simplest drag & drop UI system inventory?

// chatGPT

Here's one way you can create a simple drag-and-drop inventory system in Unity using the UnityEngine.UI library:

  • Create an empty GameObject and name it "Inventory". Add a GridLayoutGroup component to it, which will be used to arrange the items in a grid pattern.

  • Create an empty GameObject and name it "InventorySlot". Add an Image component and a Button component to it. The Image component will be used to display the item, and the Button component will be used to detect drag-and-drop events.

  • Create a script that will handle the drag-and-drop functionality. Attach this script to the InventorySlot GameObject. In the script, you'll need to handle the following events:

@unitycoder
unitycoder / json.md
Last active January 23, 2024 17:04
JSON notes

json validator error: "Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', ']', "got 'undefined'

you have backslash in your script, like "c:\asdf" need to escape it: "c:\asdf\"

using newtonsoft.json in unity

@unitycoder
unitycoder / C# Programming Patterns and Concepts.md
Created January 13, 2023 15:32
C# Programming Patterns and Concepts

// chatGPT

C# Programming Patterns and Concepts

Interfaces

  • Interfaces define a contract for a class, specifying a set of methods and properties that the class must implement.
  • Use interfaces when you want to define a contract that multiple classes can implement.
  • Interfaces cannot contain implementation code, only method signatures.

Abstract Classes

@unitycoder
unitycoder / CustomGameObjectEditor.cs
Last active January 16, 2023 09:45
Unity Custom Inspector Header
// chatGPT
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(GameObject))]
public class CustomGameObjectEditor : Editor
{
public override void OnInspectorGUI()
{
// Your custom inspector header code here
@unitycoder
unitycoder / GetColorForUid0.cs
Last active January 17, 2023 09:47
c# generate unique colors for integer UID numbers
sing UnityEngine;
class Example
{
public static Color GetColorForUid(int uid)
{
// You can use the mod operator to map the UID to a value between 0 and 1.
float r = (float)(uid % 256) / 256.0f;
float g = (float)((uid / 256) % 256) / 256.0f;
float b = (float)((uid / 65536) % 256) / 256.0f;
@unitycoder
unitycoder / 0GlobalObjectId.md
Last active January 17, 2023 11:54
unity GlobalObjectId returns 00000000000000000000000000000 for asset GUID, when inside prefab edit mode?

// chatGPT
The GlobalObjectId struct in Unity is used to uniquely identify an object across different Scenes and across different instances of the same Prefab. When you are in prefab edit mode, the GlobalObjectId of an object inside the Prefab will be set to all zeroes, 00000000000000000000000000000, because the object is not considered to be "live" while in edit mode. Instead, the Prefab is considered to be the live object, and the objects inside it are considered to be instances of that Prefab.

When you exit prefab edit mode, Unity will assign the GlobalObjectId for each object inside the prefab, which can be used to identify the object in the scene.

This is the expected behavior of Unity when working with prefabs. When you want to get the GlobalObjectId of an object that is inside a Prefab and you are in the Prefab edit mode, you should first exit the Prefab edit mode and then get the GlobalObjectId of the object.

refs: https://docs.unity3d.com/ScriptReference/GlobalObjectId.html

@unitycoder
unitycoder / Package.md
Last active August 10, 2023 06:21
Unity Customizing Packages (Edit Package files, without reverting back)

I believe you don't actually need to move (package name) from the Packages/ folder to the Assets/ folder in order to change the code. All you need to do is go to the Preferences > External Tools and enable "Generate .csproj files for: Local packages". This will allow you to change local packages' content (i.e. files in the Packages/) folder and trigger the recompilation. Or, you could just refresh the Asset Database manually and trigger the recompilation from within the Project window by selecting Refresh menu entry (or by using a CTRL+R shortcut).

@unitycoder
unitycoder / how new antibiotics are made.md
Created January 18, 2023 13:12
how new antibiotics are made?

New antibiotics can be developed through a variety of methods, including:

  • Natural product discovery: This involves isolating and identifying naturally occurring compounds, such as those produced by bacteria or fungi, that have antibiotic properties. These compounds can then be modified to improve their effectiveness or reduce potential side effects.
  • Synthetic drug design: This involves creating new compounds in the lab that mimic the structure and function of known antibiotics. Computer-aided drug design can be used to identify potential compounds that may have antibiotic activity.
  • Repurposing existing drugs: This involves identifying drugs that were developed for other purposes but have been found to have antibiotic properties.
  • Phage therapy: This is a new approach which is based on using bacteriophages (viruses that infect bacteria) to treat bacterial infections. Phages can be used to target specific strains of bacteria, and may be an effective alternative to traditional antibiotics.
  • Genome minin
@unitycoder
unitycoder / UpdateRotation.cs
Created January 26, 2023 07:51
Mouse Camera using Yaw, Pitch
float lookSpeed = 10;
float theta=0;
float phi=0;
// https://twitter.com/BenSimsTech/status/1618451726121701378/photo/1
private void UpdateRotation(float mouseX, float mouseY)
{
// Theta = yaw, phi = pitch
theta = Mathf.Repeat(theta — mouseX * *lookSpeed, 2.0*Mathf.PI);
phi = Mathf.Clamp(phi — mouseY * lookSpeed, Of, mathf.PI);