Private & Confidential
Extending Igloo Toolkit
Extending the Igloo toolkit is a great way to incorporate igloo functionality into your existing project. The most used reason for extending the toolkit, is the addition of your own selection system via the Igloo Player Pointer, so this is the example we have chosen to demonstrate. However, regardless of what you need to achieve, the process will be very similar for other scripts.
Extending the PlayerPointer.cs
To demonstrate the process let’s extend the playerPointer.cs script, to make it change the colour of our infamous floating spheres in our example project.
Load Example - 1 Scene
Create a new script, in your own scripting area (outside of the IglooToolkit folder) and name it ‘CustomPlayerPointer'
Open the script, and in your code editor, change the inherit class from Monobehavior to PlayerPointer
In order to interact with the Unity Toolkit, you will need add a using statement to your code, and to make compiling scripts even faster we’ve split up our code into three sections: Common, UI, and Controller.
To access the PlayerPointer script we need to add ‘using Igloo.Common’ to the references at the top of the script.The compiler will often tell you which reference you need to add when you write an Igloo class.
The Update function will not be happy as it’s currently hiding an inherited member from the PlayerPointer class. To rectify this, delete everything within the class (specifically just the Start and Update functions) Then Right Click the CustomPlayerPointer class name → Quick Actions and Refractorings -> Generate Overrides.
Then select the last two overrides, AwakeInternal(), and Update().
Whilst its possible to write these yourself, this saves a lot of time and sets everything up correctly.
Your script should now look like this.Let’s add some code to the update function
Here if the player is pressing “Fire1” (mouse 0, Left Ctrl, or Return), the raycast hit isn’t empty, and the object hit by the raycast has a name containing “Sphere” then it will get the renderer of the hit object, and change it’s colour to something random.
You can see there is no Raycast here, this is due to a raycast already happening every frame within the PlayerPointer update function, which also sets the hit variable as it runs. This is a benefit of extending this script, we are using the existing raycast to generate a new feature rather than creating a new raycast to achieve the same goal.
Within the PlayerPointer.cs file, the hit variable looks like this:Now, the original script is still assigned to the player, so we much swap it with the newly created one.
Save your script, and jump back into the Unity Editor.
After a short compile, navigate within the Asset Browser to:
Igloo Toolkit → Resources → Prefabs
And open the Igloo Prefab
Within the Hierarchy, select the Camera
Remove the current ‘old’ PlayerPointer script, and in it’s place add the new CustomPlayerPointer script.Be sure to remember to add the WorldSpaceCrosshair to the Crosshair variable field.
You will also need to add the Camera back to the Pointer variable field of PlayerManager on the root Igloo game object. Another benefit of extending the PlayerPointer, is that any functions that exist within it for the normal function of the Igloo Camera System are still present.
Save the Igloo prefab.Back in the scene you can now test that it works. Enter play mode.
(c) Igloo Vision 2020