protected virtual void Awake() { anchorable = GetComponent <AnchorableBehaviour>(); placementInteraction = GetComponent <InteractionBehaviour>(); placementRigidbody = GetComponent <Rigidbody>(); spaceChanger = GetComponent <Editing.SpaceChanger>(); switch (mode) { case ControlMode.Runtime: // look for panel in parent attachedPanel = GetComponentInParent <Panel>(); break; case ControlMode.Design: // if InteractionBehavior doesn't exist, // create it. AnchorableBehavior not necessary? // delete it if it exists? if (placementInteraction == null) { placementInteraction = gameObject.AddComponent <InteractionBehaviour>(); } placementInteraction.allowMultiGrasp = true; placementInteraction.graspedMovementType = InteractionBehaviour.GraspedMovementType.Kinematic; // if we're in design mode or design palette mode, // create our edit sound emitters CreateEditSoundEmitters(); spaceChanger.SpaceChanged += SpaceChanger_SpaceChanged; break; case ControlMode.Design_Palette: // if anchorable and InteractionBehavior don't exist, // create them if (placementInteraction == null) { placementInteraction = gameObject.AddComponent <InteractionBehaviour>(); } if (anchorable == null) { anchorable = gameObject.AddComponent <AnchorableBehaviour>(); } placementInteraction.allowMultiGrasp = true; placementInteraction.graspedMovementType = InteractionBehaviour.GraspedMovementType.Nonkinematic; // if we're in design mode or design palette mode, // create our edit sound emitters CreateEditSoundEmitters(); spaceChanger.SpaceChanged += SpaceChanger_SpaceChanged; break; default: break; } }
private void SpaceChanger_SpaceChanged(Editing.SpaceChanger sender, GameObject oldSpace, GameObject newSpace) { if (attachedPanel) { // we're leaving our current panel, tell it to remove us from its recordkeeping system attachedPanel.RemoveUIControl(this); attachedPanel = null; } Panel panelCandidate = newSpace.GetComponent <Panel>(); if (panelCandidate) { attachedPanel = panelCandidate; // we're joining this new panel, tell it to add us to its recordkeeping system. string newName = ""; if (attachedPanel.MustRenameControl(this._name, out newName)) { this._name = newName; attachedPanel.AddUIControl(this); } } }