/// <summary> /// 文字列からピボットを解析する /// </summary> /// <param name="text">テキスト</param> /// <param name="defaultValue">デフォルト値</param> /// <returns>解析したピボット値。文字列が設定されてなかったらデフォルト値を。解析できなかったら例外を投げる</returns> public static Vector2 ParsePivotOptional(string text, Vector2 defaultValue) { //何も設定がなければデフォルト値を if (string.IsNullOrEmpty(text)) { return(defaultValue); } Vector2 pivot = Vector2.one * 0.5f; Pivot pivotEnum; if (TryParaseEnum <Pivot>(text, out pivotEnum)) { return(PivotUtil.PivotEnumToVector2(pivotEnum)); } if (TryParseVector2Optional(text, pivot, out pivot)) { return(pivot); } else { throw new System.Exception(LanguageErrorMsg.LocalizeTextFormat(ErrorMsg.PivotParse, text)); } }
public static Vector2 ParsePivotOptional(string text, Vector2 defaultValue) { Pivot pivot; if (string.IsNullOrEmpty(text)) { return(defaultValue); } Vector2 vector = (Vector2)(Vector2.get_one() * 0.5f); if (TryParaseEnum <Pivot>(text, out pivot)) { return(PivotUtil.PivotEnumToVector2(pivot)); } if (TryParseVector2Optional(text, vector, out vector)) { return(vector); } object[] args = new object[] { text }; throw new Exception(LanguageErrorMsg.LocalizeTextFormat(ErrorMsg.PivotParse, args)); }
/// <summary> /// StringGridのデータ解析 /// </summary> /// <param name="grid">解析するデータ</param> protected override void ParseFromStringGrid(StringGrid grid) { string name = ""; foreach (StringGridRow row in grid.Rows) { if (row.RowIndex < grid.DataTopRow) { continue; //データの行じゃない } if (row.IsEmpty) { continue; //データがない } //名前は空白なら、直前のものと同じ name = AdvParser.ParseCellOptional <string>(row, AdvColumnName.CharacterName, name); string key = ToFileKey(name, AdvParser.ParseCellOptional <string>(row, AdvColumnName.Pattern, "")); Vector2 pivot = Vector2.one * 0.5f; try { pivot = PivotUtil.ParsePivotOptional(AdvParser.ParseCellOptional <string>(row, AdvColumnName.Pivot, ""), pivot); } catch (System.Exception e) { Debug.LogError(row.ToErrorString(e.Message)); } //データ追加 AdvCharacterSettingData data = new AdvCharacterSettingData(); data.Init(key, pivot, AdvParser.ParseCellOptional <float>(row, AdvColumnName.Scale, 1.0f), AdvParser.ParseCell <string>(row, AdvColumnName.FileName), AdvParser.ParseCellOptional <int>(row, AdvColumnName.Version, 0)); Add(data); if (!defaultKey.ContainsKey(name)) { defaultKey.Add(name, key); } } }
/// <summary> /// StringGridの一行からデータ初期化 /// </summary> /// <param name="row">初期化するためのデータ</param> /// <returns>成否</returns> public override bool InitFromStringGridRow(StringGridRow row) { string key = AdvParser.ParseCell <string>(row, AdvColumnName.Label); InitKey(key); this.type = AdvParser.ParseCell <Type>(row, AdvColumnName.Type); this.pivot = Vector2.one * 0.5f; try { this.pivot = PivotUtil.ParsePivotOptional(AdvParser.ParseCellOptional <string>(row, AdvColumnName.Pivot, ""), pivot); } catch (System.Exception e) { Debug.LogError(row.ToErrorString(e.Message)); } this.scale = AdvParser.ParseCellOptional <float>(row, AdvColumnName.Scale, 1.0f); this.fileName = AdvParser.ParseCell <string>(row, AdvColumnName.FileName); this.version = AdvParser.ParseCellOptional <int>(row, AdvColumnName.Version, 0); this.thumbnailName = AdvParser.ParseCellOptional <string>(row, AdvColumnName.Thumbnail, ""); this.thumbnailVersion = AdvParser.ParseCellOptional <int>(row, AdvColumnName.ThumbnailVersion, 0); return(true); }