• Twitter
  • Facebook
  • Google+
  • Instagram
  • Youtube

Friday, 24 February 2017

Trading Card Game - Dev Log 03

Trading Card Game - Dev Log 03

  • Date: 25 Feb 2017

Content

  • Rope and timer

    • UnityEvent: A zero argument persistent callback that can be saved with the scene.
      • It's an event as a field.
      • This event raises when the timer expires.
      • For example, when time runs out, call EndTurn method from TurnManager
    • Why SerializeField?
      • Force Unity to turn this field into serial of bits.
      • Later use: communication between different application
    •     [SerializeField]
    •     public UnityEvent TimerExpired = new UnityEvent();
    • How an UnityEvent raises registered method
      • Use Invoke: TimerExpired.Invoke();

  • Turn Manager

  • SerializeField in Unity

    • It's an attribute.
    • Force Unity to serialize a private field into serial of bits.
    • From Unity's document, we almost never need to serialize a field because Unity will serialize all your scripts.

  • Differences between delegate invoke and call a method directly?

    • Directly call a method (early binding)
      • the compiler
        • generate code
        • to look up the method start address in the virtual table
        • push the parameters onto the stack
        • invoke the method
      • Pros
        • Highly optimised and very fast given modern processors.  
        • the ideal mechanism to use
      • Cons
        • must know at compilation time the type being referenced, the method name and its signature
        • If the method information changes then your code won't compile
    • Invoke is a late binding technique 
      • postpone determining a method name and signature
      • until you are actually ready to call it. 
      • dynamically load assemblies and types
      • You can't use early binding because the types were not available during compilation
      • Invoke is slow compared to early binding. 
      • Furthermore, if you get the method information wrong then an exception will occur. The compiler can not help you at all because the method is being referenced at runtime. In general, you should use invoke only when you absolutely have no idea at compilation time what a method might be. In general, interfaces are used to provide a hybrid approach where you can early bind to the method but late bind to the actual implementation.


0 comments:

Post a Comment

Contact

Get in touch with me


Adress/Street

Jozi Studio -Sydney, New South Wales

Phone number

+(12) 3456 789

Website

www.learnwithjoe.blogpost.com.au