public static void AddStyle(ref LinkedList <RichTextStyle> styles, RichTextStyle newSet, bool overrideOldStyle) { if (newSet.end <= newSet.start || newSet.start < 0 || !newSet.hasAnyStyle) { return; } if (styles == null) { styles = new LinkedList <RichTextStyle>(); } if (styles.Count == 0) { styles.AddLast(newSet); return; } LinkedListNode <RichTextStyle> node = styles.First; while (node != null) { RichTextStyle set = node.Value; LinkedListNode <RichTextStyle> next = node.Next; if (newSet.end <= set.start) { styles.AddBefore(node, newSet); return; } else if (newSet.start >= set.end) { node = next; continue; } //newSet.end>set.Start, newSet.start<set.end int off0, off1; //左边区域 off0 = Mathf.Min(newSet.start, set.start); off1 = Mathf.Max(newSet.start, set.start); if (off0 < off1) { RichTextStyle insert = newSet.start < set.start ? newSet.CopyTo(off0, off1) : set.CopyTo(off0, off1); styles.AddBefore(node, insert); newSet.start = off1; set.start = off1; node.Value = set; } //公共区域 off0 = off1; off1 = Mathf.Min(set.end, newSet.end); if (off0 < off1) { RichTextStyle insert; if (overrideOldStyle) { insert = set.CopyTo(off0, off1); insert.OverrideSet(newSet); } else { insert = newSet.CopyTo(off0, off1); insert.OverrideSet(set); } node.Value = insert; set.start = off1; newSet.start = off1; } if (newSet.start >= newSet.end) { styles.AddAfter(node, set); break; } else { node = next; } } if (newSet.start < newSet.end) { styles.AddLast(newSet); } }