Главная | Обратная связь | Поможем написать вашу работу!
МегаЛекции

ProBuilder. Shaders. Info Dump. Creating a Noise image. C# Scripting. Callbacks. Programming Patterns. Declarative vs Imperative Programming




ProBuilder

Shaders

Info Dump

Lighting types:

○ Lambert: Basic, single-source lighting

○ Blinn Phong: More taxing, but allows for PBR

Pragma: Tells the compiler how the code is supposed to be used

Fallback: Provide a fallback shader to use; it will search the GPU for a program that accomplishes a similar function to what you are trying to perform, but written more efficiently

○ Specified as a string at the bottom of the script

○ Allows the shader to continue to function on less powerful hardware

Fixed, Half, Float: Different precision levels

Creating a Noise image

● Using Photoshop, create a canvas which is a power of 2; this should make the image tile evenly across all edges

● Render > Clouds

C# Scripting

Callbacks

Pass-Through Method:

Get and Give the same: A “pass-through” method is so-called because it takes something of a given Type as a parameter and returns something of an identical type as a result.

Sneak this in: A Pass-Through method can be inserted into code to modify data pretty easily because the data that it modifies comes out the type that was already expected. This is most easily demonstrated through example:

textMeshProInstance. text = “Hello World”;

○ The above code assigns a string “Hello World” to the text parameter of a TextMeshPro instance.

○ We can imagine a “Translate” static method which takes in a type “String” and returns a Type “String” now translated into a language of our choice.

○ Because “Translate” takes in a string and returns a string, we can pass into it the existing “Hello World” string:
textMeshProInstance. text = Translate(“Hello World”);

As keyword:

Give me null, not an exception: When trying to perform a cast, the “as” keyword will give us back “null” instead of throwing an exception if the cast fails

Programming Patterns

Declarative vs Imperative Programming

Imperative Programming:

○ Specify how something should be done.

○ Take Control of Every Step

○ Give explicit instructions to control every aspect of how code is executed

Declarative Programming:

○ Specify what you want done

○ Give instructions to guide the execution but leave the particulars up to the PC

Example; LINQ

Singleton Pattern

Dependency Injection

Unity Features

RequireComponent

Automatic Component Inclusion: When you are writing a script which requires a particular Unity component to exist on a GameObject, you can prevent errors by using RequireComponent to have the required Component automatically added to the GameObject at the time the script is added.

Prevents removal: Using “RequireComponent” prevents the user from removing the required Component in the Inspector

Implementation: Insert above the class declaration using []

[ RequireComponent (typeof(requiredComponent))]

public class className : MonoBehaviour

● https: //docs. unity3d. com/ScriptReference/RequireComponent. html

Scriptable Objects

Coroutines

https: //docs. unity3d. com/Manual/Coroutines. html

● Nested Coroutines

Namespaces

Using directive

https: //docs. microsoft. com/en-us/dotnet/csharp/language-reference/keywords/using-directive

C# Language Features

Enums

Declare an Enum:

Simple Declaration:
public enum EnumName { FIRST, SECOND, ETC }

Declare with values assigned:
public enum EnumName { FIRST = 5, SECOND = 10, ETC = 15}

Get the name of an Enum:

The Easy way: Use “ToString()”
string str = EnumName. FIRST_ELEMENT. ToString();

The Hard way: Use Enum. GetName
EnumName myEnum = EnumName. FIRST_ELEMENT;
string str = Enum. GetName(typeof(EnumName), myEnum);

Create a Switch based on an Enum: Visual Studio can automatically fill out the cases of a switch based on an enum
public void SetWindowActive(UIWindows window, bool _isActive) {

       switch(window) {

           case UIWindows. Politics: politics. SetWindowActive(_isActive); break;

           case UIWindows. RICO: rico. SetWindowActive(_isActive); break;

           case UIWindows. Infographs: infograph. SetWindowActive(_isActive); break;

           default: Debug. Log(" Cannot open window: " + window); break;

       }

   }

Enumerate over an enum: Do something for each element in an enum:
public enum Suit { Spades, Hearts, Clubs, Diamonds }

foreach (var item in (Suit[]) Enum. GetValues(typeof(Suit))) {
           

}

○ https: //stackoverflow. com/questions/105372/how-to-enumerate-an-enum

Statements vs Expressions:

Statement:

○ An action a program takes:

■ Declaring variables

■ Assigning values

■ Calling methods

■ Etc.

○ Broken up into single-lines denoted by “; ” or into multi-line statements denoted between braces “{ }”

○ Statements are broken up into several keywords outlined in the “ Statement Keywords ” section

Expression:

Partial

Divide code into separate files: Include the “partial” keyword before the definition of a class, struct, or interface to split the code into different files

Partial Methods: Methods can also be partially defined, but with lots of restrictions; (they must be void and private)

Implementation: Simply include the “partial” keyword in front of the class keyword when defining a class:
public partial class Employee

● https: //docs. microsoft. com/en-us/dotnet/csharp/programming-guide/classes-and-structs/partial-classes-and-methods

Поделиться:





Воспользуйтесь поиском по сайту:



©2015 - 2024 megalektsii.ru Все авторские права принадлежат авторам лекционных материалов. Обратная связь с нами...