خرید بک لینک

Vote count: 0

I'm new to Unity and I don't know very much about it. However, I've played around with Java and Objective-C in the past; two object-oriented C-based programming languages that are very much like the C# Unity uses.

Objective-C has blocks that are variables that allow you to store a function inside of them and call them later. When used in practice, you can use blocks as function parameters and class properties, saving a programmer "if" statements and instead simply calling the block.

An example of that syntax would be (taken from the linked tutorial site):

// Declare a block variable
double (^distanceFromRateAndTime)(double rate, double time);

// Create and assign the block
distanceFromRateAndTime = ^double(double rate, double time) {
   retu rate * time;
};

// Call the block
double dx = distanceFromRateAndTime(35, 1.5);

NSLog(@"A car driving 35 mph will travel %.2f miles in 1.5 hours.", dx);

Java has the Ruable class, which is the basis of its multithreading structure. (Thread inherits from Ruable.) I leaed about that class from a previous question I asked. There are two ways of making a Ruable: The Java 8 way of using lambdas...

Ruable r = () -> { System.out.println("This is just an example!"); }

The Java 8 using lambdas as a function parameter...

void someFunction(Ruable r) {
    r.run();
}

// In a method, not sure about the semicolons
someFunction( () -> { System.out.println("This will work, too!"); });

And finally, pre-Java 8...

Ruable r = Ruable(){
    @Override
    public void run() {
         System.out.println("Yet another example");
    }
}

My question is, how would I go about achieving this in Unity's variant of C#?

asked 3 mins ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 30 ارديبهشت 1395 ساعت: 5:09

صفحه بندی