Glow effect on selected items

This commit is contained in:
Mediha Zukic
2017-05-19 22:38:58 +03:00
parent cdb36e6c52
commit a56cc6a4ad
5 changed files with 213 additions and 93 deletions

View File

@@ -0,0 +1,78 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 1264499954100932}
m_IsPrefabParent: 1
--- !u!1 &1264499954100932
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4150400866480204}
- component: {fileID: 108424420294056842}
m_Layer: 0
m_Name: HaloPrefab
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4150400866480204
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1264499954100932}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -1, y: -2.3999987, z: -0}
m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!108 &108424420294056842
Light:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1264499954100932}
m_Enabled: 1
serializedVersion: 8
m_Type: 2
m_Color: {r: 1, g: 0.024137914, b: 0.024137914, a: 1}
m_Intensity: 2
m_Range: 7
m_SpotAngle: 30
m_CookieSize: 10
m_Shadows:
m_Type: 0
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_Cookie: {fileID: 0}
m_DrawHalo: 1
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6ead2541b42799549a0f85e8d7a8305f
timeCreated: 1495219100
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -145,7 +145,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4768720760334766, guid: e6ccb8aba69569f4cadf68b15c30ed54, type: 2}
propertyPath: m_RootOrder
value: 42
value: 41
objectReference: {fileID: 0}
- target: {fileID: 1770846723999120, guid: e6ccb8aba69569f4cadf68b15c30ed54, type: 2}
propertyPath: m_Name
@@ -524,7 +524,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4385760647239650, guid: 316087cc66e75a549ba7824efb8aa376, type: 2}
propertyPath: m_RootOrder
value: 41
value: 40
objectReference: {fileID: 0}
- target: {fileID: 1721467186906536, guid: 316087cc66e75a549ba7824efb8aa376, type: 2}
propertyPath: m_Name
@@ -575,7 +575,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4724797087419746, guid: e250d80cdc32e06449d8033b134593e2, type: 2}
propertyPath: m_RootOrder
value: 35
value: 34
objectReference: {fileID: 0}
- target: {fileID: 1199879222312558, guid: e250d80cdc32e06449d8033b134593e2, type: 2}
propertyPath: m_Name
@@ -648,7 +648,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4874331222016684, guid: 1b3c1473dc239594ab45997a15141a33, type: 2}
propertyPath: m_RootOrder
value: 44
value: 43
objectReference: {fileID: 0}
- target: {fileID: 1149312733166908, guid: 1b3c1473dc239594ab45997a15141a33, type: 2}
propertyPath: m_Name
@@ -757,7 +757,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4192187277304830, guid: 1112299e74c1e3c48ae5011243210c35, type: 2}
propertyPath: m_RootOrder
value: 30
value: 29
objectReference: {fileID: 0}
- target: {fileID: 1713026141056038, guid: 1112299e74c1e3c48ae5011243210c35, type: 2}
propertyPath: m_IsActive
@@ -975,8 +975,7 @@ MonoBehaviour:
scoreText: {fileID: 1104804435}
questionText: {fileID: 104311976}
btnNextQuestion: {fileID: 697668435}
objController: {fileID: 1498947098205658, guid: 16f9cc8467eeee74ea53d9a93ab6d914,
type: 2}
haloPrefab: {fileID: 1264499954100932, guid: 6ead2541b42799549a0f85e8d7a8305f, type: 2}
--- !u!1001 &489612504
Prefab:
m_ObjectHideFlags: 0
@@ -1077,7 +1076,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4897873487176348, guid: 13c12adba67add34480e6a386eae2409, type: 2}
propertyPath: m_RootOrder
value: 31
value: 30
objectReference: {fileID: 0}
- target: {fileID: 1703930244184252, guid: 13c12adba67add34480e6a386eae2409, type: 2}
propertyPath: m_Name
@@ -1275,7 +1274,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4867910457373622, guid: 20709c16e0a493345a8307d9f7eb3671, type: 2}
propertyPath: m_RootOrder
value: 43
value: 42
objectReference: {fileID: 0}
- target: {fileID: 1162164963410328, guid: 20709c16e0a493345a8307d9f7eb3671, type: 2}
propertyPath: m_Name
@@ -1568,7 +1567,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4874331222016684, guid: 1b3c1473dc239594ab45997a15141a33, type: 2}
propertyPath: m_RootOrder
value: 34
value: 33
objectReference: {fileID: 0}
- target: {fileID: 1149312733166908, guid: 1b3c1473dc239594ab45997a15141a33, type: 2}
propertyPath: m_Name
@@ -1631,7 +1630,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4199814138892948, guid: 003191dee8f682442bb4146197bcbf73, type: 2}
propertyPath: m_RootOrder
value: 38
value: 37
objectReference: {fileID: 0}
- target: {fileID: 1362918718393460, guid: 003191dee8f682442bb4146197bcbf73, type: 2}
propertyPath: m_Name
@@ -2207,7 +2206,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4860354476573126, guid: 3998251d464483147bf8336ab8cc1cbe, type: 2}
propertyPath: m_RootOrder
value: 37
value: 36
objectReference: {fileID: 0}
- target: {fileID: 1918381462868588, guid: 3998251d464483147bf8336ab8cc1cbe, type: 2}
propertyPath: m_Name
@@ -2348,7 +2347,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4699736727481082, guid: 4454b74f07f2b314885bc47fe71e3cb8, type: 2}
propertyPath: m_RootOrder
value: 36
value: 35
objectReference: {fileID: 0}
- target: {fileID: 1796366585001624, guid: 4454b74f07f2b314885bc47fe71e3cb8, type: 2}
propertyPath: m_Name
@@ -2437,52 +2436,6 @@ GameObject:
m_PrefabParentObject: {fileID: 1953543111501018, guid: 5980049694612fa40bb82af0c06f6cb8,
type: 2}
m_PrefabInternal: {fileID: 1420768590}
--- !u!1001 &1449828102
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4342544762097680, guid: f30480f046aa8234a8645f8bf4663891, type: 2}
propertyPath: m_LocalPosition.x
value: -40.6
objectReference: {fileID: 0}
- target: {fileID: 4342544762097680, guid: f30480f046aa8234a8645f8bf4663891, type: 2}
propertyPath: m_LocalPosition.y
value: -38.25
objectReference: {fileID: 0}
- target: {fileID: 4342544762097680, guid: f30480f046aa8234a8645f8bf4663891, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4342544762097680, guid: f30480f046aa8234a8645f8bf4663891, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4342544762097680, guid: f30480f046aa8234a8645f8bf4663891, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4342544762097680, guid: f30480f046aa8234a8645f8bf4663891, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4342544762097680, guid: f30480f046aa8234a8645f8bf4663891, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4342544762097680, guid: f30480f046aa8234a8645f8bf4663891, type: 2}
propertyPath: m_RootOrder
value: 29
objectReference: {fileID: 0}
- target: {fileID: 1213039722467880, guid: f30480f046aa8234a8645f8bf4663891, type: 2}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: f30480f046aa8234a8645f8bf4663891, type: 2}
m_IsPrefabParent: 0
--- !u!1001 &1459504339
Prefab:
m_ObjectHideFlags: 0
@@ -2520,7 +2473,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4556538709896258, guid: 52133eadd2cd88d4cb5375d1e88f21a9, type: 2}
propertyPath: m_RootOrder
value: 46
value: 45
objectReference: {fileID: 0}
- target: {fileID: 1570709421877212, guid: 52133eadd2cd88d4cb5375d1e88f21a9, type: 2}
propertyPath: m_Name
@@ -2820,7 +2773,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4304307219157248, guid: 16f9cc8467eeee74ea53d9a93ab6d914, type: 2}
propertyPath: m_RootOrder
value: 39
value: 38
objectReference: {fileID: 0}
- target: {fileID: 1553387382474820, guid: 16f9cc8467eeee74ea53d9a93ab6d914, type: 2}
propertyPath: m_Name
@@ -2871,7 +2824,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4364813615723870, guid: 43eb157858cc49e4d9bb2757450de4d1, type: 2}
propertyPath: m_RootOrder
value: 32
value: 31
objectReference: {fileID: 0}
- target: {fileID: 1369782314676404, guid: 43eb157858cc49e4d9bb2757450de4d1, type: 2}
propertyPath: m_Name
@@ -2980,7 +2933,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4536243161988224, guid: f3a2cb9460018bd42a06d7e4261f2ce3, type: 2}
propertyPath: m_RootOrder
value: 40
value: 39
objectReference: {fileID: 0}
- target: {fileID: 4536243161988224, guid: f3a2cb9460018bd42a06d7e4261f2ce3, type: 2}
propertyPath: m_LocalScale.x
@@ -3152,7 +3105,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4438459384064586, guid: b332b1b3464a9334280862a492523d11, type: 2}
propertyPath: m_RootOrder
value: 45
value: 44
objectReference: {fileID: 0}
- target: {fileID: 1210971768504384, guid: b332b1b3464a9334280862a492523d11, type: 2}
propertyPath: m_Name
@@ -3501,7 +3454,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4867910457373622, guid: 20709c16e0a493345a8307d9f7eb3671, type: 2}
propertyPath: m_RootOrder
value: 33
value: 32
objectReference: {fileID: 0}
- target: {fileID: 1162164963410328, guid: 20709c16e0a493345a8307d9f7eb3671, type: 2}
propertyPath: m_Name

