/// <summary> /// Saves the script. /// </summary> /// <returns><c>true</c>, if script was saved, <c>false</c> otherwise.</returns> /// <param name="path">Path.</param> /// <param name="subFix">Sub fix.</param> /// <param name="code">Code.</param> /// <param name="overwrite">If set to <c>true</c> overwrite.</param> /// <param name="currentBaseType">Current base type.</param> /// <param name="newBaseType">New base type.</param> public static bool SaveScript(string path, string code, bool overwrite, string currentBaseType = "", string newBaseType = "") { try { if (!overwrite && File.Exists(path)) { return(false); } var currentCode = ""; if (File.Exists(path)) { currentCode = AssetDatabase.LoadAssetAtPath <TextAsset>(path).text; } if (!code.Equals(currentCode)) { using (var writer = new StreamWriter(path)) { writer.Write(code); } return(true); } else { return(false); } } catch (IOException ex) { UnuLogger.LogException(ex); return(false); } }
/// <summary> /// Notify the property which has change to all binder that has been subcribed with property name and value. /// </summary> /// <param name="propertyName"></param> /// <param name="value"></param> public virtual void NotifyPropertyChanged(string propertyName, object value) { if (!this.actions.TryGetValue(propertyName, out Action <object> actions)) { return; } try { actions?.Invoke(value); } catch (Exception e) { UnuLogger.LogException(e, this); } }
/// <summary> /// Raise the change event automatically, /// only use this function in property getter /// </summary> public void OnPropertyChanged(string propertyName, object value) { this.PropertyChanged?.Invoke(this); if (this.actions.TryGetValue($"set_{propertyName}", out Action <object> actions)) { try { actions?.Invoke(value); } catch (Exception e) { UnuLogger.LogException(e); } } DataContext.NotifyObjectChange(this, propertyName, value); }
public static string DeleteScript(string path) { var code = ""; if (!File.Exists(path)) { return(null); } try { code = AssetDatabase.LoadAssetAtPath <TextAsset>(path).text; AssetDatabase.DeleteAsset(path); } catch (IOException ex) { UnuLogger.LogException(ex); } return(code); }
public void TriggerEvent(string eventType) { if (this.Routers.TryGetValue(eventType, out Delegate @delegate)) { Delegate[] invocationList = @delegate.GetInvocationList(); for (var i = 0; i < invocationList.Length; i++) { if (!(invocationList[i] is Action action)) { throw new EventException(string.Format("TriggerEvent {0} error: types of parameters are not match.", eventType)); } try { action(); } catch (Exception ex) { UnuLogger.LogException(ex); } } } }