﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

#if UNITY_EDITOR
using UnityEditor;
#endif

namespace Onward.CustomContent
{
    public class ContentException : System.Exception
    {
        public ContentException(string msg, GameObject go = null)
            : base(msg)
        {
            Debug.LogError(msg, go);
        }
    }
    
    public class ContentExceptionMissingLevel : ContentException
    {
        public ContentExceptionMissingLevel()
            : base("Could not find LevelDescriptor. Make sure to place a LevelDescriptor prefab into your scene!")
        {

        }
    }

    public class ContentExceptionWithGameObject : ContentException
    {
        static string FormatErrorMessage(GameObject go, string msg) => go.name + ": " + msg;

        public ContentExceptionWithGameObject(GameObject go, string msg)
           : base(FormatErrorMessage(go, msg), go)
        {
#if UNITY_EDITOR
            if (go != null)
            {
                Selection.activeGameObject = go;
            }
#endif
        }
    }
}