// ======================================================================
        // Change in display options.
        // ----------------------------------------------------------------------
        // OK
        public static void Unfold(iCS_EditorObject node)
        {
#if DEBUG
            Debug.Log("iCanScript: Unfold => " + node.DisplayName);
#endif
            if (!node.IsNode || node.DisplayOption == iCS_DisplayOptionEnum.Unfolded)
            {
                return;
            }
            var iStorage = node.IStorage;
            OpenTransaction(iStorage);
            try {
                SendStartRelayoutOfTree(iStorage);
                iStorage.AnimateGraph(null,
                                      _ => {
                    node.Unfold();
                    node.SetAsHighestLayoutPriority();
                    iStorage.ForcedRelayoutOfTree();
                    node.ClearLayoutPriority();
                    var visualEditor = iCS_EditorController.FindVisualEditor();
                    if (visualEditor != null)
                    {
                        visualEditor.SmartFocusOn(node);
                    }
                }
                                      );
                SendEndRelayoutOfTree(iStorage);
            }
            catch (System.Exception) {
                CancelTransaction(iStorage);
                return;
            }
            CloseTransaction(iStorage, "Unfold " + node.DisplayName);
        }
Exemplo n.º 2
0
        // ======================================================================
        // Create from Drag & Drop
        // ----------------------------------------------------------------------
        // OK
        public static iCS_EditorObject CreateGameObject(GameObject go, iCS_EditorObject parent, Vector2 globalPos)
        {
#if SHOW_DEBUG
            Debug.Log("iCanScript: Create Game Object => " + go.name);
#endif
            if (parent == null)
            {
                return(null);
            }
            if (!IsCreationAllowed())
            {
                return(null);
            }
            var iStorage = parent.IStorage;

            iCS_EditorObject instance = null;
            OpenTransaction(iStorage);
            try {
                iStorage.AnimateGraph(null,
                                      _ => {
                    parent.Unfold();
                    instance     = iStorage.CreatePackage(parent.InstanceId, go.name, VSObjectType.Package, go.GetType());
                    var thisPort = iStorage.PropertiesWizardGetInputThisPort(instance);
                    if (thisPort != null)
                    {
                        thisPort.Value = go;
                    }
                    instance.SetInitialPosition(globalPos);
                    iStorage.ForcedRelayoutOfTree();
                }
                                      );
            }
            catch (System.Exception) {
                CancelTransaction(iStorage);
                return(null);
            }
            if (instance == null)
            {
                CancelTransaction(iStorage);
                return(null);
            }
            CloseTransaction(iStorage, "Create " + go.name);
            SystemEvents.AnnounceVisualScriptElementAdded(instance);
            return(instance);
        }
        // ----------------------------------------------------------------------
        public static void PasteIntoGraph(iCS_MonoBehaviourImp sourceMonoBehaviour, iCS_EngineObject sourceRoot,
                                          iCS_IStorage iStorage, iCS_EditorObject parent, Vector2 globalPos)
        {
            if (!IsCreationAllowed())
            {
                return;
            }
            OpenTransaction(iStorage);
            iCS_EditorObject pasted = null;

            try {
                iStorage.AnimateGraph(null,
                                      _ => {
                    if (parent.IsFoldedInLayout || parent.IsIconizedInLayout)
                    {
                        parent.Unfold();
                    }
                    iCS_IStorage srcIStorage = new iCS_IStorage(sourceMonoBehaviour);
                    iCS_EditorObject srcRoot = srcIStorage.EditorObjects[sourceRoot.InstanceId];
                    pasted = iStorage.Copy(srcRoot, srcIStorage, parent, globalPos, iStorage);
                    if (pasted != null)
                    {
                        if (pasted.IsUnfoldedInLayout)
                        {
                            pasted.Fold();
                        }
                        iStorage.SelectedObject = pasted;
                        iStorage.ForcedRelayoutOfTree();
                    }
                }
                                      );
            }
            catch (System.Exception) {
                CancelTransaction(iStorage);
                return;
            }
            if (pasted != null)
            {
                SystemEvents.AnnounceVisualScriptElementAdded(pasted);
            }
            CloseTransaction(iStorage, "Add Prefab " + sourceRoot.RawName);
        }