This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| /// <summary> | |
| /// provides an easy way to create singletons in unity based on monobehaviours | |
| /// </summary> | |
| /// <typeparam name="T">T must be the same type as the declaring type</typeparam> | |
| public class MBSingleton<T> : MonoBehaviour where T : MonoBehaviour | |
| { | |
| protected static T _instance; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static T CopyComponent<T>(T component, GameObject destination) where T : Component | |
| { | |
| var type = component.GetType(); | |
| var copy = destination.AddComponent(type); | |
| var fields = type.GetRuntimeFields(); | |
| // component, gameobject, etc. will override the name and tags, we don't want that | |
| var properties = type.GetRuntimeProperties().Where(p => p.SetMethod != null && p.GetGetMethod(false) != null && | |
| p.DeclaringType != typeof(GameObject) | |
| && p.DeclaringType != typeof(Component) | |
| && p.DeclaringType != typeof(UnityEngine.Object)).ToArray(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| public class SelfCreatingPrefab : MonoBehaviour | |
| { | |
| private int fieldA; | |
| private int fieldB; | |
| public SelfCreatingPrefab Init(int arg1, int arg2) | |
| { | |
| if (!gameObject.scene.IsValid()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using UnityEngine; | |
| #if UNITY_EDITOR | |
| using UnityEditor; | |
| #endif | |
| [AttributeUsage(AttributeTargets.Field)] | |
| public class PrefabOnlyAttribute : PropertyAttribute { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Console.Beep(523, 300); | |
| Console.Beep(587, 300); | |
| Console.Beep(659, 300); | |
| Console.Beep(698, 300); | |
| Console.Beep(587, 900); | |
| Console.Beep(783, 300); | |
| Console.Beep(880, 300); | |
| Console.Beep(783, 1200); | |
| Console.Beep(523, 150); | |
| Console.Beep(587, 150); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Orioginally by maybe_an_username | |
| // https://www.reddit.com/r/PowerShell/comments/q8l24k/some_powershell_beep/ | |
| Console.Beep(196, 1200); | |
| Console.Beep(196, 300); | |
| Console.Beep(220, 400); | |
| Console.Beep(196, 400); | |
| Console.Beep(174, 300); | |
| Console.Beep(155, 1000); | |
| Console.Beep(146, 1000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Originally by Shensd | |
| // https://gist.github.com/Shensd/01342e2f399de4dca2ca87b36059ba0a | |
| Console.Beep(369, 200); | |
| Console.Beep(369, 200); | |
| Console.Beep(369, 200); | |
| Console.Beep(293, 300); | |
| Console.Beep(246, 200); | |
| Console.Beep(329, 250); | |
| Console.Beep(329, 200); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Scene physicsScene = new Scene(); | |
| var go1 = physicsScene.Instantiate(); | |
| var rb1 = new Rigidbody(go1) { Gravity = 0, Velocity = new Vector2(0, 1) }; | |
| go1.AddComponent(rb1); | |
| go1.AddComponent(new Collider(rb1, go1, 1)); | |
| var go2 = physicsScene.Instantiate(); | |
| go2.transform.Position = new Vector2(0, 10); | |
| var rb2 = new Rigidbody(go2) { Gravity = 0, Velocity = new Vector2(0, 0) }; | |
| go2.AddComponent(rb2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Managed managed = new Managed(); | |
| await Task.Delay(1000); | |
| Console.WriteLine("managed is now null."); | |
| managed = null; | |
| Console.WriteLine("press any key to make the GC collect"); | |
| Console.ReadLine(); | |
| GC.Collect(); | |
| Console.ReadLine(); |
NewerOlder