void Start() { if (!target) { if (GameObject.FindObjectOfType <QK_Character_Movement>()) { target = (Transform)GameObject.FindObjectOfType <QK_Character_Movement>().transform; player = target; _curState = CameraState.Normal; } else { Debug.Error("camera", "Cannot find this.target. Please connect the GameObject to the component using the inspector."); target = transform; } if (!gameObject.GetComponent <CheckTargets>()) { Debug.Warning("camera", "\"CheckTargets\" object not on Camera. Targeting is not enabled"); } } Go.defaultUpdateType = GoUpdateType.FixedUpdate; distance = Mathf.Clamp(distance, distanceMin, distanceMax); cameraLatency = Mathf.Clamp(cameraLatency, 0.05f, 1f); // Bit Shift our layermasks PlayerLM = 1 << playerLayer | 1 << IgnoreRaycastLayer; NoOcclusionLM = 1 << noOcclusionLayer | 1 << noTartedOccludionLayer | 1 << IgnoreRaycastLayer; // Inverse both masks PlayerLM = ~PlayerLM; NoOcclusionLM = ~NoOcclusionLM; Reset(); }
//! Sets all achievements to false(0) public bool ClearAchievements() { //Checking to see if achievement json file exists if it doesnt return if (!System.IO.File.Exists(Application.dataPath + "/Resources/Json/achievementJson")) { Debug.Error("serilaization", "Could not find Achievement JSON file"); return(false); } //read in achievement json file string jsonRead = System.IO.File.ReadAllText(Application.dataPath + "/Resources/Json/achievementJson"); JSONNode jsonParsed = JSON.Parse(jsonRead); //iterate through json file and load each key and its value into to check against playerpref keys and set them to false(0) for (int count = 0; count < jsonParsed["Achievements"].Count; count = count + 1) { string loadedAchievement = jsonParsed["Achievements"][count]; PlayerPrefs.SetInt(loadedAchievement, 0); } //save to playerprefs just in case PlayerPrefs.Save(); //return true when operation is complete return(true); }
//!checks JSON file isnt empty and loads data into audio dictionaries public bool loadListFromJson(string json) { JSONNode soundData = JSON.Parse(json); //the whole JSON file if (soundData == null) { Debug.Error("audio", "Json file is empty"); return(false); } JSONNode audioNode = soundData["audio"]; //Just the ones under audio string[] types = { "ambience", "effect", "music", "voice" }; foreach (string type in types) { JSONArray tempArray = audioNode[type].AsArray; //just the objects under the type foreach (JSONNode j in tempArray) { var name = j[0]; //j[0] is name of object bool priority = j[1].AsBool; //j[1] priority of object addSound(type, name, priority); //if(priority) // loadPriority(type, name); } } return(true); }
//!checks JSON file exists and loads it public bool loadListFromFile(string path) //checks to make sure json file is there { if (!System.IO.File.Exists(Application.dataPath + path)) { Debug.Error("audio", "File does not exist: " + Application.dataPath + path); return(false); } string json = System.IO.File.ReadAllText(Application.dataPath + path); return(loadListFromJson(json)); }
void Awake() { #region singletonEnforcement if (instance == null) { instance = this; } else { Destroy(this.gameObject); Debug.Error("core", "Second GameHUD detected. Deleting gameOject."); return; } #endregion UIhud = GameObject.Find("_UI"); mainHUDCanvas = GameObject.Find("mainHUD"); worldMapCanvas = GameObject.Find("worldMapCanvas"); gameMap = GameObject.Find("mapBG"); player = GameObject.Find("_Player"); testObjective = GameObject.Find("TestObjective"); if (!pauseMenu) { pauseMenu = GameObject.Find("pauseMenu"); } pauseMenu.SetActive(false); //!Turn on UI stuff worldMapCanvas.SetActive(true); //!Fill mapLabels array mapLabels = GameObject.FindGameObjectsWithTag("worldMapLabel"); closeMapButton = GameObject.Find("CloseMapButton"); closeMapButton.SetActive(false); //!Set mapcam reference mapCam = GameObject.Find("mapCam"); //!Set compassCameraPoint reference compassCameraPoint = GameObject.Find("compassCameraPoint"); compass = GameObject.Find("compassSlider"); slider = compass.transform.FindChild("Handle Slide Area").gameObject; slider.SetActive(false); leftArrow = compass.transform.FindChild("leftArrow").gameObject; leftArrow.SetActive(false); rightArrow = compass.transform.FindChild("rightArrow").gameObject; rightArrow.SetActive(false); //!Set objective text reference objectiveText = GameObject.Find("objectiveText"); phoneButtons = GameObject.Find("PhoneButtons"); mapElements = GameObject.Find("MapElements"); mapElements.SetActive(false); }
//! Load string protected string Load(string key) { if (PlayerPrefs.HasKey(key)) { return(PlayerPrefs.GetString(key)); } else { Debug.Error("core", "Loading from PlayerPrefs failed. Key \"" + key + "\" does not exist."); } return(null); }
} //END public Transform FindNearestCheckpointByPath(Vector3 player) //creates debug error and returns true if list is empty, false if list contains a checkpoint bool ListEmpty() { if (AllCheckpoints.Count < 1) { Debug.Error("checkpoint", "list AllCheckpoints is empty"); return(true); } else { return(false); } } //END bool ListEmpty()
void Start() { if (instance == null) { instance = this; } else { Destroy(this.gameObject); Debug.Error("core", "Second ObjectManager detected. Deleting gameOject."); return; } }
void Awake() { if (instance == null) { instance = this; } else { Destroy(this.gameObject); Debug.Error("core", "Second MasterSceneManager detected. Deleting gameOject."); return; } }
//! Sets one inputed key (achievement) to ture(1) as completed public bool CompleteAchievement(string inputAchievement) { //check to see if input string has a key in playerprefs if (!PlayerPrefs.HasKey(inputAchievement)) { Debug.Error("serialization", "Could Not Complete Achievement " + inputAchievement + " does not exist in PlayerPrefs"); return(false); } //save data to playerPrefs and set vale to true(1) PlayerPrefs.SetInt(inputAchievement, 1); //return true when operation is complete return(true); }
//!Creates a JSONNode from the JSON file and calls a function to build the lists of gameobjects protected void LoadCharacterModelsFromJson() { //Checking to see if character builder json file exists if it doesnt return if (!System.IO.File.Exists(Application.dataPath + "/Resources/Json/characterBuilderJson")) { Debug.Error("serilaization", "Could not find Character Models JSON file"); return; } //read in character builder json file string jsonRead = System.IO.File.ReadAllText(Application.dataPath + "/Resources/Json/characterBuilderJson"); JSONNode jsonParsed = JSON.Parse(jsonRead); //Call function to build and fill the appropriate lists with gameobjects and their respective models from the project folder BuildLists(jsonParsed); }
void Start() { inputs.Add(Inputs.UI, this.gameObject.AddComponent <UIInputType>()); inputs.Add(Inputs.Game, this.gameObject.AddComponent <GameInputType>()); inputs.Add(Inputs.Keyboard, this.gameObject.AddComponent <KeyboardInputType>()); if (inputs.Count > 0) { ChangeInputType(Inputs.Game); } else { Debug.Error("input", "InputManager.inputs is empty."); } ChangeInputType(Inputs.Game); }
//! Unity Start function void Start() { Debug.Log("audio", "SoundManager has started"); #region singletonCreation if (_instance == null) { //If I am the first instance, make me the Singleton Debug.Log("audio", "Audio Singleton did not exist, creating"); _instance = this; DontDestroyOnLoad(this); } else { //If a Singleton already exists and you find //another reference in scene, destroy it! Debug.Error("audio", "There is more than one Audio Singleton, Destroying"); if (this != _instance) { Destroy(this.gameObject); } } #endregion if (testing) { player = new GameObject("PlayerTest"); Debug.Warning("audio", "Audio testing is enabled"); } //JSON file load check if (!loadListFromFile(soundListFilePath)) { Debug.Error("audio", "JSON file did not load"); } else { Debug.Log("audio", "JSON file loaded"); } changeVol("master", 40f); generatePriority(); }
//! Checks to see if input string(achievement) is a completed event (true(1)) or not (false(0)) public bool CheckAchievement(string inputAchievement) { //check to see if input string has a key in playerprefs if (!PlayerPrefs.HasKey(inputAchievement)) { Debug.Error("serialization", "Could Not Complete Achievement " + inputAchievement + " does not exist in PlayerPrefs"); return(false); } //check to see if input string as a key is set to true(1) or false(0) in playerprefs if (PlayerPrefs.GetInt(inputAchievement) == 1) { return(true); } else { return(false); } }
private void LoadScenesDictionary() { try{ TextAsset textAsset = Resources.Load(StringManager.SCENELIST) as TextAsset; string text = textAsset.ToString(); if (text == "") { Debug.Warning("core", "SceneList empty"); } else { JSONNode N = JSON.Parse(text); scenes.Clear(); for (int i = 0; i < N.Count; i++) { scenes.Add(N[i].Value); } Debug.Log("core", "Scenes dictionary loaded."); } }catch (NullReferenceException e) { Debug.Error("core", "SceneList missing: " + e); } }
void Awake() { start_moving = false; end_movement = false; updateKeyframes(); //!<see the function for notes on what this does //the two public gameobjects are important to the script, so they are needed if (!start_state) { Debug.Error("level", "There is no start_state for " + name + ", need one in public variable"); error_flagged = true; } else if (!end_state) { Debug.Error("level", "There is no end_state for " + name + ", need one in public variable"); error_flagged = true; } else { end_position = new Vector3(end_state.transform.position.x, end_state.transform.position.y, end_state.transform.position.z); start_position = new Vector3(start_state.transform.position.x, start_state.transform.position.y, start_state.transform.position.z); start_rotation = new Vector3(start_state.transform.eulerAngles.x, start_state.transform.eulerAngles.y, start_state.transform.eulerAngles.z); end_rotation = new Vector3(end_state.transform.eulerAngles.x, end_state.transform.eulerAngles.y, end_state.transform.eulerAngles.z); } cur_transform = start_state.transform; Destroy(end_state); if (duration <= 0) { duration = 0.01f; } }
//! Load achievements into playerprefs, all loaded achievements are set to false(0) for value by defualt protected void LoadAchievementsFromJson() { //Checking to see if achievement json file exists if it doesnt return if (!System.IO.File.Exists(Application.dataPath + "/Resources/Json/achievementJson")) { Debug.Error("serilaization", "Could not find Achievement JSON file"); return; } //read in achievement json file string jsonRead = System.IO.File.ReadAllText(Application.dataPath + "/Resources/Json/achievementJson"); JSONNode jsonParsed = JSON.Parse(jsonRead); //iterate through json file and load each key and its value into playerprefs //all achievements are set to false(0) by defualt for (int count = 0; count < jsonParsed["Achievements"].Count; count = count + 1) { string loadedAchievement = jsonParsed["Achievements"][count]; PlayerPrefs.SetInt(loadedAchievement, 0); } //save to playerprefs just in case PlayerPrefs.Save(); }
//!Coroutine that checks the play medium(editor/application), creates file path, loads sound into a clip, if its a priority it adds it to list else it calls the audio source builder function IEnumerator loadAudio(GameObject target, string type, string name, string loadType) { string typePath; string filename; AudioMixer mixerGroup; //checking if its a play or a priority load if (loadType == "play") { filename = name + ".ogg"; Debug.Log("audio", "LoadAudio: load type is " + loadType + " filename is " + filename); } else if (loadType == "priority") { filename = name; Debug.Log("audio", "LoadAudio: load type is " + loadType + " filename is " + filename); } else { filename = "temp"; Debug.Log("audio", "LoadAudio: load type is " + loadType + " filename is " + filename); } //files handled differently between editor and player //in editor: /Assets/StreamingAssets //in player: Application.streamingAssetsPath string dir; if (Application.isEditor) { dir = Application.dataPath + "/Audio"; switch (type.ToLower()) { case "ambience": typePath = "file:///" + dir + "/ambience/" + filename; mixerGroup = ambienceMixer; break; case "effect": typePath = "file:///" + dir + "/Effects/" + filename; mixerGroup = effectMixer; break; case "music": typePath = "file:///" + dir + "/Music/" + filename; mixerGroup = musicMixer; break; case "voice": typePath = "file:///" + dir + "/Voice/" + filename; mixerGroup = voiceMixer; break; default: Debug.Log("audio", type + " is not an option, or you spelled it wrong"); typePath = "path is invalid"; mixerGroup = null; break; } } else { dir = Application.streamingAssetsPath + "/Audio"; //Untested switch (type.ToLower()) { case "ambience": typePath = "file:///" + dir + "/ambience/" + filename; mixerGroup = ambienceMixer; break; case "effect": typePath = "file:///" + dir + "/Effects/" + filename; mixerGroup = effectMixer; break; case "music": typePath = "file:///" + dir + "/Music/" + filename; mixerGroup = musicMixer; break; case "voice": typePath = "file:///" + dir + "/Voice/" + filename; mixerGroup = voiceMixer; break; default: Debug.Log("audio", type + "is not an option, or you spelled it wrong"); typePath = "path is invalid"; mixerGroup = null; break; } } //if its already loaded if (priorityAudio.ContainsKey(name)) { Debug.Log("audio", "LoadAudio: " + name + " is already on the priority list, finishing loading"); finishedLoading(priorityAudio[name], mixerGroup, target, name, loadType); } else { //build and log path based on filename Debug.Log("audio", "LoadAudio: file path created: " + typePath); var www = new WWW(typePath); yield return(www); //now we wait if (string.IsNullOrEmpty(www.error)) { //we have now finished loading the file //if you do use an asset bundle, you just handle it a bit differently here AudioClip clip = www.audioClip; Debug.Log("audio", "LoadAudio: " + name + " Audio clip loaded from file, " + mixerGroup + " is the mixer group"); //finished loading -- fire callback name = Path.GetFileNameWithoutExtension(typePath); if (loadType == "priority") { priorityAudio.Add(name, clip); } else { finishedLoading(clip, mixerGroup, target, name, loadType); } } else { //bail out! Debug.Error("audio", "LoadAudio: WWW Error: " + www.error); } } }