Unityxyz
007-Custom Editors Exercise-2
1.1 Introduction
1. Open the 007 folder of the project.
2. In this assignment we are going to be adding few functionalities to our custom editor that we added previously. We are going to create a script called Test007 to which functionalities are going to be added.
3. Functionalities are:
a. Clamp the positions of selected GameObjects.
b. Delete Selected gameObjects
c. Add Rigidbodies to selected gameObjects
1.2 Assignment Solution
1. Let us create a custom Editor for our class Test007 called as TestEditor007.
2. Make it inherit from Editor and use CustomEditor attribute to tell is used for Test007 class.
1.3 Adding buttons
1. Let us add three buttons to the custom editor called as:
-"Clamp Position for the selected"
-"Delete Selected Game Objects"
-"Add Rigidbody to selected GameObjects"
​
​
1.3 Assignment-2 Part-a Clamping Position
1. Let us make a function called as ClampPositionsForSelected()
2. In this function we are going to iterate over the selected gameObjects and then clamp their position.
3. For the ClampPosition function we are going to round the position along all three axes and then assign it back to the transform.
4. Undock the window to use it like a custom editor.Press Alt+p on the
Test007 gameObject.
5. Now let us select few gameObjects in the scene and test the clamping function.
Before clamping
After Clamping
1.3 Assignment-2 Part-b Deleting selected GameObjects
1. Let us make a function called as DeleteSelectedGameObjects() and attach it to the button called as "Delete Selected Game Objects".​
2. In this function we are simply going to iterate over the collection of gameObjects from the Selection function and then perform the DestroyImmediate() function to delete the selected gameObjects.
Before deleting
After Deleting
1.3 Assignment-2 Part-c Adding rigidbody to selected gameObjects
1. Let us make a function called as AddRigidbodySelectedObjects() and connect it to the button "Add Rigidbody to selected GameObjects"
2. In this function we are going to iterate over the selected gameObjects and add a rigidbody to each of them.
Before adding the rigidbody
After pressing the button and adding the rigidbody