internal SceneCondition CreateNewCondition(string name, System.Type conditionType)
        {
            if (string.IsNullOrEmpty(name))
            {
                Debug.LogError("Name not provided");
                return(null);
            }

            if (conditionType == null)
            {
                return(null);
            }

            if (!conditionType.IsOrIsSubclassOf(typeof(SceneCondition)))
            {
                Debug.LogError("Provided type does not derive from Scene Condition, cannot create");
                return(null);
            }

            SceneCondition newCondition =
                AssetDatabaseExtensions.CreateSubScriptableObject(TargetManager,
                                                                  conditionType, name) as SceneCondition;

            Undo.RegisterCreatedObjectUndo(newCondition, "Create Condition");

            return(newCondition);
        }
        private void OnNewConditionTypeSelected(System.Object selectedType)
        {
            Type type = selectedType as Type;

            if (type == null)
            {
                return;
            }

            string assetName = AssetDatabaseExtensions.GetUniqueSubAssetName(
                serializedManager.TargetManager, type.Name, StringComparison.OrdinalIgnoreCase);

            SceneCondition created =
                serializedManager.CreateNewCondition(assetName, type);

            conditionsListProperty.AddArrayObjectValue(created);
        }
        internal void DeleteCondition(SerializedProperty conditionListProp, int index)
        {
            if (conditionListProp == null)
            {
                Debug.LogError("Condition prop not provided");
                return;
            }

            serializedManager.Update();

            SerializedProperty conditionProp =
                conditionListProp.GetArrayElementAtIndex(index);

            SceneCondition condition = conditionProp.objectReferenceValue as SceneCondition;

            if (condition == null)
            {
                Debug.LogError("Failed to find condition at index " + index);
                return;
            }

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

            Undo.RegisterCompleteObjectUndo(TargetManager, "Condition Deleted");
            Undo.DestroyObjectImmediate(condition);

            // Need to call delete twice to actually remove it from the array
            conditionListProp.DeleteArrayElementAtIndex(index);
            conditionListProp.DeleteArrayElementAtIndex(index);

            conditionListProp.serializedObject.ApplyModifiedProperties();

            Undo.CollapseUndoOperations(undoGroup);

            serializedManager.ApplyModifiedProperties();

            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(TargetManager));
        }