Advertisement
Dieton

UnityNotes.cs

May 18th, 2023 (edited)
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.56 KB | Gaming | 0 0
  1. ////Welcome to my notes where i throw a bunch of information i need to go back and look at but probably wont
  2. /*
  3. ////-=-=-=- Things To Learn -=-=-=-////
  4. Generics
  5. Lambda
  6. c# recursive function
  7.  
  8. Dependacy
  9.  
  10. //For Unity
  11. c# function design pattern
  12.     //you dont need to use singletons
  13.     1. singleton = https://youtu.be/mpM0C6quQjs
  14.     2. Abstract Factory = https://youtu.be/vj_3b9JXaZE
  15.     3. Factory Method https://youtu.be/xN7EFHU_rXA
  16.     4. Builder https://youtu.be/R-_Ud2egx7M
  17.     5. Prototype
  18.     6. Adapter
  19.     7. Bridge
  20.     9. Composite
  21.     10. Decorator
  22.     11. Facade
  23.     12. Flyweight
  24.     13. Proxy
  25.     14. hain of Responsibility
  26.     15. Command
  27.     16. Interpreter
  28.     17. Iterator
  29.     18. Mediator
  30.     18. Memento
  31.     20. Observer
  32.     21. State
  33.     22. Strategy
  34.     23. Template Method
  35.     24. Visitor
  36. and i cant think of enything elses beacus i dont know what i dont know
  37.  
  38. Notes:
  39. Concatenate = “1”+”2” = “12”
  40.  
  41.  
  42. //Shorter If statement
  43. variavleA = VariableB?.someField;
  44.  
  45. is equivalent to
  46. if (VariableB== null)
  47.   variavleA = null;
  48. else
  49.   variavleA = VariableB.someField;
  50.  
  51. and
  52. VariableB?.SomeMethod();
  53.  
  54. to
  55. if (VariableB != null)
  56.   VariableB.SomeMethod();
  57.  
  58.  
  59. //transform.LookAt(2 * transform.position - lookingAt.position);
  60. */
  61. using System;
  62. using System.Collections;
  63. using System.Collections.Generic;
  64. using UnityEngine;
  65. using System.Text;
  66. using UnityEngine.Events;
  67. using Microsoft;
  68. using UnityEngine.Lumin;
  69. using System.IO;
  70. using UnityEngine.Networking;
  71. using System;
  72. using UnityEngine.UI;
  73. using TMPro;
  74.  
  75. //you can add if statements to just about anything for just about any reason
  76. #if ENABLE_INPUT_SYSTEM
  77. using UnityEngine.InputSystem;
  78. #endif
  79.  
  80. //make it so your script requires stuff inorder to use to reduce the chance of errors
  81. [RequireComponent(typeof(GameObject))]
  82. public class UnityNotes : MonoBehaviour
  83. {
  84.     //list Class
  85.     public List<myListClass> _myListClass = new List<myListClass>();
  86.  
  87.     //setup restrictions like you and only send or receve
  88.     public int settersAndGetter { get; set; }
  89.  
  90.     //test UI Button
  91.     private Button[] teleportButtons = defult;//im not sure what defult is, might need to look into that more
  92.  
  93.     //mulypurpose function overriding
  94.     public void Example(int myInt) {
  95.         //Do Something
  96.     }
  97.  
  98.     public void Example(Color myColor)
  99.     {
  100.         //DoSomething
  101.     }
  102.    
  103.     public void Example(int myInt, Color myColor)
  104.     {
  105.         Example(myInt);
  106.         Example(myColor);
  107.     }
  108.  
  109.     //==== Variable Function (parameter) ====// "arguments" (or "parameters" interchangeably)
  110.     public bool GreaterThanFive(int value) {
  111.         if (value > 5)
  112.             return true;
  113.         else
  114.             return false;
  115.     }
  116.  
  117.     //regions are a good way to organise and make code less overwelming
  118.     #region Basics
  119.    
  120.     //overloading (the different versions of a method with a same name are "overloads")
  121.     public void Example(int myInt) {
  122.         //Do Something
  123.     }
  124.  
  125.     public void Example(Color myColor)
  126.     {
  127.         //DO Something
  128.     }
  129.  
  130.     public void Example(int myInt, Color myColor)
  131.     {
  132.         Example(myInt);
  133.         Example(myColor);
  134.     }
  135.  
  136.     private int sgExample_1;
  137.     public int settersAndGetter_2
  138.     {
  139.         get
  140.         {
  141.             return sgExample_1;
  142.         }
  143.  
  144.         set
  145.         {
  146.             value = sgExample_1;
  147.         }
  148.     }
  149.  
  150.     //==== START ====//
  151.     // Start is called before the first frame update
  152.     void Start()
  153.     {
  154.         StartCoroutine(CoroutineExample());
  155.         SetupTeleportButtons();
  156.     }
  157.     //==== End START ====//
  158.  
  159.     // Update is called once per frame
  160.     void Update()
  161.     {
  162.        
  163.     }
  164.     #endregion
  165.  
  166.     IEnumerator CoroutineExample()
  167.     {
  168.         while (true) {
  169.             MyShortFunction();
  170.             yield return new WaitForSeconds(1);
  171.         }
  172.     }
  173.    
  174.     //This is a neet thing you can do to buttons, you can asighn functions to them withought using the on click event
  175.     public void SetupTeleportButtons() {
  176.         testbutton.onClick.AddListener(() =>
  177.         {
  178.             if(true)
  179.             TestButton("Button Pushed");
  180.         });
  181.     }
  182.  
  183.     public void TestButton(string testtext)
  184.     {
  185.         Debug.Log(testtext);
  186.     }  
  187.  
  188.     //Short function
  189.     private void MyShortFunction() => Debug.Log("This is a Short Function");
  190.    
  191.     //==== ExampleFunction ====//
  192.     [ContextMenu("hat")]// this alows you to call it from the editer
  193.     public void ExampleFunction(int index)
  194.     {
  195.         if (index == 0)
  196.             return;
  197.  
  198.         List<int> values = new List<int>();
  199.  
  200.         values.Add(1);
  201.  
  202.         //for loop alows you to loop through lists arrays and dictionaries
  203.         for (int i = 0; i < values.Count; i++)
  204.         {
  205.             if(youWantToSkipForLoop == true)
  206.             {
  207.                 //This will stop runing thought the for loop
  208.                 continue;
  209.             }
  210.             Debug.Log(values[i]);
  211.         }
  212.  
  213.         //foreach loop alows you to loop through lists arrays and dictionaries
  214.         foreach (var item in values)
  215.         {
  216.             if(youWantToSkipforeachLoop == true)
  217.             {
  218.                 //This will stop runing thought the foreach loop
  219.                 continue;
  220.             }
  221.             Debug.Log(item);
  222.         }
  223.        
  224.         //case switch
  225.         switch (index)
  226.         {
  227.             case 1:
  228.                 Debug.Log("index: 5");
  229.                 break;
  230.             case 2:
  231.                 Debug.Log("index: 4");
  232.                 break;
  233.             case 3:
  234.                 Debug.Log("index: 3");
  235.                 break;
  236.             default:
  237.                 Debug.Log("index: 0");
  238.                 break;
  239.         }
  240.  
  241.         Debug.Log($"Test Index Value: {index}");
  242.     }
  243. }
  244.  
  245. [Serializable]//Serializable makes it visable in the editer
  246. public class myListClass{
  247.     public string name;
  248.     //you can put another listClass in a List class have have list class layers
  249. }
Tags: Unity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement