Commit 2964ffe2 authored by Priyanka P D M K 's avatar Priyanka P D M K

unity game and model

parent 6f494b12
This source diff could not be displayed because it is too large. You can view the blob instead.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class DragObject : MonoBehaviour, IDragHandler,IEndDragHandler
{
internal bool isCorrectObject;
internal Vector3 defaultPosition;
private void Awake() {
defaultPosition = transform.localPosition;
}
void IDragHandler.OnDrag(PointerEventData eventData) {
transform.position = eventData.position;
}
void IEndDragHandler.OnEndDrag(PointerEventData eventData) {
float distance = Vector3.Distance(transform.position, GameManager.Instance.DragBucket.transform.position);
if (distance < 50) {
if (isCorrectObject) {
transform.position = GameManager.Instance.DragBucket.transform.position;
GameManager.Instance.IsCorrectDrag(true);
} else {
transform.localPosition = defaultPosition;
GameManager.Instance.IsCorrectDrag(false);
}
} else {
transform.localPosition = defaultPosition;
}
}
}
fileFormatVersion: 2
guid: 940dd1133628f6f419cde93814ce812c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class GameManager : MonoBehaviour {
#region PROPERTIES
public static GameManager Instance { get; private set; }
[Header("Drag Objects")]
[SerializeField] internal GameObject DragBucket;
[SerializeField] internal GameObject[] DragObjects;
[SerializeField] ImageAndNameData[] ImageAndNameData;
[Header("UI")]
[SerializeField] internal TextMeshProUGUI TargetName;
[SerializeField] internal AudioSource TargetAudioSource;
[SerializeField] internal TextMeshProUGUI TimerTxt;
[SerializeField] internal TextMeshProUGUI QuestionCount;
[Header("Correct Wrong Pop Up Panel")]
[SerializeField] internal GameObject CWPopUpPanel;
[SerializeField] internal TextMeshProUGUI CWPopUpText;
[Header("Congrats Pop Up Panel")]
[SerializeField] internal GameObject CongratsPopUpPanel;
[SerializeField] internal TextMeshProUGUI CongratsPopUpText;
List<int> selectedIndexs;
List<int> askedQuesIndexsInThisLevel;
float timeLimit = 16;
float timeLeft;
float spentTime;
bool isTimerStarted;
CURRENT_LEVEL currentLevel;
int askedQustionCount;
int correctAnswersCount;
int totalPoints;
int pointsForThisQuestion;
[Header("Progress Map")]
[SerializeField] private GameObject ProgressmapPanel;
[SerializeField] private GameObject[] ProgressImgArray;
[SerializeField] internal TextMeshProUGUI ProgressDiscription;
int currentLvelProgress;
enum CURRENT_LEVEL {
SoundSet, Letters_3_Words, Letters_4_Words, Letters_5_Words, Compound_Words
}
#endregion
#region UNITY METHODS
private void Awake() {
if (Instance == null) {
Instance = this;
}
selectedIndexs = new List<int>();
askedQuesIndexsInThisLevel = new List<int>();
currentLvelProgress = PlayerPrefs.GetInt("currentLvelProgress", 0);
}
private void Start() {
Reset();
}
private void Update() {
if (isTimerStarted) {
timeLeft -= Time.deltaTime;
}
TimerTxt.text = "Time: " + ((int)timeLeft).ToString();
if (timeLeft < 0) {
ReloadQuiz();
spentTime += timeLimit;
}
}
public void Reset() {
currentLevel = CURRENT_LEVEL.SoundSet;
askedQustionCount = 0;
correctAnswersCount = 0;
totalPoints = 0;
askedQuesIndexsInThisLevel.Clear();
spentTime = 0;
ReloadQuiz();
}
public void ReTry() {
currentLevel = CURRENT_LEVEL.Letters_3_Words;
askedQustionCount = 3;
correctAnswersCount = 3;
totalPoints = 3;
askedQuesIndexsInThisLevel.Clear();
spentTime = 0;
ReloadQuiz();
}
public void ReloadQuiz() {
if (askedQustionCount == 15) {
SetCongratsPopUpPanel();
return;
}
selectedIndexs.Clear();
int correctObject = UnityEngine.Random.Range(0, DragObjects.Length);
for (int i = 0; i < DragObjects.Length; i++) {
int ranDataIndex;
do {
ranDataIndex = UnityEngine.Random.Range(0, ImageAndNameData[(int)currentLevel].mImageAndNameDataSet.Length);
} while (selectedIndexs.Contains(ranDataIndex) || askedQuesIndexsInThisLevel.Contains(ranDataIndex));
selectedIndexs.Add(ranDataIndex);
DragObjects[i].GetComponent<Image>().sprite = ImageAndNameData[(int)currentLevel].mImageAndNameDataSet[ranDataIndex].mImage;
DragObjects[i].transform.localPosition = DragObjects[i].GetComponent<DragObject>().defaultPosition;
if (i == correctObject) {
DragObjects[i].GetComponent<DragObject>().isCorrectObject = true;
TargetName.text = ImageAndNameData[(int)currentLevel].mImageAndNameDataSet[ranDataIndex].mName;
TargetAudioSource.clip = ImageAndNameData[(int)currentLevel].mImageAndNameDataSet[ranDataIndex].mAudioClip;
askedQuesIndexsInThisLevel.Add(ranDataIndex); ;
TargetAudioSource.Play();
} else {
DragObjects[i].GetComponent<DragObject>().isCorrectObject = false;
}
}
timeLeft = timeLimit;
isTimerStarted = true;
TimerTxt.gameObject.SetActive(true);
if (currentLevel == CURRENT_LEVEL.SoundSet) {
pointsForThisQuestion = 1;
} else if (currentLevel == CURRENT_LEVEL.Letters_3_Words) {
pointsForThisQuestion = 2;
} else if (currentLevel == CURRENT_LEVEL.Letters_4_Words) {
pointsForThisQuestion = 3;
} else if (currentLevel == CURRENT_LEVEL.Letters_5_Words) {
pointsForThisQuestion = 4;
} else if (currentLevel == CURRENT_LEVEL.Compound_Words) {
pointsForThisQuestion = 5;
}
askedQustionCount++;
if (askedQustionCount > 11) {
currentLevel = CURRENT_LEVEL.Compound_Words;
askedQuesIndexsInThisLevel.Clear();
} else if (askedQustionCount > 8) {
currentLevel = CURRENT_LEVEL.Letters_5_Words;
askedQuesIndexsInThisLevel.Clear();
} else if (askedQustionCount > 5) {
currentLevel = CURRENT_LEVEL.Letters_4_Words;
askedQuesIndexsInThisLevel.Clear();
} else if (askedQustionCount > 2) {
currentLevel = CURRENT_LEVEL.Letters_3_Words;
askedQuesIndexsInThisLevel.Clear();
}
QuestionCount.text = "Question: " + askedQustionCount;
}
internal void IsCorrectDrag(bool state) {
if (state) {
CWPopUpText.text = "Correct Answer !";
CWPopUpPanel.transform.GetChild(2).gameObject.SetActive(true);
CWPopUpPanel.transform.GetChild(3).gameObject.SetActive(false);
correctAnswersCount++;
totalPoints += pointsForThisQuestion;
isTimerStarted = false;
TimerTxt.gameObject.SetActive(false);
spentTime += timeLimit - timeLeft;
} else {
CWPopUpText.text = "Wrong Answer !";
CWPopUpPanel.transform.GetChild(2).gameObject.SetActive(false);
CWPopUpPanel.transform.GetChild(3).gameObject.SetActive(true);
}
CWPopUpPanel.gameObject.SetActive(true);
}
private void SetCongratsPopUpPanel() {
isTimerStarted = false;
TimerTxt.gameObject.SetActive(false);
CongratsPopUpText.text = "Correct answers: " + correctAnswersCount;
CongratsPopUpPanel.gameObject.SetActive(true);
}
public void SubmitData() {
Debug.Log("spentTime: " + spentTime);
Debug.Log("correctAnswersCount: " + correctAnswersCount);
Debug.Log("pointsCount: " + totalPoints);
StartCoroutine(SendData());
//LevelData level = new LevelData();
//level.level = 0;
//UpdateProgressMap(level);
}
public IEnumerator SendData() {
UnityWebRequest web = UnityWebRequest.Get("http://192.168.80.132:5000/predictLevel?&time=" + spentTime + "&TotalPoints=" + totalPoints);
web.method = "GET";
yield return web.SendWebRequest();
if (web.result == UnityWebRequest.Result.ConnectionError || web.responseCode != 200)
Debug.LogError(web.error);
else {
LevelData level = new LevelData();
level = JsonUtility.FromJson<LevelData>(web.downloadHandler.text);
UpdateProgressMap(level);
Debug.Log(level.level+1);
}
web.Dispose();
}
#endregion
private void UpdateProgressMap(LevelData level) {
for (int i = 0; i < ProgressImgArray.Length; i++) {
ProgressImgArray[i].gameObject.GetComponent<Image>().color = new Vector4(1, 1, 1, 0.5f);
}
for (int i = 0; i < ProgressImgArray.Length; i++) {
if (i <= level.level) {
ProgressImgArray[i].gameObject.GetComponent<Image>().color = new Vector4(1, 1, 1, 1);
} else {
ProgressImgArray[i].gameObject.GetComponent<Image>().color = new Vector4(1, 1, 1, 0.5f);
}
}
if (currentLvelProgress == 0) {
if (level.level == 0) {
ProgressDiscription.text = "You are at the same level as your previous attempt, Let's try to move forward!";
} else if (level.level == 1) {
ProgressDiscription.text = "Congratulations! You just moved 1 level up!";
} else if (level.level == 2) {
ProgressDiscription.text = "Congratulations! You just moved 2 levels up!";
} else if (level.level == 3) {
ProgressDiscription.text = "Congratulations! You are showing great preformance";
}
} else if (currentLvelProgress == 1) {
if (level.level == 0) {
ProgressDiscription.text = "Oops! You just moved 1 level down, Let's try to do well next time!";
} else if (level.level == 1) {
ProgressDiscription.text = "You are at the same level as your previous attempt, Let's try to move forward!";
} else if (level.level == 2) {
ProgressDiscription.text = "Congratulations! You just moved 1 level up!";
} else if (level.level == 3) {
ProgressDiscription.text = "Congratulations! You just moved 2 levels up!";
}
} else if (currentLvelProgress == 2) {
if (level.level == 0) {
ProgressDiscription.text = "Oops! You are moving down, Let's try to move forward!";
} else if (level.level == 1) {
ProgressDiscription.text = "Oops! You just moved 1 level down, Let's try to do well next time!";
} else if (level.level == 2) {
ProgressDiscription.text = "You are at the same level as your previous attempt, Let's try to move forward!";
} else if (level.level == 3) {
ProgressDiscription.text = "Congratulations! You just moved 1 level up!";
}
} else if (currentLvelProgress == 3) {
if (level.level == 0) {
ProgressDiscription.text = "Oops! You are moving down, Let's try to move forward!";
} else if (level.level == 1) {
ProgressDiscription.text = "Oops! You are moving down, Let's try to move forward!";
} else if (level.level == 2) {
ProgressDiscription.text = "Oops! You just moved 1 level down, Let's try to do well next time!";
} else if (level.level == 3) {
ProgressDiscription.text = "You are at the same level as your previous attempt, Let's try to move forward!";
}
}
currentLvelProgress = level.level;
PlayerPrefs.SetInt("currentLvelProgress", currentLvelProgress);
ProgressmapPanel.gameObject.SetActive(true);
}
public void ResetProgress() {
LevelData level = new LevelData();
level.level = 0;
currentLvelProgress = 0;
UpdateProgressMap(level);
}
}
[Serializable]
public struct LevelData {
[SerializeField] public int level;
}
\ No newline at end of file
fileFormatVersion: 2
guid: 0071c3d3958e7e24cbec950f195ea07c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEngine;
using UnityEngine.UI;
[CreateAssetMenu(fileName = "ImageAndNameData", menuName = "ScriptableObjects/ImageAndNameData")]
public class ImageAndNameData : ScriptableObject {
public ImageAndName[] mImageAndNameDataSet;
}
[Serializable]
public class ImageAndName {
public string mName;
public Sprite mImage;
public AudioClip mAudioClip;
}
fileFormatVersion: 2
guid: f10b0c284416a244ab47540ae4a7c184
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!11 &1
AudioManager:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Volume: 1
Rolloff Scale: 1
Doppler Factor: 1
Default Speaker Mode: 2
m_SampleRate: 0
m_DSPBufferSize: 1024
m_VirtualVoiceCount: 512
m_RealVoiceCount: 32
m_SpatializerPlugin:
m_AmbisonicDecoderPlugin:
m_DisableAudio: 0
m_VirtualizeEffects: 1
m_RequestedDSPBufferSize: 1024
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!236 &1
ClusterInputManager:
m_ObjectHideFlags: 0
m_Inputs: []
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!55 &1
PhysicsManager:
m_ObjectHideFlags: 0
serializedVersion: 11
m_Gravity: {x: 0, y: -9.81, z: 0}
m_DefaultMaterial: {fileID: 0}
m_BounceThreshold: 2
m_SleepThreshold: 0.005
m_DefaultContactOffset: 0.01
m_DefaultSolverIterations: 6
m_DefaultSolverVelocityIterations: 1
m_QueriesHitBackfaces: 0
m_QueriesHitTriggers: 1
m_EnableAdaptiveForce: 0
m_ClothInterCollisionDistance: 0
m_ClothInterCollisionStiffness: 0
m_ContactsGeneration: 1
m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
m_AutoSimulation: 1
m_AutoSyncTransforms: 0
m_ReuseCollisionCallbacks: 1
m_ClothInterCollisionSettingsToggle: 0
m_ContactPairsMode: 0
m_BroadphaseType: 0
m_WorldBounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 250, y: 250, z: 250}
m_WorldSubdivisions: 8
m_FrictionType: 0
m_EnableEnhancedDeterminism: 0
m_EnableUnifiedHeightmaps: 1
m_DefaultMaxAngluarSpeed: 7
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1045 &1
EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes:
- enabled: 1
path: Assets/Scenes/SampleScene.unity
guid: 9fc0d4010bbf28b4594072e72b8655ab
m_configObjects: {}
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!159 &1
EditorSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_ExternalVersionControlSupport: Visible Meta Files
m_SerializationMode: 2
m_LineEndingsForNewScripts: 0
m_DefaultBehaviorMode: 0
m_PrefabRegularEnvironment: {fileID: 0}
m_PrefabUIEnvironment: {fileID: 0}
m_SpritePackerMode: 0
m_SpritePackerPaddingPower: 1
m_EtcTextureCompressorBehavior: 1
m_EtcTextureFastCompressor: 1
m_EtcTextureNormalCompressor: 2
m_EtcTextureBestCompressor: 4
m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef;rsp;asmref
m_ProjectGenerationRootNamespace:
m_CollabEditorSettings:
inProgressEnabled: 1
m_EnableTextureStreamingInEditMode: 1
m_EnableTextureStreamingInPlayMode: 1
m_AsyncShaderCompilation: 1
m_EnterPlayModeOptionsEnabled: 0
m_EnterPlayModeOptions: 3
m_ShowLightmapResolutionOverlay: 1
m_UseLegacyProbeSampleCount: 0
m_SerializeInlineMappingsOnOneLine: 1
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!30 &1
GraphicsSettings:
m_ObjectHideFlags: 0
serializedVersion: 13
m_Deferred:
m_Mode: 1
m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0}
m_DeferredReflections:
m_Mode: 1
m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0}
m_ScreenSpaceShadows:
m_Mode: 1
m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0}
m_LegacyDeferred:
m_Mode: 1
m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0}
m_DepthNormals:
m_Mode: 1
m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0}
m_MotionVectors:
m_Mode: 1
m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0}
m_LightHalo:
m_Mode: 1
m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0}
m_LensFlare:
m_Mode: 1
m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0}
m_AlwaysIncludedShaders:
- {fileID: 7, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}
m_CustomRenderPipeline: {fileID: 0}
m_TransparencySortMode: 0
m_TransparencySortAxis: {x: 0, y: 0, z: 1}
m_DefaultRenderingPath: 1
m_DefaultMobileRenderingPath: 1
m_TierSettings: []
m_LightmapStripping: 0
m_FogStripping: 0
m_InstancingStripping: 0
m_LightmapKeepPlain: 1
m_LightmapKeepDirCombined: 1
m_LightmapKeepDynamicPlain: 1
m_LightmapKeepDynamicDirCombined: 1
m_LightmapKeepShadowMask: 1
m_LightmapKeepSubtractive: 1
m_FogKeepLinear: 1
m_FogKeepExp: 1
m_FogKeepExp2: 1
m_AlbedoSwatchInfos: []
m_LightsUseLinearIntensity: 0
m_LightsUseColorTemperature: 0
m_LogWhenShaderIsCompiled: 0
m_AllowEnlightenSupportForUpgradedProject: 0
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!13 &1
InputManager:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Axes:
- serializedVersion: 3
m_Name: Horizontal
descriptiveName:
descriptiveNegativeName:
negativeButton: left
positiveButton: right
altNegativeButton: a
altPositiveButton: d
gravity: 3
dead: 0.001
sensitivity: 3
snap: 1
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Vertical
descriptiveName:
descriptiveNegativeName:
negativeButton: down
positiveButton: up
altNegativeButton: s
altPositiveButton: w
gravity: 3
dead: 0.001
sensitivity: 3
snap: 1
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire1
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: left ctrl
altNegativeButton:
altPositiveButton: mouse 0
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire2
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: left alt
altNegativeButton:
altPositiveButton: mouse 1
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Fire3
descriptiveName:
descriptiveNegativeName: