/// <summary> /// Activated by an event which is called from the Selectable.cs objects. /// </summary> /// <param name="selectingObject"></param> private void SelectObject(Selectable selectingObject) { //deselect CurrentlySelectedObject if selecting the same object again //trigger deselect event if (CurrentlySelectedObject != null && CurrentlySelectedObject.Equals(selectingObject)) { DeselectObject(); return; } //multi selection if (Input.GetKey(KeyCode.LeftControl)) { return; } //deselect previously selected object if the new one selectingObject != CurrentlySelectedObject //trigger deselect event if (CurrentlySelectedObject != null && CurrentlySelectedObject != selectingObject) { //reset object selection & invoke deselection event DeselectObject(); } //set newly selected object cache CurrentlySelectedObject = selectingObject; CurrentlySelectedObject.selected = true; //UpdateSelectionUI(CurrentlySelectedObject); }
private bool ResetSelected(bool objectBeingDeleted, bool deleteChildren) { bool flag = false; if (CurrentlySelectedObject != null) { ManipulatableObject component = CurrentlySelectedObject.GetComponent <ManipulatableObject>(); ObjectManipulator componentInParent = CurrentlySelectedObject.GetComponentInParent <ObjectManipulator>(); if (componentInParent != null) { if (componentInParent.IsAllowed) { Transform parent = CurrentlySelectedObject.transform.parent; CurrentlySelectedObject.transform.SetParent(oldParentOfSelectedObject, worldPositionStays: true); component.SetParent(parent); componentInParent.WasReparented = true; } else if (!restoreOldObject()) { flag = true; } if (!objectBeingDeleted && this.ObjectDeselected != null) { this.ObjectDeselected.InvokeSafe(componentInParent); } if (flag) { component.RemoveObject(deleteChildren); } } } CurrentlySelectedObject = null; return(flag); }
private void DeleteSelectedItem(bool deleteChildren) { GameObject gameObject = CurrentlySelectedObject; UnityEngine.Object.Destroy(oldObject); oldObject = null; if (!deleteChildren) { ManipulatableObject component = CurrentlySelectedObject.GetComponent <ManipulatableObject>(); if (component != null) { this.ObjectBeforeDelete.InvokeSafe(component); } } bool flag = ResetSelected(objectBeingDeleted: true, deleteChildren); if (gameObject != null && !flag) { ManipulatableObject componentInParent = gameObject.GetComponentInParent <ManipulatableObject>(); if (componentInParent != null) { componentInParent.RemoveObject(deleteChildren); } } }
public CollisionRuleResult GetCollisionRule(CollidableObject installedDecoration) { if (CurrentlySelectedObject != null) { CollidableObject component = CurrentlySelectedObject.GetComponent <CollidableObject>(); if (component == null || component.CollisionRuleSet == null || installedDecoration == null || component.CollisionRuleSet == null) { Log.LogError(this, "Problem: Installed decoration or selected object is not tracked properly and the placement rule cannot be found. Defaulting to stacking"); return(CollisionRuleResult.Stack); } if (decorationInstallationRulesets.ContainsKey(installedDecoration.CollisionRuleSet.Id)) { CollisionRuleSetDefinition collisionRuleSetDefinition = decorationInstallationRulesets[component.CollisionRuleSet.Id]; CollisionRuleDefinition[] installedItemRules = collisionRuleSetDefinition.InstalledItemRules; foreach (CollisionRuleDefinition collisionRuleDefinition in installedItemRules) { if (collisionRuleDefinition.InstalledItem.Id == installedDecoration.CollisionRuleSet.Id) { return(collisionRuleDefinition.Result); } } throw new InvalidOperationException(string.Format("No rule was found for the combination {0} and {1} on of the selected object {0} and the installed object", component.CollisionRuleSet.Id, installedDecoration.CollisionRuleSet.Id, CurrentlySelectedObject, installedDecoration.gameObject)); } Log.LogErrorFormatted(this, "Unknown rule: {0}, found for the selected item {1}. Defaulting to stacking", installedDecoration.CollisionRuleSet.Id, CurrentlySelectedObject); return(CollisionRuleResult.Stack); } throw new InvalidOperationException("Selected item is null"); }
public void SelectNewObject(GameObject obj, SelectState setSelectStateTo = SelectState.Drag) { if (!(obj != null)) { return; } ResetSelected(objectBeingDeleted: false, deleteChildren: false); CurrentState.ExitState(); addNewSelectedObject(obj); InputProcessingPaused = false; if (this.NewObjectAdded != null && CurrentlySelectedObject != null) { ManipulatableObject component = CurrentlySelectedObject.GetComponent <ManipulatableObject>(); if (component != null) { this.NewObjectAdded.InvokeSafe(component); } } switch (setSelectStateTo) { case SelectState.Active: CurrentState = activeSelectionState; break; case SelectState.Drag: CurrentState = dragItemInputInteractionState; break; } CurrentState.EnterState(TargetLayerMask, MinTimeToMoveInput); }
private void OnDragItemInputInteractionStateTouchPhaseStationary(RaycastHit topHit, TouchEquivalent touch) { PositionDragItem(topHit, touch); if (this.DragStateStationary != null) { ObjectManipulator componentInParent = CurrentlySelectedObject.GetComponentInParent <ObjectManipulator>(); this.DragStateStationary(componentInParent.gameObject, touch); } }
private bool restoreOldObject() { if (oldObject != null) { copyTransform(oldObject.transform, CurrentlySelectedObject.transform); ManipulatableObject component = CurrentlySelectedObject.GetComponent <ManipulatableObject>(); component.SetParent(oldParent); return(true); } return(false); }
private void OnSwipeScreenInputStateTouchPhaseEnded() { CurrentState.ExitState(); if (CurrentlySelectedObject == null || CurrentlySelectedObject.GetComponentInParent <ManipulatableObject>() == null) { CurrentState = noSelectionState; } else { CurrentState = activeSelectionState; } CurrentState.EnterState(TargetLayerMask, MinTimeToMoveInput); }
private void OnDragItemInputInteractionStateTouchPhaseEnded(RaycastHit topHit, TouchEquivalent touch) { CurrentState.ExitState(); CurrentState = activeSelectionState; bool flag = false; if (CurrentlySelectedObject != null) { if (topHit.Equals(default(RaycastHit))) { CurrentlySelectedObject.transform.position = new Vector3(0f, 1000f, 0f); DeleteSelectedItem(deleteChildren: true); InputProcessingPaused = false; CurrentState = noSelectionState; CurrentState.EnterState(TargetLayerMask, MinTimeToMoveInput); return; } PositionDragItem(topHit, touch); ObjectManipulator i = CurrentlySelectedObject.GetComponentInParent <ObjectManipulator>(); if (i != null && i.IsAllowed) { if (BeforeDragComplete != null) { flag = true; BeforeDragComplete.InvokeSafe(i, delegate(bool success) { if (success) { storeOldObject(); CurrentState.EnterState(TargetLayerMask, MinTimeToMoveInput); } else { i.BaseLocationIsValid = false; } }); } else { storeOldObject(); } } } if (!flag) { CurrentState.EnterState(TargetLayerMask, MinTimeToMoveInput); } }
private void PositionDragItem(RaycastHit topHit, TouchEquivalent touch) { if (this.BeforeDragPosition != null) { Cancelable cancelable = new Cancelable(); this.BeforeDragPosition.InvokeSafe(touch.position, cancelable); if (cancelable.isCancelled()) { return; } } ObjectManipulator component = CurrentlySelectedObject.GetComponent <ObjectManipulator>(); CollidableObject component2 = CurrentlySelectedObject.GetComponent <CollidableObject>(); if (!(component != null)) { return; } bool flag = component.transform != Container; CollidableObject componentInParent = topHit.transform.gameObject.GetComponentInParent <CollidableObject>(); if (componentInParent != null) { switch (GetCollisionRule(componentInParent)) { case CollisionRuleResult.StackXNormal: PositionDragItemForStacking(topHit, component, component2, componentInParent, Vector3.right); break; case CollisionRuleResult.Stack: PositionDragItemForStacking(topHit, component, component2, componentInParent, Vector3.up); break; case CollisionRuleResult.NotAllowed: case CollisionRuleResult.Intersect: { for (int i = 0; i < dragItemInputInteractionState.RaycastHits.Length; i++) { componentInParent = dragItemInputInteractionState.RaycastHits[i].transform.gameObject.GetComponentInParent <CollidableObject>(); if (componentInParent == null) { setPositionAtPointOnTopHit(dragItemInputInteractionState.RaycastHits[i], component); break; } if (componentInParent.transform.IsChildOf(component2.transform)) { continue; } switch (GetCollisionRule(componentInParent)) { case CollisionRuleResult.Stack: PositionDragItemForStacking(dragItemInputInteractionState.RaycastHits[i], component, component2, componentInParent, Vector3.up); break; case CollisionRuleResult.StackXNormal: PositionDragItemForStacking(dragItemInputInteractionState.RaycastHits[i], component, component2, componentInParent, Vector3.right); break; default: continue; } break; } break; } default: setPositionAtPointOnTopHit(topHit, component); break; } } else { setPositionAtPointOnTopHit(topHit, component); } if (NaturalDragFromTouchPosition && !flag) { Vector2 vector = Camera.main.WorldToScreenPoint(component.transform.position); dragItemInputInteractionState.TouchOffset = (touchOffset = vector - touch.position); } }