Esempio n. 1
0
        // ----------------------------------------------------------------------
        public static void DeleteKeepChildren(iCS_EditorObject obj)
        {
            if (!IsDeletionAllowed())
            {
                return;
            }
            var iStorage = obj.IStorage;

            OpenTransaction(iStorage);
            try {
                var newParent  = obj.ParentNode;
                var childNodes = obj.BuildListOfChildNodes(_ => true);
                var childPos   = P.map(n => n.GlobalPosition, childNodes);
                iStorage.AnimateGraph(obj,
                                      _ => {
                    // Move the selection to the parent node
                    var parent = obj.ParentNode;
                    iStorage.SelectedObject = parent;

                    P.forEach(n => { iStorage.ChangeParent(n, newParent); }, childNodes);
                    SystemEvents.AnnounceVisualScriptElementWillBeRemoved(obj);
                    iStorage.DestroyInstance(obj.InstanceId);
                    P.zipWith((n, p) => { n.LocalAnchorFromGlobalPosition = p; }, childNodes, childPos);
                    iStorage.ForcedRelayoutOfTree();
                }
                                      );
            }
            catch (System.Exception) {
                CancelTransaction(iStorage);
                return;
            }
            CloseTransaction(iStorage, "Delete " + obj.DisplayName);
        }
Esempio n. 2
0
        // ----------------------------------------------------------------------
        public void ReduceChildrenAnchorPosition()
        {
            var childNodes = BuildListOfChildNodes(_ => true);

            if (childNodes.Length == 0)
            {
                return;
            }
            // Reduce Local anchor position
            var max = P.fold(
                (acc, n) => {
                var lap = n.LocalAnchorPosition;
                return(new Vector2(Mathf.Max(acc.x, lap.x), Mathf.Max(acc.y, lap.y)));
            },
                childNodes[0].LocalAnchorPosition, childNodes
                );
            var min = P.fold(
                (acc, n) => {
                var lap = n.LocalAnchorPosition;
                return(new Vector2(Mathf.Min(acc.x, lap.x), Mathf.Min(acc.y, lap.y)));
            },
                childNodes[0].LocalAnchorPosition, childNodes
                );
            var delta  = (max - min) / 2;
            var offset = max - delta;

            P.forEach(n => n.LocalAnchorPosition = n.LocalAnchorPosition - offset, childNodes);
        }
 // =======================================================================
 // General Iterations
 // -----------------------------------------------------------------------
 // Executes for each valid engine object
 public static void ForEach(Action <iCS_EngineObject> fnc, iCS_IVisualScriptData vsd)
 {
     P.forEach(o => { if (IsValid(o, vsd))
                      {
                          fnc(o);
                      }
               }, vsd.EngineObjects);
 }