void InitializeSFX() { ProjectPath.dbLocale = "China"; if (LuaTasker.hasInitialized == false || LuaDatabase.sharedInstance == null) { LuaStartup.ReInitialize(); } Skill.EnsureLoaded(); Skill.CacheAll(); m_RSS = AssetDatabase.LoadAssetAtPath <RoleSkillSFX>("Assets/Samples/ActionPreviewer/RoleSkillSFXsSo.asset"); if (m_RSS != null) { RoleSkillSFXEditor.ReadFromJSON(m_RSS); for (int i = 0; i < m_RSS.m_RoleSkill.Count; i++) { if (m_RSS.m_RoleSkill[i].m_RolePrefab.name == m_mainRole.name) { m_PrefabSkillID = m_RSS.m_RoleSkill[i]; break; } } if (m_PrefabSkillID == null) { Debug.LogWarning("There is no this prefab's skill ID list in the Role Prefabs & Skill ID List!\nAssets/Samples/ActionPreviewer/RoleSkillSFXsSo.asset"); } } else { Debug.LogError("没有找到ScriptableObject文件 Assets/Samples/ActionPreviewer/RoleSkillSFXsSo.asset"); } }
public static void ReadFromJSON(RoleSkillSFX rss) { string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments).Replace("\\", "/") + "/ActionPreviewer/RoleSkillSFXsSo.json"; if (File.Exists(path)) { StreamReader sr = new StreamReader(path); string json = sr.ReadToEnd(); JsonUtility.FromJsonOverwrite(json, rss); sr.Close(); } AssetDatabase.Refresh(); }
private void OnEnable() { m_RSS = target as RoleSkillSFX; ReadFromJSON(m_RSS); m_ReorderableList = new ReorderableList(m_RSS.m_RoleSkill, typeof(RoleSkillSFX.PrefabSkillID)); m_ReorderableList.drawElementCallback = (rect, index, isActive, isFocused) => { var element = m_RSS.m_RoleSkill[index]; float y = rect.yMin + 1f; element.m_RolePrefab = ( GameObject )EditorGUI.ObjectField(new Rect(rect.xMin, y, rect.width, 16f), new GUIContent(element.m_RolePrefab == null ? string.Format("player{0}", index) : element.m_RolePrefab.name, element.m_RolePrefab == null ? "只能添加有Animation组件的预制体" : ""), element.m_RolePrefab, typeof(GameObject), false); y += 16f; if (element.m_RolePrefab != null) { Animation anim = element.m_RolePrefab.GetComponent <Animation>(); if (anim == null) { element.m_RolePrefab = null; } else { if (element.m_InitCount == 0) { foreach (AnimationState state in anim) { element.m_Animations.Add(state.clip); element.m_SkillIDList.Add(0); element.m_InitCount += 1; } } } element.isFoldout = EditorGUI.Foldout(new Rect(rect.xMin, y, rect.width, 16f), element.isFoldout, "Animation SkillID"); if (element.isFoldout) { y += 16f; EditorGUI.BeginChangeCheck(); int count = element.m_Animations != null ? element.m_Animations.Count : 0; count = EditorGUI.DelayedIntField(new Rect(rect.xMin + 16f, y, rect.width - 16f, 16f), "Size", count); if (EditorGUI.EndChangeCheck()) { m_RSS.CheckListCount(element.m_SkillIDList, count, element.m_InitCount); m_RSS.CheckListCount(element.m_Animations, count, element.m_InitCount); } for (int i = 0; i < count; i++) { y += 16f; if (i < element.m_InitCount) { EditorGUI.ObjectField(new Rect(rect.xMin + 16f, y, rect.width - 100f, 16f), string.Format("Element{0}", i), element.m_Animations[i], typeof(AnimationClip), false); } else { element.m_Animations[i] = ( AnimationClip )EditorGUI.ObjectField(new Rect(rect.xMin + 16f, y, rect.width - 100f, 16f), string.Format("Element{0}", i), element.m_Animations[i], typeof(AnimationClip), false); } element.m_SkillIDList[i] = EditorGUI.IntField(new Rect(rect.xMax - 80f, y, 80f, 16f), element.m_SkillIDList[i]); } } } }; m_ReorderableList.drawHeaderCallback = (rect) => { EditorGUI.LabelField(rect, "Role Prefabs & Skill ID List"); }; m_ReorderableList.elementHeightCallback = (index) => { float height = 20f; var element = m_RSS.m_RoleSkill[index]; if (element.m_RolePrefab != null) { height += 16f; if (element.isFoldout) { height += 16f * (element.m_SkillIDList.Count + 1); } } return(height); }; }