Ejemplo n.º 1
0
        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");
            }
        }
Ejemplo n.º 2
0
        void CreateRoleSwitchButtons()
        {
            roleSwitchButtons.Clear();
            if (m_prefab != null)
            {
                m_prefabPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(m_prefab);
            }
            if (m_mainRole != null && m_prefabPath != null)
            {
                m_prefabPath = m_prefabPath.Substring(0, m_prefabPath.LastIndexOf('/'));
                string[] allPath = AssetDatabase.FindAssets("t:Prefab", new string[] { m_prefabPath });
                for (int i = 0; i < allPath.Length; i++)
                {
                    string path = AssetDatabase.GUIDToAssetPath(allPath[i]);
                    var    obj  = AssetDatabase.LoadAssetAtPath <GameObject>(path);
                    if (obj != null)
                    {
                        if (obj.name == m_prefab.name)
                        {
                            obj = m_prefab;
                        }
                        if (!m_RSS.Contains(obj))
                        {
                            continue;
                        }

                        Button button = Instantiate(roleButtonSource, roleButtonSource.transform.parent);
                        button.name = "  " + obj.name;
                        button.transform.Find("Text").GetComponent <Text>().text = button.name;
                        button.onClick.AddListener(delegate
                        {
                            if (obj.name == m_mainRole.name)
                            {
                                return;
                            }

                            Vector3 pos    = m_mainRole.transform.position;
                            Quaternion rot = m_mainRole.transform.rotation;
                            DestroyImmediate(m_mainRole.gameObject);
                            var go = Instantiate(obj);

                            if (go != null)
                            {
                                var root = go.GetComponent <MonoBehaviourBinderRoot>();
                                if (root != null)
                                {
                                    var binders = root.GetBinders();
                                    if (binders != null)
                                    {
                                        for (int k = 0; k < binders.Length; k++)
                                        {
                                            if (binders[k] != null)
                                            {
                                                DestroyImmediate(binders[k]);
                                            }
                                        }
                                    }
                                    DestroyImmediate(root);
                                }
                                var cache = go.GetComponent <ModelInfoCache>();
                                if (cache != null)
                                {
                                    DestroyImmediate(cache);
                                }
                                var colls = go.GetComponents <Collider>();
                                if (colls != null)
                                {
                                    for (int k = 0; k < colls.Length; k++)
                                    {
                                        colls[k].enabled = false;
                                    }
                                }
                                go.SetActive(true);
                                go.name = go.name.Replace("(Clone)", "");
                                go.transform.position       = pos;
                                go.transform.rotation       = rot;
                                m_mainRole                  = go;
                                m_cameraController.m_target = m_mainRole.transform;
                                m_roleAnim                  = m_mainRole.GetComponent <Animation>();
                                CreateAnimationButtons();
                                bool isFoundSkillID = false;
                                for (int k = 0; k < m_RSS.m_RoleSkill.Count; k++)
                                {
                                    if (m_RSS.m_RoleSkill[k].m_RolePrefab.name == m_mainRole.name)
                                    {
                                        m_PrefabSkillID = m_RSS.m_RoleSkill[k];
                                        isFoundSkillID  = true;
                                        break;
                                    }
                                }
                                if (!isFoundSkillID)
                                {
                                    Debug.LogWarning("There is no this prefab's skill ID list in the Role Prefabs & Skill ID List!\nAssets/Samples/ActionPreviewer/RoleSkillSFXsSo.asset");
                                }
                            }
                        });
                        roleSwitchButtons.Add(button);
                    }
                }
                roleButtonSource.gameObject.SetActive(false);
            }
        }