private bool ReadClsn(out Rect[] clsn2DArr, ConfigSection section, ref int aniStartIdx, string clsnName, string clsnKeyName) { clsn2DArr = null; if (string.IsNullOrEmpty(clsnName)) { return(false); } string str = section.GetContent(aniStartIdx); if (string.IsNullOrEmpty(str)) { clsn2DArr = null; return(false); } bool ret = false; if (str.StartsWith(clsnName)) { string defClsStr = str.Substring(clsnName.Length).Trim(); int defClsCnt; if (!int.TryParse(defClsStr, out defClsCnt)) { clsn2DArr = null; return(false); } if (defClsCnt > 0) { clsn2DArr = new Rect[defClsCnt]; for (int i = aniStartIdx + 1; i <= aniStartIdx + defClsCnt; ++i) { string key; string value; if (section.GetKeyValue(i, out key, out value)) { if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value)) { int idx = key.IndexOf(clsnKeyName, StringComparison.CurrentCultureIgnoreCase); if (idx >= 0) { key = key.Substring(idx + clsnKeyName.Length); int startIdx = key.IndexOf("["); int endIdx = key.IndexOf("]"); if (startIdx >= 0 && endIdx >= 0 && endIdx > startIdx + 1) { string idxStr = key.Substring(startIdx + 1, endIdx - startIdx - 1); if (!string.IsNullOrEmpty(idxStr)) { idxStr = idxStr.Trim(); if (!string.IsNullOrEmpty(idxStr)) { int index = int.Parse(idxStr); if (index >= 0 && index < clsn2DArr.Length) { string[] values = value.Split(ConfigSection._cContentArrSplit, StringSplitOptions.RemoveEmptyEntries); if (values != null && values.Length > 0) { Rect r = new Rect(); if (values.Length >= 4) { string v = values[0].Trim(); int left = int.Parse(v); v = values[1].Trim(); int top = int.Parse(v); v = values[2].Trim(); int right = int.Parse(v); v = values[3].Trim(); int bottom = int.Parse(v); r.min = new Vector2(left, top); r.max = new Vector2(right, bottom); } clsn2DArr[index] = r; ret = true; } } } } } } } } } aniStartIdx += defClsCnt + 1; } } if (!ret) { clsn2DArr = null; } return(ret); }
public BeginAction(/*PlayerState state, */ ConfigSection section) { //this.State = state; if (section != null) { int aniStartIdx = 0; Rect[] clsn2DefaultArr = null; ReadClsn(out clsn2DefaultArr, section, ref aniStartIdx, _cClsn2Default, _cClsn2DKeyName); string str = section.GetContent(aniStartIdx); Rect[] frameClsn2 = null; Rect[] frameClsn1 = null; if (!string.IsNullOrEmpty(str)) { List <string> arr = new List <string>(); bool isLoopStart = false; int i = aniStartIdx; while (i < section.ContentListCount) { arr.Clear(); string line = section.GetContent(i); if (string.IsNullOrEmpty(line)) { ++i; continue; } if (line.StartsWith("Loopstart", StringComparison.CurrentCultureIgnoreCase)) { isLoopStart = true; ++i; continue; } // 说明需要设置默认clsDefault if (line.StartsWith(_cClsn2Default)) { aniStartIdx = i; if (ReadClsn(out clsn2DefaultArr, section, ref aniStartIdx, _cClsn2Default, _cClsn2DKeyName)) { i = aniStartIdx; } else { ++i; } continue; } if (line.StartsWith(_cClsn2)) { aniStartIdx = i; if (ReadClsn(out frameClsn2, section, ref aniStartIdx, _cClsn2, _cClsn2DKeyName)) { i = aniStartIdx; } else { ++i; } continue; } if (line.StartsWith(_cClsn1)) { aniStartIdx = i; if (ReadClsn(out frameClsn1, section, ref aniStartIdx, _cClsn1, _cClsn1DKeyName)) { i = aniStartIdx; } else { ++i; } continue; } if (section.GetArray(i, arr)) { if (arr.Count >= 5) { int ImageGroup = GetIntFromStr(arr[0], -1); int ImageIndex = GetIntFromStr(arr[1], -1); int Tick = int.Parse(arr[4].Trim()); bool hasFlip = arr.Count >= 6; ActionFlip flipMode = ActionFlip.afNone; if (hasFlip) { string flipStr = arr[5].Trim(); if (string.Compare(flipStr, "H", true) == 0) { flipMode = ActionFlip.afH; } else if (string.Compare(flipStr, "V", true) == 0) { flipMode = ActionFlip.afV; } else if (string.Compare(flipStr, "HV", true) == 0 || string.Compare(flipStr, "VH", true) == 0) { flipMode = ActionFlip.afHV; } } ActionFrame frame = new ActionFrame(); frame.Group = ImageGroup; frame.Index = ImageIndex; frame.Tick = Tick; frame.Flip = flipMode; if (aniStartIdx > 0 && clsn2DefaultArr != null) { frame.defaultClsn2Arr = clsn2DefaultArr; clsn2DefaultArr = null; } if (frameClsn2 != null) { frame.localClsn2Arr = frameClsn2; frameClsn2 = null; } if (frameClsn1 != null) { frame.localCls1Arr = frameClsn1; frameClsn1 = null; } if (isLoopStart) { frame.IsLoopStart = isLoopStart; isLoopStart = false; } ActionFrameList.Add(frame); } } ++i; } } } }