private void onConfirmSquashedObjectBeforeDragComplete(ObjectManipulator selected, Action <bool> callback)
        {
            if (selected == null)
            {
                return;
            }
            HashSet <ManipulatableObject> squashed = new HashSet <ManipulatableObject>();

            foreach (Collider currentCollider in selected.CurrentColliders)
            {
                ManipulatableObject componentInParent = currentCollider.GetComponentInParent <ManipulatableObject>();
                if (componentInParent != null && componentInParent.IsSquashed)
                {
                    squashed.Add(componentInParent);
                    ManipulatableObject[] componentsInChildren = componentInParent.GetComponentsInChildren <ManipulatableObject>();
                    for (int i = 0; i < componentsInChildren.Length; i++)
                    {
                        squashed.Add(componentsInChildren[i]);
                    }
                }
            }
            Action <int, Action <bool> > confirmObjectRemoval = Service.Get <ObjectManipulationService>().ConfirmObjectRemoval;

            if (squashed.Count > 0 && confirmObjectRemoval != null)
            {
                confirmObjectRemoval(squashed.Count, delegate(bool delete)
                {
                    if (delete)
                    {
                        foreach (ManipulatableObject item in squashed)
                        {
                            if (item != null)
                            {
                                item.RemoveObject(deleteChildren: false);
                            }
                        }
                    }
                    objectManipulationInputController.SkipOneFrame = true;
                    if (callback != null)
                    {
                        callback(delete);
                    }
                });
                return;
            }
            foreach (ManipulatableObject item2 in squashed)
            {
                if (item2 != null)
                {
                    item2.RemoveObject(deleteChildren: false);
                }
            }
            if (callback != null)
            {
                callback(obj: true);
            }
        }
示例#2
0
        public void ScaleTo(float value)
        {
            bool      flag   = false;
            Transform parent = base.transform.parent;

            base.transform.SetParent(null, worldPositionStays: true);
            if (base.transform.localScale.x != value)
            {
                Dictionary <ManipulatableObject, GameObject> dictionary = new Dictionary <ManipulatableObject, GameObject>();
                ManipulatableObject[] componentsInChildren = GetComponentsInChildren <ManipulatableObject>();
                for (int i = 0; i < componentsInChildren.Length; i++)
                {
                    if (componentsInChildren[i].transform.parent == base.transform)
                    {
                        GameObject gameObject = null;
                        gameObject = new GameObject();
                        dictionary.Add(componentsInChildren[i], gameObject);
                        gameObject.transform.SetParent(componentsInChildren[i].transform.parent);
                        gameObject.transform.position = componentsInChildren[i].transform.position;
                        componentsInChildren[i].transform.SetParent(null, worldPositionStays: true);
                    }
                }
                base.transform.localScale = new Vector3(value, value, value);
                for (int i = 0; i < componentsInChildren.Length; i++)
                {
                    if (componentsInChildren[i].transform != base.transform)
                    {
                        ManipulatableObject manipulatableObject = componentsInChildren[i];
                        if (dictionary.ContainsKey(manipulatableObject))
                        {
                            GameObject gameObject = dictionary[manipulatableObject];
                            manipulatableObject.transform.SetParent(gameObject.transform.parent, worldPositionStays: true);
                            manipulatableObject.transform.position = gameObject.transform.position;
                        }
                    }
                }
                foreach (GameObject value2 in dictionary.Values)
                {
                    UnityEngine.Object.Destroy(value2);
                }
                flag = true;
            }
            base.transform.SetParent(parent, worldPositionStays: true);
            if (flag && this.ScaleChanged != null)
            {
                this.ScaleChanged.InvokeSafe(this);
            }
        }