public override void OnEnable()
        {
            base.OnEnable();

            m_ForceToMono      = serializedObject.FindProperty("m_ForceToMono");
            m_Normalize        = serializedObject.FindProperty("m_Normalize");
            m_PreloadAudioData = serializedObject.FindProperty("m_PreloadAudioData");
            m_Ambisonic        = serializedObject.FindProperty("m_Ambisonic");
            m_LoadInBackground = serializedObject.FindProperty("m_LoadInBackground");
            m_OrigSize         = serializedObject.FindProperty("m_PreviewData.m_OrigSize");
            m_CompSize         = serializedObject.FindProperty("m_PreviewData.m_CompSize");

            m_DefaultSampleSettings = serializedObject.FindProperty("m_DefaultSettings");

            m_SelectionContainsTrackerFile = false;
            foreach (AudioImporter importer in GetAllAudioImporterTargets())
            {
                string assetPath = importer.assetPath;
                string ext       = FileUtil.GetPathExtension(assetPath).ToLowerInvariant();
                if (ext == "mod" || ext == "it" || ext == "s3m" || ext == "xm")
                {
                    m_SelectionContainsTrackerFile = true;
                    break;
                }
            }

            m_DirtyCount = new List <int>(targets.Length);
            for (int i = 0; i < targets.Length; i++)
            {
                m_DirtyCount.Add(EditorUtility.GetDirtyCount(targets[i]));
            }
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            for (int i = 0; i < targets.Length; i++)
            {
                var newCount = EditorUtility.GetDirtyCount(targets[i]);
                if (m_DirtyCount[i] != newCount)
                {
                    InitializeExtraDataInstance(extraDataTargets[i], i);
                }
            }

            extraDataSerializedObject.Update();

            OnAudioImporterGUI(m_SelectionContainsTrackerFile);

            int origSize = 0, compSize = 0;

            foreach (AudioImporter importer in GetAllAudioImporterTargets())
            {
                origSize += importer.origSize;
                compSize += importer.compSize;
            }

            GUILayout.Space(10);

            EditorGUILayout.HelpBox("Original Size: \t" + EditorUtility.FormatBytes(origSize) + "\nImported Size: \t" + EditorUtility.FormatBytes(compSize) + "\n" +
                                    "Ratio: \t\t" + (100.0f * (float)compSize / (float)origSize).ToString("0.00", CultureInfo.InvariantCulture.NumberFormat) + "%", MessageType.Info);

            if (CurrentPlatformHasAutoTranslatedCompression())
            {
                GUILayout.Space(10);
                EditorGUILayout.HelpBox("The selection contains different compression formats to the default settings for the current build platform.", MessageType.Info);
            }

            if (CurrentSelectionContainsHardwareSounds())
            {
                GUILayout.Space(10);
                EditorGUILayout.HelpBox("The selection contains sounds that are decompressed in hardware. Advanced mixing is not available for these sounds.", MessageType.Info);
            }

            extraDataSerializedObject.ApplyModifiedProperties();
            serializedObject.ApplyModifiedProperties();

            ApplyRevertGUI();

            for (int i = 0; i < targets.Length; i++)
            {
                m_DirtyCount[i] = EditorUtility.GetDirtyCount(targets[i]);
            }
        }
