/// <summary>
        /// Handles the Click event of the makePrototypeButton control.
        /// Makes the actor a prototype.
        /// First checks if the actor contains any scene specific variable values, if yes then it shows an option to automatically clear this values.
        /// </summary>
        private void makePrototypeButton_Click(object sender, EventArgs e)
        {
            // clone actor
            Actor clonedActor = (Actor)CloningHelper.Clone(Actor);

            // check if actor contains scene specific variable values (for actor and path)
            HashSet <ItemForDeletion> itemsToClear = new HashSet <ItemForDeletion>();
            List <Actor> allActors = new List <Actor>();

            AddAllActors(clonedActor, allActors);

            CheckActorBeforeMakingPrototype(clonedActor, allActors, itemsToClear);

            if (itemsToClear.Count == 0)
            {
                Project.Singleton.Prototypes.Add(clonedActor);
                Messages.ShowInfo("Prototype created.");
            }
            else
            {
                if (MessageBox.Show("Actor contains scene specific variable values. Do you want to clear these values to create prototype?", "Make Prototype", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                {
                    foreach (ItemForDeletion item in itemsToClear)
                    {
                        item.Delete();
                    }

                    Project.Singleton.Prototypes.Add(clonedActor);
                    Messages.ShowInfo("Prototype created.");
                }
            }
        }
Example #2
0
        /// <summary>
        /// Handles the DragDrop event of the SceneScreenControl control.
        /// If drawable asset is dropped to the scene new actor with the specified drawable asset is created and added to the scene.
        /// If prototype (actor) is dropped to the scene the prototype is cloned and added to the scene.
        /// </summary>
        private void SceneScreenControl_DragDrop(object sender, DragEventArgs e)
        {
            Vector2 position = PointAtScene(PointToClient(new System.Drawing.Point(e.X, e.Y)));

            if (e.Data.GetDataPresent(typeof(DrawableAsset)))
            {
                DrawableAsset drawableAsset = (DrawableAsset)e.Data.GetData(typeof(DrawableAsset));

                if (drawableAsset != null)
                {
                    if (Scene.SelectedLayer == null)
                    {
                        Messages.ShowWarning("No layer selected.");
                        return;
                    }

                    // create new actor
                    Actor newActor = new Actor(drawableAsset, position);

                    // add to the scene selected layer
                    Scene.SelectedLayer.Add(newActor);

                    // add dropped objects to the history
                    History.Add(newActor.CreateAddCommand());
                }
            }
            else if (e.Data.GetDataPresent(typeof(Actor)))
            {
                Actor actor = (Actor)e.Data.GetData(typeof(Actor));

                if (actor != null)
                {
                    if (Scene.SelectedLayer == null)
                    {
                        Messages.ShowWarning("No layer selected.");
                        return;
                    }

                    // create new actor
                    Actor newActor = (Actor)CloningHelper.Clone(actor);
                    newActor.Position = position;

                    // add to the scene selected layer
                    Scene.SelectedLayer.Add(newActor);

                    // add dropped objects to the history
                    History.Add(newActor.CreateAddCommand());
                }
            }
        }
Example #3
0
    // Update is called once per frame
    public override void Update()
    {
        if (!tested.HasValue)
        {
            tested = true;

            GameObject    go   = new GameObject();
            CloningHelper help = go.AddComponent <CloningHelper>();
            help.val           = 100;
            help.nm            = "Tested";
            help.reference     = gameObject;
            help.referenceList = new List <GameObject>();
            help.referenceList.Add(gameObject);
            help.referenceArray   = new GameObject[] { gameObject };
            help.objReference     = new CloneObject();
            help.objReferenceList = new List <CloneObject>();
            help.objReferenceList.Add(help.objReference);
            help.objReferenceArray = new CloneObject[] { help.objReference };

            CloningHelper helpClone = (CloningHelper)Instantiate(help);

            try {
                helpClone.val.Should().Be(help.val);
                helpClone.nm.Should().Be(help.nm);
                helpClone.reference.Should().Be(gameObject);
                ((object)helpClone.referenceList).Should().NotBe(help.referenceList);
                helpClone.referenceList.Should().NotBeEmpty();
                helpClone.referenceList.Should().Contain(gameObject);
                helpClone.referenceArray.Should().NotBeNull();
                helpClone.referenceArray.Should().NotBeEmpty();
                helpClone.referenceArray.Should().Contain(gameObject);
                helpClone.objReference.Should().NotBe(help.objReference);
                helpClone.objReference.Should().BeNull();
                helpClone.objReferenceArray.Should().BeNull();
                ((object)helpClone.objReferenceList).Should().NotBe(help.objReferenceList);
                ((object)helpClone.objReferenceList).Should().BeNull();
                Debug.Log(GetType().Name + " succeeded");
            } catch (Exception ex) {
                // Log the merror
                Debug.LogError(ex.Message);
            } finally {
                Destroy(go);
                Destroy(helpClone.gameObject);
            }
        }
    }
Example #4
0
    // ReSharper disable once FunctionComplexityOverflow
    public override void OnInspectorGUI()
    {
        _settings  = (WavePrefabPool)target;
        _poolTrans = _settings.transform;

        WorldVariableTracker.ClearInGamePlayerStats();

        DTInspectorUtility.DrawTexture(CoreGameKitInspectorResources.LogoTexture);

        _isDirty = false;

        var allStats = KillerVariablesHelper.AllStatNames;

        var           myParent      = _settings.transform.parent;
        LevelSettings levelSettings = null;

        if (myParent != null)
        {
            var levelSettingObj = myParent.parent;
            if (levelSettingObj != null)
            {
                levelSettings = levelSettingObj.GetComponent <LevelSettings>();
            }
        }

        if (levelSettings == null)
        {
            return;
        }

        EditorGUI.indentLevel = 0;
        var newSeq = (WavePrefabPool.PoolDispersalMode)EditorGUILayout.EnumPopup("Spawn Sequence", _settings.dispersalMode);

        if (newSeq != _settings.dispersalMode)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "change Spawn Sequence");
            _settings.dispersalMode = newSeq;
        }
        if (_settings.dispersalMode == WavePrefabPool.PoolDispersalMode.Randomized)
        {
            var newExhaust = EditorGUILayout.Toggle("Exhaust before repeat", _settings.exhaustiveList);
            if (newExhaust != _settings.exhaustiveList)
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "toggle Exhaust before repeat");
                _settings.exhaustiveList = newExhaust;
            }
        }

        var hadNoListener = _settings.listener == null;
        var newListener   = (WavePrefabPoolListener)EditorGUILayout.ObjectField("Listener", _settings.listener, typeof(WavePrefabPoolListener), true);

        if (newListener != _settings.listener)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "assign Listener");
            _settings.listener = newListener;
            if (hadNoListener && _settings.listener != null)
            {
                _settings.listener.sourcePrefabPoolName = _settings.transform.name;
            }
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Scene Objects Using");

        GUI.contentColor = DTInspectorUtility.BrightButtonColor;
        if (GUILayout.Button("List", EditorStyles.toolbarButton, GUILayout.MinWidth(55)))
        {
            FindMatchingSpawners(_poolTrans, false);
        }
        GUILayout.Space(10);
        if (GUILayout.Button("Select", EditorStyles.toolbarButton, GUILayout.MinWidth(55)))
        {
            FindMatchingSpawners(_poolTrans, true);
        }
        GUILayout.FlexibleSpace();

        GUI.contentColor = Color.white;
        EditorGUILayout.EndHorizontal();

        DTInspectorUtility.VerticalSpace(4);

        if (!Application.isPlaying)
        {
            EditorGUILayout.BeginVertical();
            var anEvent = Event.current;

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(4);
            GUI.color = DTInspectorUtility.DragAreaColor;
            var dragArea = GUILayoutUtility.GetRect(0f, 30f, GUILayout.ExpandWidth(true));
            GUI.Box(dragArea, "Drag prefabs here in bulk to add them to the Pool!");
            GUI.color = Color.white;

            switch (anEvent.type)
            {
            case EventType.DragUpdated:
            case EventType.DragPerform:
                if (!dragArea.Contains(anEvent.mousePosition))
                {
                    break;
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                if (anEvent.type == EventType.DragPerform)
                {
                    DragAndDrop.AcceptDrag();

                    foreach (var dragged in DragAndDrop.objectReferences)
                    {
                        AddPoolItem(dragged);
                    }
                }
                Event.current.Use();
                break;
            }
            GUILayout.Space(4);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            DTInspectorUtility.VerticalSpace(4);
        }

        EditorGUI.indentLevel = 0;

        var state = _settings.isExpanded;
        var text  = string.Format("Prefab Pool Items ({0})", _settings.poolItems.Count);

        // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
        if (!state)
        {
            GUI.backgroundColor = DTInspectorUtility.InactiveHeaderColor;
        }
        else
        {
            GUI.backgroundColor = DTInspectorUtility.ActiveHeaderColor;
        }

        GUILayout.BeginHorizontal();

#if UNITY_3_5_7
        if (!state)
        {
            text += " (Click to expand)";
        }
#else
        text = "<b><size=11>" + text + "</size></b>";
#endif
        if (state)
        {
            text = "\u25BC " + text;
        }
        else
        {
            text = "\u25BA " + text;
        }
        if (!GUILayout.Toggle(true, text, "dragtab", GUILayout.MinWidth(20f)))
        {
            state = !state;
        }

        GUILayout.Space(2f);



        if (state != _settings.isExpanded)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "toggle expand Prefab Pool Items");
            _settings.isExpanded = state;
        }
        // BUTTONS...
        EditorGUILayout.BeginHorizontal(GUILayout.MinWidth(16));

        DTInspectorUtility.ResetColors();

        var alphaSort = false;

        //DTInspectorUtility.UseLightSkinButtonColor();
        // Add expand/collapse buttons if there are items in the list
        if (_settings.poolItems.Count > 0)
        {
            GUI.contentColor = DTInspectorUtility.BrightButtonColor;
            alphaSort        = GUILayout.Button("Alpha Sort", EditorStyles.toolbarButton, GUILayout.Height(16));

            const string collapseIcon   = "Collapse";
            var          content        = new GUIContent(collapseIcon, "Click to collapse all");
            var          masterCollapse = GUILayout.Button(content, EditorStyles.toolbarButton, GUILayout.Height(16));

            const string expandIcon = "Expand";
            content = new GUIContent(expandIcon, "Click to expand all");
            var masterExpand = GUILayout.Button(content, EditorStyles.toolbarButton, GUILayout.Height(16));
            if (masterExpand)
            {
                ExpandCollapseAll(_settings, true);
            }
            if (masterCollapse)
            {
                ExpandCollapseAll(_settings, false);
            }
            GUI.contentColor = Color.white;
        }
        else
        {
            GUILayout.FlexibleSpace();
        }

        EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(50));

        var topAdded = false;

        var addText = string.Format("Click to add Pool item{0}.", _settings.poolItems.Count > 0 ? " before the first" : "");

        GUI.contentColor = DTInspectorUtility.AddButtonColor;
        // Main Add button
        if (GUILayout.Button(new GUIContent("Add", addText), EditorStyles.toolbarButton, GUILayout.Height(16)))
        {
            topAdded = true;
        }
        GUI.contentColor = Color.white;

        GUILayout.Space(4);

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndHorizontal();

        int?itemToDelete    = null;
        int?itemToInsert    = null;
        int?itemToShiftUp   = null;
        int?itemToShiftDown = null;
        int?itemToClone     = null;

        if (_settings.isExpanded)
        {
            if (_settings.poolItems.Count > 0)
            {
                DTInspectorUtility.BeginGroupedControls();
            }
            for (var i = 0; i < _settings.poolItems.Count; i++)
            {
                var item = _settings.poolItems[i];

                DTInspectorUtility.StartGroupHeader(1);

                EditorGUILayout.BeginHorizontal();
                EditorGUI.indentLevel = 1;

                var sName = "";
                if (!item.isExpanded)
                {
                    if (item.prefabToSpawn == null)
                    {
                        sName = " " + LevelSettings.EmptyValue;
                    }
                    else
                    {
                        sName = " (" + item.prefabToSpawn.name + ")";
                    }
                }

                var sDisabled    = "";
                var itemDisabled = item.activeMode == LevelSettings.ActiveItemMode.Never;
                if (!item.isExpanded && itemDisabled)
                {
                    sDisabled = " - DISABLED";
                }

                var newItemExpanded = DTInspectorUtility.Foldout(item.isExpanded,
                                                                 string.Format("Pool Item #{0}{1}{2}", (i + 1), sName, sDisabled));
                if (newItemExpanded != item.isExpanded)
                {
                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "toggle expand Pool Item");
                    item.isExpanded = newItemExpanded;
                }

                GUILayout.FlexibleSpace();

                if (Application.isPlaying)
                {
                    GUI.contentColor = DTInspectorUtility.BrightTextColor;
                    var itemCount = _settings.PoolInstancesOfIndex(i);
                    GUILayout.Label("Remaining: " + itemCount);
                    GUI.contentColor = Color.white;
                }

                var poolItemButton = DTInspectorUtility.AddFoldOutListItemButtons(i, _settings.poolItems.Count, "Pool Item", false, null, false, true, true);

                switch (poolItemButton)
                {
                case DTInspectorUtility.FunctionButtons.Remove:
                    itemToDelete = i;
                    _isDirty     = true;
                    break;

                case DTInspectorUtility.FunctionButtons.Add:
                    itemToInsert = i;
                    _isDirty     = true;
                    break;

                case DTInspectorUtility.FunctionButtons.ShiftUp:
                    itemToShiftUp = i;
                    _isDirty      = true;
                    break;

                case DTInspectorUtility.FunctionButtons.ShiftDown:
                    itemToShiftDown = i;
                    _isDirty        = true;
                    break;

                case DTInspectorUtility.FunctionButtons.Copy:
                    itemToClone = i;
                    _isDirty    = true;
                    break;
                }

                EditorGUI.indentLevel = 0;
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();

                if (itemDisabled)
                {
                    DTInspectorUtility.ShowColorWarningBox("This item is currently disabled and will never spawn.");
                }

                if (!item.isExpanded)
                {
                    EditorGUILayout.EndVertical();
                    continue;
                }
                EditorGUI.indentLevel = 0;

                if (item.prefabToSpawn == null && !itemDisabled)
                {
                    DTInspectorUtility.ShowColorWarningBox("Nothing will spawn when this item is chosen from the pool.");
                }

                var newActive = (LevelSettings.ActiveItemMode)EditorGUILayout.EnumPopup("Active Mode", item.activeMode);
                if (newActive != item.activeMode)
                {
                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "toggle Active Mode");
                    item.activeMode = newActive;
                }

                switch (item.activeMode)
                {
                case LevelSettings.ActiveItemMode.IfWorldVariableInRange:
                case LevelSettings.ActiveItemMode.IfWorldVariableOutsideRange:
                    var missingStatNames = new List <string>();
                    missingStatNames.AddRange(allStats);
                    missingStatNames.RemoveAll(delegate(string obj) {
                        return(item.activeItemCriteria.HasKey(obj));
                    });

                    var newStat = EditorGUILayout.Popup("Add Active Limit", 0, missingStatNames.ToArray());
                    if (newStat != 0)
                    {
                        AddActiveLimit(missingStatNames[newStat], item);
                    }

                    if (item.activeItemCriteria.statMods.Count == 0)
                    {
                        DTInspectorUtility.ShowRedErrorBox("You have no Active Limits. Item will never be Active.");
                    }
                    else
                    {
                        EditorGUILayout.Separator();

                        int?indexToDelete = null;

                        for (var j = 0; j < item.activeItemCriteria.statMods.Count; j++)
                        {
                            var modifier = item.activeItemCriteria.statMods[j];
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Space(15);
                            var statName = modifier._statName;
                            GUILayout.Label(statName);

                            GUILayout.FlexibleSpace();
                            GUILayout.Label("Min");

                            switch (modifier._varTypeToUse)
                            {
                            case WorldVariableTracker.VariableType._integer:
                                var newMin = EditorGUILayout.IntField(modifier._modValueIntMin, GUILayout.MaxWidth(60));
                                if (newMin != modifier._modValueIntMin)
                                {
                                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "change Active Limit Min");
                                    modifier._modValueIntMin = newMin;
                                }

                                GUILayout.Label("Max");
                                var newMax = EditorGUILayout.IntField(modifier._modValueIntMax, GUILayout.MaxWidth(60));
                                if (newMax != modifier._modValueIntMax)
                                {
                                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "change Active Limit Max");
                                    modifier._modValueIntMax = newMax;
                                }
                                break;

                            case WorldVariableTracker.VariableType._float:
                                var newMinFloat = EditorGUILayout.FloatField(modifier._modValueFloatMin, GUILayout.MaxWidth(60));
                                if (newMinFloat != modifier._modValueFloatMin)
                                {
                                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "change Active Limit Min");
                                    modifier._modValueFloatMin = newMinFloat;
                                }

                                GUILayout.Label("Max");
                                var newMaxFloat = EditorGUILayout.FloatField(modifier._modValueFloatMax, GUILayout.MaxWidth(60));
                                if (newMaxFloat != modifier._modValueFloatMax)
                                {
                                    UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "change Active Limit Max");
                                    modifier._modValueFloatMax = newMaxFloat;
                                }
                                break;

                            default:
                                Debug.LogError("Add code for varType: " + modifier._varTypeToUse.ToString());
                                break;
                            }
                            var oldBG = GUI.backgroundColor;

                            GUI.backgroundColor = DTInspectorUtility.DeleteButtonColor;
                            if (GUILayout.Button(new GUIContent("Delete", "Remove this limit"), EditorStyles.miniButtonMid, GUILayout.MaxWidth(64)))
                            {
                                indexToDelete = j;
                            }
                            GUI.backgroundColor = oldBG;
                            GUILayout.Space(5);
                            EditorGUILayout.EndHorizontal();

                            var min = modifier._varTypeToUse == WorldVariableTracker.VariableType._integer ? modifier._modValueIntMin : modifier._modValueFloatMin;
                            var max = modifier._varTypeToUse == WorldVariableTracker.VariableType._integer ? modifier._modValueIntMax : modifier._modValueFloatMax;

                            if (min > max)
                            {
                                DTInspectorUtility.ShowRedErrorBox(modifier._statName + " Min cannot exceed Max, please fix!");
                            }
                        }

                        DTInspectorUtility.ShowColorWarningBox("Limits are inclusive: i.e. 'Above' means >=");
                        if (indexToDelete.HasValue)
                        {
                            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "delete Active Limit");
                            item.activeItemCriteria.DeleteByIndex(indexToDelete.Value);
                        }

                        DTInspectorUtility.VerticalSpace(2);
                    }

                    break;
                }

                PoolBossEditorUtility.DisplayPrefab(ref _isDirty, _settings, ref item.prefabToSpawn, ref item.prefabPoolBossCategory, "Prefab Pool Item");

                KillerVariablesHelper.DisplayKillerInt(ref _isDirty, item.thisWeight, "Weight", _settings);
                EditorGUILayout.EndVertical();
                DTInspectorUtility.AddSpaceForNonU5();
            }

            if (_settings.poolItems.Count > 0)
            {
                DTInspectorUtility.EndGroupedControls();
            }
        }

        if (topAdded)
        {
            var newItem = new WavePrefabPoolItem();
            var index   = 0;
            if (_settings.poolItems.Count > 0)
            {
                index = _settings.poolItems.Count - 1;
            }

            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "add Prefab Pool Item");
            _settings.poolItems.Insert(index, newItem);
        }
        else if (itemToDelete.HasValue)
        {
            if (_settings.poolItems.Count == 1)
            {
                DTInspectorUtility.ShowAlert("You cannot delete the only Prefab Pool item. Delete the entire Pool from the hierarchy if you wish.");
            }
            else
            {
                UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "remove Prefab Pool Item");
                _settings.poolItems.RemoveAt(itemToDelete.Value);
            }
        }
        else if (itemToInsert.HasValue)
        {
            var newItem = new WavePrefabPoolItem();
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "add Prefab Pool Item");
            _settings.poolItems.Insert(itemToInsert.Value + 1, newItem);
        }

        if (itemToClone.HasValue)
        {
            var newItem = CloningHelper.CloneWavePrefabPoolItem(_settings.poolItems[itemToClone.Value]);
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "clone Prefab Pool Item");
            _settings.poolItems.Insert(itemToClone.Value, newItem);
        }

        if (itemToShiftUp.HasValue)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "shift up Prefab Pool Item");
            var item = _settings.poolItems[itemToShiftUp.Value];
            _settings.poolItems.Insert(itemToShiftUp.Value - 1, item);
            _settings.poolItems.RemoveAt(itemToShiftUp.Value + 1);
        }

        if (itemToShiftDown.HasValue)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "shift down Prefab Pool Item");
            var index = itemToShiftDown.Value + 1;
            var item  = _settings.poolItems[index];
            _settings.poolItems.Insert(index - 1, item);
            _settings.poolItems.RemoveAt(index + 1);
        }

        if (alphaSort)
        {
            UndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _settings, "Alpha Sort Prefab Pool Items");
            _settings.poolItems.Sort(delegate(WavePrefabPoolItem x, WavePrefabPoolItem y) {
                if (x.prefabToSpawn == null)
                {
                    return(-1);
                }
                if (y.prefabToSpawn == null)
                {
                    return(1);
                }

                return(x.prefabToSpawn.name.CompareTo(y.prefabToSpawn.name));
            });
        }

        if (GUI.changed || topAdded || _isDirty)
        {
            EditorUtility.SetDirty(target);     // or it won't save the data!!
        }

        //DrawDefaultInspector();
    }
        /// <inheritdoc />
        /// <summary>
        /// Saves the selected scene nodes to the clipboard by Ctrl+C.
        /// Pastes the scene nodes from the clipboard by Ctrl+V.
        /// Deletes the selected scene nodes from the scene by Delete.
        /// </summary>
        public override void KeyDown(object sender, KeyEventArgs e)
        {
            base.KeyDown(sender, e);

            // copy selected objects at the scene to the clipboard
            if (e.Control && e.KeyCode == Keys.C)
            {
                // clear the current clipboard
                Screen.Clipboard.Clear();
                // rectangle of selected nodes for calculate clipboard position
                Vector2? lowerBound = null, upperBound = null;

                // add selected objects at the scene to the clipboard
                foreach (SceneNode selectedNode in Screen.SelectedNodes)
                {
                    if (selectedNode.Visible)
                    {
                        Screen.Clipboard.Add(selectedNode);

                        if (lowerBound == null)
                        {
                            lowerBound = selectedNode.Rectangle.LowerBound;
                            upperBound = selectedNode.Rectangle.UpperBound;
                        }
                        else
                        {
                            lowerBound = Vector2.Min(lowerBound.Value, selectedNode.Rectangle.LowerBound);
                            upperBound = Vector2.Max(upperBound.Value, selectedNode.Rectangle.UpperBound);
                        }
                    }
                }
                // calculate clipboard position
                if (lowerBound != null) Screen.ClipboardPosition = 0.5f * (lowerBound.Value + upperBound.Value);
            }

            // paste objects from clipboard to the scene
            else if (e.Control && e.KeyCode == Keys.V && Screen.Clipboard.Count != 0)
            {
                // compute move vector for placing objects at the correct position at the scene
                Vector2 moveVector = Screen.MouseScenePosition - Screen.ClipboardPosition;

                // save copied objects to the history
                CompositeCommand command = new CompositeCommand();

                List<GameObject> objectsToCloned = new List<GameObject>();

                // copy all objects from clipboard to the scene
                foreach (SceneNode node in Screen.Clipboard)
                {
                    if (node.Visible && !ContainsAnyParent(Screen.Clipboard, node))
                    {
                        objectsToCloned.Add(node.Tag);
                    }
                }

                foreach (GameObject clonedObject in CloningHelper.Clone(objectsToCloned, Screen.Scene.SelectedLayer, true, true))
                {
                    // move object to the new position
                    Screen.Find(clonedObject).Move(moveVector);

                    command.Commands.Add(clonedObject.CreateAddCommand());
                }

                // add command to history
                if (command.Commands.Count != 0) Screen.History.Add(command);
            }

            // delete selected objects from the scene and copy them to the clipboard
            // NOT WORKING when safe deleting is on because it will clear clipboard
            /*else if (e.Control && e.KeyCode == Keys.X)
            {
                // clear the current clipboard
                Screen.Clipboard.Clear();
                // rectangle of selected nodes for calculate clipboard position
                Vector2? lowerBound = null, upperBound = null;
                // save deleted objects to the history
                CompositeCommand command = new CompositeCommand();

                List<ItemForDeletion> itemsForDeletion = new List<ItemForDeletion>();

                // add selected objects at the scene to the clipboard
                foreach (SceneNode selectedNode in Screen.SelectedNodes)
                {
                    if (selectedNode.Visible)
                    {
                        command.Commands.Add(selectedNode.Tag.CreateDeleteCommand());

                        if (selectedNode.Tag is Actor) itemsForDeletion.Add(new ConsistentDeletionHelper.ActorForDeletion((Actor)selectedNode.Tag));
                        else if (selectedNode.Tag is Path) itemsForDeletion.Add(new ConsistentDeletionHelper.PathForDeletion((Path)selectedNode.Tag));
                        else
                        {
                            Debug.Assert(true, "Not supported game objects deleting.");
                            selectedNode.Tag.Remove();
                        }

                        // add to the clipboard
                        Screen.Clipboard.Add(selectedNode);

                        if (lowerBound == null)
                        {
                            lowerBound = selectedNode.Rectangle.LowerBound;
                            upperBound = selectedNode.Rectangle.UpperBound;
                        }
                        else
                        {
                            lowerBound = Vector2.Min(lowerBound.Value, selectedNode.Rectangle.LowerBound);
                            upperBound = Vector2.Max(upperBound.Value, selectedNode.Rectangle.UpperBound);
                        }
                    }
                }
                // calculate clipboard position
                if (lowerBound != null) Screen.ClipboardPosition = 0.5f * (lowerBound.Value + upperBound.Value);

                if ((new ConsistentDeletionForm(itemsForDeletion) { ProcessWhenEmptyList = true }).ShowDialog() == DialogResult.OK)
                {
                    if (command.Commands.Count != 0) Screen.History.Add(command);

                    // clear selected objects at the scene
                    Screen.SelectedNodes.Clear();

                    // selected nodes changed
                    Screen.InvokeSelectedNodesChanged();
                }
            }*/

            // delete selected objects from the scene
            else if (e.KeyCode == Keys.Delete)
            {
                // save deleted objects to the history
                CompositeCommand command = new CompositeCommand();

                List<ItemForDeletion> itemsForDeletion = new List<ItemForDeletion>();

                // remove all selected objects from the scene
                foreach (SceneNode selectedNode in Screen.SelectedNodes)
                {
                    if (selectedNode.Visible)
                    {
                        command.Commands.Add(selectedNode.Tag.CreateDeleteCommand());

                        if (selectedNode.Tag is Actor) itemsForDeletion.Add(new ConsistentDeletionHelper.ActorForDeletion((Actor)selectedNode.Tag));
                        else if (selectedNode.Tag is Path) itemsForDeletion.Add(new ConsistentDeletionHelper.PathForDeletion((Path)selectedNode.Tag));
                        else
                        {
                            Debug.Assert(true, "Not supported game objects deleting.");
                            selectedNode.Tag.Remove();
                        }
                    }
                }

                if ((new ConsistentDeletionForm(itemsForDeletion) { ProcessWhenEmptyList = true }).ShowDialog() == DialogResult.OK)
                {
                    if (command.Commands.Count != 0) Screen.History.Add(command);

                    // clear selected objects at the scene
                    Screen.SelectedNodes.Clear();

                    // selected nodes changed
                    Screen.InvokeSelectedNodesChanged();
                }
            }
        }
Example #6
0
    // Update is called once per frame
    void Update()
    {
        if (!tested.HasValue)
        {
            tested = true;
#if !XBOX || !WINDOWS_PHONE
            GameObject    go   = new GameObject();
            CloningHelper help = go.AddComponent <CloningHelper>();
            help.val           = 100;
            help.nm            = "Tested";
            help.reference     = gameObject;
            help.referenceList = new List <GameObject>();
            help.referenceList.Add(gameObject);
            help.referenceArray   = new GameObject[] { gameObject };
            help.objReference     = new CloneObject();
            help.objReferenceList = new List <CloneObject>();
            help.objReferenceList.Add(help.objReference);
            help.objReferenceArray = new CloneObject[] { help.objReference };
            help.intList           = new List <int>()
            {
                1, 2, 3
            };
            help.strList = new List <string>()
            {
                "One", "Two"
            };
            help.enumList = new List <EnumTest>()
            {
                EnumTest.ON
            };
            help.intArray    = new int[] { 1, 2, 3 };
            help.stringArray = new string[] { "One", "Two" };
            help.enumArray   = new EnumTest[] { EnumTest.ON };

            CloningHelper helpClone = (CloningHelper)Instantiate(help);

            try {
                helpClone.val.Should().Be(help.val);
                helpClone.nm.Should().Be(help.nm);
                helpClone.reference.Should().Be(gameObject);
                ((object)helpClone.referenceList).Should().NotBe(help.referenceList);
                helpClone.referenceList.Should().NotBeEmpty();
                helpClone.referenceList.Should().Contain(gameObject);
                helpClone.referenceArray.Should().NotBeNull();
                helpClone.referenceArray.Should().NotBeEmpty();
                helpClone.referenceArray.Should().Contain(gameObject);
                helpClone.objReference.Should().NotBe(help.objReference);
                helpClone.objReference.Should().BeNull();
                helpClone.objReferenceArray.Should().BeNull();
                ((object)helpClone.objReferenceList).Should().NotBe(help.objReferenceList);
                ((object)helpClone.objReferenceList).Should().BeNull();
                ((object)helpClone.intList).Should().NotBe(help.intList);
                ((object)helpClone.intList).Should().NotBeNull();
                helpClone.intList.Count.Should().Be(help.intList.Count);
                ((object)helpClone.strList).Should().NotBe(help.strList);
                ((object)helpClone.strList).Should().NotBeNull();
                helpClone.strList.Count.Should().Be(help.strList.Count);
                ((object)helpClone.enumList).Should().NotBe(help.enumList);
                ((object)helpClone.enumList).Should().NotBeNull();
                helpClone.enumList.Count.Should().Be(help.enumList.Count);
                ((object)helpClone.intArray).Should().NotBe(help.intList);
                ((object)helpClone.intArray).Should().NotBeNull();
                ((object)helpClone.stringArray).Should().NotBe(help.strList);
                ((object)helpClone.stringArray).Should().NotBeNull();
                ((object)helpClone.enumArray).Should().NotBe(help.enumList);
                ((object)helpClone.enumArray).Should().NotBeNull();

                Debug.Log(GetType().Name + " succeeded");
            } catch (Exception ex) {
                // Log the merror
                Debug.LogError(ex.Message);
            } finally {
                Destroy(go);
                Destroy(helpClone.gameObject);
            }
#endif
        }
    }