public void DeleteData(StoryDataBase data) { if (!m_storyDic.Remove(data.id)) { throw new Exception($"没有id为{data.id}的Story"); } }
private void AddStoryItem(StoryDataBase story) { var storyToggle = new ToolbarToggle() { text = story.name, style = { width = 60, height = 60, marginLeft = 5, marginTop = 5, marginRight = 5, marginBottom = 5, unityTextAlign = TextAnchor.MiddleCenter, } }; storyToggle.RegisterValueChangedCallback((e) => { OnStoryToggleValueChange(story, e); }); m_scrollView.Add(storyToggle); if (m_selectedId.Contains(story.id)) { storyToggle.value = true; } }
private void OnStoryToggleValueChange(StoryDataBase storyData, ChangeEvent <bool> e) { if (e.newValue) { AddId(storyData.id); } else { if (!m_selectedId.Remove(storyData.id)) { throw new Exception("有问题"); } } }
/// <summary> /// 根据类型创建一条剧情 /// </summary> /// <param name="type"></param> /// <returns></returns> public StoryDataBase CreateData(Type type) { if (!type.IsSubclassOf(typeof(StoryDataBase))) { throw new Exception($"类型错误, {type.Name}不是StoryDataBase派生类"); } StoryDataBase data = (StoryDataBase)Activator.CreateInstance(type); data.id = Id; while (m_storyDic.ContainsKey(data.id)) { data.id = Id; } AddData(data); return(data); }
public void AddData(StoryDataBase data) { m_storyDic.Add(data.id, data); }