예제 #3
0
        public void OnGUI(float width, bool fixedWidth)
        {
            bool isRepaintEvent = Event.current.type == EventType.Repaint;

            // Name of current emitter
            string selectedEmitterName = null;

            if (m_ParticleSystems.Length > 1)
            {
                selectedEmitterName = "Multiple Particle Systems";
            }
            else if (m_ParticleSystems.Length > 0)
            {
                selectedEmitterName = m_ParticleSystems[0].gameObject.name;
            }

            if (fixedWidth)
            {
                EditorGUIUtility.labelWidth = width * 0.4f;
                EditorGUILayout.BeginVertical(GUILayout.Width(width));
            }
            else
            {
                // First make sure labelWidth is at default width, then subtract
                EditorGUIUtility.labelWidth = 0;
                EditorGUIUtility.labelWidth = EditorGUIUtility.labelWidth - 4;

                EditorGUILayout.BeginVertical();
            }

            {
                InitialModuleUI initial = (InitialModuleUI)m_Modules[0];
                for (int i = 0; i < m_Modules.Length; ++i)
                {
                    ModuleUI module = m_Modules[i];
                    if (module == null)
                    {
                        continue;
                    }

                    bool initialModule = (module == m_Modules[0]);

                    // Skip if not visible (except initial module which should always be visible)
                    if (!module.visibleUI && !initialModule)
                    {
                        continue;
                    }

                    // Module header size
                    GUIContent headerLabel = new GUIContent();
                    Rect       moduleHeaderRect;
                    if (initialModule)
                    {
                        moduleHeaderRect = GUILayoutUtility.GetRect(width, 25);
                    }
                    else
                    {
                        moduleHeaderRect = GUILayoutUtility.GetRect(width, 15);
                    }

                    // Module content here to render it below the the header
                    if (module.foldout)
                    {
                        using (new EditorGUI.DisabledScope(!module.enabled))
                        {
                            Rect moduleSize = EditorGUILayout.BeginVertical(ParticleSystemStyles.Get().modulePadding);
                            {
                                moduleSize.y      -= 4; // pull background 'up' behind title to fill rounded corners.
                                moduleSize.height += 4;
                                GUI.Label(moduleSize, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle);
                                module.OnInspectorGUI(initial);
                            }
                            EditorGUILayout.EndVertical();
                        }
                    }

                    // TODO: Get Texture instead of static preview. Render Icon (below titlebar due to rounded corners)
                    if (initialModule)
                    {
                        // Get preview of material or mesh
                        ParticleSystemRenderer renderer = m_ParticleSystems[0].GetComponent <ParticleSystemRenderer>();
                        float iconSize = 21;
                        Rect  iconRect = new Rect(moduleHeaderRect.x + 4, moduleHeaderRect.y + 2, iconSize, iconSize);

                        if (isRepaintEvent && renderer != null)
                        {
                            bool iconRendered = false;

                            if (!multiEdit)
                            {
                                int instanceID = 0;

                                if (renderer.renderMode == ParticleSystemRenderMode.Mesh)
                                {
                                    if (renderer.mesh != null)
                                    {
                                        instanceID = renderer.mesh.GetInstanceID();

                                        // If the asset is dirty we ensure to get a updated one by clearing cache of temporary previews
                                        if (m_CachedMeshInstanceID != instanceID)
                                        {
                                            m_CachedMeshInstanceID = instanceID;
                                            m_CachedMeshDirtyCount = -1;
                                        }
                                        if (EditorUtility.GetDirtyCount(instanceID) != m_CachedMeshDirtyCount)
                                        {
                                            AssetPreview.ClearTemporaryAssetPreviews();
                                            m_CachedMeshDirtyCount = EditorUtility.GetDirtyCount(instanceID);
                                        }
                                    }
                                }
                                else if (renderer.sharedMaterial != null)
                                {
                                    instanceID = renderer.sharedMaterial.GetInstanceID();

                                    // If the asset is dirty we ensure to get a updated one by clearing cache of temporary previews
                                    if (m_CachedMaterialInstanceID != instanceID)
                                    {
                                        m_CachedMaterialInstanceID = instanceID;
                                        m_CachedMaterialDirtyCount = -1;
                                    }
                                    if (EditorUtility.GetDirtyCount(instanceID) != m_CachedMaterialDirtyCount)
                                    {
                                        AssetPreview.ClearTemporaryAssetPreviews();
                                        m_CachedMaterialDirtyCount = EditorUtility.GetDirtyCount(instanceID);
                                    }
                                }

                                if (instanceID != 0)
                                {
                                    Texture2D icon = AssetPreview.GetAssetPreview(instanceID);
                                    if (icon != null)
                                    {
                                        GUI.DrawTexture(iconRect, icon, ScaleMode.StretchToFill, true);
                                        iconRendered = true;
                                    }
                                }
                            }

                            // Fill so we do not see the background when we have no icon (eg multi-edit)
                            if (!iconRendered)
                            {
                                GUI.Label(iconRect, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle);
                            }
                        }

                        // Select gameObject when clicking on icon
                        if (!multiEdit && EditorGUI.DropdownButton(iconRect, GUIContent.none, FocusType.Passive, GUIStyle.none))
                        {
                            // Toggle selected particle system from selection
                            if (EditorGUI.actionKey)
                            {
                                List <int> newSelection = new List <int>();
                                int        instanceID   = m_ParticleSystems[0].gameObject.GetInstanceID();
                                newSelection.AddRange(Selection.instanceIDs);
                                if (!newSelection.Contains(instanceID) || newSelection.Count != 1)
                                {
                                    if (newSelection.Contains(instanceID))
                                    {
                                        newSelection.Remove(instanceID);
                                    }
                                    else
                                    {
                                        newSelection.Add(instanceID);
                                    }
                                }

                                Selection.instanceIDs = newSelection.ToArray();
                            }
                            else
                            {
                                Selection.instanceIDs      = new int[0];
                                Selection.activeInstanceID = m_ParticleSystems[0].gameObject.GetInstanceID();
                            }
                        }
                    }

                    // Button logic for enabledness (see below for UI)
                    Rect checkMarkRect = new Rect(moduleHeaderRect.x + 2, moduleHeaderRect.y + 1, 13, 13);
                    if (!initialModule && GUI.Button(checkMarkRect, GUIContent.none, GUIStyle.none))
                    {
                        module.enabled = !module.enabled;
                    }

                    // Button logic for plus/minus (see below for UI)
                    Rect plusRect         = new Rect(moduleHeaderRect.x + moduleHeaderRect.width - 10, moduleHeaderRect.y + moduleHeaderRect.height - 10, 10, 10);
                    Rect plusRectInteract = new Rect(plusRect.x - 4, plusRect.y - 4, plusRect.width + 4, plusRect.height + 4);
                    Rect infoRect         = new Rect(plusRect.x - 23, plusRect.y - 8, 20, 20);

                    if (initialModule && EditorGUI.DropdownButton(plusRectInteract, s_Texts.addModules, FocusType.Passive, GUIStyle.none))
                    {
                        ShowAddModuleMenu();
                    }

                    // Module header (last to become top most renderered)
                    if (!string.IsNullOrEmpty(selectedEmitterName))
                    {
                        headerLabel.text = initialModule ? selectedEmitterName : module.displayName;
                    }
                    else
                    {
                        headerLabel.text = module.displayName;
                    }
                    headerLabel.tooltip = module.toolTip;

                    bool newToggleState = module.DrawHeader(moduleHeaderRect, headerLabel);

                    if (newToggleState != module.foldout)
                    {
                        switch (Event.current.button)
                        {
                        case 0:
                            bool newFoldoutState = !module.foldout;
                            if (Event.current.control)
                            {
                                foreach (var moduleUi in m_Modules)
                                {
                                    if (moduleUi != null && moduleUi.visibleUI)
                                    {
                                        moduleUi.foldout = newFoldoutState;
                                    }
                                }
                            }
                            else
                            {
                                module.foldout = newFoldoutState;
                            }
                            break;

                        case 1:
                            if (initialModule)
                            {
                                ShowEmitterMenu();
                            }
                            else
                            {
                                ShowModuleMenu(i);
                            }
                            break;
                        }
                    }

                    // Render checkmark on top (logic: see above)
                    if (!initialModule)
                    {
                        EditorGUI.showMixedValue = module.enabledHasMultipleDifferentValues;
                        GUIStyle style = EditorGUI.showMixedValue ? ParticleSystemStyles.Get().toggleMixed : ParticleSystemStyles.Get().toggle;
                        GUI.Toggle(checkMarkRect, module.enabled, GUIContent.none, style);
                        EditorGUI.showMixedValue = false;
                    }

                    // Render plus/minus on top
                    if (isRepaintEvent && initialModule)
                    {
                        GUI.Label(plusRect, GUIContent.none, ParticleSystemStyles.Get().plus);
                    }

                    if (initialModule && !string.IsNullOrEmpty(m_SupportsCullingTextLabel))
                    {
                        var supportsCullingText = new GUIContent("", ParticleSystemStyles.Get().warningIcon, m_SupportsCullingTextLabel);
                        GUI.Label(infoRect, supportsCullingText);
                    }

                    GUILayout.Space(1); // dist to next module
                } // foreach module
                GUILayout.Space(-1);
            }
            EditorGUILayout.EndVertical(); // end fixed moduleWidth

            // Apply the property, handle undo
            ApplyProperties();
        }