Saturday, February 6, 2016

MonoDevelop WhiteSpace

White space drives me nuts in an IDE.  Here is how to set the whitespace in Mono:

To change it for all future instances of projects go to  Tools > Options and set the fields below.


To change the whitespace for the current project (if the prior step hasn't been done), go to Project > Solution Options, and set the following fields.


If you want to apply those changes to open files you can go to:  Edit > Format > Format Document, and it should apply the changes to the current document.

Delegates or Callbacks

Here is an example for using Delegates to achieve a callback capability.

In the class that is going to call the callback function:

public class PointBasketManager : MonoBehaviour
{
   public delegate void GameOverEvent ();

   private GameOverEvent game_over;

   public void SetGameOverCallback (GameOverEvent newCallback)
   {
      game_over = newCallback;
   }

   public void BasketTriggered (uint points)
   {
      // trigger game is over
      game_over ();
   }
}

The using class calls the function SetGameOverCallback() and passes in the function that should be called when game_over() is called.

public class GameSystem : MonoBehaviour

{
   void Start()
   {
      point_mgr.SetGameOverCallback(OnGameEnd);
   }

   public void OnGameEnd ()
   {
      // end game stuff

   }
}

Quick Prefab Creation


  1. Create the object in the scene (Hierarchy)
  2. Modify all desired attributes and components
  3. Drag the game object from the Hierarchy view to the Project view

Friday, February 5, 2016

Add Bounce


To add bounce to an object, first you need to create a Physic Material, and this can be done in the Assets > Create > Physic Material menu.  Note that upon creation, you should name the material.

 Set the attributes according to your desired behavior.

Attach the material to the Collider component on your game object.

Pseudo Polymorphism in Inspector

This is the closest I've been able to come in creating polymorphic assignment with game objects in the inspector.

The interface or abstract-base-class would be defined as below.  Note the keyword "virtual" must be used here.

public class IEventTrigger : MonoBehaviour
{
   public virtual void OnEvent()
   {}
}

Next the derived class inherits from this pseudo-interface.  Note in this case, the implementation must be overridden using the "override" keyword.

public class TriggerPrint : IEventTrigger
{
   public override void OnEvent()
   {
      Debug.Log("Event Logged");
   }
}

An example now of a class that takes a game-object that has the TriggerPrint script component.  When eventHandler.OnEvent() is called, it will call the TriggerPrint.OnEvent().

public class InputManager : MonoBehaviour 
{
   [SerializeField]
   private IEventTrigger eventHandler;

   // Use this for initialization
   void Start ()
   {
      eventHandler.OnEvent();
   }
}

Class Fields in Inspector

Examples of making fields available to the inspector

   public int myInt;

or

   [SerializeField]
   private int myInt; 

Unity Install - Conflict with MSVC

Received error code 1603 while trying to install Unity.

Read on a forum this is a non-issue.  Ignored the error, and as far as I can tell, Unity finished installing successfully.

Scene Navigation

F - Center on object

Left-Click - Box Select
Right-Click - Orbit Object
Middle-Click - Pan View
Alt+Right-Click - Zoom