/// <summary> /// Assign Global enter/exit Delegates for the MmRelaySwitchNode's FSM. /// </summary> public override void Start() { MmLogger.LogResponder("MmSwitchResponder Start"); // Assign default responder for transitioning between MmRelayNodes MmRelaySwitchNode.RespondersFSM.GlobalExit += delegate { MmLogger.LogApplication("MmRelaySwitchNode GlobalExit"); MmRelaySwitchNode.Current.MmInvoke(MmMethod.SetActive, false, new MmMetadataBlock(MmLevelFilterHelper.Default, MmActiveFilter.All, default(MmSelectedFilter), MmNetworkFilter.Local)); }; MmRelaySwitchNode.RespondersFSM.GlobalEnter += delegate { MmLogger.LogApplication("MmRelaySwitchNode GlobalEnter"); MmRelaySwitchNode.Current.MmInvoke(MmMethod.SetActive, true, new MmMetadataBlock(MmLevelFilterHelper.Default, MmActiveFilter.All, default(MmSelectedFilter), MmNetworkFilter.Local)); }; base.Start(); }
/// <summary> /// If a TaskSequence was interrupted, it is possible to continue /// from the last loaded trial before the interruption. /// </summary> /// <returns>Current sequence index after load.</returns> public virtual int LoadPartiallyFinishedTaskSequence() { if (!File.Exists(Path.Combine(MmTaskUserData.DirPath, PartialDataFile))) { return(0); } var reader = new StreamReader(Path.Combine(MmTaskUserData.DirPath, PartialDataFile), Encoding.UTF8); string line = reader.ReadLine(); if (line == null) { MmLogger.LogError("Partial Sequence File Empty"); return(-1); } var curSequenceIndex = int.Parse(line.Split(',')[1]); reader.Close(); return(curSequenceIndex); }
/// <summary> /// Get attached ItaskInfoCollectionLoader, which must be attached to the /// same game object. /// </summary> public override void Awake() { MmLogger.LogApplication("MmTaskManager Awake"); taskInfoCollectionLoader = GetComponent <ITaskInfoCollectionLoader <U> >(); MmTaskUserData = GetComponent <MmTaskUserConfigurator>(); }
/// <summary> /// Auto-grabs the MmRelaySwitchNode. Also assigns/invokes /// Awake callbacks. /// </summary> public override void Awake() { MmLogger.LogResponder("MmSwitchResponder Awake"); MmRelaySwitchNode = GetComponent <MmRelaySwitchNode>(); //This is to avoid the situation where the MmRelaySwitchNode is started // before this script is. if (MmRelaySwitchNode.Initialized) { OnMmSwitchNodeAwakeCompleteCallback(); } else { MmRelaySwitchNode.MmRegisterAwakeCompleteCallback(OnMmSwitchNodeAwakeCompleteCallback); } MmRelaySwitchNode.MmRegisterStartCompleteCallback(OnMmNodeSwitchStartCompleteCallback); if (MmRelaySwitchNode.MmNetworkResponder == null || MmRelaySwitchNode.MmNetworkResponder.IsActiveAndEnabled) { MmRegisterStartCompleteCallback(MmSwitchSetup); } else { MmRelaySwitchNode.MmNetworkResponder.MmRegisterStartCompleteCallback(MmSwitchSetup); } base.Awake(); }
/// <summary> /// Setup app states in derivations. /// Get handle to singleton instance MmGuiHandler, is present. /// </summary> public virtual void SetupAppStates() { //Todo: Remove MmGuiHandler = MmGuiHandler.Instance; MmLogger.LogApplication(gameObject.name + ": Initializing Application States."); }
/// <summary> /// Load the data for use by deserializer. /// </summary> public override void Load() { base.Load(); MmLogger.LogApplication("Serializing CSV"); // TODO: Serialize XML here }
/// <summary> /// Callback called after associated MmRelaySwitchNode started. /// </summary> public virtual void OnMmNodeSwitchStartCompleteCallback() { MmLogger.LogResponder("OnMmNodeSwitchStartComplete invoked"); if (MmRelaySwitchNode.RoutingTable.Count == 0) { MmLogger.LogResponder("No MmRelayNodes in RespondersFSM on: " + gameObject.name); } }
/// <summary> /// Close DataHandler file/stream. /// </summary> public virtual void Close() { #if UNITY_STANDALONE || UNITY_EDITOR Writer.Close(); #else Writer.Dispose(); #endif MmLogger.LogApplication("File closed: " + FileName); }
/// <summary> /// Load file and read into data field member of class. /// </summary> public virtual void Load() { StreamReader r = File.OpenText(Path.Combine(FileLocation, FileName)); Data = r.ReadToEnd(); #if UNITY_STANDALONE || UNITY_EDITOR r.Close(); #else r.Dispose(); #endif MmLogger.LogApplication("File read: " + FileName); }
/// <summary> /// Prepare the tasks that were loaded by the /// TaskInfoCollectionLoader. /// </summary> public virtual void PrepareTasks() { int taskLoadStatus = taskInfoCollectionLoader.PrepareTasks( ref TaskInfos, MmTaskUserData.UserId); if (taskLoadStatus >= 0) { currentTaskInfo = GetNodeAt(taskLoadStatus); } else { MmLogger.LogError("Task Load Failed"); } ApplySequenceID(); }
/// <summary> /// Open DataHandler file/stream. /// </summary> /// <param name="overwrite">Should the handler override content /// if file exists.</param> /// <returns>New File created? /// 0 - No /// 1 - Yes /// </returns> public virtual int Open(bool overwrite = false) { int newItem = 0; #if UNITY_STANDALONE || UNITY_EDITOR FileInfo t = new FileInfo(Path.Combine(FileLocation, FileName)); newItem = (!t.Exists || overwrite) ? 1 : 0; if (overwrite && t.Exists) { t.Delete(); MmLogger.LogApplication("File Deleted: " + FileName); } Writer = t.AppendText(); MmLogger.LogApplication("File opened: " + FileName); #endif return(newItem); }
/// <summary> /// This is called when the MmNetworkResponder is started /// Important Note: this will only trigger locally. The reason for this is that /// the following code needs to execute on every instance of the MmRelayNode across the network /// Thus, in order to avoid triggering the message each time a client connects, we just trigger the message locally. /// </summary> public virtual void MmSwitchSetup() { MmLogger.LogResponder(gameObject.name + " MmSwitchSetup Invoked."); MmRelaySwitchNode.MmInvoke(MmMethod.Initialize, new MmMetadataBlock(MmLevelFilter.Child, MmActiveFilter.All, default(MmSelectedFilter), MmNetworkFilter.Local)); MmRelaySwitchNode.MmInvoke(MmMethod.SetActive, false, new MmMetadataBlock(MmLevelFilter.Child, MmActiveFilter.All, default(MmSelectedFilter), MmNetworkFilter.Local)); if (InitialState != "") { MmLogger.LogResponder(gameObject.name + " attempting to jump to: " + InitialState); MmRelaySwitchNode.MmInvoke(MmMethod.Switch, MmRelaySwitchNode.RoutingTable[InitialState].Name, new MmMetadataBlock(MmLevelFilter.Self, MmActiveFilter.All, default(MmSelectedFilter), MmNetworkFilter.Local)); } }
/// <summary> /// Given a collection of task infos, load /// the task sequence from file into the collection. /// </summary> /// <param name="taskInfos">Collection filled by task sequence from /// file. Can be empty if file unloaded.</param> public virtual void LoadTaskSequence(ref LinkedList <U> taskInfos) { var filename = MmTaskUserData.BaseDirectory + "/" + TaskSeqFilename; try { using (var sr = new StreamReader(filename, Encoding.UTF8)) { // Skip header line var line = sr.ReadLine(); if (string.IsNullOrEmpty(line)) { return; } taskInfos = new LinkedList <U>(); while ((line = sr.ReadLine()) != null) { var t = new U(); t.Parse(line); // Only load current user if (t.UserId != MmTaskUserData.UserId) { continue; } taskInfos.AddLast(t); } } } catch (Exception e) { MmLogger.LogError("The file could not be read:"); MmLogger.LogError(e.Message); } }
/// <summary> /// Callback called after associated MmRelaySwitchNode awoken. /// </summary> public virtual void OnMmSwitchNodeAwakeCompleteCallback() { MmLogger.LogResponder("OnMmSwitchNodeAwakeComplete invoked"); }
/// <summary> /// Prepare the tasks that were loaded. /// </summary> public override void Start() { MmLogger.LogApplication("MmTaskManager Start"); PrepareTasks(); }