Created
July 12, 2017 19:36
-
-
Save unity3dcollege/a276259db5f60fd3f10d4d7e04098d5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
[CreateAssetMenuAttribute] | |
public class QuizQuestion : ScriptableObject | |
{ | |
[SerializeField] | |
private string question; | |
[SerializeField] | |
private string[] answers; | |
[SerializeField] | |
private int correctAnswer; | |
public string Question { get { return question; } } | |
public string[] Answers { get { return answers; } } | |
public int CorrectAnswer { get { return correctAnswer; } } | |
public bool Asked { get; internal set; } | |
private void OnValidate() | |
{ | |
if (correctAnswer > answers.Length) | |
{ | |
correctAnswer = 0; | |
} | |
RenameScriptableObjectToMatchQuestionAndAnswer(); | |
} | |
private void RenameScriptableObjectToMatchQuestionAndAnswer() | |
{ | |
string desiredName = string.Format("{0} [{1}]", | |
question.Replace("?", ""), | |
answers[correctAnswer]); | |
string assetPath = AssetDatabase.GetAssetPath(this.GetInstanceID()); | |
string shouldEndWith = "/" + desiredName + ".asset"; | |
if (assetPath.EndsWith(shouldEndWith) == false) | |
{ | |
Debug.Log("Want to rename to " + desiredName); | |
AssetDatabase.RenameAsset(assetPath, desiredName); | |
AssetDatabase.SaveAssets(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment