Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 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");
 }
Beispiel #4
0
        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);
        }
Beispiel #5
0
 private bool restoreOldObject()
 {
     if (oldObject != null)
     {
         copyTransform(oldObject.transform, CurrentlySelectedObject.transform);
         ManipulatableObject component = CurrentlySelectedObject.GetComponent <ManipulatableObject>();
         component.SetParent(oldParent);
         return(true);
     }
     return(false);
 }
Beispiel #6
0
        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);
            }
        }