internal void DeleteSceneNode(int sceneId, bool addToExclusionFilter)
        {
            SceneModel model = TargetManager.scenes.Find((x) => x.SceneId == sceneId);

            if (sceneId == TargetManager.AnyScene.SceneId)
            {
                return;
            }

            if (model == null)
            {
                return;
            }

            Undo.SetCurrentGroupName("Delete Scene Node");
            int undoGroup = Undo.GetCurrentGroup();

            Undo.RegisterCompleteObjectUndo(SceneNodesObject.targetObject, "Scene Nodes");

            SerializedProperty scenesProperty = ScenesProp;

            for (int i = scenesProperty.arraySize - 1; i >= 0; i--)
            {
                SerializedSceneModel serializedScene = GetSerializedSceneModel(i);

                serializedScene.DeleteTransitionsInvolving(sceneId);

                if (serializedScene.SceneIdProp.intValue == sceneId)
                {
                    scenesProperty.DeleteArrayElementAtIndex(i);
                }
            }

            SerializedManager.ApplyModifiedProperties();

            for (int i = 0; i < SceneNodesProp.arraySize; i++)
            {
                if (GetSceneNodeIdProperty(i).intValue == sceneId)
                {
                    SceneNodesProp.DeleteArrayElementAtIndex(i);
                    break;
                }
            }

            SceneNodesObject.ApplyModifiedProperties();

            if (addToExclusionFilter)
            {
                SerializedProperty exclusion = SerializedSceneFilter.FindProperty("FilesToExclude");
                SerializedProperty newEntry  = exclusion.AddArrayElement();
                newEntry.stringValue = model.SceneAssetPath;
                SerializedSceneFilter.ApplyModifiedProperties();
            }

            Undo.CollapseUndoOperations(undoGroup);
        }
Exemple #2
0
        internal static Rect DrawReplacementRules(Rect position, SerializedProperty property)
        {
            // Header
            property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, Styles.replacementCharacters);
            position.y         += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
            if (!property.isExpanded)
            {
                return(position);
            }

            float indent         = EditorGUI.indentLevel * 15;
            float width          = position.width - indent;
            var   originalPos    = new Rect(position.x + indent, position.y, width * 0.5f, position.height);
            var   replacementPos = new Rect(originalPos.xMax + 2, position.y, width - originalPos.width - 2 - k_RemoveButtonSize, position.height);
            var   btnPos         = new Rect(replacementPos.xMax + 2, position.y, k_RemoveButtonSize - 2, position.height);

            GUI.Label(originalPos, Styles.original);
            GUI.Label(replacementPos, Styles.replacement);

            if (GUI.Button(btnPos, Styles.addItem))
            {
                var element     = property.AddArrayElement();
                var original    = element.FindPropertyRelative("original");
                var replacement = element.FindPropertyRelative("replacement");
                original.intValue    = ('A' + property.arraySize - 1);
                replacement.intValue = 0;
            }

            for (int i = 0; i < property.arraySize; ++i)
            {
                originalPos.y   += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
                replacementPos.y = btnPos.y = originalPos.y;

                var element     = property.GetArrayElementAtIndex(i);
                var original    = element.FindPropertyRelative("original");
                var replacement = element.FindPropertyRelative("replacement");

                EditorGUI.PropertyField(originalPos, original, GUIContent.none);
                EditorGUI.PropertyField(replacementPos, replacement, GUIContent.none);

                if (GUI.Button(btnPos, Styles.removeItem))
                {
                    property.DeleteArrayElementAtIndex(i);
                }

                position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
            }

            position.y = originalPos.y;
            return(position);
        }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        SerializedProperty pList    = property.FindPropertyRelative("list");
        SerializedProperty pIndexes = property.FindPropertyRelative("indexes");
        NameListAttribute  attr     = attribute as NameListAttribute;

        string[] fullList = attr.FullList;
        //initial load data:
        int starter = 0;

        if (SelectedIndexed.Count == 0)
        {
            for (int i = 0; i < pList.arraySize; i++)
            {
                for (int j = starter; j < fullList.Length; j++)
                {
                    if (pList.GetArrayElementAtIndex(i).stringValue == fullList[j])
                    {
                        starter = j + 1;
                        SelectedIndexed.Add(j);
                        break;
                    }
                }
            }
        }

        //Show button, show pop up when btn clicked and Set editor values on clicks
        DrawPointSelectorInspector(position, property, fullList);

        //Save the values to the serialized object within the class of this drawer:
        //SerializedProperty pList = property.serializedObject.FindProperty("list");
        pList.ClearArray();
        pIndexes.ClearArray();
        for (int i = 0; i < SelectedIndexed.Count; i++)
        {
            pList.AddArrayElement(fullList[SelectedIndexed[i]]);
            pIndexes.AddArrayElement(SelectedIndexed[i]);
        }

        /*string outp = "";
        *       outp += "elements: ";
        *       for (int i = 0; i < pList.arraySize; i++) {
        *           outp += pList.GetArrayElementAtIndex(i).stringValue;
        *           outp += ";   ";
        *       }
        *       Debug.Log(outp); */
    }