The following are lists of functions you can and cannot use. When unsure, please ask.
Please do not use RigidBody in your MP solution. This means, you cannot work with Unity Colliders, and your code cannot contain any form of OnTriggerAnything(). If you see a compelling reason to do so, please come talk to me.
Vector3 methods that you CAN use
- Static properties:back/down/forward/left/one/right/up/zero/x/y/z
- Properties:magnitude/normalized/sqrMagnitude
- Static Methods:Cross()/Dot()/Normalize()
- All operators are ok
Quaternion methods that you CAN use
- Static properties:identity
- Properties:eulerAngles/normalized/x/y/z/w
- Public Methods:ToAngleAxis
- Static MethodsAngle/AngleAxis/Euler
All operators are ok
Transform methods that you CANNOT use
- LookAt()
- Rotate()
- LookRotation()
- RotateAround()
- SetPositionAndRotation()
We will build a simple hierarchical editor, one where we can select, manipulate, and add
new primitive GameObjects.
Initially, your world will consist of a static plane (for friendly
reference), GrandParent, Parent, and Child.
•
•
•
GrandParent:
o Cube
o blue-ish color
Parent:
o Sphere
o Green-ish color
o A child of GrandParent
Child:
o Cylinder
o Red-ish color
o A child of Parent
At any point, you can click the left mouse button (LMB) to select any of the GameObject
defined in the scene. LMB clicking on the static plane or an empty space results in
selecting nothing. Selected object must:
•
•
•
Be displayed in a unique color (mine is some kind of yellow-ish)
Be semi-transparent
Unselecting an object must cause it to return to its original color.
You will create two simple GUI widget to support editing operations.
XformControl: this widget will allow the editing of the transform of the currently
selected GameObject:
•
•
•
Name: name of the GameObject currently under editing.
Mode: mode of editing, either Translation, Scaling, or Rotation
Sliders: x/y/z slider for controlling the current mode
o You must use the same sliders to support all three transformation
modes
o Sliders must show numeric echos
o Slider ranges must change according to the current selected
transformation mode and must make sense, e.g., translation
between -10 to +10, rotation between -180 to 180, and scaling
between 1 to 5.
At any point, you can create a new GameObject primitive as the child of the current
selected GameObject with the CreateObject dropdown menu. The primitives you must
support creating are: Cube, Sphere, and Cylinder. When creating a new object,
let mSelected be the currently selected GameObject:
•
•
If mSelected is null
o Newly created GameObject will be in black
Else
o Newly created GameObject will:
§ have mSelected as parent
§ if mSelected has other children
§ Have the same materials as the siblings sharing
the same mSelected parent
§ Else
§ Be in White.
§ Note: the above means, new root object will always be in
black, and new leaf objects will always be in white.
For convenience, so that you can see the newly created objects, new object should be
slight offset (e.g., by (0.1, 0.1, 0.1) of the currently selected object. When mSelected is
null, I create new objects at (1, 1, 1). For the purpose of avoiding overlap, you can
assume the parent’s scale is (1, 1, 1).
There you have it, with the above, you have a functional but quite un-usable editor that
is good for really not much. You do not need to support object deletion (but should be
trivial).
Hints:
1. You can assume a resolution of 1280×768
2. Take a look at: EventSystem.current.IsPointerOverGameObject(), when
figuring out how to support selecting null when click on nothing.
3. Take a look at Rendering Mode of Materials, these must be set
to Transparent to get transparency working. A color’s alpha, or a, channel (r, g,
b, a) controls transparency. Values of less than 1.0 is transparent. I use 0.5 for
mine, my selected color is: (0.8, 0.8, 0.1, 0.5).
4. Notice Transform represents rotations as Quaternion (we will learn about
this). For now,
o Access the rotation as EulerAngles: Vector3 p =
localRotation.eulerAngles;
o Set a rotation from x/y/z EulerAngles by:
Quaternion q = new Quaternion();
q.eulerAngles = p;
mSelected.transform.localRotation = q;
5. Some interesting (or not?) to note: if you edit the rotation an object by its
EulerAngles, a few adjustments in x/y/z is all you have to make before the
object will get into an orientation where you lost complete track of how to
further adjust it. I will explain this better in class, but, the term we are looking
for is: Gimbal Lock. We will learn much more about this in the next few
lectures.
6. My “Radio buttons” for choosing between TSR is implemented based on the
Unity “ToggleGroup,” (https://docs.unity3d.com/Manual/scriptToggleGroup.html). I found this by googling, “how to radio button in unity”.
7. Give serious thoughts on how you want to separate responsibilities, define
classes to hide implementation accordingly. We have a pretty clear Model (M),
and pretty clear Controllers (C), no real View (V) yet.
8. Watch out for mouse click passing through UI, if you are running into problem
with clicking on GUI item resulting in de-selecting (or selecting) objects, take a
read on:
EventSystem.current.IsPointerOverGameObject()
I googled: “unity mouse click passing through UI” and found this:
https://forum.unity.com/threads/preventing-ugui-mouse-click-from-passing-through-guicontrols.272114/
Credit Distribution:
1. (5%) Initial scene with the static plane, GrandParent, Parent, and Child
o (5%) Reasonable size
o (5%) Proper setup
o (-50%) If the initial setup is not entirely and conveniently visible at
1280×768
2. (20%) LMB Selection
o (10%) Able to select nothing (clicking on the plane or nothing)
o (5%) Proper color and transparency changes of the selected
o (10%) Able to restore color after de-selecting
3. (40%) XformControl
o (5%) Proper and neat layout
o (10%) Show current selected name (or null)
o (10%) Proper support of the three modes: T, S, R
o (10%) Proper adjustments by the three slider bars
o (15%) Proper update binding:
When changing slider modes, newly selected mode is
properly set to the values in the Transform. When object
selection change, newly selected does not jump to
previous GUI setting.
§ It is difficult, if not impossible, to support rotation based
on (x, y, z) rotations [these are call Euler’s angles]. So, no
worries if after manipulating rotations, you select another
object, and then re-select the manipulated object only to
observe different slider values. As long as the object does
not jump, you are ok.
§ Yes: it is true my rotation implementation does not work
exactly correctly (e.g., check out move rotate X-slider bar
to large angles, notice the object starts to jump around!
Don’t worry if you have similar problem. As long as when
angles are small the object behaves well, and, when you
re-select a transformed object, it does not “jump”.
4. (30%) Created Primitive Behavior:
o (5%) Able to create three primitive types
o (10%) Proper parenting
o (10%) Proper color scheme
o (5%) Proper initial placement after creation (not overlapped)
§
5. (5%) Submission and Others:
o (5%) Submission include all source code and exe folder zipped
o (5%) Submission with proper zipfile naming: FirstLastMP1.zip