View File

@@ -14,6 +14,6 @@ public class ObjectController : MonoBehaviour {
// Update is called once per frame
void Update () {
}
//transform.GetComponent<Light>().intensity = 1.0f + Mathf.Abs(Mathf.Sin(2*Time.time));
}
}

View File

@@ -17,7 +17,11 @@ public class QuizController : MonoBehaviour {
public Button btnNextQuestion;
private float counterValue;
public GameObject haloPrefab;
private int scoreValue = 0;
private int questionIdx = 0;
private const int numberOfAnswers = 4;
@@ -31,16 +35,19 @@ public class QuizController : MonoBehaviour {
private const int counterDisplayAnswersInitialValue = 3;
private float counterValue;
private float counterDisplayAnswersValue;
private bool counterDisplayAnswersStarted = false;
private int scoreValue = 0;
private int questionIdx = 0;
// List of selected answers
private List<int> selectedAnswers;
// References to answers halo prefabs
private List<GameObject> answersHaloPrefabs;
// List of questions and correct answers
List<Question> questions = new List<Question>() {
new Question("1. Neki od ovih prozora imaju 2-3 puta manje toplotnih gubitaka za razliku od drugih, koji su to?", new int[] {1, 4}),
new Question("2. Na jedan od načina možete uštedjeti i do 10 litara vode po osobi dnevno, uz koji predmet?", new int[] {3, 4}),
@@ -54,20 +61,24 @@ public class QuizController : MonoBehaviour {
new Question("10. Uvijek odaberite program s najnižom temperaturom vode koji još uvijek obezbjeđuje dobar kvalitet pranja, za šta od navedenog? ", new int[] {1, 4}),
};
public GameObject objController;
// Use this for initialization
/// <summary>
/// Use this for initialization
/// </summary>
void Start () {
selectedAnswers = new List<int>();
answersHaloPrefabs = new List<GameObject>();
counterValue = counterInitialValue;
UpdateScene();
UpdateCounter();
UpdateScore();
btnNextQuestion.GetComponent<Button>().onClick.AddListener(LoadNextQuestion);
InstantiateHaloPrefabs();
}
// Update is called once per frame
/// <summary>
/// // Update is called once per frame
/// </summary>
void Update()
{
if (counterValue > 0)
@@ -79,9 +90,7 @@ public class QuizController : MonoBehaviour {
}
}
else
{
LoadNextQuestion();
}
if (counterDisplayAnswersValue > 0 && counterDisplayAnswersStarted)
counterDisplayAnswersValue -= Time.deltaTime;
else
@@ -90,7 +99,7 @@ public class QuizController : MonoBehaviour {
counterDisplayAnswersStarted = false;
}
// Select answers event handler
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
@@ -101,20 +110,37 @@ public class QuizController : MonoBehaviour {
if (counterDisplayAnswersStarted)
return;
Debug.Log(hit.transform.gameObject.name);
int answerIdx = GetAnswerIdx(hit.transform.gameObject.name) - numberOfAnswers * questionIdx;
// answerArrayIdx: [1, 40]
int answerArrayIdx = GetAnswerIdx(hit.transform.gameObject.name);
// answerIdx: [1, 4]
int answerIdx = answerArrayIdx - numberOfAnswers * questionIdx;
// Answer not selected - select it
if (!selectedAnswers.Contains(answerIdx))
{
SetGlowEffect(answerArrayIdx, true);
selectedAnswers.Add(answerIdx);
}
// Answer selected - unselect it
else
{
SetGlowEffect(answerArrayIdx, false);
selectedAnswers.Remove(answerIdx);
}
}
}
}
/// <summary>
/// Next question btn click event handler
/// </summary>
void LoadNextQuestion()
{
if (counterDisplayAnswersStarted)
return;
scoreValue += GetScore();
UpdateScore();
selectedAnswers.Clear();
ClearCurrentSceneGlowEffect();
counterDisplayAnswersValue = counterDisplayAnswersInitialValue;
counterDisplayAnswersStarted = true;
counterValue = counterInitialValue;
@@ -122,16 +148,25 @@ public class QuizController : MonoBehaviour {
questionIdx = (questionIdx + 1) % questions.Count;
}
/// <summary>
/// Updates score value - called from Update() method
/// </summary>
private void UpdateScore()
{
scoreText.text = scoreValue.ToString();
}
/// <summary>
/// Updates counter value - called from Update() method
/// </summary>
private void UpdateCounter()
{
counterText.text = counterValue.ToString("f0");
}
/// <summary>
/// Shows correct answers
/// </summary>
private void ShowAnswers()
{
for(int i = numberOfAnswers * questionIdx; i < numberOfAnswers * (questionIdx + 1); i++)
@@ -140,19 +175,15 @@ public class QuizController : MonoBehaviour {
}
}
private void MarkAnswer(bool isCorrect, int idx)
{
answers[idx].GetComponent<ObjectController>().imageCorrect.enabled = isCorrect;
answers[idx].GetComponent<ObjectController>().imageIncorrect.enabled = !isCorrect;
}
// Update scene with new question + answers
/// <summary>
/// Updates scene with new question and related answers
/// </summary>
private void UpdateScene()
{
RemoveMarks();
// Set new question
questionText.text = questions[questionIdx].getQuestionText();
// Set right answers
// Set answers for selected question
for(int i = 0; i < answers.Length; i++)
{
if (i >= numberOfAnswers * questionIdx && i < numberOfAnswers * (questionIdx + 1))
@@ -164,19 +195,68 @@ public class QuizController : MonoBehaviour {
}
}
/// <summary>
/// Hides correct/incorrect images for currently shown answers
/// </summary>
private void RemoveMarks()
{
foreach(GameObject answer in answers)
{
answer.GetComponent<ObjectController>().imageCorrect.enabled = false;
answer.GetComponent<ObjectController>().imageIncorrect.enabled = false;
for(int i = 0; i < numberOfAnswers; i++) {
int answerIdx = questionIdx * numberOfAnswers + i;
answers[answerIdx].GetComponent<ObjectController>().imageCorrect.enabled = false;
answers[answerIdx].GetComponent<ObjectController>().imageIncorrect.enabled = false;
}
}
/// <summary>
/// Sets visibility of correct/incorrect overlay images
/// </summary>
/// <param name="isCorrect"></param>
/// <param name="idx"></param>
private void MarkAnswer(bool isCorrect, int idx)
{
answers[idx].GetComponent<ObjectController>().imageCorrect.enabled = isCorrect;
answers[idx].GetComponent<ObjectController>().imageIncorrect.enabled = !isCorrect;
}
/// <summary>
/// Adds Halo prefabs to all answers
/// </summary>
private void InstantiateHaloPrefabs()
{
for(int i = 0; i < answers.Count(); i++)
{
GameObject answerPrefab = Instantiate(haloPrefab) as GameObject;
answerPrefab.SetActive(false);
answerPrefab.transform.SetParent(answers[i].transform, false);
answersHaloPrefabs.Add(answerPrefab);
}
}
/// <summary>
/// Clears glow from all currently shown answers
/// </summary>
private void ClearCurrentSceneGlowEffect()
{
for (int i = 0; i < numberOfAnswers; i++)
{
int prefabIdx = questionIdx * numberOfAnswers + i;
answersHaloPrefabs[prefabIdx].SetActive(false);
}
}
/// <summary>
/// Clears/Adds glow from a specific answer GameObject
/// </summary>
/// <param name="prefabIdx"></param>
private void SetGlowEffect(int prefabIdx, bool showGlowEffect)
{
answersHaloPrefabs[prefabIdx - 1].SetActive(showGlowEffect);
}
/// <summary>
/// Returns answer index (X) from answer's name (AnswerX)
/// </summary>
/// <param name="gameObjName"></param>
/// <param name="gameObjName">GameObject's name</param>
/// <returns></returns>
private int GetAnswerIdx(string gameObjName)
{