예제 #1
0
        private void Awake()
        {
            if (m_instance != null)
            {
                Debug.LogWarning("Another instance of RuntimeEditor exists");
            }
            m_instance = this;

            m_projectManager = Dependencies.ProjectManager;
            if (m_projectManager == null)
            {
                Debug.LogWarning("ProjectManager not found");
            }

            if (m_projectManager != null)
            {
                m_projectManager.IgnoreTypes(
                    typeof(SpriteGizmo),
                    typeof(AudioReverbZoneGizmo),
                    typeof(AudioSourceGizmo),
                    typeof(BoxColliderGizmo),
                    typeof(CapsuleColliderGizmo),
                    typeof(SphereColliderGizmo),
                    typeof(LightGizmo),
                    typeof(DirectionalLightGizmo),
                    typeof(PointLightGizmo),
                    typeof(SpotlightGizmo),
                    typeof(SkinnedMeshRendererGizmo));

                m_projectManager.SceneLoaded  += OnSceneLoaded;
                m_projectManager.SceneCreated += OnSceneCreated;
            }

            RuntimeEditorApplication.IsOpenedChanged       += OnIsOpenedChanged;
            RuntimeEditorApplication.PlaymodeStateChanging += OnPlaymodeStateChanging;

            ExposeToEditor[] editorObjects = ExposeToEditor.FindAll(ExposeToEditorObjectType.Undefined, false).Select(go => go.GetComponent <ExposeToEditor>()).ToArray();
            for (int i = 0; i < editorObjects.Length; ++i)
            {
                editorObjects[i].ObjectType = ExposeToEditorObjectType.EditorMode;
                editorObjects[i].Init();
            }

            ExposeToEditor.Awaked  += OnObjectAwaked;
            ExposeToEditor.Started += OnObjectStarted;
            RuntimeEditorApplication.SceneCameras = SceneCameras;

            PrepareCameras();
            RuntimeEditorApplication.SceneCameras[0].gameObject.SetActive(true);
            for (int i = 1; i < RuntimeEditorApplication.SceneCameras.Length; ++i)
            {
                RuntimeEditorApplication.SceneCameras[i].gameObject.SetActive(false);
            }

            EditorsMap.LoadMap();
        }
        private void Init()
        {
            m_map = Resources.Load <EditorsMapStorage>(EditorsMapStorage.EditorsMapPrefabName);
            EditorsMap.LoadMap();

            Assembly unityAssembly       = typeof(GameObject).Assembly;
            Assembly unityEditorAssembly = typeof(Editor).Assembly;
            Assembly unityUI             = typeof(UnityEngine.UI.Button).Assembly;
            Assembly unityNet            = typeof(UnityEngine.Networking.NetworkBehaviour).Assembly;
            Assembly yetAnotherAssembly  = typeof(NetworkScenePostProcess).Assembly;

            Assembly[] otherAssemblies = AppDomain.CurrentDomain.GetAssemblies().Except(new[] { unityAssembly, unityEditorAssembly, unityUI, unityNet, yetAnotherAssembly }).ToArray();

            m_objectEditorDescriptors = new[] { typeof(GameObject) }
            .Where(t => t.IsPublic && !t.IsGenericType)
            .Select(t => new EditorDescriptor(t, m_map != null && EditorsMap.IsObjectEditorEnabled(t), m_map != null ? EditorsMap.GetObjectEditor(t, true) : null, false)).ToArray();
            m_propertyEditorDescriptors = new[] { typeof(object), typeof(UnityEngine.Object), typeof(bool), typeof(Enum), typeof(List <>), typeof(Array), typeof(string), typeof(int), typeof(float), typeof(Range), typeof(Vector2), typeof(Vector3), typeof(Vector4), typeof(Quaternion), typeof(Color), typeof(Bounds) }
            .Where(t => t.IsPublic)
            .Select(t => new EditorDescriptor(t, m_map != null && EditorsMap.IsPropertyEditorEnabled(t), m_map != null ? EditorsMap.GetPropertyEditor(t, true) : null, true)).ToArray();
            m_stdComponentEditorDescriptors = unityAssembly.GetTypes()
                                              .Where(t => typeof(Component).IsAssignableFrom(t) && t.IsPublic && !t.IsGenericType)
                                              .OrderBy(t => (t == typeof(Component)) ? string.Empty : t.Name)
                                              .Select(t => new EditorDescriptor(t, m_map != null && EditorsMap.IsObjectEditorEnabled(t), m_map != null ? EditorsMap.GetObjectEditor(t, true) : null, false)).ToArray();
            m_scriptEditorDescriptors = otherAssemblies.SelectMany(a => a.GetTypes())
                                        .Where(t => typeof(MonoBehaviour).IsAssignableFrom(t) && t.IsPublic && !t.IsGenericType)
                                        .OrderBy(t => t.FullName)
                                        .Select(t => new EditorDescriptor(t, m_map != null && EditorsMap.IsObjectEditorEnabled(t), m_map != null ? EditorsMap.GetObjectEditor(t, true) : null, false)).ToArray();

            List <Material> materials = new List <Material>();

            string[] assets = AssetDatabase.GetAllAssetPaths();
            foreach (string asset in assets)
            {
                if (!asset.EndsWith(".mat"))
                {
                    continue;
                }
                Material material = AssetDatabase.LoadAssetAtPath <Material>(asset);

                if (material == null ||
                    (material.hideFlags & HideFlags.DontSaveInBuild) != 0 ||
                    material.shader == null ||
                    (material.shader.hideFlags & HideFlags.DontSaveInBuild) != 0)
                {
                    continue;
                }
                materials.Add(material);
            }
            MaterialEditorDescriptor[] defaultDescriptors  = new[] { new MaterialEditorDescriptor(null, m_map != null && m_map.IsDefaultMaterialEditorEnabled, m_map != null ? m_map.DefaultMaterialEditor : null) };
            MaterialEditorDescriptor[] materialDescriptors = materials.Where(m => m.shader != null && !m.shader.name.StartsWith("Hidden/"))
                                                             .Select(m => m.shader).Distinct()
                                                             .OrderBy(s => s.name.StartsWith("Standard") ? string.Empty : s.name)
                                                             .Select(s => new MaterialEditorDescriptor(s, m_map != null && EditorsMap.IsMaterialEditorEnabled(s), m_map != null ? EditorsMap.GetMaterialEditor(s, true) : null)).ToArray();

            m_materialDescriptors = defaultDescriptors.Union(materialDescriptors).ToArray();
        }
        private void Init()
        {
            m_map = Resources.Load <EditorsMapStorage>(EditorsMapStorage.EditorsMapPrefabName);
            if (m_map == null)
            {
                m_map = Resources.Load <EditorsMapStorage>(EditorsMapStorage.EditorsMapTemplateName);
            }

            GameObject editorsMapGo = new GameObject();
            EditorsMap editorsMap   = editorsMapGo.AddComponent <EditorsMap>();

            editorsMap.LoadMap();

            Assembly[] allAssemblies;
            Type[]     types;
            GetUOAssembliesAndTypes(out allAssemblies, out types);

            Assembly[] unityAssemblies = allAssemblies.Where(a => a != null && a.FullName != null && a.FullName.Contains("UnityEngine")).ToArray();
            Assembly[] otherAssemblies = allAssemblies.Where(a => a != null && a.FullName != null && !a.FullName.Contains("UnityEngine")).ToArray();

            m_objectEditorDescriptors = new[] { typeof(GameObject) }
            .Where(t => t.IsPublic && !t.IsGenericType)
            .Select(t => new EditorDescriptor(t, m_map != null && editorsMap.IsObjectEditorEnabled(t), m_map != null ? editorsMap.GetObjectEditor(t, true) : null, false)).ToArray();
            m_propertyEditorDescriptors = new[] { typeof(object), typeof(UnityEngine.Object), typeof(bool), typeof(Enum), typeof(List <>), typeof(Array), typeof(string), typeof(int), typeof(float), typeof(Range), typeof(Vector2), typeof(Vector3), typeof(Vector4), typeof(Quaternion), typeof(Color), typeof(Bounds), typeof(RangeInt), typeof(RangeOptions), typeof(HeaderText), typeof(MethodInfo) }
            .Where(t => t.IsPublic)
            .Select(t => new EditorDescriptor(t, m_map != null && editorsMap.IsPropertyEditorEnabled(t), m_map != null ? editorsMap.GetPropertyEditor(t, true) : null, true)).ToArray();
            m_stdComponentEditorDescriptors = unityAssemblies.SelectMany(a => a.GetTypes())
                                              .Where(t => typeof(Component).IsAssignableFrom(t) && t.IsPublic && !t.IsGenericType)
                                              .OrderBy(t => (t == typeof(Component)) ? string.Empty : t.Name)
                                              .Select(t => new EditorDescriptor(t, m_map != null && editorsMap.IsObjectEditorEnabled(t), m_map != null ? editorsMap.GetObjectEditor(t, true) : null, false)).ToArray();
            m_scriptEditorDescriptors = otherAssemblies.SelectMany(a => a.GetTypes())
                                        .Where(t => typeof(MonoBehaviour).IsAssignableFrom(t) && t.IsPublic && !t.IsGenericType)
                                        .OrderBy(t => t.FullName)
                                        .Select(t => GetScriptEditorDescriptor(t, editorsMap)).ToArray();

            List <Material> materials = new List <Material>();

            string[] assets = AssetDatabase.GetAllAssetPaths();
            foreach (string asset in assets)
            {
                if (!asset.EndsWith(".mat"))
                {
                    continue;
                }
                Material material = AssetDatabase.LoadAssetAtPath <Material>(asset);

                if (material == null ||
                    (material.hideFlags & HideFlags.DontSaveInBuild) != 0 ||
                    material.shader == null ||
                    (material.shader.hideFlags & HideFlags.DontSaveInBuild) != 0)
                {
                    continue;
                }
                materials.Add(material);
            }
            MaterialEditorDescriptor[] defaultDescriptors  = new[] { new MaterialEditorDescriptor(null, m_map != null && m_map.IsDefaultMaterialEditorEnabled, m_map != null ? m_map.DefaultMaterialEditor : null) };
            MaterialEditorDescriptor[] materialDescriptors = materials.Where(m => m.shader != null && !m.shader.name.StartsWith("Hidden/"))
                                                             .Select(m => m.shader).Distinct()
                                                             .OrderBy(s => s.name.StartsWith("Standard") ? string.Empty : s.name)
                                                             .Select(s => new MaterialEditorDescriptor(s, m_map != null && editorsMap.IsMaterialEditorEnabled(s), m_map != null ? editorsMap.GetMaterialEditor(s, true) : null)).ToArray();

            m_materialDescriptors = defaultDescriptors.Union(materialDescriptors).ToArray();

            DestroyImmediate(editorsMapGo);
        }