Beispiel #1
0
    /// <summary>
    /// Custom Inspector
    /// </summary>
    public override void OnInspectorGUI()
    {
        // Start custom Inspector
        serializedObject.Update();
        EditorGUI.BeginChangeCheck();
        m_target.layerIndex = m_reorderableTilemapLayerList.index;

        if (m_target.toolIndex > 0 && m_target.toolIndex < 5)
        {
            Tools.hidden = true;
        }
        else
        {
            Tools.hidden = false;
        }
        //
        // References
        //
        m_showReferencesGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showReferencesGroup.isExpanded, "References");
        if (m_showReferencesGroup.isExpanded)
        {
            GUILayout.Space(1);
            // Standard diffuse shader
            GUI.color = m_greenColor;
            if (!m_legacyShader.objectReferenceValue)
            {
                GUI.color = m_redColor;
            }
            EditorGUILayout.PropertyField(m_legacyShader, m_guiContent[7]);

            // Universal diffuse shader
            GUI.color = m_greenColor;
            if (!m_universalShader.objectReferenceValue)
            {
                GUI.color = m_redColor;
            }
            EditorGUILayout.PropertyField(m_universalShader, m_guiContent[8]);
            GUI.color = Color.white;
        }
        EditorGUILayout.EndFoldoutHeaderGroup();
        //
        // Settings
        //
        m_showSettingsGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showSettingsGroup.isExpanded, "Settings");
        if (m_showSettingsGroup.isExpanded)
        {
            GUILayout.Space(1);
            // Render pipeline
            EditorGUILayout.PropertyField(m_renderPipeline, m_guiContent[9]);
            if (m_target.renderPipeline == TilemapSystemPipeline.Universal)
            {
                EditorGUILayout.HelpBox("Universal Render Pipeline is still a work in progress and is not fully functional.", MessageType.Info);
            }

            // Tilemap size
            EditorGUILayout.IntPopup(m_tilesetSize, m_tilesetSizeContentArray, m_tilesetSizeArray, m_guiContent[16]);

            // Grid size
            EditorGUILayout.BeginVertical("Box");
            EditorGUILayout.LabelField(m_guiContent[0]);
            m_gridMapSize.x = EditorGUILayout.IntField(m_guiContent[1], (int)m_target.gridMapSize.x);
            m_gridMapSize.y = EditorGUILayout.IntField(m_guiContent[2], (int)m_target.gridMapSize.y);
            EditorGUILayout.EndVertical();

            // Layer list
            m_reorderableTilemapLayerList.DoLayoutList();
        }
        EditorGUILayout.EndFoldoutHeaderGroup();
        //
        // Data
        //
        m_showDataGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showDataGroup.isExpanded, "Data");
        if (m_showDataGroup.isExpanded)
        {
            GUILayout.Space(1);
            if (m_reorderableTilemapLayerList.count > 0)
            {
                EditorGUI.BeginDisabledGroup(true);
                // Tilemap data
                if (!m_tilemapData.objectReferenceValue)
                {
                    GUI.color = m_redColor;
                }
                EditorGUI.ObjectField(EditorGUILayout.GetControlRect(), m_tilemapData, m_guiContent[6]);
                GUI.color = Color.white;
                // Tilemap texture field
                if (!m_target.tilemapTexture)
                {
                    GUI.color = m_redColor;
                }
                EditorGUI.ObjectField(EditorGUILayout.GetControlRect(), m_guiContent[13], m_target.tilemapTexture, typeof(Texture3D), false);
                GUI.color = Color.white;
                // Tileset texture field
                if (!m_target.tilesetTexture)
                {
                    GUI.color = m_redColor;
                }
                EditorGUI.ObjectField(EditorGUILayout.GetControlRect(), m_guiContent[15], m_target.tilesetTexture, typeof(Texture3D), false);
                GUI.color = Color.white;
                // Array texture field
                if (!m_target.layerArrayTexture)
                {
                    GUI.color = m_redColor;
                }
                EditorGUI.ObjectField(EditorGUILayout.GetControlRect(), m_guiContent[17], m_target.layerArrayTexture, typeof(Texture2D), false);
                GUI.color = Color.white;
                // Render material field
                if (!m_target.renderMaterial)
                {
                    GUI.color = m_redColor;
                }
                EditorGUI.ObjectField(EditorGUILayout.GetControlRect(), m_guiContent[14], m_target.renderMaterial, typeof(Material), false);
                GUI.color = Color.white;
                EditorGUI.EndDisabledGroup();

                // Button
                if (GUILayout.Button("Generate Tilemap Data"))
                {
                    m_target.GenerateTilemapData();
                    if (m_target.tilemapData)
                    {
                        TilePalette[] palettes   = new TilePalette[m_target.tilemapLayerList.Count];
                        int[]         tilesCount = new int[m_target.tilemapLayerList.Count];
                        for (int i = 0; i < palettes.Length; i++)
                        {
                            palettes[i] = m_target.tilemapLayerList[i].tilePalette;
                            if (palettes[i])
                            {
                                tilesCount[i] = m_target.tilemapLayerList[i].tilePalette.tilesCount;
                            }
                            else
                            {
                                tilesCount[i] = 0;
                            }
                        }

                        m_target.tilemapData.settingsState  = new TilemapSettings(m_target.tilemapLayerList.Count, tilesCount, palettes, (int)m_gridMapSize.x, (int)m_gridMapSize.y, m_tilesetSize.intValue);
                        m_target.tilemapData.layerIntensity = new float[m_target.tilemapLayerList.Count];
                    }
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no layer created yet! Create a tilemap layer.", MessageType.Error);
            }
        }
        EditorGUILayout.EndFoldoutHeaderGroup();
        //
        // Painting
        //
        m_showPantingGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showPantingGroup.isExpanded, "Painting");
        if (m_showPantingGroup.isExpanded)
        {
            if (m_reorderableTilemapLayerList.count > 0 && m_target.layerIndex >= 0 && m_target.tilemapLayerList.Count > 0)
            {
                if (m_tilemapData.objectReferenceValue)
                {
                    // Tile palette field
                    EditorGUILayout.BeginVertical("Box");
                    m_tilePalette = m_reorderableTilemapLayerList.serializedProperty.GetArrayElementAtIndex(m_target.layerIndex).FindPropertyRelative("tilePalette");
                    GUI.color     = m_greenColor;
                    if (!m_tilePalette.objectReferenceValue)
                    {
                        GUI.color = m_redColor;
                    }
                    EditorGUILayout.PropertyField(m_tilePalette, m_guiContent[5]);
                    GUI.color = Color.white;
                    EditorGUILayout.EndVertical();

                    if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette)
                    {
                        // Painting mode
                        EditorGUILayout.BeginVertical("Box");
                        EditorGUILayout.PropertyField(m_paintingMode, m_guiContent[10]);

                        // Auto tile layout popup
                        if (m_target.paintingMode == TilemapSystemPaintingMode.AutoTiles)
                        {
                            m_autoTileElements = GetAutoTileElements();

                            if (m_autoTileElements.Length > 0)
                            {
                                m_autoTileLayoutIndex          = m_reorderableTilemapLayerList.serializedProperty.GetArrayElementAtIndex(m_target.layerIndex).FindPropertyRelative("layoutIndex");
                                m_autoTileLayoutIndex.intValue = EditorGUILayout.Popup(m_guiContent[17], m_autoTileLayoutIndex.intValue, m_autoTileElements);
                            }
                            else
                            {
                                EditorGUILayout.HelpBox("The Auto Tile list is empty. Please, set some auto tile layout first.", MessageType.Error);
                            }
                        }
                        EditorGUILayout.EndVertical();
                        GUILayout.Space(-3);

                        if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette.tilesCount > 0)
                        {
                            EditorGUILayout.BeginVertical("Box");
                            if (m_target.tilesetTexture)
                            {
                                if (CanPaint())
                                {
                                    // Reset layer button
                                    if (GUILayout.Button("Reset This Layer Using the Selected Tile"))
                                    {
                                        // Register the texture in the undo stack
                                        Undo.RegisterCompleteObjectUndo(m_target.tilemapTexture, "Tilemap Change");
                                        m_target.ResetLayer(m_target.layerIndex);
                                    }

                                    // Toolbar
                                    EditorGUILayout.BeginHorizontal();
                                    m_isPicking = m_target.toolIndex == 1 ? true : false;
                                    if (GUILayout.Toggle(m_isPicking, m_paintingToolIcons[0], EditorStyles.miniButtonLeft))
                                    {
                                        m_target.toolIndex = 1;
                                    }
                                    else if (m_target.toolIndex == 1)
                                    {
                                        m_target.toolIndex = 0;
                                    }

                                    m_isPainting = m_target.toolIndex == 2 ? true : false;
                                    if (GUILayout.Toggle(m_isPainting, m_paintingToolIcons[1], EditorStyles.miniButtonMid))
                                    {
                                        m_target.toolIndex = 2;
                                    }
                                    else if (m_target.toolIndex == 2)
                                    {
                                        m_target.toolIndex = 0;
                                    }

                                    m_isFilling = m_target.toolIndex == 3 ? true : false;
                                    if (GUILayout.Toggle(m_isFilling, m_paintingToolIcons[2], EditorStyles.miniButtonMid))
                                    {
                                        m_target.toolIndex = 3;
                                    }
                                    else if (m_target.toolIndex == 3)
                                    {
                                        m_target.toolIndex = 0;
                                    }

                                    m_isErasing = m_target.toolIndex == 4 ? true : false;
                                    if (GUILayout.Toggle(m_isErasing, m_paintingToolIcons[3], EditorStyles.miniButtonRight))
                                    {
                                        m_target.toolIndex = 4;
                                    }
                                    else if (m_target.toolIndex == 4)
                                    {
                                        m_target.toolIndex = 0;
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }
                                else
                                {
                                    EditorGUILayout.HelpBox("It looks like you have changed some settings. Please, regenerate the Tilemap Data to update the 3D Textures.", MessageType.Error);
                                }
                            }
                            else
                            {
                                EditorGUILayout.HelpBox("There is no Tileset Texture yet. Please, regenerate the Tilemap Data again to create the 3D Tileset texture so you can start painting.", MessageType.Error);
                            }

                            // Tile grid
                            m_scrollPos = EditorGUILayout.BeginScrollView(m_scrollPos);
                            EditorGUILayout.LabelField("", GUILayout.Width(442));
                            GUILayout.Space(-20);
                            m_buttonIndex = 0;

                            // Start the selectable loop
                            for (int vertical = 0; vertical < 256;)
                            {
                                m_controlRect = EditorGUILayout.GetControlRect(GUILayout.Width(24), GUILayout.Height(24));

                                EditorGUILayout.BeginHorizontal();
                                for (int horizontal = 0; horizontal < 16; horizontal++)
                                {
                                    // Get the tile texture
                                    m_tileTexture = m_target.tilemapLayerList[m_target.layerIndex].tilePalette.temporaryTileTextureArray[vertical] ? m_target.tilemapLayerList[m_target.layerIndex].tilePalette.temporaryTileTextureArray[vertical] : emptyIconTexture;

                                    // Draw the selectable button
                                    m_isSelected = m_target.tileIndex == m_buttonIndex ? true : false;
                                    if (GUI.Toggle(m_controlRect, m_isSelected, GUIContent.none, GUI.skin.button))
                                    {
                                        m_target.tileIndex = m_buttonIndex;
                                    }

                                    // Draw the tile texture
                                    if (m_isSelected)
                                    {
                                        GUI.color = m_selectedTileColor;
                                    }
                                    GUI.DrawTexture(m_controlRect, m_tileTexture, ScaleMode.StretchToFill, true, 0);
                                    GUI.color = Color.white;

                                    m_controlRect.x += 28;
                                    vertical++;
                                    m_buttonIndex++;
                                }

                                EditorGUILayout.EndHorizontal();
                            }

                            EditorGUILayout.EndScrollView();
                            EditorGUILayout.EndVertical();
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("The Tile Palette used in this layer is empty. Please, add the tiles to the Tile Palette first.", MessageType.Error);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("The tile palette of this layer is missing! Add a Tile Palette to start painting.", MessageType.Error);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("There is no tilemap data created yet! Generate the Tilemap Data.", MessageType.Error);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no layer created yet! Create a tilemap layer.", MessageType.Error);
            }
        }
        EditorGUILayout.EndFoldoutHeaderGroup();
        //
        // Auto tiles
        //
        m_showAutoTileGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showAutoTileGroup.isExpanded, "Auto Tiles");
        if (m_showAutoTileGroup.isExpanded)
        {
            if (m_reorderableTilemapLayerList.count > 0 && m_target.layerIndex >= 0 && m_target.tilemapLayerList.Count > 0)
            {
                if (m_tilemapData.objectReferenceValue)
                {
                    if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette)
                    {
                        if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette.tilesCount > 0)
                        {
                            // Editor stuff here
                            GUILayout.Space(3);
                            m_autoTileDictionary[m_target.layerIndex].DoLayoutList();
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("The Tile Palette used in this layer is empty. Please, add the tiles to the Tile Palette first.", MessageType.Error);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("The tile palette of this layer is missing! Add a Tile Palette to start painting.", MessageType.Error);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("There is no tilemap data created yet! Generate the Tilemap Data.", MessageType.Error);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no layer created yet! Create a tilemap layer.", MessageType.Error);
            }
        }
        EditorGUILayout.EndFoldoutHeaderGroup();
        //
        // Random tile painting
        //
        EditorGUI.BeginDisabledGroup(true);
        m_showRandomTilePaintingGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showRandomTilePaintingGroup.isExpanded, "Random Tile Painting");
        if (m_showRandomTilePaintingGroup.isExpanded)
        {
            if (m_reorderableTilemapLayerList.count > 0 && m_target.layerIndex >= 0 && m_target.tilemapLayerList.Count > 0)
            {
                if (m_tilemapData.objectReferenceValue)
                {
                    if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette)
                    {
                        if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette.tilesCount > 0)
                        {
                            // Editor stuff here
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("The Tile Palette used in this layer is empty. Please, add the tiles to the Tile Palette first.", MessageType.Error);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("The tile palette of this layer is missing! Add a Tile Palette to start painting.", MessageType.Error);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("There is no tilemap data created yet! Generate the Tilemap Data.", MessageType.Error);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no layer created yet! Create a tilemap layer.", MessageType.Error);
            }
        }
        EditorGUILayout.EndFoldoutHeaderGroup();

        // Random tiles
        m_showRandomizeTileGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showRandomizeTileGroup.isExpanded, "Randomize Tiles");
        if (m_showRandomizeTileGroup.isExpanded)
        {
            if (m_reorderableTilemapLayerList.count > 0 && m_target.layerIndex >= 0 && m_target.tilemapLayerList.Count > 0)
            {
                if (m_tilemapData.objectReferenceValue)
                {
                    if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette)
                    {
                        if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette.tilesCount > 0)
                        {
                            // Editor stuff here
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("The Tile Palette used in this layer is empty. Please, add the tiles to the Tile Palette first.", MessageType.Error);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("The tile palette of this layer is missing! Add a Tile Palette to start painting.", MessageType.Error);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("There is no tilemap data created yet! Generate the Tilemap Data.", MessageType.Error);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no layer created yet! Create a tilemap layer.", MessageType.Error);
            }
        }
        EditorGUILayout.EndFoldoutHeaderGroup();

        // Tile brushes
        m_showTileBrushesGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showTileBrushesGroup.isExpanded, "Tile Brushes");
        if (m_showTileBrushesGroup.isExpanded)
        {
            if (m_reorderableTilemapLayerList.count > 0 && m_target.layerIndex >= 0 && m_target.tilemapLayerList.Count > 0)
            {
                if (m_tilemapData.objectReferenceValue)
                {
                    if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette)
                    {
                        if (m_target.tilemapLayerList[m_target.layerIndex].tilePalette.tilesCount > 0)
                        {
                            // Editor stuff here
                        }
                        else
                        {
                            EditorGUILayout.HelpBox("The Tile Palette used in this layer is empty. Please, add the tiles to the Tile Palette first.", MessageType.Error);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("The tile palette of this layer is missing! Add a Tile Palette to start painting.", MessageType.Error);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("There is no tilemap data created yet! Generate the Tilemap Data.", MessageType.Error);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("There is no layer created yet! Create a tilemap layer.", MessageType.Error);
            }
        }
        EditorGUILayout.EndFoldoutHeaderGroup();
        EditorGUI.EndDisabledGroup();

        // About group
        m_showAboutGroup.isExpanded = EditorGUILayout.BeginFoldoutHeaderGroup(m_showAboutGroup.isExpanded, "About");
        if (m_showAboutGroup.isExpanded)
        {
            EditorGUILayout.HelpBox("3D Tilemap System v1.0.0 by Seven Stars Games", MessageType.None);
            if (GUILayout.Button(m_guiContent[18]))
            {
                Application.OpenURL("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=S8AB7CVH5VMZS&source=url");
            }
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("My other assets you may like:");
            if (GUILayout.Button(m_guiContent[19]))
            {
                Application.OpenURL("https://assetstore.unity.com/packages/tools/particles-effects/azure-sky-dynamic-skybox-36050");
            }
            if (GUILayout.Button(m_guiContent[20]))
            {
                Application.OpenURL("https://assetstore.unity.com/packages/vfx/shaders/azure-sky-lite-89858");
            }
        }

        // Update layer intensity when there is a change in the Inspector
        if (m_target.tilemapData)
        {
            if (NeedUpdateLayerIntensity())
            {
                m_target.UpdateLayerSettings();
                m_target.tilemapData.layerIntensity = new float[m_target.tilemapLayerList.Count];
                for (int i = 0; i < m_target.tilemapLayerList.Count; i++)
                {
                    m_target.tilemapData.layerIntensity[i] = m_target.tilemapLayerList[i].intensity;
                }
            }
        }

        // End custom Inspector
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(m_target, "3D Tilemap System");
            serializedObject.ApplyModifiedProperties();
            m_target.gridMapSize = m_gridMapSize;
            m_target.UpdateMaterialSettings();
        }
    }
        void DrawMaterialEditor()
        {
            // Upgrade
            int numAltMaterials = 0;

            foreach (var v in SpriteCollection.altMaterials)
            {
                if (v != null)
                {
                    numAltMaterials++;
                }
            }

            if ((SpriteCollection.altMaterials.Length == 0 || numAltMaterials == 0) && SpriteCollection.atlasMaterials.Length != 0)
            {
                SpriteCollection.altMaterials = new Material[1] {
                    SpriteCollection.atlasMaterials[0]
                }
            }
            ;

            if (SpriteCollection.altMaterials.Length > 0)
            {
                GUILayout.BeginHorizontal();
                DrawHeaderLabel("Materials");
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("+", EditorStyles.miniButton))
                {
                    int sourceIndex = -1;
                    int i;
                    for (i = 0; i < SpriteCollection.altMaterials.Length; ++i)
                    {
                        if (SpriteCollection.altMaterials[i] != null)
                        {
                            sourceIndex = i;
                            break;
                        }
                    }
                    for (i = 0; i < SpriteCollection.altMaterials.Length; ++i)
                    {
                        if (SpriteCollection.altMaterials[i] == null)
                        {
                            break;
                        }
                    }
                    if (i == SpriteCollection.altMaterials.Length)
                    {
                        System.Array.Resize(ref SpriteCollection.altMaterials, SpriteCollection.altMaterials.Length + 1);
                    }

                    Material mtl = null;
                    if (sourceIndex == -1)
                    {
                        Debug.LogError("Sprite collection has null materials. Fix this in the debug inspector.");
                    }
                    else
                    {
                        mtl = DuplicateMaterial(SpriteCollection.altMaterials[sourceIndex]);
                    }

                    SpriteCollection.altMaterials[i] = mtl;
                    SpriteCollection.Trim();

                    if (SpriteCollection.platforms.Count > 1)
                    {
                        SpriteCollection.platforms[0].spriteCollection.altMaterials = SpriteCollection.altMaterials;
                        EditorUtility.SetDirty(SpriteCollection.platforms[0].spriteCollection);

                        for (int j = 1; j < SpriteCollection.platforms.Count; ++j)
                        {
                            if (!SpriteCollection.platforms[j].Valid)
                            {
                                continue;
                            }
                            tk2dSpriteCollection data = SpriteCollection.platforms[j].spriteCollection;
                            System.Array.Resize(ref data.altMaterials, SpriteCollection.altMaterials.Length);
                            data.altMaterials[i] = DuplicateMaterial(data.altMaterials[sourceIndex]);
                            EditorUtility.SetDirty(data);
                        }
                    }

                    host.Commit();
                }
                GUILayout.EndHorizontal();

                if (SpriteCollection.altMaterials != null)
                {
                    EditorGUI.indentLevel++;

                    for (int i = 0; i < SpriteCollection.altMaterials.Length; ++i)
                    {
                        if (SpriteCollection.altMaterials[i] == null)
                        {
                            continue;
                        }

                        bool deleteMaterial = false;

                        Material newMaterial = EditorGUILayout.ObjectField(SpriteCollection.altMaterials[i], typeof(Material), false) as Material;
                        if (newMaterial == null)
                        {
                            // Can't delete the last one
                            if (numAltMaterials > 1)
                            {
                                bool inUse = false;
                                foreach (var v in SpriteCollection.textureParams)
                                {
                                    if (v.materialId == i)
                                    {
                                        inUse = true;
                                        break;
                                    }
                                }
                                foreach (var v in SpriteCollection.fonts)
                                {
                                    if (v.materialId == i)
                                    {
                                        inUse = true;
                                        break;
                                    }
                                }

                                if (inUse)
                                {
                                    if (EditorUtility.DisplayDialog("Delete material",
                                                                    "This material is in use. Deleting it will reset materials on " +
                                                                    "sprites that use this material.\n" +
                                                                    "Do you wish to proceed?", "Yes", "Cancel"))
                                    {
                                        deleteMaterial = true;
                                    }
                                }
                                else
                                {
                                    deleteMaterial = true;
                                }
                            }
                        }
                        else
                        {
                            SpriteCollection.altMaterials[i] = newMaterial;
                        }

                        if (deleteMaterial)
                        {
                            SpriteCollection.altMaterials[i] = null;

                            // fix up all existing materials
                            int targetMaterialId;
                            for (targetMaterialId = 0; targetMaterialId < SpriteCollection.altMaterials.Length; ++targetMaterialId)
                            {
                                if (SpriteCollection.altMaterials[targetMaterialId] != null)
                                {
                                    break;
                                }
                            }
                            foreach (var sprite in SpriteCollection.textureParams)
                            {
                                if (sprite.materialId == i)
                                {
                                    sprite.materialId = targetMaterialId;
                                }
                            }
                            foreach (var font in SpriteCollection.fonts)
                            {
                                if (font.materialId == i)
                                {
                                    font.materialId = targetMaterialId;
                                }
                            }
                            SpriteCollection.Trim();

                            // Do the same on inherited sprite collections
                            for (int j = 0; j < SpriteCollection.platforms.Count; ++j)
                            {
                                if (!SpriteCollection.platforms[j].Valid)
                                {
                                    continue;
                                }
                                tk2dSpriteCollection data = SpriteCollection.platforms[j].spriteCollection;
                                data.altMaterials[i] = null;

                                for (int lastIndex = data.altMaterials.Length - 1; lastIndex >= 0; --lastIndex)
                                {
                                    if (data.altMaterials[lastIndex] != null)
                                    {
                                        int count = data.altMaterials.Length - 1 - lastIndex;
                                        if (count > 0)
                                        {
                                            System.Array.Resize(ref data.altMaterials, lastIndex + 1);
                                        }
                                        break;
                                    }
                                }

                                EditorUtility.SetDirty(data);
                            }

                            host.Commit();
                        }
                    }

                    EditorGUI.indentLevel--;
                }
            }
        }

        void DrawHeaderLabel(string name)
        {
            GUILayout.Label(name, EditorStyles.boldLabel);
        }

        void BeginHeader(string name)
        {
            DrawHeaderLabel(name);
            GUILayout.Space(2);
            EditorGUI.indentLevel++;
        }

        void EndHeader()
        {
            EditorGUI.indentLevel--;
            GUILayout.Space(8);
        }

        void DrawSystemSettings()
        {
            BeginHeader("System");

            // Loadable
            bool allowSwitch = SpriteCollection.spriteCollection != null;
            bool loadable    = SpriteCollection.spriteCollection?SpriteCollection.loadable:false;
            bool newLoadable = EditorGUILayout.Toggle("Loadable asset", loadable);

            if (newLoadable != loadable)
            {
                if (!allowSwitch)
                {
                    EditorUtility.DisplayDialog("Please commit the sprite collection before attempting to make it loadable.", "Make loadable.", "Ok");
                }
                else
                {
                    if (newLoadable)
                    {
                        if (SpriteCollection.assetName.Length == 0)
                        {
                            SpriteCollection.assetName = SpriteCollection.spriteCollection.spriteCollectionName;                             // guess something
                        }
                        tk2dSystemUtility.MakeLoadableAsset(SpriteCollection.spriteCollection, SpriteCollection.assetName);
                    }
                    else
                    {
                        if (tk2dSystemUtility.IsLoadableAsset(SpriteCollection.spriteCollection))
                        {
                            tk2dSystemUtility.UnmakeLoadableAsset(SpriteCollection.spriteCollection);
                        }
                    }
                    loadable = newLoadable;
                    SpriteCollection.loadable = loadable;
                }
            }
            if (loadable)
            {
                SpriteCollection.assetName = EditorGUILayout.TextField("Asset Name/Path", SpriteCollection.assetName);
            }

            // Clear data
            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("References");
            if (GUILayout.Button("Clear References", EditorStyles.miniButton))
            {
                if (EditorUtility.DisplayDialog("Clear references",
                                                "Clearing references will clear references to data (atlases, materials) owned by this sprite collection. " +
                                                "This will only remove references, and will not delete the data or textures. " +
                                                "Use after duplicating a sprite collection to sever links with the original.\n\n" +
                                                "Are you sure you want to do this?"
                                                , "Yes", "No"))
                {
                    SpriteCollection.ClearReferences();

                    foreach (tk2dSpriteCollectionPlatform plat in SpriteCollection.platforms)
                    {
                        plat.spriteCollection = null;
                    }
                }
            }
            GUILayout.EndHorizontal();

            EndHeader();
        }

        string linkedCollectionName = "";

        void DrawLinked()
        {
            BeginHeader("Linked Collections");

            if (!SpriteCollection.disableTrimming)
            {
                EditorGUILayout.HelpBox("Linked collections are only supported when trimming is disabled.", SpriteCollection.linkedSpriteCollections.Count == 0 ? MessageType.Info : MessageType.Error);
                return;
            }

            GUILayout.BeginHorizontal();
            linkedCollectionName = EditorGUILayout.TextField(linkedCollectionName, GUILayout.ExpandWidth(true));
            GUI.enabled          = linkedCollectionName.Trim().Length > 0;
            if (GUILayout.Button("Add"))
            {
                bool allowAdd = true;
                foreach (var v in SpriteCollection.linkedSpriteCollections)
                {
                    if (v.name == linkedCollectionName)
                    {
                        allowAdd = false;
                        break;
                    }
                }
                if (!allowAdd)
                {
                    EditorUtility.DisplayDialog("Add Linked Collection", "Unable to add linked collection", "Ok");
                }
                else
                {
                    tk2dLinkedSpriteCollection s = new tk2dLinkedSpriteCollection();
                    s.name = linkedCollectionName;
                    linkedCollectionName = "";
                    SpriteCollection.linkedSpriteCollections.Add(s);
                }
            }
            GUI.enabled = true;
            GUILayout.EndHorizontal();

            int toDelete = -1;

            for (int i = 0; i < SpriteCollection.linkedSpriteCollections.Count; ++i)
            {
                tk2dLinkedSpriteCollection lsc = SpriteCollection.linkedSpriteCollections[i];
                GUILayout.BeginHorizontal();
                GUILayout.Label(lsc.name);
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("X", EditorStyles.miniButton))
                {
                    toDelete = i;
                }
                GUILayout.EndHorizontal();
            }

            if (toDelete != -1)
            {
                SpriteCollection.linkedSpriteCollections.RemoveAt(toDelete);
            }
        }

        void DrawPlatforms()
        {
            // Asset Platform
            BeginHeader("Platforms");
            tk2dSystem system = tk2dSystem.inst_NoCreate;

            if (system == null && GUILayout.Button("Add Platform Support"))
            {
                system = tk2dSystem.inst;                 // force creation
            }
            if (system)
            {
                int toDelete = -1;
                for (int i = 0; i < SpriteCollection.platforms.Count; ++i)
                {
                    tk2dSpriteCollectionPlatform currentPlatform = SpriteCollection.platforms[i];

                    GUILayout.BeginHorizontal();
                    string label = (i == 0)?"Current platform":"Platform";
                    currentPlatform.name = tk2dGuiUtility.PlatformPopup(system, label, currentPlatform.name);
                    bool displayDelete = ((SpriteCollection.platforms.Count == 1 && SpriteCollection.platforms[0].name.Length > 0) ||
                                          (SpriteCollection.platforms.Count > 1 && i > 0));
                    if (displayDelete && GUILayout.Button("Delete", EditorStyles.miniButton, GUILayout.MaxWidth(50)))
                    {
                        toDelete = i;
                    }
                    GUILayout.EndHorizontal();
                }

                if (toDelete != -1)
                {
                    tk2dSpriteCollection deletedSpriteCollection = null;
                    if (SpriteCollection.platforms.Count == 1)
                    {
                        if (SpriteCollection.platforms[0].spriteCollection != null && SpriteCollection.platforms[0].spriteCollection.spriteCollection != null)
                        {
                            deletedSpriteCollection = SpriteCollection.platforms[0].spriteCollection;
                        }
                        SpriteCollection.platforms[0].name             = "";
                        SpriteCollection.platforms[0].spriteCollection = null;
                    }
                    else
                    {
                        if (SpriteCollection.platforms[toDelete].spriteCollection != null && SpriteCollection.platforms[toDelete].spriteCollection.spriteCollection != null)
                        {
                            deletedSpriteCollection = SpriteCollection.platforms[toDelete].spriteCollection;
                        }
                        SpriteCollection.platforms.RemoveAt(toDelete);
                    }
                    if (deletedSpriteCollection != null)
                    {
                        foreach (tk2dSpriteCollectionFont f in deletedSpriteCollection.fonts)
                        {
                            tk2dSystemUtility.UnmakeLoadableAsset(f.data);
                        }
                        tk2dSystemUtility.UnmakeLoadableAsset(deletedSpriteCollection.spriteCollection);
                    }
                }

                if (SpriteCollection.platforms.Count > 1 ||
                    (SpriteCollection.platforms.Count == 1 && SpriteCollection.platforms[0].name.Length > 0))
                {
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel(" ");
                    if (GUILayout.Button("Add new platform", EditorStyles.miniButton))
                    {
                        SpriteCollection.platforms.Add(new tk2dSpriteCollectionPlatform());
                    }
                    GUILayout.EndHorizontal();
                }
            }

            EndHeader();
        }

        void DrawTextureSettings()
        {
            BeginHeader("Texture Settings");

            SpriteCollection.atlasFormat = (tk2dSpriteCollection.AtlasFormat)EditorGUILayout.EnumPopup("Atlas Format", SpriteCollection.atlasFormat);
            if (SpriteCollection.atlasFormat == tk2dSpriteCollection.AtlasFormat.UnityTexture)
            {
                SpriteCollection.filterMode                 = (FilterMode)EditorGUILayout.EnumPopup("Filter Mode", SpriteCollection.filterMode);
                SpriteCollection.textureCompression         = (tk2dSpriteCollection.TextureCompression)EditorGUILayout.EnumPopup("Compression", SpriteCollection.textureCompression);
                SpriteCollection.userDefinedTextureSettings = EditorGUILayout.Toggle("User Defined", SpriteCollection.userDefinedTextureSettings);
                if (SpriteCollection.userDefinedTextureSettings)
                {
                    GUI.enabled = false;
                }
                EditorGUI.indentLevel++;
                SpriteCollection.wrapMode      = (TextureWrapMode)EditorGUILayout.EnumPopup("Wrap Mode", SpriteCollection.wrapMode);
                SpriteCollection.anisoLevel    = (int)EditorGUILayout.IntSlider("Aniso Level", SpriteCollection.anisoLevel, 0, 9);
                SpriteCollection.mipmapEnabled = EditorGUILayout.Toggle("Mip Maps", SpriteCollection.mipmapEnabled);
                EditorGUI.indentLevel--;
                GUI.enabled = true;
            }
            else if (SpriteCollection.atlasFormat == tk2dSpriteCollection.AtlasFormat.Png)
            {
                tk2dGuiUtility.InfoBox("Png atlases will decrease on disk game asset sizes, at the expense of increased load times.",
                                       tk2dGuiUtility.WarningLevel.Warning);
                SpriteCollection.textureCompression = (tk2dSpriteCollection.TextureCompression)EditorGUILayout.EnumPopup("Compression", SpriteCollection.textureCompression);
                SpriteCollection.filterMode         = (FilterMode)EditorGUILayout.EnumPopup("Filter Mode", SpriteCollection.filterMode);
                SpriteCollection.mipmapEnabled      = EditorGUILayout.Toggle("Mip Maps", SpriteCollection.mipmapEnabled);
            }

            int curRescaleSelection = 0;

            if (SpriteCollection.globalTextureRescale > 0.4 && SpriteCollection.globalTextureRescale < 0.6)
            {
                curRescaleSelection = 1;
            }
            if (SpriteCollection.globalTextureRescale > 0.2 && SpriteCollection.globalTextureRescale < 0.3)
            {
                curRescaleSelection = 2;
            }
            int newRescaleSelection = EditorGUILayout.Popup("Rescale", curRescaleSelection, new string[] { "1", "0.5", "0.25" });

            switch (newRescaleSelection)
            {
            case 0: SpriteCollection.globalTextureRescale = 1.0f; break;

            case 1: SpriteCollection.globalTextureRescale = 0.5f; break;

            case 2: SpriteCollection.globalTextureRescale = 0.25f; break;
            }

            EndHeader();
        }

        void DrawSpriteCollectionSettings()
        {
            BeginHeader("Sprite Collection Settings");

            tk2dGuiUtility.SpriteCollectionSize(SpriteCollection.sizeDef);

            GUILayout.Space(4);

            SpriteCollection.padAmount = EditorGUILayout.IntPopup("Pad Amount", SpriteCollection.padAmount, padAmountLabels, padAmountValues);
            if (SpriteCollection.padAmount == 0 && SpriteCollection.filterMode != FilterMode.Point)
            {
                tk2dGuiUtility.InfoBox("Filter mode is not set to Point." +
                                       " Some bleeding will occur at sprite edges.",
                                       tk2dGuiUtility.WarningLevel.Info);
            }

            SpriteCollection.premultipliedAlpha = EditorGUILayout.Toggle("Premultiplied Alpha", SpriteCollection.premultipliedAlpha);
            SpriteCollection.disableTrimming    = EditorGUILayout.Toggle("Disable Trimming", SpriteCollection.disableTrimming);
            GUIContent gc = new GUIContent("Disable rotation", "Disable rotation of sprites in atlas. Use this if you need consistent UV direction for shader special effects.");

            SpriteCollection.disableRotation      = EditorGUILayout.Toggle(gc, SpriteCollection.disableRotation);
            SpriteCollection.normalGenerationMode = (tk2dSpriteCollection.NormalGenerationMode)EditorGUILayout.EnumPopup("Normal Generation", SpriteCollection.normalGenerationMode);

            EndHeader();
        }

        void DrawPhysicsSettings()
        {
            BeginHeader("Physics Settings");

#if (UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
            GUI.enabled = false;
            SpriteCollection.physicsEngine = tk2dSpriteDefinition.PhysicsEngine.Physics3D;
#endif
            SpriteCollection.physicsEngine = (tk2dSpriteDefinition.PhysicsEngine)EditorGUILayout.EnumPopup("Physics Engine", SpriteCollection.physicsEngine);
#if (UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
            GUI.enabled = false;
#endif
            GUI.enabled = SpriteCollection.physicsEngine == tk2dSpriteDefinition.PhysicsEngine.Physics3D;
            SpriteCollection.physicsDepth = EditorGUILayout.FloatField("Collider depth", SpriteCollection.physicsDepth);
            GUI.enabled = true;

            EndHeader();
        }

        void DrawAtlasSettings()
        {
            BeginHeader("Atlas Settings");

#if (UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9)
            int[] allowedAtlasSizes = { 64, 128, 256, 512, 1024, 2048, 4096 };
#else
            int[] allowedAtlasSizes = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
#endif
            string[] allowedAtlasSizesString = new string[allowedAtlasSizes.Length];
            for (int i = 0; i < allowedAtlasSizes.Length; ++i)
            {
                allowedAtlasSizesString[i] = allowedAtlasSizes[i].ToString();
            }

            SpriteCollection.forceTextureSize = EditorGUILayout.Toggle("Force Atlas Size", SpriteCollection.forceTextureSize);
            EditorGUI.indentLevel++;
            if (SpriteCollection.forceTextureSize)
            {
                SpriteCollection.forcedTextureWidth  = EditorGUILayout.IntPopup("Width", SpriteCollection.forcedTextureWidth, allowedAtlasSizesString, allowedAtlasSizes);
                SpriteCollection.forcedTextureHeight = EditorGUILayout.IntPopup("Height", SpriteCollection.forcedTextureHeight, allowedAtlasSizesString, allowedAtlasSizes);
            }
            else
            {
                SpriteCollection.maxTextureSize   = EditorGUILayout.IntPopup("Max Size", SpriteCollection.maxTextureSize, allowedAtlasSizesString, allowedAtlasSizes);
                SpriteCollection.forceSquareAtlas = EditorGUILayout.Toggle("Force Square", SpriteCollection.forceSquareAtlas);
            }
            EditorGUI.indentLevel--;

            bool allowMultipleAtlases = EditorGUILayout.Toggle("Multiple Atlases", SpriteCollection.allowMultipleAtlases);
            if (allowMultipleAtlases != SpriteCollection.allowMultipleAtlases)
            {
                // Disallow switching if using unsupported features
                if (allowMultipleAtlases == true)
                {
                    bool hasDicing = false;
                    for (int i = 0; i < SpriteCollection.textureParams.Count; ++i)
                    {
                        if (SpriteCollection.textureParams[i].texture != null &
                            SpriteCollection.textureParams[i].dice)
                        {
                            hasDicing = true;
                            break;
                        }
                    }

                    if (SpriteCollection.fonts.Count > 0 || hasDicing)
                    {
                        EditorUtility.DisplayDialog("Multiple atlases",
                                                    "Multiple atlases not allowed. This sprite collection contains fonts and/or " +
                                                    "contains diced sprites.", "Ok");
                        allowMultipleAtlases = false;
                    }
                }

                SpriteCollection.allowMultipleAtlases = allowMultipleAtlases;
            }

            if (SpriteCollection.allowMultipleAtlases)
            {
                tk2dGuiUtility.InfoBox("Sprite collections with multiple atlas spanning enabled cannot be used with the Static Sprite" +
                                       " Batcher, Fonts, the TileMap Editor and doesn't support Sprite Dicing and material level optimizations.\n\n" +
                                       "Avoid using it unless you are simply importing a" +
                                       " large sequence of sprites for an animation.", tk2dGuiUtility.WarningLevel.Info);
            }

            if (SpriteCollection.allowMultipleAtlases)
            {
                EditorGUILayout.LabelField("Num Atlases", SpriteCollection.atlasTextures.Length.ToString());
            }
            else
            {
                EditorGUILayout.LabelField("Atlas Width", SpriteCollection.atlasWidth.ToString());
                EditorGUILayout.LabelField("Atlas Height", SpriteCollection.atlasHeight.ToString());
                EditorGUILayout.LabelField("Atlas Wastage", SpriteCollection.atlasWastage.ToString("0.00") + "%");
            }

            if (SpriteCollection.atlasFormat == tk2dSpriteCollection.AtlasFormat.Png)
            {
                int totalAtlasSize = 0;
                foreach (TextAsset ta in SpriteCollection.atlasTextureFiles)
                {
                    if (ta != null)
                    {
                        totalAtlasSize += ta.bytes.Length;
                    }
                }
                EditorGUILayout.LabelField("Atlas File Size", EditorUtility.FormatBytes(totalAtlasSize));
            }

            GUIContent remDuplicates = new GUIContent("Remove Duplicates", "Remove duplicate textures after trimming and other processing.");
            SpriteCollection.removeDuplicates = EditorGUILayout.Toggle(remDuplicates, SpriteCollection.removeDuplicates);

            EndHeader();
        }
Beispiel #3
0
        /// <summary>
        /// Display the texture section.
        /// </summary>
        private void DisplayTextureSettingsSection()
        {
            _showTextureSettings = EditorGUILayout.Foldout(_showTextureSettings, "Texture Atlas Settings:");
            if (_showTextureSettings)
            {
                if (_superCombiner._combiningState == SuperCombiner.CombineStatesList.Uncombined)
                {
                    GUI.enabled = true;
                }
                else
                {
                    GUI.enabled = false;
                }

                //GUILayout.Label ("Texture Atlas", EditorStyles.boldLabel);
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                GUILayout.Label("The first _material found in all game objects to combine will be used as a reference for the combined _material.", EditorStyles.wordWrappedMiniLabel);

                // Atlas Texture Size choice
                _superCombiner._textureAtlasSize = EditorGUILayout.IntPopup("Texture Atlas size", _superCombiner._textureAtlasSize, _TextureAtlasSizesNames.ToArray(), _TextureAtlasSizes.ToArray(), GUILayout.ExpandWidth(true));

                _showAdditionalParameters = EditorGUILayout.Foldout(_showAdditionalParameters, "Additional parameters");
                if (_showAdditionalParameters)
                {
                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);

                    // Multi materials group
                    DisplayMultiMaterialSettingsSection();

                    // Custom Shader propertues
                    EditorGUILayout.PropertyField(_customShaderProperties, new GUIContent("Custom shader properties", "Super Combiner uses the list of texture properties from standard shader. If you are using custom shader with different texture properties, add their exact name in the list."), true);

                    // Tiling factor
                    _superCombiner._tilingFactor = EditorGUILayout.Slider(new GUIContent("tiling factor", "Apply a tiling factor on the textures. This may be helpfull if you observe strange artifacts after combining materials with heightmap"), _superCombiner._tilingFactor, 1, 2, GUILayout.ExpandWidth(true));

                    //Atlas Padding
                    _superCombiner._atlasPadding = EditorGUILayout.IntField(new GUIContent("padding", "Padding between textures in the atlas"), _superCombiner._atlasPadding, GUILayout.ExpandWidth(true));

                    // Force UV to [0, 1] mode
                    //_superCombiner._forceUVTo0_1 = EditorGUILayout.Toggle(new GUIContent("Force UV to [0,1]", "Only consider UV that are in [0, 1] range so that textures won't be tiled in the atlas"), _superCombiner._forceUVTo0_1);

                    EditorGUILayout.EndVertical();
                }

                if (_superCombiner._combiningState == SuperCombiner.CombineStatesList.Uncombined)
                {
                    if (GUILayout.Button(new GUIContent("Create atlas texture", "This will combine materials and create the atlas texture(s) only. This is usefull to check if atlas texture(s) are correct without having to combine meshes which is time consuming. When materials have been combined, you'll need to hit 'Combine' button to finish the process and combine meshes."), GUILayout.MinHeight(20)))
                    {
                        _superCombiner.FindMeshesToCombine();
                        //_superCombiner.InitializeMultipleMaterialElements();
                        _superCombiner.CombineMaterials(_superCombiner._meshList, _superCombiner._skinnedMeshList);
                    }
                }
                else if (_superCombiner._combiningState == SuperCombiner.CombineStatesList.CombinedMaterials)
                {
                    GUI.enabled = true;
                    if (GUILayout.Button("Uncombine materials", GUILayout.MinHeight(20)))
                    {
                        _superCombiner.UnCombine();
                    }
                }

                EditorGUILayout.EndVertical();
                GUI.enabled = true;
            }
        }
 static void Drawer_FieldTargetEye(SerializedHDCamera p, Editor owner)
 {
     EditorGUILayout.IntPopup(p.baseCameraSettings.targetEye, k_TargetEyes, k_TargetEyeValues, targetEyeContent);
 }
Beispiel #5
0
    public override void OnInspectorGUI()
    {
        AddScriptNameField(m_Sel);

        int  nClickIndex  = -1;
        int  nClickButton = 0;
        Rect rect;
        int  nLeftWidth    = 34;
        int  nAddHeight    = 30;
        int  nDelWidth     = 35;
        int  nLineHeight   = 18;
        int  nSpriteHeight = nLeftWidth;
        List <NcSpriteFactory.NcSpriteNode> spriteList = m_Sel.m_SpriteList;

        m_FxmPopupManager = GetFxmPopupManager();

        // --------------------------------------------------------------
        bool bClickButton = false;

        EditorGUI.BeginChangeCheck();
        {
            m_UndoManager.CheckUndo();
            // --------------------------------------------------------------
            m_Sel.m_fUserTag = EditorGUILayout.FloatField(GetCommonContent("m_fUserTag"), m_Sel.m_fUserTag);

            EditorGUILayout.Space();
            m_Sel.m_SpriteType = (NcSpriteFactory.SPRITE_TYPE)EditorGUILayout.EnumPopup(GetHelpContent("m_SpriteType"), m_Sel.m_SpriteType);

            // --------------------------------------------------------------
            if (m_Sel.m_SpriteType == NcSpriteFactory.SPRITE_TYPE.NcSpriteAnimation && m_Sel.gameObject.GetComponent("NcSpriteAnimation") == null)
            {
                rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(m_fButtonHeight));
                {
                    if (FXMakerLayout.GUIButton(rect, GetHelpContent("Add NcSpriteAnimation Component"), true))
                    {
                        m_Sel.gameObject.AddComponent <NcSpriteAnimation>();
                    }
                    GUILayout.Label("");
                }
                EditorGUILayout.EndHorizontal();
            }
            // --------------------------------------------------------------
            if (m_Sel.m_SpriteType == NcSpriteFactory.SPRITE_TYPE.NcSpriteTexture && m_Sel.gameObject.GetComponent("NcSpriteTexture") == null)
            {
                rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(m_fButtonHeight));
                {
                    if (FXMakerLayout.GUIButton(rect, GetHelpContent("Add NcSpriteTexture Component"), true))
                    {
                        m_Sel.gameObject.AddComponent <NcSpriteTexture>();
                    }
                    GUILayout.Label("");
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.Space();

            // --------------------------------------------------------------
            int   nSelIndex = EditorGUILayout.IntSlider(GetHelpContent("m_nCurrentIndex"), m_Sel.m_nCurrentIndex, 0, (spriteList == null ? 0 : spriteList.Count - 1));
            float fUvScale  = EditorGUILayout.FloatField(GetHelpContent("m_fUvScale"), m_Sel.m_fUvScale);
            if (m_Sel.m_nCurrentIndex != nSelIndex || fUvScale != m_Sel.m_fUvScale)
            {
                m_Sel.m_nCurrentIndex = nSelIndex;
                m_Sel.m_fUvScale      = fUvScale;
                m_Sel.SetSprite(nSelIndex, false);
            }

            // Rebuild Check
            EditorGUI.BeginChangeCheck();
            m_Sel.m_bTrimBlack           = EditorGUILayout.Toggle(GetHelpContent("m_bTrimBlack"), m_Sel.m_bTrimBlack);
            m_Sel.m_bTrimAlpha           = EditorGUILayout.Toggle(GetHelpContent("m_bTrimAlpha"), m_Sel.m_bTrimAlpha);
            m_Sel.m_nMaxAtlasTextureSize = EditorGUILayout.IntPopup("nMaxAtlasTextureSize", m_Sel.m_nMaxAtlasTextureSize, NgEnum.m_TextureSizeStrings, NgEnum.m_TextureSizeIntters);
//          m_Sel.m_AtlasMaterial		= (Material)EditorGUILayout.ObjectField(GetHelpContent("m_AtlasMaterial")	, m_Sel.m_AtlasMaterial, typeof(Material), false);
            if (EditorGUI.EndChangeCheck())
            {
                m_Sel.m_bNeedRebuild = true;
            }

            int nBuildStartIndex = EditorGUILayout.IntSlider("m_nBuildStartIndex", m_Sel.m_nBuildStartIndex, 0, (spriteList == null ? 0 : spriteList.Count - 1));
            if (spriteList != null && nBuildStartIndex != m_Sel.m_nBuildStartIndex)
            {
                for (int n = Mathf.Min(m_Sel.m_nBuildStartIndex, nBuildStartIndex); n < Mathf.Max(m_Sel.m_nBuildStartIndex, nBuildStartIndex); n++)
                {
                    if (spriteList[n].IsUnused() == false && spriteList[n].IsEmptyTexture() == false)
                    {
                        m_Sel.m_bNeedRebuild = true;
                    }
                }
                m_Sel.m_nBuildStartIndex = nBuildStartIndex;
            }

            // Add Button ------------------------------------------------------
            EditorGUILayout.Space();
            rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(nAddHeight * 2));
            {
                Rect lineRect = FXMakerLayout.GetInnerVerticalRect(rect, 2, 0, 1);
                if (GUI.Button(FXMakerLayout.GetInnerHorizontalRect(lineRect, 3, 0, 1), GetHelpContent("Add Sprite")))
                {
                    bClickButton = true;
                    m_Sel.AddSpriteNode();
                }

                bool bHighLight = m_Sel.m_bNeedRebuild;
                if (bHighLight)
                {
                    FXMakerLayout.GUIColorBackup(FXMakerLayout.m_ColorHelpBox);
                }
                if (GUI.Button(FXMakerLayout.GetInnerHorizontalRect(lineRect, 3, 1, 1), GetHelpContent("Build Sprite")))
                {
#if UNITY_WEBPLAYER
                    Debug.LogError("In WEB_PLAYER mode, you cannot run the FXMaker.");
                    Debug.Break();
#else
                    bClickButton = true;
                    CreateSpriteAtlas(m_Sel.GetComponent <Renderer>().sharedMaterial);
                    m_Sel.m_bNeedRebuild = false;
#endif
                }
                if (bHighLight)
                {
                    FXMakerLayout.GUIColorRestore();
                }
                if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerHorizontalRect(lineRect, 3, 2, 1), GetHelpContent("Clear All"), (0 < m_Sel.GetSpriteNodeCount())))
                {
                    bClickButton = true;
                    if (m_FxmPopupManager != null)
                    {
                        m_FxmPopupManager.CloseNcPrefabPopup();
                    }
                    m_Sel.ClearAllSpriteNode();
                }
                lineRect = FXMakerLayout.GetInnerVerticalRect(rect, 2, 1, 1);
                if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerHorizontalRect(lineRect, 3, 0, 1), GetHelpContent("Sequence"), (0 < m_Sel.GetSpriteNodeCount())))
                {
                    m_Sel.m_bSequenceMode = true;
                    bClickButton          = true;
                    m_Sel.SetSprite(0, false);
                }
                if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerHorizontalRect(lineRect, 3, 1, 1), GetHelpContent("NewMaterial"), true))
                {
                    Material newMat  = new Material(m_Sel.GetComponent <Renderer>().sharedMaterial);
                    string   matPath = AssetDatabase.GetAssetPath(m_Sel.GetComponent <Renderer>().sharedMaterial);
                    NgMaterial.SaveMaterial(newMat, NgFile.TrimFilenameExt(matPath), m_Sel.name);
                    m_Sel.GetComponent <Renderer>().sharedMaterial = newMat;
//                  m_Sel.renderer.sharedMaterial = (Material)AssetDatabase.LoadAssetAtPath(savePath, typeof(Material));
                }

                GUILayout.Label("");
            }
            EditorGUILayout.EndHorizontal();

            // Select ShotType -------------------------------------------------
//			showType		= (NcSpriteFactory.SHOW_TYPE)EditorGUILayout.EnumPopup		(GetHelpContent("m_ShowType")	, showType);
            // --------------------------------------------------------------
            EditorGUILayout.Space();
            NcSpriteFactory.SHOW_TYPE showType = (NcSpriteFactory.SHOW_TYPE)EditorPrefs.GetInt("NcSpriteFactory.SHOW_TYPE", 0);

            rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(nLineHeight));
            {
                showType = FXMakerLayout.GUIToggle(FXMakerLayout.GetInnerHorizontalRect(rect, 5, 0, 1), showType == NcSpriteFactory.SHOW_TYPE.NONE, GetHelpContent("NONE"), true) ? NcSpriteFactory.SHOW_TYPE.NONE        : showType;
                showType = FXMakerLayout.GUIToggle(FXMakerLayout.GetInnerHorizontalRect(rect, 5, 1, 1), showType == NcSpriteFactory.SHOW_TYPE.ALL, GetHelpContent("ALL"), true) ? NcSpriteFactory.SHOW_TYPE.ALL         : showType;
                if (m_Sel.m_SpriteType == NcSpriteFactory.SPRITE_TYPE.NcSpriteAnimation)
                {
                    showType = FXMakerLayout.GUIToggle(FXMakerLayout.GetInnerHorizontalRect(rect, 5, 2, 1), showType == NcSpriteFactory.SHOW_TYPE.SPRITE, GetHelpContent("SPRITE"), true) ? NcSpriteFactory.SHOW_TYPE.SPRITE              : showType;
                    showType = FXMakerLayout.GUIToggle(FXMakerLayout.GetInnerHorizontalRect(rect, 5, 3, 1), showType == NcSpriteFactory.SHOW_TYPE.ANIMATION, GetHelpContent("ANIMATION"), true) ? NcSpriteFactory.SHOW_TYPE.ANIMATION   : showType;
                }
                showType = FXMakerLayout.GUIToggle(FXMakerLayout.GetInnerHorizontalRect(rect, 5, 4, 1), showType == NcSpriteFactory.SHOW_TYPE.EFFECT, GetHelpContent("EFFECT"), true) ? NcSpriteFactory.SHOW_TYPE.EFFECT              : showType;
                GUILayout.Label("");
            }
            EditorGUILayout.EndHorizontal();

            EditorPrefs.SetInt("NcSpriteFactory.SHOW_TYPE", ((int)showType));

            // Show Option -------------------------------------------------
            EditorGUILayout.Space();
            rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(nLineHeight));
            {
                m_Sel.m_bShowEffect = FXMakerLayout.GUIToggle(FXMakerLayout.GetInnerHorizontalRect(rect, 3, 0, 1), m_Sel.m_bShowEffect, GetHelpContent("m_bShowEffect"), true);
                if (m_Sel.m_SpriteType == NcSpriteFactory.SPRITE_TYPE.NcSpriteAnimation)
                {
                    m_Sel.m_bTestMode     = FXMakerLayout.GUIToggle(FXMakerLayout.GetInnerHorizontalRect(rect, 3, 1, 1), m_Sel.m_bTestMode, GetHelpContent("m_bTestMode"), true);
                    m_Sel.m_bSequenceMode = FXMakerLayout.GUIToggle(FXMakerLayout.GetInnerHorizontalRect(rect, 3, 2, 1), m_Sel.m_bSequenceMode, GetHelpContent("m_bSequenceMode"), true);
                }
                GUILayout.Label("");
            }
            EditorGUILayout.EndHorizontal();

            // Node List ------------------------------------------------------
            for (int n = 0; n < (spriteList != null ? spriteList.Count : 0); n++)
            {
                if (m_Sel.IsUnused(n))
                {
                    continue;
                }

                EditorGUILayout.Space();

                EditorGUI.BeginChangeCheck();
                // Load Texture ---------------------------------------------------------
                Texture2D selTexture = null;
                if (spriteList[n].m_TextureGUID != "")
                {
                    selTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(spriteList[n].m_TextureGUID), typeof(Texture2D));
                }

                // Enabled --------------------------------------------------------------
                rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(nLineHeight));
                {
                    Rect subRect;
                    EditorGUI.BeginChangeCheck();
                    // enable
                    spriteList[n].m_bIncludedAtlas = GUILayout.Toggle(spriteList[n].m_bIncludedAtlas, "Idx", GUILayout.Width(nLeftWidth));
                    // change index
                    subRect       = rect;
                    subRect.x    += nLeftWidth;
                    subRect.width = nLineHeight * 2;
                    int newPos = EditorGUI.IntPopup(subRect, n, NgConvert.GetIntStrings(0, spriteList.Count), NgConvert.GetIntegers(0, spriteList.Count));
                    if (newPos != n)
                    {
                        NcSpriteFactory.NcSpriteNode node = spriteList[n];
                        m_Sel.m_SpriteList.Remove(node);
                        m_Sel.m_SpriteList.Insert(newPos, node);
                        return;
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        m_Sel.m_bNeedRebuild = true;
                    }

                    // name
                    subRect        = rect;
                    subRect.x     += nLeftWidth + nLineHeight * 2;
                    subRect.width -= nLeftWidth + nLineHeight * 2;
                    spriteList[n].m_TextureName = selTexture == null ? "" : selTexture.name;
                    GUI.Label(subRect, (selTexture == null ? "" : "(" + spriteList[n].m_nFrameCount + ") " + selTexture.name));
                    GUI.Box(subRect, "");
                    GUI.Box(rect, "");

                    // delete
                    if (GUI.Button(new Rect(subRect.x + subRect.width - nDelWidth, subRect.y, nDelWidth, subRect.height), GetHelpContent("Del")))
                    {
                        m_Sel.m_bNeedRebuild = true;
                        bClickButton         = true;
                        if (m_FxmPopupManager != null)
                        {
                            m_FxmPopupManager.CloseNcPrefabPopup();
                        }
                        m_Sel.DeleteSpriteNode(n);
                        return;
                    }
                }
                EditorGUILayout.EndHorizontal();

                // SpriteName MaxAlpha -----------------------------------------------------------
                rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(nLineHeight));
                {
                    GUILayout.Label("", GUILayout.Width(nLineHeight));
                    GUI.Label(FXMakerLayout.GetInnerHorizontalRect(rect, 7, 0, 2), "Name,fMaxAlpha");
                    spriteList[n].m_SpriteName       = EditorGUI.TextField(FXMakerLayout.GetInnerHorizontalRect(rect, 7, 2, 4), spriteList[n].m_SpriteName);
                    spriteList[n].m_fMaxTextureAlpha = EditorGUI.FloatField(FXMakerLayout.GetInnerHorizontalRect(rect, 7, 6, 1), spriteList[n].m_fMaxTextureAlpha);
                }
                EditorGUILayout.EndHorizontal();

                // Texture --------------------------------------------------------------
                rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(nSpriteHeight / (selTexture == null ? 2 : 1)));
                {
                    GUILayout.Label("", GUILayout.Width(nLeftWidth));

                    Rect subRect = rect;
                    subRect.width = nLeftWidth;
                    FXMakerLayout.GetOffsetRect(rect, 0, 5, 0, -5);
                    EditorGUI.BeginChangeCheck();
                    selTexture = (Texture2D)EditorGUI.ObjectField(subRect, GetHelpContent(""), selTexture, typeof(Texture2D), false);
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (selTexture != null)
                        {
                            spriteList[n].m_TextureGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(selTexture));
                        }
                        m_Sel.m_bNeedRebuild = true;
                    }

                    // draw texture
                    subRect = FXMakerLayout.GetOffsetRect(rect, nLeftWidth + 4, 0, 0, -4);
                    Rect drawRect = FXMakerLayout.GetOffsetRect(subRect, 0, 0, -nDelWidth, 0);

                    if (selTexture != null)
                    {
                        // draw texture
                        GUI.DrawTexture(drawRect, selTexture, ScaleMode.ScaleToFit, true, selTexture.width / selTexture.height);

                        // draw tile
                        float fDrawRatio  = drawRect.width / drawRect.height;
                        float fImageRatio = selTexture.width / selTexture.height;
                        if (fDrawRatio < fImageRatio)
                        {
                            drawRect = FXMakerLayout.GetVOffsetRect(drawRect, drawRect.height * -(1 - (fDrawRatio / fImageRatio)) / 2);
                        }
                        else
                        {
                            drawRect = FXMakerLayout.GetHOffsetRect(drawRect, drawRect.width * -(1 - (fImageRatio / fDrawRatio)) / 2);
                        }
                        float tileWidth  = (drawRect.width / spriteList[n].m_nTilingX);
                        float tileHeight = (drawRect.height / spriteList[n].m_nTilingY);

                        for (int tn = spriteList[n].m_nStartFrame; tn < Mathf.Min(spriteList[n].m_nStartFrame + spriteList[n].m_nFrameCount, spriteList[n].m_nTilingX * spriteList[n].m_nTilingY); tn++)
                        {
                            int  posx     = tn % spriteList[n].m_nTilingX;
                            int  posy     = tn / spriteList[n].m_nTilingX;
                            Rect tileRect = new Rect(drawRect.x + posx * tileWidth, drawRect.y + posy * tileHeight, tileWidth, tileHeight);
                            NgGUIDraw.DrawBox(FXMakerLayout.GetOffsetRect(tileRect, -1), Color.green, 1, false);
                        }
                    }

                    // delete
                    if (GUI.Button(new Rect(subRect.x + subRect.width - nDelWidth, subRect.y, nDelWidth, subRect.height), GetHelpContent("Rmv")))
                    {
                        spriteList[n].SetEmpty();
                    }
                    GUI.Box(rect, "");
                }
                EditorGUILayout.EndHorizontal();

                // Change selIndex
                Event e = Event.current;
                if (e.type == EventType.MouseDown && rect.Contains(e.mousePosition))
                {
                    nClickIndex  = n;
                    nClickButton = e.button;
                }

                // -----------------------------------------------------------------------------------------------------------------------------------------------
                if (spriteList[n].IsEmptyTexture() == false)
                {
                    // Frame tile
                    rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(nLineHeight));
                    {
                        GUILayout.Label("", GUILayout.Width(nLineHeight));
                        GUI.Label(FXMakerLayout.GetInnerHorizontalRect(rect, 8, 0, 4), "nTileXY,Start,Count");

                        // m_nTilingX, m_nTilingY
                        EditorGUI.BeginChangeCheck();
                        spriteList[n].m_nTilingX = EditorGUI.IntField(FXMakerLayout.GetInnerHorizontalRect(rect, 8, 4, 1), spriteList[n].m_nTilingX);
                        spriteList[n].m_nTilingY = EditorGUI.IntField(FXMakerLayout.GetInnerHorizontalRect(rect, 8, 5, 1), spriteList[n].m_nTilingY);
                        SetMinValue(ref spriteList[n].m_nTilingX, 1);
                        SetMinValue(ref spriteList[n].m_nTilingY, 1);
                        if (EditorGUI.EndChangeCheck())
                        {
                            spriteList[n].m_nFrameCount = spriteList[n].m_nTilingX * spriteList[n].m_nTilingY - spriteList[n].m_nStartFrame;
                            m_Sel.m_bNeedRebuild        = true;
                        }

                        // m_nStartFrame, m_nFrameCount
                        EditorGUI.BeginChangeCheck();
                        spriteList[n].m_nStartFrame = EditorGUI.IntField(FXMakerLayout.GetInnerHorizontalRect(rect, 8, 6, 1), spriteList[n].m_nStartFrame);
                        spriteList[n].m_nFrameCount = EditorGUI.IntField(FXMakerLayout.GetInnerHorizontalRect(rect, 8, 7, 1), spriteList[n].m_nFrameCount);
                        SetMaxValue(ref spriteList[n].m_nStartFrame, spriteList[n].m_nTilingX * spriteList[n].m_nTilingY - 1);
                        SetMinValue(ref spriteList[n].m_nStartFrame, 0);
                        SetMaxValue(ref spriteList[n].m_nFrameCount, spriteList[n].m_nTilingX * spriteList[n].m_nTilingY - spriteList[n].m_nStartFrame);
                        SetMinValue(ref spriteList[n].m_nFrameCount, 1);
                        if (EditorGUI.EndChangeCheck())
                        {
                            m_Sel.m_bNeedRebuild = true;
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    // SpriteNode ----------------------------------------------------------
                    if (bClickButton == false)
                    {
                        if (m_Sel.m_SpriteType == NcSpriteFactory.SPRITE_TYPE.NcSpriteAnimation && (showType == NcSpriteFactory.SHOW_TYPE.ALL || showType == NcSpriteFactory.SHOW_TYPE.SPRITE))
                        {
                            rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(nLineHeight));
                            {
                                GUILayout.Label("", GUILayout.Width(nLineHeight));
                                GUI.Label(FXMakerLayout.GetInnerHorizontalRect(rect, 8, 0, 4), "Loop,Start,FCnt,LCnt");

                                bool bOldLoop = spriteList[n].m_bLoop;
                                spriteList[n].m_bLoop = EditorGUI.Toggle(FXMakerLayout.GetInnerHorizontalRect(rect, 8, 4, 1), spriteList[n].m_bLoop);
                                if (!bOldLoop && spriteList[n].m_bLoop)
                                {
                                    spriteList[n].m_nLoopStartFrame = 0;
                                    spriteList[n].m_nLoopFrameCount = spriteList[n].m_nFrameCount;
                                    spriteList[n].m_nLoopingCount   = 0;
                                }
                                if (spriteList[n].m_bLoop)
                                {
                                    spriteList[n].m_nLoopStartFrame = EditorGUI.IntField(FXMakerLayout.GetInnerHorizontalRect(rect, 8, 5, 1), spriteList[n].m_nLoopStartFrame);
                                    spriteList[n].m_nLoopFrameCount = EditorGUI.IntField(FXMakerLayout.GetInnerHorizontalRect(rect, 8, 6, 1), spriteList[n].m_nLoopFrameCount);
                                    spriteList[n].m_nLoopingCount   = EditorGUI.IntField(FXMakerLayout.GetInnerHorizontalRect(rect, 8, 7, 1), spriteList[n].m_nLoopingCount);
                                }
                                // check
                                SetMaxValue(ref spriteList[n].m_nLoopStartFrame, spriteList[n].m_nFrameCount - 1);
                                SetMinValue(ref spriteList[n].m_nLoopStartFrame, 0);
                                SetMaxValue(ref spriteList[n].m_nLoopFrameCount, spriteList[n].m_nFrameCount - spriteList[n].m_nLoopStartFrame);
                                SetMinValue(ref spriteList[n].m_nLoopingCount, 0);
                            }
                            EditorGUILayout.EndHorizontal();

                            spriteList[n].m_fTime = EditorGUILayout.Slider(GetHelpContent("m_fTime"), spriteList[n].m_nFrameCount / spriteList[n].m_fFps, 0, 5, null);
                            spriteList[n].m_fFps  = EditorGUILayout.Slider(GetHelpContent("m_fFps"), spriteList[n].m_nFrameCount / spriteList[n].m_fTime, 50, 1, null);
                        }

                        if (m_Sel.m_SpriteType == NcSpriteFactory.SPRITE_TYPE.NcSpriteAnimation && (showType == NcSpriteFactory.SHOW_TYPE.ALL || showType == NcSpriteFactory.SHOW_TYPE.ANIMATION))
                        {
                            spriteList[n].m_nNextSpriteIndex = EditorGUILayout.Popup("m_nNextSpriteIndex", spriteList[n].m_nNextSpriteIndex + 1, GetSpriteNodeNames()) - 1;
                            if (0 <= spriteList[n].m_nNextSpriteIndex)
                            {
                                spriteList[n].m_nTestMode  = EditorGUILayout.Popup("m_nTestMode", spriteList[n].m_nTestMode, NgConvert.ContentsToStrings(FxmTestControls.GetHcEffectControls_Trans(FxmTestControls.AXIS.Z)), GUILayout.MaxWidth(Screen.width));
                                spriteList[n].m_fTestSpeed = EditorGUILayout.FloatField("m_fTestSpeed", spriteList[n].m_fTestSpeed);

                                SetMinValue(ref spriteList[n].m_fTestSpeed, 0.01f);
                            }
                        }

                        if (showType == NcSpriteFactory.SHOW_TYPE.ALL || showType == NcSpriteFactory.SHOW_TYPE.EFFECT)
                        {
                            EditorGUILayout.Separator();
                            // char effect -------------------------------------------------------------
                            spriteList[n].m_EffectPrefab = (GameObject)EditorGUILayout.ObjectField(GetHelpContent("m_EffectPrefab"), spriteList[n].m_EffectPrefab, typeof(GameObject), false, null);

                            rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(m_fButtonHeight * 0.7f));
                            {
                                if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerHorizontalRect(rect, 3, 0, 1), GetHelpContent("SelEffect"), (m_FxmPopupManager != null)))
                                {
                                    m_FxmPopupManager.ShowSelectPrefabPopup(m_Sel, n, 0, true);
                                }
                                if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerHorizontalRect(rect, 3, 1, 1), GetHelpContent("ClearEffect"), (spriteList[n].m_EffectPrefab != null)))
                                {
                                    bClickButton = true;
                                    spriteList[n].m_EffectPrefab = null;
                                }
                                if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerHorizontalRect(rect, 3, 2, 1), GetHelpContent("OpenEffect"), (m_FxmPopupManager != null) && (spriteList[n].m_EffectPrefab != null)))
                                {
                                    bClickButton = true;
                                    GetFXMakerMain().OpenPrefab(spriteList[n].m_EffectPrefab);
                                    return;
                                }
                                GUILayout.Label("");
                            }
                            EditorGUILayout.EndHorizontal();

                            if (spriteList[n].m_EffectPrefab != null)
                            {
                                spriteList[n].m_bEffectInstantiate = EditorGUILayout.Toggle(GetHelpContent("m_bEffectInstantiate"), spriteList[n].m_bEffectInstantiate);

                                if (m_Sel.m_SpriteType == NcSpriteFactory.SPRITE_TYPE.NcSpriteAnimation)
                                {
                                    spriteList[n].m_nEffectFrame = EditorGUILayout.IntSlider(GetHelpContent("m_nEffectFrame"), spriteList[n].m_nEffectFrame, 0, spriteList[n].m_nFrameCount, null);

                                    rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(nLineHeight));
                                    {
                                        GUILayout.Label("", GUILayout.Width(nLineHeight));
                                        GUI.Label(FXMakerLayout.GetInnerHorizontalRect(rect, 4, 0, 2), "bOnlyFirst,bEffDetach");
                                        spriteList[n].m_bEffectOnlyFirst = EditorGUI.Toggle(FXMakerLayout.GetInnerHorizontalRect(rect, 4, 2, 1), spriteList[n].m_bEffectOnlyFirst);
                                        spriteList[n].m_bEffectDetach    = EditorGUI.Toggle(FXMakerLayout.GetInnerHorizontalRect(rect, 4, 3, 1), spriteList[n].m_bEffectDetach);
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }
                                rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(nLineHeight));
                                {
                                    GUILayout.Label("", GUILayout.Width(nLineHeight));
                                    GUI.Label(FXMakerLayout.GetInnerHorizontalRect(rect, 4, 0, 2), "fSpeed, fScale");
                                    spriteList[n].m_fEffectSpeed = EditorGUI.FloatField(FXMakerLayout.GetInnerHorizontalRect(rect, 4, 2, 1), spriteList[n].m_fEffectSpeed);
                                    spriteList[n].m_fEffectScale = EditorGUI.FloatField(FXMakerLayout.GetInnerHorizontalRect(rect, 4, 3, 1), spriteList[n].m_fEffectScale);
                                }
                                EditorGUILayout.EndHorizontal();

                                spriteList[n].m_EffectPos = EditorGUILayout.Vector3Field("m_EffectPos", spriteList[n].m_EffectPos, null);
                                spriteList[n].m_EffectRot = EditorGUILayout.Vector3Field("m_EffectRot", spriteList[n].m_EffectRot, null);

                                SetMinValue(ref spriteList[n].m_fEffectScale, 0.001f);
                            }

                            EditorGUILayout.Space();

                            // char sound -------------------------------------------------------------
                            spriteList[n].m_AudioClip = (AudioClip)EditorGUILayout.ObjectField(GetHelpContent("m_AudioClip"), spriteList[n].m_AudioClip, typeof(AudioClip), false, null);

                            rect = EditorGUILayout.BeginHorizontal(GUILayout.Height(m_fButtonHeight * 0.7f));
                            {
                                //                          if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerHorizontalRect(rect, 2, 0, 1), GetHelpContent("SelAudio"), (m_FxmPopupManager != null)))
                                //								m_FxmPopupManager.ShowSelectAudioClipPopup(m_Sel);
                                if (FXMakerLayout.GUIButton(FXMakerLayout.GetInnerHorizontalRect(rect, 2, 1, 1), GetHelpContent("ClearAudio"), (spriteList[n].m_AudioClip != null)))
                                {
                                    bClickButton = true;
                                    spriteList[n].m_AudioClip = null;
                                }
                                GUILayout.Label("");
                            }
                            EditorGUILayout.EndHorizontal();

                            if (spriteList[n].m_AudioClip != null)
                            {
                                if (m_Sel.m_SpriteType == NcSpriteFactory.SPRITE_TYPE.NcSpriteAnimation)
                                {
                                    spriteList[n].m_nSoundFrame     = EditorGUILayout.IntSlider(GetHelpContent("m_nSoundFrame"), spriteList[n].m_nSoundFrame, 0, spriteList[n].m_nFrameCount, null);
                                    spriteList[n].m_bSoundOnlyFirst = EditorGUILayout.Toggle(GetHelpContent("m_bSoundOnlyFirst"), spriteList[n].m_bSoundOnlyFirst);
                                }
                                spriteList[n].m_bSoundLoop   = EditorGUILayout.Toggle(GetHelpContent("m_bSoundLoop"), spriteList[n].m_bSoundLoop);
                                spriteList[n].m_fSoundVolume = EditorGUILayout.Slider(GetHelpContent("m_fSoundVolume"), spriteList[n].m_fSoundVolume, 0, 1.0f, null);
                                spriteList[n].m_fSoundPitch  = EditorGUILayout.Slider(GetHelpContent("m_fSoundPitch"), spriteList[n].m_fSoundPitch, -3, 3.0f, null);
                            }
                        }
                    }
                }

                if (EditorGUI.EndChangeCheck())
                {
                    nClickIndex = n;
                }

                selTexture = null;
            }

            // Select Node ----------------------------------------------------
            if (0 <= nClickIndex)
            {
                m_Sel.SetSprite(nClickIndex, false);
                if (m_Sel.m_bTestMode && 0 <= spriteList[nClickIndex].m_nTestMode && GetFXMakerMain())
                {
                    GetFXMakerMain().GetFXMakerControls().SetTransIndex(spriteList[nClickIndex].m_nTestMode, (4 <= spriteList[nClickIndex].m_nTestMode ? 1.8f : 1.0f), spriteList[nClickIndex].m_fTestSpeed);
                }
                // Rotate
                if (nClickButton == 1)
                {
                    m_Sel.transform.Rotate(0, 180, 0);
                }
                nClickIndex  = -1;
                bClickButton = true;
            }

            m_UndoManager.CheckDirty();
        }
        // --------------------------------------------------------------
        if ((EditorGUI.EndChangeCheck() || bClickButton) && GetFXMakerMain())
        {
            OnEditComponent();
        }
        // ---------------------------------------------------------------------
        if (GUI.tooltip != "")
        {
            m_LastTooltip = GUI.tooltip;
        }
        HelpBox(m_LastTooltip);
    }
        public void DrawSpriteEditorInspector(List <SpriteCollectionEditorEntry> entries, bool allowDelete, bool editingSpriteSheet)
        {
            var entry         = entries[entries.Count - 1];
            var param         = SpriteCollection.textureParams[entry.index];
            var spriteTexture = param.extractRegion?host.GetTextureForSprite(entry.index):SpriteCollection.textureRefs[entry.index];

            // Inspector
            EditorGUILayout.BeginVertical();

            // Header
            EditorGUILayout.BeginVertical(tk2dEditorSkin.SC_InspectorHeaderBG, GUILayout.MaxWidth(host.InspectorWidth), GUILayout.ExpandHeight(true));
            if (entries.Count > 1)
            {
                EditorGUILayout.TextField("Name", param.name);
            }
            else
            {
                string name = EditorGUILayout.TextField("Name", param.name);
                if (name != param.name)
                {
                    param.name = name;
                    entry.name = name;
                    host.OnSpriteCollectionSortChanged();
                }
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Sprite Id");
                EditorGUILayout.SelectableLabel(entry.index.ToString(), EditorStyles.textField, GUILayout.ExpandWidth(true), GUILayout.Height(16));
                EditorGUILayout.EndHorizontal();
            }
            GUILayout.BeginHorizontal();
            bool doDelete            = false;
            bool doSelect            = false;
            bool doSelectSpriteSheet = false;

            if (entries.Count == 1)
            {
                if (param.extractRegion)
                {
                    EditorGUILayout.ObjectField("Texture", spriteTexture, typeof(Texture2D), false);
                }
                else
                {
                    SpriteCollection.textureRefs[entry.index] = EditorGUILayout.ObjectField("Texture", spriteTexture, typeof(Texture2D), false) as Texture2D;
                }
                GUILayout.FlexibleSpace();
                GUILayout.BeginVertical();
                if (editingSpriteSheet && GUILayout.Button("Edit...", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    doSelect = true;
                }
                if (!editingSpriteSheet && param.hasSpriteSheetId && GUILayout.Button("Source", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    doSelectSpriteSheet = true;
                }
                if (allowDelete && GUILayout.Button("Delete", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    doDelete = true;
                }
                GUILayout.EndVertical();
            }
            else
            {
                string countLabel = (entries.Count > 1)?entries.Count.ToString() + " sprites selected":"";
                GUILayout.Label(countLabel);
                GUILayout.FlexibleSpace();
                if (editingSpriteSheet && GUILayout.Button("Edit...", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    doSelect = true;
                }
                if (!editingSpriteSheet && param.hasSpriteSheetId)
                {
                    int id = param.spriteSheetId;
                    foreach (var v in entries)
                    {
                        var p = SpriteCollection.textureParams[v.index];
                        if (!p.hasSpriteSheetId ||
                            p.spriteSheetId != id)
                        {
                            id = -1;
                            break;
                        }
                    }
                    if (id != -1 && GUILayout.Button("Source", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                    {
                        doSelectSpriteSheet = true;
                    }
                }
                if (allowDelete && GUILayout.Button("Delete", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    doDelete = true;
                }
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();

            // Body
            EditorGUILayout.BeginVertical(tk2dEditorSkin.SC_InspectorBG, GUILayout.MaxWidth(host.InspectorWidth), GUILayout.ExpandHeight(true));

            if (SpriteCollection.AllowAltMaterials && SpriteCollection.altMaterials.Length > 1)
            {
                List <int>    altMaterialIndices = new List <int>();
                List <string> altMaterialNames   = new List <string>();
                for (int i = 0; i < SpriteCollection.altMaterials.Length; ++i)
                {
                    var mat = SpriteCollection.altMaterials[i];
                    if (mat == null)
                    {
                        continue;
                    }
                    altMaterialIndices.Add(i);
                    altMaterialNames.Add(mat.name);
                }

                GUILayout.BeginHorizontal();
                param.materialId = EditorGUILayout.IntPopup("Material", param.materialId, altMaterialNames.ToArray(), altMaterialIndices.ToArray());
                if (GUILayout.Button("Select", EditorStyles.miniButton, GUILayout.Width(miniButtonWidth)))
                {
                    List <int> spriteIdList = new List <int>();
                    for (int i = 0; i < SpriteCollection.textureParams.Count; ++i)
                    {
                        if (SpriteCollection.textureParams[i].materialId == param.materialId)
                        {
                            spriteIdList.Add(i);
                        }
                    }
                    host.SelectSpritesFromList(spriteIdList.ToArray());
                }
                GUILayout.EndHorizontal();
                HandleMultiSelection(entries, (a, b) => a.materialId == b.materialId, (a, b) => b.materialId = a.materialId);
            }

            if (SpriteCollection.premultipliedAlpha)
            {
                param.additive = EditorGUILayout.Toggle("Additive", param.additive);
                HandleMultiSelection(entries, (a, b) => a.additive == b.additive, (a, b) => b.additive = a.additive);
            }
            // fixup
            if (param.scale == Vector3.zero)
            {
                param.scale = Vector3.one;
            }
            param.scale = EditorGUILayout.Vector3Field("Scale", param.scale);
            HandleMultiSelection(entries, (a, b) => a.scale == b.scale, (a, b) => b.scale = a.scale);

            // Anchor
            param.anchor = (tk2dSpriteCollectionDefinition.Anchor)EditorGUILayout.EnumPopup("Anchor", param.anchor);
            if (param.anchor == tk2dSpriteCollectionDefinition.Anchor.Custom)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.BeginHorizontal();
                param.anchorX = EditorGUILayout.FloatField("X", param.anchorX);
                bool roundAnchorX = GUILayout.Button("R", EditorStyles.miniButton, GUILayout.MaxWidth(24));
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                param.anchorY = EditorGUILayout.FloatField("Y", param.anchorY);
                bool roundAnchorY = GUILayout.Button("R", EditorStyles.miniButton, GUILayout.MaxWidth(24));
                EditorGUILayout.EndHorizontal();

                if (roundAnchorX)
                {
                    param.anchorX = Mathf.Round(param.anchorX);
                }
                if (roundAnchorY)
                {
                    param.anchorY = Mathf.Round(param.anchorY);
                }
                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();

                HandleMultiSelection(entries,
                                     (a, b) => (a.anchor == b.anchor && a.anchorX == b.anchorX && a.anchorY == b.anchorY),
                                     delegate(tk2dSpriteCollectionDefinition a, tk2dSpriteCollectionDefinition b) {
                    b.anchor  = a.anchor;
                    b.anchorX = a.anchorX;
                    b.anchorY = a.anchorY;
                });
            }
            else
            {
                HandleMultiSelection(entries, (a, b) => a.anchor == b.anchor, (a, b) => b.anchor = a.anchor);
            }

            param.colliderType = (tk2dSpriteCollectionDefinition.ColliderType)EditorGUILayout.EnumPopup("Collider Type", param.colliderType);
            if (param.colliderType == tk2dSpriteCollectionDefinition.ColliderType.BoxCustom)
            {
                EditorGUI.indentLevel++;
                param.boxColliderMin = EditorGUILayout.Vector2Field("Min", param.boxColliderMin);
                param.boxColliderMax = EditorGUILayout.Vector2Field("Max", param.boxColliderMax);
                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();

                HandleMultiSelection(entries,
                                     (a, b) => (a.colliderType == b.colliderType && a.boxColliderMin == b.boxColliderMin && a.boxColliderMax == b.boxColliderMax),
                                     delegate(tk2dSpriteCollectionDefinition a, tk2dSpriteCollectionDefinition b) {
                    b.colliderType   = a.colliderType;
                    b.boxColliderMin = a.boxColliderMin;
                    b.boxColliderMax = a.boxColliderMax;
                });
            }
            else if (param.colliderType == tk2dSpriteCollectionDefinition.ColliderType.Polygon)
            {
                EditorGUI.indentLevel++;
                param.polyColliderCap = (tk2dSpriteCollectionDefinition.PolygonColliderCap)EditorGUILayout.EnumPopup("Collider Cap", param.polyColliderCap);
                param.colliderConvex  = EditorGUILayout.Toggle("Convex", param.colliderConvex);
                param.colliderSmoothSphereCollisions = EditorGUILayout.Toggle(new GUIContent("SmoothSphereCollisions", "Smooth Sphere Collisions"), param.colliderSmoothSphereCollisions);
                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();

                HandleMultiSelection(entries,
                                     (a, b) => (a.colliderType == b.colliderType && a.polyColliderCap == b.polyColliderCap &&
                                                a.colliderConvex == b.colliderConvex && a.colliderSmoothSphereCollisions == b.colliderSmoothSphereCollisions &&
                                                ComparePolyCollider(a.polyColliderIslands, b.polyColliderIslands)),
                                     delegate(tk2dSpriteCollectionDefinition a, tk2dSpriteCollectionDefinition b) {
                    b.colliderType    = a.colliderType;
                    b.polyColliderCap = a.polyColliderCap;
                    b.colliderConvex  = a.colliderConvex;
                    b.colliderSmoothSphereCollisions = a.colliderSmoothSphereCollisions;
                    CopyPolyCollider(a.polyColliderIslands, ref b.polyColliderIslands);
                });
            }
            else
            {
                HandleMultiSelection(entries, (a, b) => a.colliderType == b.colliderType, (a, b) => b.colliderType = a.colliderType);
            }

            // Mesh type
            if (param.dice && param.customSpriteGeometry)             // sanity check
            {
                param.dice = false; param.customSpriteGeometry = false;
            }
            CustomMeshType meshType = CustomMeshType.Default;

            if (param.customSpriteGeometry)
            {
                meshType = CustomMeshType.Custom;
            }
            else if (param.dice)
            {
                meshType = CustomMeshType.Diced;
            }
            CustomMeshType newMeshType = (CustomMeshType)EditorGUILayout.EnumPopup("Render Mesh", meshType);

            if (newMeshType != meshType)
            {
                // Fix up
                switch (newMeshType)
                {
                case CustomMeshType.Custom: param.customSpriteGeometry = true;  param.dice = false; break;

                case CustomMeshType.Diced:      param.customSpriteGeometry = false;     param.dice = true;      break;

                case CustomMeshType.Default: param.customSpriteGeometry = false; param.dice = false;     break;
                }
            }

            // Sanity check dicing & multiple atlases
            if (param.dice && SpriteCollection.allowMultipleAtlases)
            {
                EditorUtility.DisplayDialog("Sprite dicing",
                                            "Sprite dicing is unavailable when multiple atlases is enabled. " +
                                            "Please disable it and try again.", "Ok");
                param.dice = false;
            }

            // Dicing parameters
            if (param.dice)
            {
                EditorGUI.indentLevel++;
                param.diceUnitX = EditorGUILayout.IntField("Dice X", param.diceUnitX);
                param.diceUnitY = EditorGUILayout.IntField("Dice Y", param.diceUnitY);
                EditorGUI.indentLevel--;
                EditorGUILayout.Separator();
            }

            HandleMultiSelection(entries,
                                 (a, b) => a.customSpriteGeometry == b.customSpriteGeometry && a.dice == b.dice && a.diceUnitX == b.diceUnitX && a.diceUnitY == b.diceUnitY,
                                 delegate(tk2dSpriteCollectionDefinition a, tk2dSpriteCollectionDefinition b) {
                b.customSpriteGeometry = a.customSpriteGeometry;
                b.dice      = a.dice;
                b.diceUnitX = a.diceUnitX;
                b.diceUnitY = a.diceUnitY;
            });


            // Disable trimming
            if (!SpriteCollection.disableTrimming)
            {
                param.disableTrimming = EditorGUILayout.Toggle("Disable Trimming", param.disableTrimming);
                HandleMultiSelection(entries, (a, b) => a.disableTrimming == b.disableTrimming, (a, b) => b.disableTrimming = a.disableTrimming);
            }

            // Pad amount
            param.pad = (tk2dSpriteCollectionDefinition.Pad)EditorGUILayout.EnumPopup("Pad method", param.pad);
            HandleMultiSelection(entries, (a, b) => a.pad == b.pad, (a, b) => b.pad = a.pad);

            // Extra padding
            param.extraPadding = EditorGUILayout.IntPopup("Extra Padding", param.extraPadding, extraPadAmountLabels, extraPadAmountValues);
            HandleMultiSelection(entries, (a, b) => a.extraPadding == b.extraPadding, (a, b) => b.extraPadding = a.extraPadding);
            GUILayout.FlexibleSpace();

            // Draw additional inspector
            textureEditor.DrawTextureInspector(param, spriteTexture);

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndVertical();             // inspector

            // Defer delete to avoid messing about anything else
            if (doDelete &&
                EditorUtility.DisplayDialog("Delete sprite", "Are you sure you want to delete the selected sprites?", "Yes", "No"))
            {
                foreach (var e in entries)
                {
                    SpriteCollection.textureRefs[e.index]   = null;
                    SpriteCollection.textureParams[e.index] = new tk2dSpriteCollectionDefinition();
                }
                SpriteCollection.Trim();
                if (editingSpriteSheet)
                {
                    host.OnSpriteCollectionChanged(true);
                }
                else
                {
                    host.OnSpriteCollectionChanged(false);
                }
            }

            if (doSelect)
            {
                List <int> spriteIdList = new List <int>();
                foreach (var e in entries)
                {
                    spriteIdList.Add(e.index);
                }
                host.SelectSpritesFromList(spriteIdList.ToArray());
            }

            if (doSelectSpriteSheet)
            {
                List <int> spriteIdList = new List <int>();
                foreach (var e in entries)
                {
                    spriteIdList.Add(e.index);
                }
                host.SelectSpritesInSpriteSheet(param.spriteSheetId, spriteIdList.ToArray());
            }
        }
Beispiel #7
0
        public override void OnInspectorGUI(NavGraph target)
        {
            GridGraph graph = target as GridGraph;

            //GUILayout.BeginHorizontal ();
            //GUILayout.BeginVertical ();
            Rect lockRect;

            GUIStyle lockStyle = AstarPathEditor.astarSkin.FindStyle("GridSizeLock");

            if (lockStyle == null)
            {
                lockStyle = new GUIStyle();
            }

        #if !UNITY_LE_4_3 || true
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            int newWidth = EditorGUILayout.IntField(new GUIContent("Width (nodes)", "Width of the graph in nodes"), graph.width);
            int newDepth = EditorGUILayout.IntField(new GUIContent("Depth (nodes)", "Depth (or height you might also call it) of the graph in nodes"), graph.depth);
            GUILayout.EndVertical();

            lockRect = GUILayoutUtility.GetRect(lockStyle.fixedWidth, lockStyle.fixedHeight);

            // Add a small offset to make it better centred around the controls
            lockRect.y += 3;
            GUILayout.EndHorizontal();

            // All the layouts mess up the margin to the next control, so add it manually
            GUILayout.Space(2);
        #elif UNITY_4
            Rect tmpLockRect;
            int  newWidth = IntField(new GUIContent("Width (nodes)", "Width of the graph in nodes"), graph.width, 100, 0, out lockRect, out sizeSelected1);
            int  newDepth = IntField(new GUIContent("Depth (nodes)", "Depth (or height you might also call it) of the graph in nodes"), graph.depth, 100, 0, out tmpLockRect, out sizeSelected2);
        #else
            Rect tmpLockRect;
            int  newWidth = IntField(new GUIContent("Width (nodes)", "Width of the graph in nodes"), graph.width, 50, 0, out lockRect, out sizeSelected1);
            int  newDepth = IntField(new GUIContent("Depth (nodes)", "Depth (or height you might also call it) of the graph in nodes"), graph.depth, 50, 0, out tmpLockRect, out sizeSelected2);
        #endif

            lockRect.width  = lockStyle.fixedWidth;
            lockRect.height = lockStyle.fixedHeight;
            lockRect.x     += lockStyle.margin.left;
            lockRect.y     += lockStyle.margin.top;

            locked = GUI.Toggle(lockRect, locked, new GUIContent("", "If the width and depth values are locked, changing the node size will scale the grid which keeping the number of nodes consistent instead of keeping the size the same and changing the number of nodes in the graph"), lockStyle);

            //GUILayout.EndHorizontal ();

            if (newWidth != graph.width || newDepth != graph.depth)
            {
                SnapSizeToNodes(newWidth, newDepth, graph);
            }

            GUI.SetNextControlName("NodeSize");
            newNodeSize = EditorGUILayout.FloatField(new GUIContent("Node size", "The size of a single node. The size is the side of the node square in world units"), graph.nodeSize);

            newNodeSize = newNodeSize <= 0.01F ? 0.01F : newNodeSize;

            float prevRatio = graph.aspectRatio;
            graph.aspectRatio = EditorGUILayout.FloatField(new GUIContent("Aspect Ratio", "Scaling of the nodes width/depth ratio. Good for isometric games"), graph.aspectRatio);

            graph.isometricAngle = EditorGUILayout.FloatField(new GUIContent("Isometric Angle", "For an isometric 2D game, you can use this parameter to scale the graph correctly."), graph.isometricAngle);

            if (graph.nodeSize != newNodeSize || prevRatio != graph.aspectRatio)
            {
                if (!locked)
                {
                    graph.nodeSize = newNodeSize;
                    Matrix4x4 oldMatrix = graph.matrix;
                    graph.GenerateMatrix();
                    if (graph.matrix != oldMatrix)
                    {
                        //Rescann the graphs
                        //AstarPath.active.AutoScan ();
                        GUI.changed = true;
                    }
                }
                else
                {
                    float delta = newNodeSize / graph.nodeSize;
                    graph.nodeSize      = newNodeSize;
                    graph.unclampedSize = new Vector2(newWidth * graph.nodeSize, newDepth * graph.nodeSize);
                    Vector3 newCenter = graph.matrix.MultiplyPoint3x4(new Vector3((newWidth / 2F) * delta, 0, (newDepth / 2F) * delta));
                    graph.center = newCenter;
                    graph.GenerateMatrix();

                    //Make sure the width & depths stay the same
                    graph.width = newWidth;
                    graph.depth = newDepth;
                    AutoScan();
                }
            }

            Vector3 pivotPoint;
            Vector3 diff;

        #if UNITY_LE_4_3
            EditorGUIUtility.LookLikeControls();
        #endif

        #if !UNITY_4
            EditorGUILayoutx.BeginIndent();
        #else
            GUILayout.BeginHorizontal();
        #endif

            switch (pivot)
            {
            case GridPivot.Center:
                graph.center = RoundVector3(graph.center);
                graph.center = EditorGUILayout.Vector3Field("Center", graph.center);
                break;

            case GridPivot.TopLeft:
                pivotPoint   = graph.matrix.MultiplyPoint3x4(new Vector3(0, 0, graph.depth));
                pivotPoint   = RoundVector3(pivotPoint);
                diff         = pivotPoint - graph.center;
                pivotPoint   = EditorGUILayout.Vector3Field("Top-Left", pivotPoint);
                graph.center = pivotPoint - diff;
                break;

            case GridPivot.TopRight:
                pivotPoint   = graph.matrix.MultiplyPoint3x4(new Vector3(graph.width, 0, graph.depth));
                pivotPoint   = RoundVector3(pivotPoint);
                diff         = pivotPoint - graph.center;
                pivotPoint   = EditorGUILayout.Vector3Field("Top-Right", pivotPoint);
                graph.center = pivotPoint - diff;
                break;

            case GridPivot.BottomLeft:
                pivotPoint   = graph.matrix.MultiplyPoint3x4(new Vector3(0, 0, 0));
                pivotPoint   = RoundVector3(pivotPoint);
                diff         = pivotPoint - graph.center;
                pivotPoint   = EditorGUILayout.Vector3Field("Bottom-Left", pivotPoint);
                graph.center = pivotPoint - diff;
                break;

            case GridPivot.BottomRight:
                pivotPoint   = graph.matrix.MultiplyPoint3x4(new Vector3(graph.width, 0, 0));
                pivotPoint   = RoundVector3(pivotPoint);
                diff         = pivotPoint - graph.center;
                pivotPoint   = EditorGUILayout.Vector3Field("Bottom-Right", pivotPoint);
                graph.center = pivotPoint - diff;
                break;
            }

            graph.GenerateMatrix();

            pivot = PivotPointSelector(pivot);

        #if !UNITY_4
            EditorGUILayoutx.EndIndent();

            EditorGUILayoutx.BeginIndent();
        #else
            GUILayout.EndHorizontal();
        #endif

            graph.rotation = EditorGUILayout.Vector3Field("Rotation", graph.rotation);

        #if UNITY_LE_4_3
            //Add some space to make the Rotation and postion fields be better aligned (instead of the pivot point selector)
            //GUILayout.Space (19+7);
        #endif
            //GUILayout.EndHorizontal ();

        #if !UNITY_4
            EditorGUILayoutx.EndIndent();
        #endif
        #if UNITY_LE_4_3
            EditorGUIUtility.LookLikeInspector();
        #endif

            if (GUILayout.Button(new GUIContent("Snap Size", "Snap the size to exactly fit nodes"), GUILayout.MaxWidth(100), GUILayout.MaxHeight(16)))
            {
                SnapSizeToNodes(newWidth, newDepth, graph);
            }

            Separator();

            graph.cutCorners = EditorGUILayout.Toggle(new GUIContent("Cut Corners", "Enables or disables cutting corners. See docs for image example"), graph.cutCorners);
            graph.neighbours = (NumNeighbours)EditorGUILayout.EnumPopup(new GUIContent("Connections", "Sets how many connections a node should have to it's neighbour nodes."), graph.neighbours);

            //GUILayout.BeginHorizontal ();
            //EditorGUILayout.PrefixLabel ("Max Climb");
            graph.maxClimb = EditorGUILayout.FloatField(new GUIContent("Max Climb", "How high, relative to the graph, should a climbable level be. A zero (0) indicates infinity"), graph.maxClimb);
            if (graph.maxClimb < 0)
            {
                graph.maxClimb = 0;
            }
            EditorGUI.indentLevel++;
            graph.maxClimbAxis = EditorGUILayout.IntPopup(new GUIContent("Climb Axis", "Determines which axis the above setting should test on"), graph.maxClimbAxis, new GUIContent[3] {
                new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z")
            }, new int[3] {
                0, 1, 2
            });
            EditorGUI.indentLevel--;

            if (graph.maxClimb > 0 && Mathf.Abs((Quaternion.Euler(graph.rotation) * new Vector3(graph.nodeSize, 0, graph.nodeSize))[graph.maxClimbAxis]) > graph.maxClimb)
            {
                EditorGUILayout.HelpBox("Nodes are spaced further apart than this in the grid. You might want to increase this value or change the axis", MessageType.Warning);
            }

            //GUILayout.EndHorizontal ();

            graph.maxSlope = EditorGUILayout.Slider(new GUIContent("Max Slope", "Sets the max slope in degrees for a point to be walkable. Only enabled if Height Testing is enabled."), graph.maxSlope, 0, 90F);

            graph.erodeIterations = EditorGUILayout.IntField(new GUIContent("Erosion iterations", "Sets how many times the graph should be eroded. This adds extra margin to objects. This will not work when using Graph Updates, so if you can, use the Diameter setting in collision settings instead"), graph.erodeIterations);
            graph.erodeIterations = graph.erodeIterations < 0 ? 0 : (graph.erodeIterations > 16 ? 16 : graph.erodeIterations);             //Clamp iterations to [0,16]

            if (graph.erodeIterations > 0)
            {
                EditorGUI.indentLevel++;
                graph.erosionUseTags = EditorGUILayout.Toggle(new GUIContent("Erosion Uses Tags", "Instead of making nodes unwalkable, " +
                                                                             "nodes will have their tag set to a value corresponding to their erosion level, " +
                                                                             "which is a quite good measurement of their distance to the closest wall.\nSee online documentation for more info."),
                                                              graph.erosionUseTags);
                if (graph.erosionUseTags)
                {
                    EditorGUI.indentLevel++;
                    graph.erosionFirstTag = EditorGUILayoutx.SingleTagField("First Tag", graph.erosionFirstTag);
                    EditorGUI.indentLevel--;
                }
                EditorGUI.indentLevel--;
            }
            DrawCollisionEditor(graph.collision);

            if (graph.collision.use2D)
            {
                if (Mathf.Abs(Vector3.Dot(Vector3.forward, Quaternion.Euler(graph.rotation) * Vector3.up)) < 0.9f)
                {
                    EditorGUILayout.HelpBox("When using 2D it is recommended to rotate the graph so that it aligns with the 2D plane.", MessageType.Warning);
                }
            }

            Separator();

            showExtra = EditorGUILayout.Foldout(showExtra, "Extra");

            if (showExtra)
            {
                EditorGUI.indentLevel += 2;

                graph.penaltyAngle = ToggleGroup(new GUIContent("Angle Penalty", "Adds a penalty based on the slope of the node"), graph.penaltyAngle);
                //bool preGUI = GUI.enabled;
                //GUI.enabled = graph.penaltyAngle && GUI.enabled;
                if (graph.penaltyAngle)
                {
                    EditorGUI.indentLevel++;
                    graph.penaltyAngleFactor = EditorGUILayout.FloatField(new GUIContent("Factor", "Scale of the penalty. A negative value should not be used"), graph.penaltyAngleFactor);
                    //GUI.enabled = preGUI;
                    HelpBox("Applies penalty to nodes based on the angle of the hit surface during the Height Testing");

                    EditorGUI.indentLevel--;
                }

                graph.penaltyPosition = ToggleGroup("Position Penalty", graph.penaltyPosition);
                //EditorGUILayout.Toggle ("Position Penalty",graph.penaltyPosition);
                //preGUI = GUI.enabled;
                //GUI.enabled = graph.penaltyPosition && GUI.enabled;
                if (graph.penaltyPosition)
                {
                    EditorGUI.indentLevel++;
                    graph.penaltyPositionOffset = EditorGUILayout.FloatField("Offset", graph.penaltyPositionOffset);
                    graph.penaltyPositionFactor = EditorGUILayout.FloatField("Factor", graph.penaltyPositionFactor);
                    HelpBox("Applies penalty to nodes based on their Y coordinate\nSampled in Int3 space, i.e it is multiplied with Int3.Precision first (" + Int3.Precision + ")\n" +
                            "Be very careful when using negative values since a negative penalty will underflow and instead get really high");
                    //GUI.enabled = preGUI;
                    EditorGUI.indentLevel--;
                }

                GUI.enabled = false;
                ToggleGroup(new GUIContent("Use Texture", AstarPathEditor.AstarProTooltip), false);
                GUI.enabled            = true;
                EditorGUI.indentLevel -= 2;
            }
        }
        private void RenderList(SerializedProperty list)
        {
            EditorGUILayout.Space();
            GUILayout.BeginVertical();

            if (GUILayout.Button(AddButtonContent, EditorStyles.miniButton))
            {
                list.arraySize += 1;
                var speechCommand = list.GetArrayElementAtIndex(list.arraySize - 1);
                var keyword       = speechCommand.FindPropertyRelative("description");
                keyword.stringValue = string.Empty;
                var gestureType = speechCommand.FindPropertyRelative("gestureType");
                gestureType.intValue = (int)GestureInputType.None;
                var action   = speechCommand.FindPropertyRelative("action");
                var actionId = action.FindPropertyRelative("id");
                actionId.intValue = 0;
                var actionDescription = action.FindPropertyRelative("description");
                actionDescription.stringValue = string.Empty;
                var actionConstraint = action.FindPropertyRelative("axisConstraint");
                actionConstraint.intValue = 0;
            }

            GUILayout.Space(12f);

            if (list == null || list.arraySize == 0)
            {
                EditorGUILayout.HelpBox("Define a new Gesture.", MessageType.Warning);
                GUILayout.EndVertical();
                UpdateGestureLabels();
                return;
            }

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            var labelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = 24f;
            EditorGUILayout.LabelField(DescriptionContent, GUILayout.ExpandWidth(true));
            EditorGUILayout.LabelField(GestureTypeContent, GUILayout.Width(80f));
            EditorGUILayout.LabelField(ActionContent, GUILayout.Width(64f));
            EditorGUILayout.LabelField(string.Empty, GUILayout.Width(24f));
            EditorGUIUtility.labelWidth = labelWidth;
            GUILayout.EndHorizontal();

            for (int i = 0; i < list.arraySize; i++)
            {
                EditorGUILayout.BeginHorizontal();
                SerializedProperty gesture = list.GetArrayElementAtIndex(i);
                var keyword           = gesture.FindPropertyRelative("description");
                var gestureType       = gesture.FindPropertyRelative("gestureType");
                var action            = gesture.FindPropertyRelative("action");
                var actionId          = action.FindPropertyRelative("id");
                var actionDescription = action.FindPropertyRelative("description");
                var actionConstraint  = action.FindPropertyRelative("axisConstraint");

                EditorGUILayout.PropertyField(keyword, GUIContent.none, GUILayout.ExpandWidth(true));

                Debug.Assert(allGestureLabels.Length == allGestureIds.Length);

                var gestureLabels = new GUIContent[allGestureLabels.Length + 1];
                var gestureIds    = new int[allGestureIds.Length + 1];

                gestureLabels[0] = new GUIContent(((GestureInputType)gestureType.intValue).ToString());
                gestureIds[0]    = gestureType.intValue;

                for (int j = 0; j < allGestureLabels.Length; j++)
                {
                    gestureLabels[j + 1] = allGestureLabels[j];
                    gestureIds[j + 1]    = allGestureIds[j];
                }

                EditorGUI.BeginChangeCheck();
                gestureType.intValue = EditorGUILayout.IntPopup(GUIContent.none, gestureType.intValue, gestureLabels, gestureIds, GUILayout.Width(80f));

                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                    UpdateGestureLabels();
                }

                EditorGUI.BeginChangeCheck();
                actionId.intValue = EditorGUILayout.IntPopup(GUIContent.none, actionId.intValue, actionLabels, actionIds, GUILayout.Width(64f));

                if (EditorGUI.EndChangeCheck())
                {
                    MixedRealityInputAction inputAction = actionId.intValue == 0 ? MixedRealityInputAction.None : MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1];
                    actionDescription.stringValue   = inputAction.Description;
                    actionConstraint.enumValueIndex = (int)inputAction.AxisConstraint;
                    serializedObject.ApplyModifiedProperties();
                }

                if (GUILayout.Button(MinusButtonContent, EditorStyles.miniButtonRight, GUILayout.Width(24f)))
                {
                    list.DeleteArrayElementAtIndex(i);
                    serializedObject.ApplyModifiedProperties();
                    UpdateGestureLabels();
                }

                EditorGUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();
            GUILayout.EndVertical();
        }
Beispiel #9
0
    // Shows the inspector.
    public override void OnInspectorGUI()
    {
        // Update the references.
        serializedObject.Update();

        // Audio input settings.
        propAudioMode.intValue = EditorGUILayout.IntPopup("Audio Source", propAudioMode.intValue, sourceLabels, sourceOptions);
        if (propAudioMode.intValue > 0)
        {
            var label = (propAudioMode.intValue == (int)Reaktor.AudioMode.SpecturmBand) ? "Band Index" : "Channel";
            propAudioIndex.intValue            = EditorGUILayout.IntField(label, propAudioIndex.intValue);
            propAudioCurve.animationCurveValue = EditorGUILayout.CurveField("Curve", propAudioCurve.animationCurveValue);
        }

        // Gain control.
        if (propAudioMode.intValue > 0)
        {
            if (propGainEnabled.boolValue || propOffsetEnabled.boolValue)
            {
                EditorGUILayout.Space();
            }

            if (propGainEnabled.boolValue = EditorGUILayout.Toggle("Gain Control", propGainEnabled.boolValue))
            {
                propGainKnobIndex.intValue        = EditorGUILayout.IntField("MIDI CC #", propGainKnobIndex.intValue);
                propGainKnobChannel.intValue      = EditorGUILayout.IntPopup("MIDI Channel", propGainKnobChannel.intValue, midiChannelLabels, midiChannelOptions);
                propGainCurve.animationCurveValue = EditorGUILayout.CurveField("Curve", propGainCurve.animationCurveValue);
            }
        }

        // Offset control.
        if (propGainEnabled.boolValue || propOffsetEnabled.boolValue)
        {
            EditorGUILayout.Space();
        }

        if (propOffsetEnabled.boolValue = EditorGUILayout.Toggle("Offset Control", propOffsetEnabled.boolValue))
        {
            propOffsetKnobIndex.intValue        = EditorGUILayout.IntField("MIDI CC #", propOffsetKnobIndex.intValue);
            propOffsetKnobChannel.intValue      = EditorGUILayout.IntPopup("MIDI Channel", propOffsetKnobChannel.intValue, midiChannelLabels, midiChannelOptions);
            propOffsetCurve.animationCurveValue = EditorGUILayout.CurveField("Curve", propOffsetCurve.animationCurveValue);
        }

        if (propGainEnabled.boolValue || propOffsetEnabled.boolValue)
        {
            EditorGUILayout.Space();
        }

        // General option.
        {
            var value = propSensitivity.floatValue;
            if (value > 0.0f)
            {
                value = EditorGUILayout.Slider("Sensitivity", (value - 0.1f) / 30, 0.0f, 1.0f);
            }
            else
            {
                value = EditorGUILayout.Slider("(Filter Off)", 1.0f, 0.0f, 1.0f);
            }
            propSensitivity.floatValue = (value == 1.0f) ? 0.0f : value * 30 + 0.1f;
        }

        // Audio input options.
        if (propAudioMode.intValue > 0)
        {
            if (propShowAudioOptions.boolValue = EditorGUILayout.Foldout(propShowAudioOptions.boolValue, "Audio Input Options"))
            {
                EditorGUILayout.Slider(propHeadroom, 0.0f, 20.0f, "Headroom [dB]");
                EditorGUILayout.Slider(propDynamicRange, 1.0f, 60.0f, "Dynamic Range [dB]");
                EditorGUILayout.Slider(propLowerBound, -100.0f, -10.0f, "Lower Bound [dB]");
                EditorGUILayout.Slider(propFalldown, 0.0f, 10.0f, "Falldown [dB/Sec]");
            }
        }

        // Apply modifications.
        serializedObject.ApplyModifiedProperties();

        // Draw the level bar on play mode.
        if (EditorApplication.isPlaying && !serializedObject.isEditingMultipleObjects)
        {
            EditorGUILayout.Space();
            DrawInputLevelBars(target as Reaktor);
            EditorUtility.SetDirty(target);  // Make it dirty to update the view.
        }
    }
    private void OnGUI()
    {
        if (_gameSettingData == null)
        {
            GetGameSettingData();
        }

        _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);
        {
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("ProductName : " + PlayerSettings.productName);
            EditorGUILayout.LabelField("Bundle Identifier : " + PlayerSettings.applicationIdentifier);
            EditorGUILayout.LabelField("Bundle Version : " + PlayerSettings.bundleVersion);
            EditorGUILayout.LabelField("Bundle Version Code: " + PlayerSettings.Android.bundleVersionCode);
            EditorGUILayout.LabelField("HttpRoot: " + _gameSettingData.httpRoot);
            EditorGUILayout.LabelField("BuildToFile: " + _buildToFileName);
            EditorGUILayout.LabelField("projmods: " + _buildProjmods);
            EditorGUILayout.Space();

            //GameType选项
            int selectGameTypeIndex = EditorGUILayout.IntPopup("GameType :", _lastSelectGameTypeIndex,
                                                               _gameTypeValues, _gameTypeKeys);

            if (_lastSelectGameTypeIndex != selectGameTypeIndex)
            {
                _lastSelectGameTypeIndex  = selectGameTypeIndex;
                _gameSettingData.gameType = _gameTypeValues[_lastSelectGameTypeIndex];
                GameInfo gameInfo = _gameInfoDic[_gameSettingData.gameType];
                _gameSettingData.gamename     = gameInfo.gamename;
                _gameSettingData.configSuffix = gameInfo.configSuffix;

                LoadSPChannelConfig(_gameSettingData.configSuffix, true);
            }

            if (_gameInfoDic.ContainsKey(_gameSettingData.gameType) == false)
            {
                EditorGUILayout.LabelField(string.Format("GameType {0} no support!!!", _gameSettingData.gameType));
                EditorGUILayout.EndScrollView();
                return;
            }

            //Domain类型选项
            UpdateDomainList(_gameSettingData.gameType, _gameSettingData.domainType);
            _lastSelectDomainIndex = EditorGUILayout.IntPopup("DomainType : ", _lastSelectDomainIndex,
                                                              _domainValues, _domainKeys);

            _gameSettingData.domainType = GetDomianType(_gameSettingData.gameType, _lastSelectDomainIndex);

            DomainInfo domainInfo = GetDomainInfo(_gameSettingData.gameType, _gameSettingData.domainType);
            if (domainInfo == null)
            {
                EditorGUILayout.LabelField(string.Format("DomainType {0} no support!!!", _gameSettingData.domainType));
                EditorGUILayout.EndScrollView();
                return;
            }
            _gameSettingData.httpRoot = domainInfo.url;
            _gameSettingData.resdir   = domainInfo.resdir;

            //Platform类型选项
            _gameSettingData.platformType = (GameSetting.PlatformType)EditorGUILayout.EnumPopup("PlatformType :", _gameSettingData.platformType);

            //Channel类型选项
            UpdateSpSdkList(_gameSettingData.domainType, _gameSettingData.platformType, _gameSettingData.channel);
            if (_channelKeys != null && _channelValues != null)
            {
                _lastSelectChannelIndex = EditorGUILayout.IntPopup("Channel : ", _lastSelectChannelIndex,
                                                                   _channelValues, _channelKeys);
            }
            else
            {
                EditorGUILayout.LabelField("Channel : Load channel Info Failed!!!");
                EditorGUILayout.EndScrollView();
                return;
            }

            if (_channelValues.Length > _lastSelectChannelIndex)
            {
                _gameSettingData.channel = _channelValues[_lastSelectChannelIndex];
            }

            //资源加载配置选项
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("注意:加载模式的更改只对编辑器运行时有效,打包手机包时选择Mobile模式");
            _resLoadMode = (AssetPipeline.AssetManager.LoadMode)EditorGUILayout.EnumPopup("资源加载模式 :", _resLoadMode);

            //调试选项
            EditorGUILayout.Space();
            _gameSettingData.release        = EditorGUILayout.Toggle("Client Release : ", _gameSettingData.release);
            _gameSettingData.testServerMode = EditorGUILayout.Toggle("压测模式 : ", _gameSettingData.testServerMode);
            _gameSettingData.gmMode         = EditorGUILayout.Toggle("GM模式 : ", _gameSettingData.gmMode);
            developmentBuild = EditorGUILayout.Toggle("Development Build : ", developmentBuild);
            EditorGUILayout.Toggle("MinRes Build : ", _minResBuild);
            _enableJSB = EditorGUILayout.Toggle("Enable JSB: ", _enableJSB);
            _useJsz    = EditorGUILayout.Toggle("Use Jsz: ", _useJsz);
            _gameSettingData.logType = (GameSetting.DebugInfoType)EditorGUILayout.EnumPopup("调试信息类型 :", _gameSettingData.logType);

            EditorGUILayout.Space();
            GUI.color = Color.yellow;
            if (GUILayout.Button("保存配置", GUILayout.Height(40)))
            {
                if (!CheckIsCompiling())
                {
                    SaveComeFromConfig();
                }
            }

#if UNITY_ANDROID
            EditorGUILayout.Space();
            if (GUILayout.Button("导出Android Project", GUILayout.Height(40)))
            {
                string outPutPath = EditorUtility.OpenFolderPanel("导出Android工程目录", "", "");
                if (!string.IsNullOrEmpty(outPutPath))
                {
                    EditorHelper.Run(() => ExportAndroidProject(outPutPath), true, false);
                }
            }

            EditorGUILayout.Space();
            if (GUILayout.Button("打包当前渠道", GUILayout.Height(40)))
            {
                if (EditorUtility.DisplayDialog("打包确认", "是否确认打包当前渠道?", "确认打包", "取消"))
                {
                    EditorApplication.delayCall += () => BuildAndroid();
                }
            }

            //			EditorGUILayout.Space ();
            //			if (GUILayout.Button ("打包所有商务渠道", GUILayout.Height (40))) {
            //				if (EditorUtility.DisplayDialog ("打包确认", "是否确认打包所有渠道?", "确认打包", "取消")) {
            //
            //				}
            //			}
#endif

#if UNITY_IPHONE
            EditorGUILayout.Space();
            if (GUILayout.Button("Expor2XCODE", GUILayout.Height(40)))
            {
                if (EditorUtility.DisplayDialog("导出确认", "是否确认导出XCODE?", "确认", "取消"))
                {
                    EditorApplication.delayCall += () =>
                    {
                        string applicationPath = Application.dataPath.Replace("/Assets", "/../..");
                        string target_dir      = EditorUtility.OpenFolderPanel("导出目录", applicationPath, "xcode");
                        BuildIOS(target_dir);
                    };
                }
            }

            EditorGUILayout.Space();
            if (GUILayout.Button("ExportAllIpa", GUILayout.Height(40)))
            {
                EditorApplication.delayCall += () => BuildAllIpa();
            }
#endif

#if UNITY_STANDALONE_WIN && !UNITY_IPHONE
            EditorGUILayout.Space();
            if (GUILayout.Button("一按键打包PC", GUILayout.Height(40)))
            {
                if (EditorUtility.DisplayDialog("打包确认", "是否确认打包PC版?", "确认打包", "取消"))
                {
                    EditorApplication.delayCall += () => BuildPC();
                }
            }
#endif
            EditorGUILayout.Space();
            GUI.color = Color.green;
            if (GUILayout.Button("清除本地数据和PlayerPrefs", GUILayout.Height(40)))
            {
                EditorApplication.delayCall += () =>
                {
                    Debug.Log("清除本地数据和PlayerPrefs");
                    PlayerPrefs.DeleteAll();
                    FileUtil.DeleteFileOrDirectory(Application.persistentDataPath);
                };
            }
            GUI.color = Color.white;

            EditorGUILayout.Space();
            if (GUILayout.Button("上传Dlls", GUILayout.Height(40)))
            {
                GameResVersionManager.UploadDllsPatch();
            }

            EditorGUILayout.Space();
            if (GUILayout.Button("一键打包", GUILayout.Height(40)))
            {
                OneKeyBuildStep1();
            }
        }
        EditorGUILayout.EndScrollView();
    }
Beispiel #11
0
        private void DebugParametersUI(HDRenderPipeline renderContext)
        {
            m_ShowDebug.boolValue = EditorGUILayout.Foldout(m_ShowDebug.boolValue, styles.debugParameters);
            if (!m_ShowDebug.boolValue)
            {
                return;
            }

            var debugParameters = renderContext.debugParameters;

            EditorGUI.indentLevel++;
            EditorGUI.BeginChangeCheck();

            if (!styles.isDebugViewMaterialInit)
            {
                var varyingNames = Enum.GetNames(typeof(Attributes.DebugViewVarying));
                var gbufferNames = Enum.GetNames(typeof(Attributes.DebugViewGbuffer));

                // +1 for the zero case
                var num = 1 + varyingNames.Length
                          + gbufferNames.Length
                          + typeof(Builtin.BuiltinData).GetFields().Length * 2 // BuildtinData are duplicated for each material
                          + typeof(Lit.SurfaceData).GetFields().Length
                          + typeof(Lit.BSDFData).GetFields().Length
                          + typeof(Unlit.SurfaceData).GetFields().Length
                          + typeof(Unlit.BSDFData).GetFields().Length;

                styles.debugViewMaterialStrings = new GUIContent[num];
                styles.debugViewMaterialValues  = new int[num];

                var index = 0;

                // 0 is a reserved number
                styles.debugViewMaterialStrings[0] = new GUIContent("None");
                styles.debugViewMaterialValues[0]  = 0;
                index++;

                FillWithPropertiesEnum(typeof(Attributes.DebugViewVarying), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, GetSubNameSpaceName(typeof(Attributes.DebugViewVarying)), false, ref index);
                FillWithProperties(typeof(Builtin.BuiltinData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, GetSubNameSpaceName(typeof(Lit.SurfaceData)), ref index);
                FillWithProperties(typeof(Lit.SurfaceData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, GetSubNameSpaceName(typeof(Lit.SurfaceData)), ref index);
                FillWithProperties(typeof(Builtin.BuiltinData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, GetSubNameSpaceName(typeof(Unlit.SurfaceData)), ref index);
                FillWithProperties(typeof(Unlit.SurfaceData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, GetSubNameSpaceName(typeof(Unlit.SurfaceData)), ref index);

                // Engine
                FillWithPropertiesEnum(typeof(Attributes.DebugViewGbuffer), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, "", true, ref index);
                FillWithProperties(typeof(Lit.BSDFData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, true, "", ref index);
                FillWithProperties(typeof(Unlit.BSDFData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, true, "", ref index);

                styles.isDebugViewMaterialInit = true;
            }

            debugParameters.debugViewMaterial = EditorGUILayout.IntPopup(styles.debugViewMaterial, (int)debugParameters.debugViewMaterial, styles.debugViewMaterialStrings, styles.debugViewMaterialValues);

            EditorGUILayout.Space();
            debugParameters.displayOpaqueObjects      = EditorGUILayout.Toggle(styles.displayOpaqueObjects, debugParameters.displayOpaqueObjects);
            debugParameters.displayTransparentObjects = EditorGUILayout.Toggle(styles.displayTransparentObjects, debugParameters.displayTransparentObjects);
            debugParameters.useForwardRenderingOnly   = EditorGUILayout.Toggle(styles.useForwardRenderingOnly, debugParameters.useForwardRenderingOnly);
            debugParameters.useDepthPrepass           = EditorGUILayout.Toggle(styles.useDepthPrepass, debugParameters.useDepthPrepass);
            debugParameters.useDistortion             = EditorGUILayout.Toggle(styles.useDistortion, debugParameters.useDistortion);

            if (EditorGUI.EndChangeCheck())
            {
                HackSetDirty(renderContext); // Repaint
            }
            EditorGUI.indentLevel--;
        }
Beispiel #12
0
        public override void OnInspectorGUI()
        {
            AnimatorData anim = target as AnimatorData;

            GUILayout.BeginVertical();

            //meta
            AnimatorMeta curMeta = aData.meta;
            AnimatorMeta newMeta = EditorGUILayout.ObjectField(new GUIContent("Meta", "Use data from the reference AnimatorMeta. Note: All modifications to the animation will be saved to the Meta."), curMeta, typeof(AnimatorMeta), false) as AnimatorMeta;

            if (curMeta != newMeta)
            {
                bool doIt = true;
                if (curMeta == null)
                {
                    doIt = UnityEditor.EditorUtility.DisplayDialog("Set Meta", "Setting the Meta will replace the current animation data, proceed?", "Yes", "No");
                }

                if (doIt)
                {
                    aData.RegisterUndo("Set Meta", true);
                    aData.MetaSet(newMeta, false);
                }
            }

            MetaCommand metaComm = MetaCommand.None;

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            GUI.backgroundColor = Color.green;

            GUI.enabled = PrefabUtility.GetPrefabType(aData.gameObject) != PrefabType.Prefab && aData.metaCanSavePrefabInstance;
            if (GUILayout.Button("Save", GUILayout.Width(100f)))
            {
                metaComm = MetaCommand.Save;
            }

            GUI.enabled = true;
            if (GUILayout.Button("Save As...", GUILayout.Width(100f)))
            {
                metaComm = MetaCommand.SaveAs;
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            GUI.backgroundColor = Color.red;

            GUI.enabled = PrefabUtility.GetPrefabType(aData.gameObject) != PrefabType.Prefab && aData.metaCanSavePrefabInstance;
            if (GUILayout.Button("Revert", GUILayout.Width(100f)))
            {
                metaComm = MetaCommand.Revert;
            }

            GUI.backgroundColor = Color.white;

            GUI.enabled = PrefabUtility.GetPrefabType(aData.gameObject) != PrefabType.Prefab && aData.meta;
            if (GUILayout.Button(new GUIContent("Break", "This will copy all data from AnimatorMeta to this AnimatorData, and then removes the reference to AnimatorMeta."), GUILayout.Width(100f)))
            {
                metaComm = MetaCommand.Instantiate;
            }
            GUI.enabled = true;

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            EditorUtility.DrawSeparator();
            //

            List <AMTakeData> takes        = aData.takes;
            string            playTakeName = aData.defaultTakeName;
            int playTakeInd = 0;

            if (!string.IsNullOrEmpty(playTakeName))
            {
                for (int i = 0; i < takes.Count; i++)
                {
                    if (takes[i].name == aData.defaultTakeName)
                    {
                        playTakeInd = i + 1;
                        break;
                    }
                }
            }

            GenerateTakeLabels();
            int newPlayTakeInd = EditorGUILayout.IntPopup("Play On Start", playTakeInd, mTakeLabels, null);

            if (newPlayTakeInd != playTakeInd)
            {
                aData.RegisterUndo("Set Play On Start", false);
                aData.defaultTakeName = newPlayTakeInd <= 0 ? "" : takes[newPlayTakeInd - 1].name;
            }

            bool isglobal = GUILayout.Toggle(aData.isGlobal, "Global");

            if (aData.isGlobal != isglobal)
            {
                aData.RegisterUndo("Set Global", false);
                aData.isGlobal = isglobal;
                if (isglobal)
                {
                    //uncheck isGlobal to any other animator data on scene
                    AnimatorData[] anims = FindObjectsOfType <AnimatorData>();
                    for (int i = 0; i < anims.Length; i++)
                    {
                        if (!aData.IsDataMatch(anims[i]) && anims[i].isGlobal)
                        {
                            anims[i].isGlobal = false;
                        }
                    }
                }
            }

            var sequenceLoadAll = GUILayout.Toggle(anim.sequenceLoadAll, "Build All Sequence On Start");

            if (anim.sequenceLoadAll != sequenceLoadAll)
            {
                aData.RegisterUndo("Set Sequence Load All", false);
                anim.sequenceLoadAll = sequenceLoadAll;
            }

            var sequenceKillWhenDone = GUILayout.Toggle(anim.sequenceKillWhenDone, "Kill Sequence When Done");

            if (anim.sequenceKillWhenDone != sequenceKillWhenDone)
            {
                aData.RegisterUndo("Set Sequence Kill All When Done", false);
                anim.sequenceKillWhenDone = sequenceKillWhenDone;
            }

            var playOnEnable = GUILayout.Toggle(anim.playOnEnable, "Play On Enable");

            if (anim.playOnEnable != playOnEnable)
            {
                aData.RegisterUndo("Set Play On Enable", false);
                anim.playOnEnable = playOnEnable;
            }

            var onDisableAction = (AnimatorData.DisableAction)EditorGUILayout.EnumPopup("On Disable", anim.onDisableAction);

            if (anim.onDisableAction != onDisableAction)
            {
                aData.RegisterUndo("Set On Disable Action", false);
                anim.onDisableAction = onDisableAction;
            }

            var updateType = (DG.Tweening.UpdateType)EditorGUILayout.EnumPopup("Update", anim.updateType);

            if (anim.updateType != updateType)
            {
                aData.RegisterUndo("Set Update Type", false);
                anim.updateType = updateType;
            }

            var updateTimeIndependent = EditorGUILayout.Toggle("Time Independent", anim.updateTimeIndependent);

            if (anim.updateTimeIndependent != updateTimeIndependent)
            {
                aData.RegisterUndo("Set Time Independent", false);
                anim.updateTimeIndependent = updateTimeIndependent;
            }

            if (PrefabUtility.GetPrefabType(aData.gameObject) != PrefabType.Prefab)
            {
                AMTimeline timeline = AMTimeline.window;

                if (timeline != null && aData == timeline.aData)
                {
                    if (GUILayout.Button("Deselect"))
                    {
                        timeline.aData = null;
                        timeline.Repaint();

                        if (Selection.activeGameObject == aData.gameObject)
                        {
                            Selection.activeGameObject = null;
                        }
                    }
                }
                else
                {
                    if (GUILayout.Button("Edit Timeline"))
                    {
                        if (timeline != null)
                        {
                            timeline.aData = aData;
                            timeline.Repaint();
                        }
                        else
                        {
                            EditorWindow.GetWindow(typeof(AMTimeline));
                        }
                    }
                }
            }

            //display missings
            string[] missings = aData.target.GetMissingTargets();
            if (missings != null && missings.Length > 0)
            {
                EditorUtility.DrawSeparator();
                mMissingsFoldout = EditorGUILayout.Foldout(mMissingsFoldout, string.Format("Missing Targets [{0}]", missings.Length));
                if (mMissingsFoldout)
                {
                    for (int i = 0; i < missings.Length; i++)
                    {
                        GUILayout.Label(missings[i]);
                    }
                }

                //fix missing targets
                if (GUILayout.Button("Generate Missing Targets"))
                {
                    aData.target.GenerateMissingTargets(missings);
                }
            }

            GUILayout.EndVertical();

            switch (metaComm)
            {
            case MetaCommand.Save:
                aData.MetaSaveInstantiate();
                GUI.changed = true;
                break;

            case MetaCommand.SaveAs:
                string path = UnityEditor.EditorUtility.SaveFilePanelInProject("Save AnimatorMeta", aData.name + ".prefab", "prefab", "Please enter a file name to save the animator data to");
                if (!string.IsNullOrEmpty(path))
                {
                    GameObject metago = new GameObject("_meta");
                    metago.AddComponent <AnimatorMeta>();
                    UnityEngine.Object pref       = PrefabUtility.CreateEmptyPrefab(path);
                    GameObject         metagopref = PrefabUtility.ReplacePrefab(metago, pref);
                    UnityEngine.Object.DestroyImmediate(metago);
                    aData.MetaSet(metagopref.GetComponent <AnimatorMeta>(), true);
                }
                break;

            case MetaCommand.Revert:
                if (UnityEditor.EditorUtility.DisplayDialog("Revert Animator Meta", "Are you sure?", "Yes", "No"))
                {
                    aData.RegisterUndo("Revert Animator Meta", true);
                    GameObject prefabGO = PrefabUtility.GetPrefabParent(aData.meta.gameObject) as GameObject;
                    aData.MetaSet(prefabGO ? prefabGO.GetComponent <AnimatorMeta>() : null, false);
                    GUI.changed = true;
                }
                break;

            case MetaCommand.Instantiate:
                //warning if there are missing targets
                bool doIt = true;
                if (missings != null && missings.Length > 0)
                {
                    doIt = UnityEditor.EditorUtility.DisplayDialog("Break Animator Meta", "There are missing targets, some keys will be removed. Do you want to proceed?", "Yes", "No");
                }
                if (doIt)
                {
                    aData.RegisterUndo("Break Animator Meta", false);
                    aData.MetaSet(null, true);
                    aData.currentTakeInd = 0;
                    GUI.changed          = true;
                }
                break;
            }

            if (GUI.changed)
            {
                if (AMTimeline.window)
                {
                    if (metaComm != MetaCommand.None)
                    {
                        AMTimeline.window.Reload();
                    }
                    else
                    {
                        AMTimeline.window.Repaint();
                    }
                }
            }
        }
Beispiel #13
0
    public static void InspectorGUI(BuildrEditMode editMode, BuildrData data)
    {
        BuildrDetail[] details         = data.details.ToArray();
        int            numberOfDetails = details.Length;

        selectedDetail = Mathf.Clamp(selectedDetail, 0, numberOfDetails - 1);

        if (numberOfDetails == 0)
        {
            EditorGUILayout.HelpBox("There are no details to show", MessageType.Info);
            if (GUILayout.Button("Add New"))
            {
                data.details.Add(new BuildrDetail("new detail " + numberOfDetails));
                numberOfDetails++;
                selectedDetail = numberOfDetails - 1;
            }
            return;
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Detail", GUILayout.Width(75));
        string[] detailNames = new string[numberOfDetails];
        for (int t = 0; t < numberOfDetails; t++)
        {
            detailNames[t] = details[t].name;
        }
        selectedDetail = EditorGUILayout.Popup(selectedDetail, detailNames);
        EditorGUILayout.EndHorizontal();

        BuildrDetail bDetail = details[selectedDetail];

        EditorGUILayout.BeginHorizontal();

        EditorGUILayout.Space();

        if (GUILayout.Button("Add New", GUILayout.Width(81)))
        {
            data.details.Add(new BuildrDetail("new detail " + numberOfDetails));
            numberOfDetails++;
            selectedDetail = numberOfDetails - 1;
        }


        if (GUILayout.Button("Duplicate", GUILayout.Width(90)))
        {
            data.details.Add(bDetail.Duplicate());
            numberOfDetails++;
            selectedDetail = numberOfDetails - 1;
        }

        if (GUILayout.Button("Delete", GUILayout.Width(71)))
        {
            if (EditorUtility.DisplayDialog("Deleting Building Detail Entry", "Are you sure you want to delete this detail?", "Delete", "Cancel"))
            {
                data.details.Remove(bDetail);
                selectedDetail = 0;
                GUI.changed    = true;

                return;
            }
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();

        details     = data.details.ToArray();
        detailNames = new string[numberOfDetails];
        for (int t = 0; t < numberOfDetails; t++)
        {
            detailNames[t] = details[t].name;
        }
        bDetail = details[selectedDetail];//reassign

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.BeginVertical();

        bDetail.name = EditorGUILayout.TextField("Name", bDetail.name);

        bDetail.mesh = (Mesh)EditorGUILayout.ObjectField("Mesh", bDetail.mesh, typeof(Mesh), false);
        EditorGUIUtility.LookLikeControls();
        bDetail.material.mainTexture = (Texture)EditorGUILayout.ObjectField("Texture", bDetail.material.mainTexture, typeof(Texture), false, GUILayout.Height(140));

        if (bDetail.material.mainTexture != null)
        {
            string          texturePath     = AssetDatabase.GetAssetPath(bDetail.material.mainTexture);
            TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(texturePath);

            if (!textureImporter.isReadable)
            {
                EditorGUILayout.HelpBox("The texture you have selected is not readable." +
                                        "\nPlease select the readable checkbox under advanced texture settings." +
                                        "\nOr move this texture to the BuildR texture folder and reimport.",
                                        MessageType.Error);
            }
        }

        BuildrPlan    plan                    = data.plan;
        int           numberOfVolumes         = plan.numberOfVolumes;
        int           numberOfFaces           = 0;
        List <int>    faceSeletionsList       = new List <int>();
        List <string> faceSeletionsStringList = new List <string>();

        if (bDetail.type == BuildrDetail.Types.Facade)
        {
            for (int s = 0; s < numberOfVolumes; s++)
            {
                int numberOfPoints = plan.volumes[s].Count;
                numberOfFaces += numberOfPoints;
                for (int p = 0; p < numberOfPoints; p++)
                {
                    int index = faceSeletionsList.Count;
                    faceSeletionsStringList.Add("facade " + index);
                    faceSeletionsList.Add(index);
                }
            }
        }
        else
        {
            bDetail.face = Mathf.Clamp(0, numberOfVolumes - 1, bDetail.face);
            for (int s = 0; s < numberOfVolumes; s++)
            {
                int index = faceSeletionsList.Count;
                faceSeletionsStringList.Add("roof " + index);
                faceSeletionsList.Add(index);
            }
        }

        if (!clickPlace)
        {
            if (GUILayout.Button("Place Detail with Mouse"))
            {
                clickPlace = true;
            }
        }
        else
        {
            if (GUILayout.Button("Cancel Place Detail"))
            {
                clickPlace = false;
            }
        }

        BuildrDetail.Types bDetailtype = (BuildrDetail.Types)EditorGUILayout.EnumPopup("Face Type", bDetail.type);
        if (bDetailtype != bDetail.type)
        {
            bDetail.type = bDetailtype;
        }
        int[]    faceSelections      = faceSeletionsList.ToArray();
        string[] faceSelectionString = faceSeletionsStringList.ToArray();
        int      bDetailface         = EditorGUILayout.IntPopup("Selected Face", bDetail.face, faceSelectionString, faceSelections);

        if (bDetailface != bDetail.face)
        {
            bDetail.face = bDetailface;
        }

        Vector2 bDetailfaceUv = EditorGUILayout.Vector2Field("Face UV", bDetail.faceUv);

        if (bDetailfaceUv != bDetail.faceUv)
        {
            bDetail.faceUv = bDetailfaceUv;
        }
        float bDetailfaceHeight = EditorGUILayout.FloatField("Face Height", bDetail.faceHeight);

        if (bDetailfaceHeight != bDetail.faceHeight)
        {
            bDetail.faceHeight = bDetailfaceHeight;
        }
        Vector3 bDetailuserRotation = EditorGUILayout.Vector3Field("Rotation", bDetail.userRotation);

        if (bDetailuserRotation != bDetail.userRotation)
        {
            bDetail.userRotation = bDetailuserRotation;
        }
        Vector3 bDetailscale = EditorGUILayout.Vector3Field("Object Scale", bDetail.scale);

        if (bDetailscale != bDetail.scale)
        {
            bDetail.scale = bDetailscale;
        }

        EditorGUILayout.EndVertical();
        EditorGUILayout.BeginVertical(GUILayout.Width(120));
        if (bDetail.mesh != null)
        {
            Texture2D previewMeshImage = AssetPreview.GetAssetPreview(bDetail.mesh);
            GUILayout.Label(previewMeshImage);
        }
        else
        {
            Texture2D previewMeshImage = new Texture2D(118, 118);
            GUILayout.Label(previewMeshImage);
            GUILayout.Label("No Mesh Selected");
        }

        if (bDetail.material.mainTexture != null)
        {
            Texture previewMeshImage = bDetail.material.mainTexture;
            GUILayout.Label(previewMeshImage, GUILayout.Width(128), GUILayout.Height(128));
        }
        else
        {
            Texture2D previewMeshImage = new Texture2D(118, 118);
            GUILayout.Label(previewMeshImage);
            GUILayout.Label("No Texture Selected");
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndHorizontal();
    }
        private void RenderList(SerializedProperty list)
        {
            // Disable gestures list if we could not initialize successfully
            using (new GUIEnabledWrapper(isInitialized, false))
            {
                EditorGUILayout.Space();
                using (new EditorGUILayout.VerticalScope())
                {
                    if (InspectorUIUtility.RenderIndentedButton(AddButtonContent, EditorStyles.miniButton))
                    {
                        list.arraySize += 1;
                        var speechCommand = list.GetArrayElementAtIndex(list.arraySize - 1);
                        var keyword       = speechCommand.FindPropertyRelative("description");
                        keyword.stringValue = string.Empty;
                        var gestureType = speechCommand.FindPropertyRelative("gestureType");
                        gestureType.intValue = (int)GestureInputType.None;
                        var action   = speechCommand.FindPropertyRelative("action");
                        var actionId = action.FindPropertyRelative("id");
                        actionId.intValue = 0;
                        var actionDescription = action.FindPropertyRelative("description");
                        actionDescription.stringValue = string.Empty;
                        var actionConstraint = action.FindPropertyRelative("axisConstraint");
                        actionConstraint.intValue = 0;
                    }

                    if (list == null || list.arraySize == 0)
                    {
                        EditorGUILayout.HelpBox("Define a new Gesture.", MessageType.Warning);
                        UpdateGestureLabels();
                        return;
                    }

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        var labelWidth = EditorGUIUtility.labelWidth;
                        EditorGUIUtility.labelWidth = 24f;
                        EditorGUILayout.LabelField(DescriptionContent, GUILayout.ExpandWidth(true));
                        EditorGUILayout.LabelField(GestureTypeContent, GUILayout.Width(80f));
                        EditorGUILayout.LabelField(ActionContent, GUILayout.Width(64f));
                        EditorGUILayout.LabelField(string.Empty, GUILayout.Width(24f));
                        EditorGUIUtility.labelWidth = labelWidth;
                    }

                    var inputActions = GetInputActions();

                    for (int i = 0; i < list.arraySize; i++)
                    {
                        using (new EditorGUILayout.HorizontalScope())
                        {
                            SerializedProperty gesture = list.GetArrayElementAtIndex(i);
                            var keyword           = gesture.FindPropertyRelative("description");
                            var gestureType       = gesture.FindPropertyRelative("gestureType");
                            var action            = gesture.FindPropertyRelative("action");
                            var actionId          = action.FindPropertyRelative("id");
                            var actionDescription = action.FindPropertyRelative("description");
                            var actionConstraint  = action.FindPropertyRelative("axisConstraint");

                            EditorGUILayout.PropertyField(keyword, GUIContent.none, GUILayout.ExpandWidth(true));

                            Debug.Assert(allGestureLabels.Length == allGestureIds.Length);

                            var gestureLabels = new GUIContent[allGestureLabels.Length + 1];
                            var gestureIds    = new int[allGestureIds.Length + 1];

                            gestureLabels[0] = new GUIContent(((GestureInputType)gestureType.intValue).ToString());
                            gestureIds[0]    = gestureType.intValue;

                            for (int j = 0; j < allGestureLabels.Length; j++)
                            {
                                gestureLabels[j + 1] = allGestureLabels[j];
                                gestureIds[j + 1]    = allGestureIds[j];
                            }

                            EditorGUI.BeginChangeCheck();
                            gestureType.intValue = EditorGUILayout.IntPopup(GUIContent.none, gestureType.intValue, gestureLabels, gestureIds, GUILayout.Width(80f));

                            if (EditorGUI.EndChangeCheck())
                            {
                                serializedObject.ApplyModifiedProperties();
                                UpdateGestureLabels();
                            }

                            EditorGUI.BeginChangeCheck();

                            actionId.intValue = EditorGUILayout.IntPopup(GUIContent.none, actionId.intValue, actionLabels, actionIds, GUILayout.Width(64f));

                            if (EditorGUI.EndChangeCheck())
                            {
                                MixedRealityInputAction inputAction = MixedRealityInputAction.None;
                                int idx = actionId.intValue - 1;
                                if (idx >= 0 && idx < inputActions.Length)
                                {
                                    inputAction = inputActions[idx];
                                }

                                actionDescription.stringValue   = inputAction.Description;
                                actionConstraint.enumValueIndex = (int)inputAction.AxisConstraint;
                                serializedObject.ApplyModifiedProperties();
                            }

                            if (GUILayout.Button(MinusButtonContent, EditorStyles.miniButtonRight, GUILayout.Width(24f)))
                            {
                                list.DeleteArrayElementAtIndex(i);
                                serializedObject.ApplyModifiedProperties();
                                UpdateGestureLabels();
                            }
                        }
                    }
                }
            }
        }
Beispiel #15
0
    void OnGUI()
    {
        GUILayout.Label("Creat VR menus", EditorStyles.boldLabel);

        NameText = EditorGUILayout.TextField("Menu Name: ", NameText);
        MenuType = EditorGUILayout.Popup("Menu Type: ", MenuType, MenuTypes);

        switch (MenuType)
        {
        case 0:     // default menu
        {
            // is root menu?
            isRootMenu = EditorGUILayout.Toggle("Root Menu? ", isRootMenu);

            // menu title
            TitleText = EditorGUILayout.TextField("Menu Title: ", TitleText);

            // buttons
            ButtonNum = EditorGUILayout.IntField("Number of Buttons: ", ButtonNum);
            if (ButtonNum > BUTTONNUMMAX_DEFAULT)
            {
                ButtonNum = BUTTONNUMMAX_DEFAULT;
            }
            else if (ButtonNum < 0)
            {
                ButtonNum = 0;
            }

            EditorGUILayout.Space();
            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

            int[]        ButtonTypes    = new int[ButtonNum];
            string[]     ButtonNames    = new string[ButtonNum];
            GameObject[] ButtonSubMenus = new GameObject[ButtonNum];
            Sprite[]     ButtonIcons    = new Sprite[ButtonNum];

            GUILayout.BeginVertical();

            for (int i = 0; i < ButtonNum; i++)
            {
                EditorGUILayout.LabelField("Button " + i);

                // button names
                _ButtonNames[i] = EditorGUILayout.TextField("    Name: ", _ButtonNames[i]);
                // button types
                _ButtonTypes[i] = EditorGUILayout.IntPopup("    Type: ", _ButtonTypes[i], _typeNames, _types);
                if (_ButtonTypes[i] == 1)         // Hierarchical button
                {
                    _ButtonSubMenus[i] = (GameObject)EditorGUILayout.ObjectField("    Sub Menu Ref: ", _ButtonSubMenus[i], typeof(GameObject), true);

                    ButtonSubMenus[i] = _ButtonSubMenus[i];
                }

                // button icons
                _ButtonIcons[i] = (Sprite)EditorGUILayout.ObjectField(_ButtonIcons[i], typeof(Sprite), true);

                ButtonNames[i] = _ButtonNames[i];
                ButtonTypes[i] = _ButtonTypes[i];
                ButtonIcons[i] = _ButtonIcons[i];
            }

            EditorGUILayout.Space();

            if (GUILayout.Button("Create a Menu!"))
            {
                //Debug.Log("Num of Btns: " + ButtonNum);

                MenuPrefab = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/xRMenuDesigner/Resources/Prefabs/DefaultMenu/DefaultMenu.prefab", typeof(GameObject));

                GameObject tempMenu = Instantiate(MenuPrefab);
                tempMenu.name = NameText;

                var MenuScript = tempMenu.GetComponent <DefaultMenu>();
                MenuScript.InitMenu(ButtonNum, isRootMenu);
                MenuScript.SetTitle(TitleText);

                // create Buttons
                for (int i = 0; i < ButtonNum; i++)
                {
                    ButtonPrefab = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/xRMenuDesigner/Resources/Prefabs/DefaultMenu/DefaultButton.prefab", typeof(GameObject));

                    var trans = tempMenu.transform;
                    foreach (Transform currTrans in trans)
                    {
                        if (currTrans.tag == "ButtonPanel")
                        {
                            GameObject tempButton   = Instantiate(ButtonPrefab, currTrans);
                            var        ButtonScript = tempButton.GetComponent <DefaultButton>();
                            ButtonScript.SetText(ButtonNames[i]);
                            ButtonScript.SetIcon(ButtonIcons[i]);
                            ButtonScript.SetSubMenuRef(ButtonSubMenus[i]);
                        }
                    }
                }
            }

            GUILayout.EndScrollView();
            GUILayout.EndVertical();
            break;
        }

        case 1:     // win10style menu
        {
            // is root menu?
            isRootMenu = EditorGUILayout.Toggle("Root Menu? ", isRootMenu);

            // menu title
            TitleText = EditorGUILayout.TextField("Menu Title: ", TitleText);

            // buttons
            ButtonNum = EditorGUILayout.IntField("Number of Buttons: ", ButtonNum);
            if (ButtonNum > BUTTONNUMMAX_WIN10)
            {
                ButtonNum = BUTTONNUMMAX_WIN10;
            }
            else if (ButtonNum < 0)
            {
                ButtonNum = 0;
            }

            EditorGUILayout.Space();
            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

            int[]        ButtonTypes    = new int[ButtonNum];
            string[]     ButtonNames    = new string[ButtonNum];
            GameObject[] ButtonSubMenus = new GameObject[ButtonNum];
            Sprite[]     ButtonIcons    = new Sprite[ButtonNum];

            GUILayout.BeginVertical();

            for (int i = 0; i < ButtonNum; i++)
            {
                EditorGUILayout.LabelField("Button " + i);

                // button names
                _ButtonNames[i] = EditorGUILayout.TextField("    Name: ", _ButtonNames[i]);
                // button types
                _ButtonTypes[i] = EditorGUILayout.IntPopup("    Type: ", _ButtonTypes[i], _typeNames, _types);
                if (_ButtonTypes[i] == 1)         // Hierarchical button
                {
                    _ButtonSubMenus[i] = (GameObject)EditorGUILayout.ObjectField("    Sub Menu Ref: ", _ButtonSubMenus[i], typeof(GameObject), true);

                    ButtonSubMenus[i] = _ButtonSubMenus[i];
                }

                // button icons
                _ButtonIcons[i] = (Sprite)EditorGUILayout.ObjectField(_ButtonIcons[i], typeof(Sprite), true);

                ButtonNames[i] = _ButtonNames[i];
                ButtonTypes[i] = _ButtonTypes[i];
                ButtonIcons[i] = _ButtonIcons[i];
            }

            EditorGUILayout.Space();

            if (GUILayout.Button("Create a Menu!"))
            {
                //Debug.Log("Num of Btns: " + ButtonNum);

                MenuPrefab = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/xRMenuDesigner/Resources/Prefabs/Win10StyleMenu/Win10StyleMenu.prefab", typeof(GameObject));

                GameObject tempMenu = Instantiate(MenuPrefab);
                tempMenu.name = NameText;

                var MenuScript = tempMenu.GetComponent <Win10StyleMenu>();
                MenuScript.InitMenu(ButtonNum, isRootMenu);
                MenuScript.SetTitle(TitleText);

                // create Buttons
                for (int i = 0; i < ButtonNum; i++)
                {
                    ButtonPrefab = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/xRMenuDesigner/Resources/Prefabs/Win10StyleMenu/Win10StyleButton.prefab", typeof(GameObject));

                    var trans = tempMenu.transform;
                    foreach (Transform currTrans in trans)
                    {
                        if (currTrans.tag == "ButtonPanel")
                        {
                            GameObject tempButton   = Instantiate(ButtonPrefab, currTrans);
                            var        ButtonScript = tempButton.GetComponent <Win10StyleButton>();
                            ButtonScript.SetText(ButtonNames[i]);
                            ButtonScript.SetIcon(ButtonIcons[i]);
                            ButtonScript.SetSubMenuRef(ButtonSubMenus[i]);
                        }
                    }
                }
            }

            GUILayout.EndScrollView();
            GUILayout.EndVertical();
            break;
        }

        case 2:     // ring menu
        {
            // is root menu?
            isRootMenu = EditorGUILayout.Toggle("Root Menu? ", isRootMenu);

            // buttons
            ButtonNum = EditorGUILayout.IntField("Number of Buttons: ", ButtonNum);
            if (ButtonNum > BUTTONNUMMAX_RING)
            {
                ButtonNum = BUTTONNUMMAX_RING;
            }
            else if (ButtonNum < 0)
            {
                ButtonNum = 0;
            }

            EditorGUILayout.Space();
            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

            string[] ButtonNames = new string[ButtonNum];
            Sprite[] ButtonIcons = new Sprite[ButtonNum];

            GUILayout.BeginVertical();

            for (int i = 0; i < ButtonNum; i++)
            {
                EditorGUILayout.LabelField("Button " + i);

                // button names
                _ButtonNames[i] = EditorGUILayout.TextField("    Name: ", _ButtonNames[i]);

                // button icons
                _ButtonIcons[i] = (Sprite)EditorGUILayout.ObjectField(_ButtonIcons[i], typeof(Sprite), true);

                ButtonNames[i] = _ButtonNames[i];
                ButtonIcons[i] = _ButtonIcons[i];
            }

            EditorGUILayout.Space();

            if (GUILayout.Button("Create a Menu!"))
            {
                //Debug.Log("Num of Btns: " + ButtonNum);

                MenuPrefab = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/xRMenuDesigner/Resources/Prefabs/RingMenu/RingMenu.prefab", typeof(GameObject));

                GameObject tempMenu = Instantiate(MenuPrefab);
                tempMenu.name = NameText;

                // create Buttons
                for (int i = 0; i < ButtonNum; i++)
                {
                    ButtonPrefab = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/xRMenuDesigner/Resources/Prefabs/RingMenu/RingButton.prefab", typeof(GameObject));

                    var trans = tempMenu.transform;
                    foreach (Transform currTrans in trans)
                    {
                        if (currTrans.tag == "ButtonPanel")
                        {
                            GameObject tempButton   = Instantiate(ButtonPrefab, currTrans);
                            var        ButtonScript = tempButton.GetComponent <RingButton>();
                            ButtonScript.SetText(ButtonNames[i]);
                            ButtonScript.SetIcon(ButtonIcons[i]);
                        }
                    }
                }
            }

            GUILayout.EndScrollView();
            GUILayout.EndVertical();
            break;
        }

        case 3:     // radial menu
        {
            if (GUILayout.Button("Create a Menu!"))
            {
                MenuPrefab = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/xRMenuDesigner/Resources/Prefabs/RadialMenu/RadialMenu.prefab", typeof(GameObject));

                GameObject tempMenu = Instantiate(MenuPrefab);
            }

            break;
        }
        }
    }
    public override void OnInspectorGUI()
    {
        int  i;
        Rect boxRect;
        bool bankIsLoaded = false;

        base.OnInspectorGUI();

        GUILayout.Space(10f);

//**********************************************************************
//********************** Pulse Box *************************************
        boxRect = EditorGUILayout.BeginVertical();

        GUI.Box(boxRect, "Pulse", __boxStyle);

        if (_pulsedPattern.Pulse != null)          //Pulse is of type MasterPulseModule, let's put a shortcut to it's Start/Stop methods
        {
            MasterPulseModule masterPulse = _pulsedPattern.Pulse as MasterPulseModule;
            GUILayout.Space(5f);

            if (masterPulse != null)
            {
                if (masterPulse.IsPulsing == false)
                {
                    GUI.color = Color.green;
                    if (GUILayout.Button("Start", __buttonOptions))
                    {
                        masterPulse.StartPulsing(0);
                    }
                }
                else
                {
                    GUI.color = Color.red;
                    if (GUILayout.Button("Stop", __buttonOptions))
                    {
                        masterPulse.Stop();
                    }
                }
            }

            GUI.color = Color.white;
        }

        GUILayout.Space(5f);

        //***************** Pulse Steps *******************************
        if (_pulsedPattern.Pulse != null)
        {
            bool[] subscribedSteps = _pulsedPattern.SubscribedSteps;

            GUILayout.BeginHorizontal();
            GUILayout.Space(45f);
            for (i = 0; i < subscribedSteps.Length; i++)
            {
                GUI.enabled = _pulsedPattern.Pulse.Steps[i];
                GUILayout.Label(i.ToString(), GUILayout.Width(15f));
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(5f);
            GUILayout.Label(__stepsFieldContent, GUILayout.Width(35f));

            for (i = 0; i < subscribedSteps.Length; i++)
            {
                GUI.enabled        = _pulsedPattern.Pulse.Steps[i];
                subscribedSteps[i] = GUILayout.Toggle(subscribedSteps[i], "", GUILayout.Width(15f));
            }
            GUILayout.EndHorizontal();

            GUI.enabled = true;
        }
        else
        {
            GUILayout.Space(30f);
        }

        GUILayout.Space(5f);
        GUILayout.BeginHorizontal();
        GUILayout.Space(5f);

        _pulsedPattern.Pulse = ( PulseModule )EditorGUILayout.ObjectField(_pulsedPattern.Pulse, typeof(PulseModule), true, GUILayout.MaxWidth(125f));

        if (_pulsedPattern.Pulse != null)
        {
            _pulsedPattern.RandomBypass = GUILayout.Toggle(_pulsedPattern.RandomBypass, "Random Bypass");
        }

        GUILayout.EndHorizontal();

        if (_pulsedPattern.RandomBypass)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(90f);
            GUILayout.Label((_pulsedPattern.RandomBypassChance * 100).ToString("0.##\\%"), GUILayout.Width(40f));
            _pulsedPattern.RandomBypassChance = GUILayout.HorizontalSlider(_pulsedPattern.RandomBypassChance, 0f, 1f, GUILayout.Width(100f));
            GUILayout.EndHorizontal();
        }

        GUILayout.Space(10f);
        EditorGUILayout.EndVertical();

//********************************************************************

        GUILayout.Space(10f);

//********************************************************************
//***************** SampleBank Box ***********************************
        boxRect = EditorGUILayout.BeginVertical();
        GUI.Box(boxRect, "Sample Bank", __boxStyle);

        GUILayout.Space(5f);

        if (_pulsedPattern.SampleBank != null)
        {
            string label;

            bankIsLoaded = _pulsedPattern.SampleBank.IsLoaded;

            if (bankIsLoaded)
            {
                label       = "Loaded";
                GUI.enabled = false;
            }
            else
            {
                label     = "Load";
                GUI.color = Color.green;
            }

            if (GUILayout.Button(new GUIContent(label, "In edit mode, SampleBanks do not automatically reload to preserve memory."), __buttonOptions))
            {
                _pulsedPattern.SampleBank.LoadAll();
                UpdateSampleOptions();
            }
            GUI.enabled = true;
            GUI.color   = Color.white;
        }
        GUILayout.Space(5f);

        GATActiveSampleBank cachedBank = _pulsedPattern.SampleBank;

        GUILayout.BeginHorizontal();
        GUILayout.Space(5f);
        _pulsedPattern.SampleBank = ( GATActiveSampleBank )EditorGUILayout.ObjectField(_pulsedPattern.SampleBank, typeof(GATActiveSampleBank), true, GUILayout.MaxWidth(125f));

        GUILayout.EndHorizontal();

        if (_pulsedPattern.SampleBank != null && bankIsLoaded == false)
        {
            EditorGUILayout.HelpBox("The selected bank is not loaded yet. Click Load to enable previewing.", MessageType.Warning);
        }

        if (_pulsedPattern.SampleBank != cachedBank)
        {
            UpdateSampleOptions();
        }

        GUILayout.Space(10f);
        EditorGUILayout.EndVertical();

//*******************************************************************

        GUILayout.Space(10f);

//*******************************************************************
//***************** Envelope Box ************************************

        boxRect = EditorGUILayout.BeginVertical();
        GUI.Box(boxRect, "Envelope", __boxStyle);

        GUILayout.Space(30f);

        GUILayout.BeginHorizontal();
        GUILayout.Space(5f);
        _pulsedPattern.Envelope = ( EnvelopeModule )EditorGUILayout.ObjectField(_pulsedPattern.Envelope, typeof(EnvelopeModule), true, GUILayout.MaxWidth(125f));

        if (_pulsedPattern.Envelope != null)
        {
            GUI.color = __blueColor;
            if (GUILayout.Button("Envelope Window", __largeButtonOptions))
            {
                EnvelopeWindow window = EditorWindow.GetWindow <EnvelopeWindow>();
                window.InitWithEnvelope(_pulsedPattern.Envelope);
            }
            GUI.color = Color.white;
        }
        GUILayout.EndHorizontal();

        if (_pulsedPattern.Envelope == null)
        {
            EditorGUILayout.HelpBox("If no envelope is set, the entire samples will be played and pitch shifting is disabled.", MessageType.Info);
        }

        GUILayout.Space(10f);

        EditorGUILayout.EndVertical();

//*******************************************************************

        GUILayout.Space(10f);

//*******************************************************************
//***************** Samples Box *************************************

        boxRect = EditorGUILayout.BeginVertical();
        GUI.Box(boxRect, "Samples", __boxStyle);

        GUILayout.Space(30f);

        //******************* Player and track fields ***********************
        GUILayout.BeginHorizontal();
        GUILayout.Space(5f);
        GUILayout.Label(__playerFieldContent, GUILayout.Width(40f));
        _pulsedPattern.Player = ( GATPlayer )EditorGUILayout.ObjectField(_pulsedPattern.Player, typeof(GATPlayer), true, GUILayout.Width(125f));
        GUILayout.Label(__trackFieldContent, GUILayout.Width(40f));
        _pulsedPattern.TrackNb = EditorGUILayout.IntPopup(_pulsedPattern.TrackNb, _playerTrackStrings, _playerTrackNumbers, GUILayout.Width(40f));
        GUILayout.Space(5f);
        GUILayout.EndHorizontal();

        GUILayout.Space(10f);

        //******************* Playing Order ***********************
        EditorGUILayout.HelpBox(__orderHelpStrings[( int )_pulsedPattern.SamplesOrdering], MessageType.Info);

        GUILayout.BeginHorizontal();
        GUILayout.Space(5f);
        _pulsedPattern.SamplesOrdering = (AGATPulsedPattern.PlayingOrder)EditorGUILayout.EnumPopup(_pulsedPattern.SamplesOrdering, GUILayout.MaxWidth(145f));
        _pulsedPattern.AddRandomDelay  = GUILayout.Toggle(_pulsedPattern.AddRandomDelay, __randomDelayContent);
        GUILayout.EndHorizontal();

        if (_pulsedPattern.AddRandomDelay)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(110f);
            GUILayout.Label((_pulsedPattern.RandomDelayMaxRatio * 100).ToString("0.##\\%"), GUILayout.Width(40f));
            _pulsedPattern.RandomDelayMaxRatio = GUILayout.HorizontalSlider(_pulsedPattern.RandomDelayMaxRatio, 0f, 1f, GUILayout.Width(100f));
            GUILayout.EndHorizontal();
        }

//******************************************************************
        GUILayout.Space(10f);

//******************************************************************
//*********************** Drawing Samples **************************

        PatternSample info;

        for (i = 0; i < _samplesInfo.Length; i++)
        {
            info = _samplesInfo[i];

            if (DrawSampleInfo(info, bankIsLoaded, i))
            {
                _pulsedPattern.PlaySample(i, AudioSettings.dspTime + .1d);
            }
        }

        if (_sampleOptions != null)
        {
            GUILayout.Space(20f);

            GUILayout.BeginHorizontal();
            GUILayout.Space(5f);
            GUI.color = Color.green;
            if (GUILayout.Button("Add", __buttonOptions))
            {
                _pulsedPattern.AddSample(_sampleOptions[_selectedSampleName]);
                _samplesInfo = _pulsedPattern.Samples;
            }
            GUI.color = Color.white;
            GUILayout.Space(5f);
            _selectedSampleName = EditorGUILayout.Popup(_selectedSampleName, _sampleOptions, GUILayout.Width(100f));
            GUILayout.EndHorizontal();
        }

        GUILayout.Space(10f);

        EditorGUILayout.EndVertical();
    }
    public override void OnInspectorGUI()
    {
        if (!CheckValid(out string text))
        {
            EditorGUILayout.HelpBox(text, MessageType.Error);
            return;
        }
        serializedObject.Update();
        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(player, new GUIContent("跟随目标"));
        EditorGUILayout.PropertyField(offset, new GUIContent("位置偏移量"));
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(use2D, new GUIContent("2D场景"));
        EditorGUILayout.PropertyField(rotateMap, new GUIContent("旋转地图"));
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.PropertyField(updateMode, new GUIContent("更新方式"));
        EditorGUILayout.PropertyField(UI);
        if (UI.objectReferenceValue)
        {
            int mode  = circle.boolValue ? 1 : 0;
            int index = EditorGUILayout.IntPopup("边框形状", mode, new string[] { "矩形", "圆形" }, new int[] { 0, 1 });
            circle.boolValue = index == 0 ? false : true;
            if (!circle.boolValue)
            {
                EditorGUILayout.PropertyField(edgeSize, new GUIContent("边框厚度"));
            }
            if (circle.boolValue)
            {
                EditorGUILayout.PropertyField(radius, new GUIContent("半径"));
            }

            if (Application.isPlaying)
            {
                GUI.enabled = false;
            }
            playerIcon.objectReferenceValue = EditorGUILayout.ObjectField("主图标", playerIcon.objectReferenceValue as Sprite, typeof(Sprite), false);
            EditorGUILayout.PropertyField(playerIconSize, new GUIContent("主图标大小"));
            defaultMarkIcon.objectReferenceValue = EditorGUILayout.ObjectField("默认标记图标", defaultMarkIcon.objectReferenceValue as Sprite, typeof(Sprite), false);
            EditorGUILayout.PropertyField(defaultMarkSize, new GUIContent("默认标记大小"));
            EditorGUILayout.PropertyField(mapCamera, new GUIContent("地图相机"));
            EditorGUILayout.PropertyField(cameraPrefab, new GUIContent("地图相机预制件"));
            EditorGUILayout.PropertyField(targetTexture, new GUIContent("采样贴图"));
            if (Application.isPlaying)
            {
                GUI.enabled = true;
            }
            EditorGUILayout.PropertyField(mapRenderMask, new GUIContent("地图相机可视层"));
            if (mapCamera.objectReferenceValue)
            {
                Camera cam = (mapCamera.objectReferenceValue as MapCamera).Camera;
                cam.cullingMask = mapRenderMask.intValue;
                if (targetTexture.objectReferenceValue && cam.targetTexture != targetTexture.objectReferenceValue)
                {
                    cam.targetTexture = targetTexture.objectReferenceValue as RenderTexture;
                }
            }
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(worldEdgeSize, new GUIContent("大地图边框厚度"));
            EditorGUILayout.PropertyField(dragSensitivity, new GUIContent("大地图拖拽灵敏度"));
            EditorGUILayout.PropertyField(animationSpeed, new GUIContent("动画速度"));
            if (Application.isPlaying)
            {
                GUI.enabled = false;
            }
            EditorGUILayout.PropertyField(isViewingWorldMap, new GUIContent("当前是大地图模式"));
            if (Application.isPlaying)
            {
                GUI.enabled = true;
            }
            DrawModeInfo(miniModeInfo, true);
            DrawModeInfo(worldModeInfo, false);
        }
        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }
    }
Beispiel #18
0
        public void SynthParameters(MidiSynth instance, SerializedObject sobject)
        {
            instance.showSynthParameter = DrawFoldoutAndHelp(instance.showSynthParameter, "Show Synth Parameters", "https://paxstellar.fr/midi-file-player-detailed-view-2/#Foldout-Synth-Parameters");
            if (instance.showSynthParameter)
            {
                EditorGUI.indentLevel++;

                GUIContent labelCore    = new GUIContent("Core Player", "Play music with a non Unity thread. Change this properties only when not running");
                string     labelRate    = "Rate Synth Output";
                string     labelBuffer  = "Buffer Synth Size";
                string     titleCore    = instance.MPTK_CorePlayer ? "'Core'" : "'Non Core'";
                string     foldoutTitle = $"Show Unity Audio Parameters - {titleCore}";
                instance.showUnitySynthParameter = DrawFoldoutAndHelp(instance.showUnitySynthParameter, foldoutTitle, "https://paxstellar.fr/midi-file-player-detailed-view-2/#Foldout-Audio-Parameters");
                if (instance.showUnitySynthParameter)
                {
                    EditorGUI.indentLevel++;
                    if (myStyle == null)
                    {
                        myStyle = new CustomStyle();
                    }
                    EditorGUILayout.LabelField("With Core Player checked (fluidsynth mode), the synthesizer is working on a thread apart from the main Unity thread. Accuracy is much better. The legacy mode which is using many AudioSource will be removed with the next major version.", myStyle.LabelGreen);
                    if (!EditorApplication.isPlaying)
                    {
                        instance.MPTK_CorePlayer = EditorGUILayout.Toggle(labelCore, instance.MPTK_CorePlayer);
                    }
                    else
                    {
                        EditorGUILayout.LabelField(labelCore, new GUIContent(instance.MPTK_CorePlayer ? "True" : "False"));
                    }

                    if (NoErrorValidator.CantChangeAudioConfiguration)
                    {
                        EditorGUILayout.LabelField("Warning: Audio configuration change is disabled on this platform.", myStyle.LabelAlert);
                    }
                    else if (instance.MPTK_CorePlayer)
                    {
                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField("Changing synthesizer rate and buffer size can produce unexpected effect according to the hardware. Save your work before!", myStyle.LabelGreen);
                        EditorGUILayout.Space();
                        if (!EditorApplication.isPlaying)
                        {
                            EditorGUILayout.LabelField("Increase the rate to get a better sound but with a cost on performance.", myStyle.LabelGreen);
                            synthRateLabel[0] = "Default: " + AudioSettings.outputSampleRate + " Hz";
                            int indexrate = EditorGUILayout.IntPopup(labelRate, instance.MPTK_IndexSynthRate, synthRateLabel, synthRateIndex);
                            if (indexrate != instance.MPTK_IndexSynthRate)
                            {
                                instance.MPTK_IndexSynthRate = indexrate;
                            }
                            EditorGUILayout.Space();
                        }
                        else
                        {
                            EditorGUILayout.LabelField(labelRate, instance.OutputRate.ToString());
                        }

                        if (!EditorApplication.isPlaying)
                        {
                            EditorGUILayout.LabelField("Decrease the buffer size to get a more accurate playing.", myStyle.LabelGreen);
                            int bufferLenght;
                            int numBuffers;
                            AudioSettings.GetDSPBufferSize(out bufferLenght, out numBuffers);
                            synthBufferSizeLabel[0] = "Default: " + bufferLenght;
                            int indexBuffSize = EditorGUILayout.IntPopup(labelBuffer, instance.MPTK_IndexSynthBuffSize, synthBufferSizeLabel, synthBufferSizeIndex);
                            if (indexBuffSize != instance.MPTK_IndexSynthBuffSize)
                            {
                                instance.MPTK_IndexSynthBuffSize = indexBuffSize;
                            }
                            EditorGUILayout.Space();
                        }
                        else
                        {
                            EditorGUILayout.LabelField(labelBuffer, instance.DspBufferSize.ToString());
                        }

                        EditorGUILayout.Space();
                        EditorGUILayout.LabelField("Interpolation is the core of the synth process. Linear is a good balacing between quality and performance", myStyle.LabelGreen);
                        instance.InterpolationMethod = (fluid_interp)EditorGUILayout.IntPopup("Interpolation Method", (int)instance.InterpolationMethod, synthInterpolationLabel, synthInterpolationIndex);
                    }
                    else
                    {
                        EditorGUILayout.LabelField("Warning: with non core mode, all voices will be played in separate Audio Source. SoundFont synth is not fully implemented. This mode will be removed with a future version.", myStyle.LabelAlert);
                    }

                    EditorGUI.indentLevel--;
                }

                instance.MPTK_LogWave = EditorGUILayout.Toggle(new GUIContent("Log Samples", "Log information about sample played for a NoteOn event."), instance.MPTK_LogWave);

                //instance.MPTK_PlayOnlyFirstWave = EditorGUILayout.Toggle(new GUIContent("Play Only First Wave", "Some Instrument in Preset are using more of one wave at the same time. If checked, play only the first wave, usefull on weak device, but sound experience is less good."), instance.MPTK_PlayOnlyFirstWave);
                //instance.MPTK_WeakDevice = EditorGUILayout.Toggle(new GUIContent("Weak Device", "Playing Midi files with WeakDevice activated could cause some bad interpretation of Midi Event, consequently bad sound."), instance.MPTK_WeakDevice);
                instance.MPTK_EnablePanChange = EditorGUILayout.Toggle(new GUIContent("Pan Change", "Enable midi event pan change when playing. Uncheck if you want to manage Pan in your application."), instance.MPTK_EnablePanChange);

                instance.MPTK_ApplyRealTimeModulator = EditorGUILayout.Toggle(new GUIContent("Apply Modulator", "Real-Time change Modulator from Midi and ADSR enveloppe Modulator parameters from SoundFont could have an impact on CPU. Initial value of Modulator set at Note On are keep. Uncheck to gain some % CPU on weak device."), instance.MPTK_ApplyRealTimeModulator);
                instance.MPTK_ApplyModLfo            = EditorGUILayout.Toggle(new GUIContent("Apply Mod LFO", "LFO modulation are defined in SoudFont. Uncheck to gain some % CPU on weak device."), instance.MPTK_ApplyModLfo);
                instance.MPTK_ApplyVibLfo            = EditorGUILayout.Toggle(new GUIContent("Apply Vib LFO", "LFO vibrato are defined in SoudFont. Uncheck to gain some % CPU on weak device."), instance.MPTK_ApplyVibLfo);

                // Moved from Midi Parameters (V2.85)
                instance.MPTK_ReleaseSameNote      = EditorGUILayout.Toggle(new GUIContent("Release Same Note", "Enable release note if the same note is hit twice on the same channel."), instance.MPTK_ReleaseSameNote);
                instance.MPTK_KillByExclusiveClass = EditorGUILayout.Toggle(new GUIContent("Kill By Exclusive Class", "Find the exclusive class of the voice. If set, kill all voices that match the exclusive class and are younger than the first voice process created by this noteon event."), instance.MPTK_KillByExclusiveClass);

                instance.showSoundFontEffect = MidiCommonEditor.DrawFoldoutAndHelp(instance.showSoundFontEffect, "Show SoundFont Effect Parameters", "https://paxstellar.fr/sound-effects/");
                if (instance.showSoundFontEffect)
#if MPTK_PRO
                { CommonProEditor.EffectSoundFontParameters(instance, myStyle); }
#else
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.LabelField("[Available with MPTK Pro] These effects will be applied independently on each voices. Effects values are defined in the SoundFont, so limited modification can't be applied.", myStyle.LabelGreen);
                    EditorGUI.indentLevel--;
                }
#endif

                instance.showUnitySynthEffect = MidiCommonEditor.DrawFoldoutAndHelp(instance.showUnitySynthEffect, "Show Unity Effect Parameters", "https://paxstellar.fr/sound-effects/");
                if (instance.showUnitySynthEffect)
#if MPTK_PRO
                { CommonProEditor.EffectUnityParameters(instance, myStyle); }
#else
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.LabelField("[Available with MPTK Pro] These effects will be applied to all voices processed by the current MPTK gameObject. You can add multiple MPTK gameObjects to apply for different effects.", myStyle.LabelGreen);
                    EditorGUI.indentLevel--;
                }
#endif
                instance.showUnityPerformanceParameter = DrawFoldoutAndHelp(instance.showUnityPerformanceParameter, "Show Performance Parameters", "https://paxstellar.fr/midi-file-player-detailed-view-2/#Foldout-Performance");
                if (instance.showUnityPerformanceParameter)
                {
                    EditorGUI.indentLevel++;
                    instance.waitThreadMidi    = EditorGUILayout.IntSlider(new GUIContent("Thread Midi Delay", "Delay in milliseconds between call to the midi sequencer"), instance.waitThreadMidi, 1, 30);
                    instance.MaxDspLoad        = EditorGUILayout.IntSlider(new GUIContent("Max Level DSP Load", "When DSP is over the 'Max Level DSP Load' (by default 50%), some actions are taken on current playing voices for better performance"), (int)instance.MaxDspLoad, 0, 100);
                    instance.DevicePerformance = EditorGUILayout.IntSlider(new GUIContent("Device Performance", "Define amount of cleaning of the voice. 1 for weak device and high cleaning. If <=25 some voice could be stopped."), instance.DevicePerformance, 1, 100);
                    EditorGUI.indentLevel--;
                }

                instance.showSynthEvents = MidiCommonEditor.DrawFoldoutAndHelp(instance.showSynthEvents, "Show Synth Unity Events", "https://paxstellar.fr/midi-file-player-detailed-view-2/#Foldout-Synth-Unity-Events");
                if (instance.showSynthEvents)
                {
                    EditorGUI.indentLevel++;
                    if (CustomEventSynthAwake == null)
                    {
                        CustomEventSynthAwake = sobject.FindProperty("OnEventSynthAwake");
                    }
                    EditorGUILayout.PropertyField(CustomEventSynthAwake);

                    if (CustomEventSynthStarted == null)
                    {
                        CustomEventSynthStarted = sobject.FindProperty("OnEventSynthStarted");
                    }
                    EditorGUILayout.PropertyField(CustomEventSynthStarted);

                    sobject.ApplyModifiedProperties();
                    EditorGUI.indentLevel--;
                }
                EditorGUI.indentLevel--;
            }
        }
    public override void OnInspectorGUI()
    {
        tk2dSpriteCollection gen = (tk2dSpriteCollection)target;

        EditorGUILayout.BeginVertical();

        bool rebuild = false;
        bool edit    = false;

        tk2dSpriteCollectionBuilder.ResetCurrentBuild();

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Commit"))
        {
            rebuild = true;
        }
        GUILayout.Space(16.0f);
        if (GUILayout.Button("Edit..."))
        {
            edit = true;
        }
        EditorGUILayout.EndHorizontal();


        DrawDefaultInspector();

        // Draw additional stuff
        gen.padAmount = EditorGUILayout.IntPopup("Pad Amount", gen.padAmount, padAmountLabels, padAmountValues);

        DrawAtlasView(gen);

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Commit"))
        {
            rebuild = true;
        }
        GUILayout.Space(16.0f);
        if (GUILayout.Button("Edit..."))
        {
            edit = true;
        }
        EditorGUILayout.EndHorizontal();


        if (rebuild)
        {
            tk2dSpriteCollectionBuilder.Rebuild(gen);
        }
        if (edit)
        {
            if (gen.textureRefs != null && gen.textureRefs.Length > 0)
            {
                bool dirty = false;
                if (gen.textureRefs.Length != gen.textureParams.Length)
                {
                    dirty = true;
                }
                if (!dirty)
                {
                    for (int i = 0; i < gen.textureRefs.Length; ++i)
                    {
                        if (gen.textureParams[i].fromSpriteSheet == false && gen.textureRefs[i] != gen.textureParams[i].texture)
                        {
                            dirty = true;
                            break;
                        }
                    }
                }

                if (dirty)
                {
                    tk2dSpriteCollectionBuilder.Rebuild(gen);
                }

                tk2dSpriteCollectionEditorPopup v = EditorWindow.GetWindow(typeof(tk2dSpriteCollectionEditorPopup), true, "Sprite Collection Editor") as tk2dSpriteCollectionEditorPopup;
                v.SetGenerator(gen);
            }
        }

        EditorGUILayout.EndVertical();
    }
Beispiel #20
0
 public override void    OnGUI()
 {
     this.value = EditorGUILayout.IntPopup(this.name, (int)this.value, this.names, this.values);
 }
Beispiel #21
0
        private void RenderInteractionList(SerializedProperty interactionList, bool useCustomInteractionMapping)
        {
            if (interactionList == null)
            {
                throw new Exception();
            }

            bool noInteractions = interactionList.arraySize == 0;

            if (currentControllerOption != null && (currentControllerOption.IsLabelFlipped == null || currentControllerOption.IsLabelFlipped.Length != interactionList.arraySize))
            {
                currentControllerOption.IsLabelFlipped = new bool[interactionList.arraySize];
            }

            GUILayout.BeginVertical();

            if (useCustomInteractionMapping)
            {
                horizontalScrollPosition = EditorGUILayout.BeginScrollView(horizontalScrollPosition, false, false, GUILayout.ExpandWidth(true), GUILayout.ExpandWidth(true));
            }

            if (useCustomInteractionMapping)
            {
                if (GUILayout.Button(InteractionAddButtonContent))
                {
                    interactionList.arraySize += 1;
                    var interaction = interactionList.GetArrayElementAtIndex(interactionList.arraySize - 1);
                    var axisType    = interaction.FindPropertyRelative("axisType");
                    axisType.enumValueIndex = 0;
                    var inputType = interaction.FindPropertyRelative("inputType");
                    inputType.enumValueIndex = 0;
                    var action            = interaction.FindPropertyRelative("inputAction");
                    var actionId          = action.FindPropertyRelative("id");
                    var actionDescription = action.FindPropertyRelative("description");
                    actionDescription.stringValue = "None";
                    actionId.intValue             = 0;
                }

                if (noInteractions)
                {
                    EditorGUILayout.HelpBox("Create an Interaction Mapping.", MessageType.Warning);
                    EditorGUILayout.EndScrollView();
                    GUILayout.EndVertical();
                    return;
                }
            }
            else if (EnableWysiwyg)
            {
                EditorGUI.BeginChangeCheck();
                editInputActionPositions = EditorGUILayout.Toggle("Edit Input Action Positions", editInputActionPositions);

                if (EditorGUI.EndChangeCheck())
                {
                    string editorWindowOptionsPath = ResolveEditorWindowOptionsPath();
                    if (!editInputActionPositions)
                    {
                        File.WriteAllText(editorWindowOptionsPath, JsonUtility.ToJson(controllerInputActionOptions, true));
                    }
                    else
                    {
                        if (!controllerInputActionOptions.Controllers.Any(
                                option => option.Controller == currentControllerMapping.SupportedControllerType && option.Handedness == currentControllerMapping.Handedness))
                        {
                            currentControllerOption = new ControllerInputActionOption
                            {
                                Controller          = currentControllerMapping.SupportedControllerType,
                                Handedness          = currentControllerMapping.Handedness,
                                InputLabelPositions = new Vector2[currentInteractionList.arraySize],
                                IsLabelFlipped      = new bool[currentInteractionList.arraySize]
                            };

                            controllerInputActionOptions.Controllers.Add(currentControllerOption);
                            isMouseInRects = new bool[currentInteractionList.arraySize];

                            if (controllerInputActionOptions.Controllers.Any(option => option.Controller == 0))
                            {
                                controllerInputActionOptions.Controllers.Remove(
                                    controllerInputActionOptions.Controllers.Find(option =>
                                                                                  option.Controller == 0));
                            }

                            File.WriteAllText(editorWindowOptionsPath, JsonUtility.ToJson(controllerInputActionOptions, true));
                        }
                    }
                }
            }

            GUILayout.BeginHorizontal();

            if (useCustomInteractionMapping)
            {
                EditorGUILayout.LabelField("Id", GUILayout.Width(32f));
                EditorGUIUtility.labelWidth = 24f;
                EditorGUIUtility.fieldWidth = 24f;
                EditorGUILayout.LabelField(ControllerInputTypeContent, GUILayout.Width(InputActionLabelWidth));
                EditorGUILayout.LabelField(AxisTypeContent, GUILayout.Width(InputActionLabelWidth));
                EditorGUILayout.LabelField(ActionContent, GUILayout.Width(InputActionLabelWidth));
                EditorGUILayout.LabelField(KeyCodeContent, GUILayout.Width(InputActionLabelWidth));
                EditorGUILayout.LabelField(XAxisContent, GUILayout.Width(InputActionLabelWidth));
                EditorGUILayout.LabelField(YAxisContent, GUILayout.Width(InputActionLabelWidth));
                GUILayout.FlexibleSpace();
                EditorGUILayout.LabelField(string.Empty, GUILayout.Width(24f));

                EditorGUIUtility.labelWidth = defaultLabelWidth;
                EditorGUIUtility.fieldWidth = defaultFieldWidth;
            }

            GUILayout.EndHorizontal();

            for (int i = 0; i < interactionList.arraySize; i++)
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    SerializedProperty interaction = interactionList.GetArrayElementAtIndex(i);

                    if (useCustomInteractionMapping)
                    {
                        EditorGUILayout.LabelField($"{i + 1}", GUILayout.Width(32f));
                        var inputType = interaction.FindPropertyRelative("inputType");
                        EditorGUILayout.PropertyField(inputType, GUIContent.none, GUILayout.Width(InputActionLabelWidth));
                        var axisType = interaction.FindPropertyRelative("axisType");
                        EditorGUILayout.PropertyField(axisType, GUIContent.none, GUILayout.Width(InputActionLabelWidth));
                        var invertXAxis = interaction.FindPropertyRelative("invertXAxis");
                        var invertYAxis = interaction.FindPropertyRelative("invertYAxis");
                        var interactionAxisConstraint = interaction.FindPropertyRelative("axisType");

                        var action            = interaction.FindPropertyRelative("inputAction");
                        var actionId          = action.FindPropertyRelative("id");
                        var actionDescription = action.FindPropertyRelative("description");
                        var actionConstraint  = action.FindPropertyRelative("axisConstraint");

                        GUIContent[] labels;
                        int[]        ids;

                        switch ((AxisType)interactionAxisConstraint.intValue)
                        {
                        default:
                        case AxisType.None:
                            labels = actionLabels;
                            ids    = actionIds;
                            break;

                        case AxisType.Raw:
                            labels = rawActionLabels;
                            ids    = rawActionIds;
                            break;

                        case AxisType.Digital:
                            labels = digitalActionLabels;
                            ids    = digitalActionIds;
                            break;

                        case AxisType.SingleAxis:
                            labels = singleAxisActionLabels;
                            ids    = singleAxisActionIds;
                            break;

                        case AxisType.DualAxis:
                            labels = dualAxisActionLabels;
                            ids    = dualAxisActionIds;
                            break;

                        case AxisType.ThreeDofPosition:
                            labels = threeDofPositionActionLabels;
                            ids    = threeDofPositionActionIds;
                            break;

                        case AxisType.ThreeDofRotation:
                            labels = threeDofRotationActionLabels;
                            ids    = threeDofRotationActionIds;
                            break;

                        case AxisType.SixDof:
                            labels = sixDofActionLabels;
                            ids    = sixDofActionIds;
                            break;
                        }

                        EditorGUI.BeginChangeCheck();
                        actionId.intValue = EditorGUILayout.IntPopup(GUIContent.none, actionId.intValue, labels, ids, GUILayout.Width(InputActionLabelWidth));

                        if (EditorGUI.EndChangeCheck())
                        {
                            var inputAction = actionId.intValue == 0 ? MixedRealityInputAction.None : MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1];
                            actionDescription.stringValue   = inputAction.Description;
                            actionConstraint.enumValueIndex = (int)inputAction.AxisConstraint;
                        }

                        if ((AxisType)axisType.intValue == AxisType.Digital)
                        {
                            var keyCode = interaction.FindPropertyRelative("keyCode");
                            EditorGUILayout.PropertyField(keyCode, GUIContent.none, GUILayout.Width(InputActionLabelWidth));
                        }
                        else
                        {
                            if ((AxisType)axisType.intValue == AxisType.DualAxis)
                            {
                                EditorGUIUtility.labelWidth = InputActionLabelWidth * 0.5f;
                                EditorGUIUtility.fieldWidth = InputActionLabelWidth * 0.5f;

                                int currentAxisSetting = 0;

                                if (invertXAxis.boolValue)
                                {
                                    currentAxisSetting += 1;
                                }

                                if (invertYAxis.boolValue)
                                {
                                    currentAxisSetting += 2;
                                }

                                EditorGUI.BeginChangeCheck();
                                currentAxisSetting = EditorGUILayout.IntPopup(InvertContent, currentAxisSetting, InvertAxisContent, InvertAxisValues, GUILayout.Width(InputActionLabelWidth));

                                if (EditorGUI.EndChangeCheck())
                                {
                                    switch (currentAxisSetting)
                                    {
                                    case 0:
                                        invertXAxis.boolValue = false;
                                        invertYAxis.boolValue = false;
                                        break;

                                    case 1:
                                        invertXAxis.boolValue = true;
                                        invertYAxis.boolValue = false;
                                        break;

                                    case 2:
                                        invertXAxis.boolValue = false;
                                        invertYAxis.boolValue = true;
                                        break;

                                    case 3:
                                        invertXAxis.boolValue = true;
                                        invertYAxis.boolValue = true;
                                        break;
                                    }
                                }

                                EditorGUIUtility.labelWidth = defaultLabelWidth;
                                EditorGUIUtility.fieldWidth = defaultFieldWidth;
                            }
                            else if ((AxisType)axisType.intValue == AxisType.SingleAxis)
                            {
                                invertXAxis.boolValue       = EditorGUILayout.ToggleLeft("Invert X", invertXAxis.boolValue, GUILayout.Width(InputActionLabelWidth));
                                EditorGUIUtility.labelWidth = defaultLabelWidth;
                            }
                            else
                            {
                                EditorGUILayout.LabelField(GUIContent.none, GUILayout.Width(InputActionLabelWidth));
                            }
                        }

                        if ((AxisType)axisType.intValue == AxisType.SingleAxis ||
                            (AxisType)axisType.intValue == AxisType.DualAxis)
                        {
                            var axisCodeX = interaction.FindPropertyRelative("axisCodeX");
                            RenderAxisPopup(axisCodeX, InputActionLabelWidth);
                        }
                        else
                        {
                            EditorGUILayout.LabelField(GUIContent.none, GUILayout.Width(InputActionLabelWidth));
                        }

                        if ((AxisType)axisType.intValue == AxisType.DualAxis)
                        {
                            var axisCodeY = interaction.FindPropertyRelative("axisCodeY");
                            RenderAxisPopup(axisCodeY, InputActionLabelWidth);
                        }
                        else
                        {
                            EditorGUILayout.LabelField(GUIContent.none, GUILayout.Width(InputActionLabelWidth));
                        }

                        if (GUILayout.Button(InteractionMinusButtonContent, EditorStyles.miniButtonRight, GUILayout.ExpandWidth(true)))
                        {
                            interactionList.DeleteArrayElementAtIndex(i);
                        }
                    }
                    else
                    {
                        var interactionDescription    = interaction.FindPropertyRelative("description");
                        var interactionAxisConstraint = interaction.FindPropertyRelative("axisType");
                        var action            = interaction.FindPropertyRelative("inputAction");
                        var actionId          = action.FindPropertyRelative("id");
                        var actionDescription = action.FindPropertyRelative("description");
                        var actionConstraint  = action.FindPropertyRelative("axisConstraint");

                        GUIContent[] labels;
                        int[]        ids;

                        switch ((AxisType)interactionAxisConstraint.intValue)
                        {
                        default:
                        case AxisType.None:
                            labels = actionLabels;
                            ids    = actionIds;
                            break;

                        case AxisType.Raw:
                            labels = rawActionLabels;
                            ids    = rawActionIds;
                            break;

                        case AxisType.Digital:
                            labels = digitalActionLabels;
                            ids    = digitalActionIds;
                            break;

                        case AxisType.SingleAxis:
                            labels = singleAxisActionLabels;
                            ids    = singleAxisActionIds;
                            break;

                        case AxisType.DualAxis:
                            labels = dualAxisActionLabels;
                            ids    = dualAxisActionIds;
                            break;

                        case AxisType.ThreeDofPosition:
                            labels = threeDofPositionActionLabels;
                            ids    = threeDofPositionActionIds;
                            break;

                        case AxisType.ThreeDofRotation:
                            labels = threeDofRotationActionLabels;
                            ids    = threeDofRotationActionIds;
                            break;

                        case AxisType.SixDof:
                            labels = sixDofActionLabels;
                            ids    = sixDofActionIds;
                            break;
                        }

                        EditorGUI.BeginChangeCheck();

                        if (currentControllerOption == null || currentControllerTexture == null)
                        {
                            bool skip        = false;
                            var  description = interactionDescription.stringValue;
                            if (currentControllerMapping.SupportedControllerType == SupportedControllerType.GGVHand &&
                                currentControllerMapping.Handedness == Handedness.None)
                            {
                                if (description != "Select")
                                {
                                    skip = true;
                                }
                            }

                            if (!skip)
                            {
                                actionId.intValue = EditorGUILayout.IntPopup(GUIContent.none, actionId.intValue, labels, ids, GUILayout.Width(80f));
                                EditorGUILayout.LabelField(description, GUILayout.ExpandWidth(true));
                            }
                        }
                        else
                        {
                            var rectPosition = currentControllerOption.InputLabelPositions[i];
                            var rectSize     = InputActionLabelPosition + InputActionDropdownPosition + new Vector2(currentControllerOption.IsLabelFlipped[i] ? 0f : 8f, EditorGUIUtility.singleLineHeight);
                            GUI.Box(new Rect(rectPosition, rectSize), GUIContent.none, EditorGUIUtility.isProSkin ? "ObjectPickerBackground" : "ObjectPickerResultsEven");
                            var offset    = currentControllerOption.IsLabelFlipped[i] ? InputActionLabelPosition : Vector2.zero;
                            var popupRect = new Rect(rectPosition + offset, new Vector2(InputActionDropdownPosition.x, EditorGUIUtility.singleLineHeight));

                            actionId.intValue = EditorGUI.IntPopup(popupRect, actionId.intValue, labels, ids);
                            offset            = currentControllerOption.IsLabelFlipped[i] ? Vector2.zero : InputActionDropdownPosition;
                            var labelRect = new Rect(rectPosition + offset, new Vector2(InputActionLabelPosition.x, EditorGUIUtility.singleLineHeight));
                            EditorGUI.LabelField(labelRect, interactionDescription.stringValue, currentControllerOption.IsLabelFlipped[i] ? flippedLabelStyle : EditorStyles.label);

                            if (editInputActionPositions)
                            {
                                offset = currentControllerOption.IsLabelFlipped[i] ? InputActionLabelPosition + InputActionDropdownPosition + HorizontalSpace : InputActionFlipTogglePosition;
                                var toggleRect = new Rect(rectPosition + offset, new Vector2(-InputActionFlipTogglePosition.x, EditorGUIUtility.singleLineHeight));

                                EditorGUI.BeginChangeCheck();
                                currentControllerOption.IsLabelFlipped[i] = EditorGUI.Toggle(toggleRect, currentControllerOption.IsLabelFlipped[i]);

                                if (EditorGUI.EndChangeCheck())
                                {
                                    if (currentControllerOption.IsLabelFlipped[i])
                                    {
                                        currentControllerOption.InputLabelPositions[i] -= InputActionLabelPosition;
                                    }
                                    else
                                    {
                                        currentControllerOption.InputLabelPositions[i] += InputActionLabelPosition;
                                    }
                                }

                                if (!isMouseInRects.Any(value => value) || isMouseInRects[i])
                                {
                                    if (Event.current.type == EventType.MouseDrag && labelRect.Contains(Event.current.mousePosition) && !isMouseInRects[i])
                                    {
                                        isMouseInRects[i] = true;
                                        mouseDragOffset   = Event.current.mousePosition - currentControllerOption.InputLabelPositions[i];
                                    }
                                    else if (Event.current.type == EventType.Repaint && isMouseInRects[i])
                                    {
                                        currentControllerOption.InputLabelPositions[i] = Event.current.mousePosition - mouseDragOffset;
                                    }
                                    else if (Event.current.type == EventType.DragUpdated && isMouseInRects[i])
                                    {
                                        currentControllerOption.InputLabelPositions[i] = Event.current.mousePosition - mouseDragOffset;
                                    }
                                    else if (Event.current.type == EventType.MouseUp && isMouseInRects[i])
                                    {
                                        currentControllerOption.InputLabelPositions[i] = Event.current.mousePosition - mouseDragOffset;
                                        mouseDragOffset   = Vector2.zero;
                                        isMouseInRects[i] = false;
                                    }
                                }
                            }
                        }

                        if (EditorGUI.EndChangeCheck())
                        {
                            MixedRealityInputAction inputAction = actionId.intValue == 0 ?
                                                                  MixedRealityInputAction.None :
                                                                  MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1];
                            actionId.intValue               = (int)inputAction.Id;
                            actionDescription.stringValue   = inputAction.Description;
                            actionConstraint.enumValueIndex = (int)inputAction.AxisConstraint;
                            interactionList.serializedObject.ApplyModifiedProperties();
                        }
                    }
                }
            }

            if (useCustomInteractionMapping)
            {
                EditorGUILayout.EndScrollView();
                interactionList.serializedObject.ApplyModifiedProperties();
            }

            GUILayout.EndVertical();
        }
Beispiel #22
0
        /// <summary>Draws the inspector for a \link Pathfinding.GraphCollision GraphCollision class \endlink</summary>
        protected virtual void DrawCollisionEditor(GraphCollision collision)
        {
            collision = collision ?? new GraphCollision();

            DrawUse2DPhysics(collision);

            collision.collisionCheck = ToggleGroup("Collision testing", collision.collisionCheck);
            if (collision.collisionCheck)
            {
                var colliderOptions = collision.use2D ? new[] { "Circle", "Point" } : new[] { "Sphere", "Capsule", "Ray" };
                var colliderValues  = collision.use2D ? new[] { 0, 2 } : new[] { 0, 1, 2 };
                // In 2D the Circle (Sphere) mode will replace both the Sphere and the Capsule modes
                // However make sure that the original value is still stored in the grid graph in case the user changes back to the 3D mode in the inspector.
                var tp = collision.type;
                if (tp == ColliderType.Capsule && collision.use2D)
                {
                    tp = ColliderType.Sphere;
                }
                EditorGUI.BeginChangeCheck();
                tp = (ColliderType)EditorGUILayout.IntPopup("Collider type", (int)tp, colliderOptions,
                                                            colliderValues);
                if (EditorGUI.EndChangeCheck())
                {
                    collision.type = tp;
                }

                // Only spheres and capsules have a diameter
                if (collision.type == ColliderType.Capsule || collision.type == ColliderType.Sphere)
                {
                    collision.diameter = EditorGUILayout.FloatField(
                        new GUIContent("Diameter", "Diameter of the capsule or sphere. 1 equals one node width"),
                        collision.diameter);
                }

                if (!collision.use2D)
                {
                    if (collision.type == ColliderType.Capsule || collision.type == ColliderType.Ray)
                    {
                        collision.height = EditorGUILayout.FloatField(
                            new GUIContent("Height/Length", "Height of cylinder or length of ray in world units"),
                            collision.height);
                    }

                    collision.collisionOffset = EditorGUILayout.FloatField(
                        new GUIContent("Offset",
                                       "Offset upwards from the node. Can be used so that obstacles can be used as ground and at the same time as obstacles for lower positioned nodes"),
                        collision.collisionOffset);
                }

                collision.mask = EditorGUILayoutx.LayerMaskField("Obstacle Layer Mask", collision.mask);
            }

            GUILayout.Space(2);

            if (collision.use2D)
            {
                EditorGUI.BeginDisabledGroup(collision.use2D);
                ToggleGroup("Height testing", false);
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                collision.heightCheck = ToggleGroup("Height testing", collision.heightCheck);
                if (collision.heightCheck)
                {
                    collision.fromHeight = EditorGUILayout.FloatField(
                        new GUIContent("Ray length", "The height from which to check for ground"),
                        collision.fromHeight);

                    collision.heightMask = EditorGUILayoutx.LayerMaskField("Mask", collision.heightMask);

                    collision.thickRaycast = EditorGUILayout.Toggle(
                        new GUIContent("Thick Raycast", "Use a thick line instead of a thin line"),
                        collision.thickRaycast);

                    if (collision.thickRaycast)
                    {
                        EditorGUI.indentLevel++;
                        collision.thickRaycastDiameter = EditorGUILayout.FloatField(
                            new GUIContent("Diameter", "Diameter of the thick raycast"),
                            collision.thickRaycastDiameter);
                        EditorGUI.indentLevel--;
                    }

                    collision.unwalkableWhenNoGround = EditorGUILayout.Toggle(
                        new GUIContent("Unwalkable when no ground",
                                       "Make nodes unwalkable when no ground was found with the height raycast. If height raycast is turned off, this doesn't affect anything"),
                        collision.unwalkableWhenNoGround);
                }
            }
        }
Beispiel #23
0
 public static int DoFontIndexSelection(int FontIndex)
 {
     return(EditorGUILayout.IntPopup(g_FontIndex, FontIndex, TEXPreference.main.FontIDsGUI, TEXPreference.main.FontIndexs));
 }
Beispiel #24
0
        private void RenderInteractionList(SerializedProperty interactionList, bool useCustomInteractionMapping)
        {
            GUI.enabled = !isLocked;

            if (interactionList == null)
            {
                Debug.LogError("No interaction list found!");
                Close();
                return;
            }

            bool noInteractions = interactionList.arraySize == 0;

            if (!useCustomInteractionMapping)
            {
                if (currentControllerOption.IsLabelFlipped.Length != interactionList.arraySize)
                {
                    var newArray = new bool[interactionList.arraySize];

                    for (int i = 0; i < currentControllerOption.IsLabelFlipped.Length; i++)
                    {
                        newArray[i] = currentControllerOption.IsLabelFlipped[i];
                    }

                    currentControllerOption.IsLabelFlipped = newArray;
                }

                if (currentControllerOption.InputLabelPositions.Length != interactionList.arraySize)
                {
                    var newArray = new Vector2[interactionList.arraySize];

                    for (int i = 0; i < currentControllerOption.InputLabelPositions.Length; i++)
                    {
                        newArray[i] = currentControllerOption.InputLabelPositions[i];
                    }

                    currentControllerOption.InputLabelPositions = newArray;
                }
            }

            GUILayout.BeginVertical();

            if (useCustomInteractionMapping)
            {
                useCustomInteractionMapping = !(currentControllerType == SupportedControllerType.WindowsMixedReality && currentHandedness == Handedness.None);
            }

            if (useCustomInteractionMapping)
            {
                horizontalScrollPosition = EditorGUILayout.BeginScrollView(horizontalScrollPosition, false, false, GUILayout.ExpandWidth(true), GUILayout.ExpandWidth(true));
            }

            if (useCustomInteractionMapping)
            {
                if (GUILayout.Button(InteractionAddButtonContent))
                {
                    interactionList.arraySize += 1;
                    var interaction = interactionList.GetArrayElementAtIndex(interactionList.arraySize - 1);
                    var axisType    = interaction.FindPropertyRelative("axisType");
                    axisType.enumValueIndex = 0;
                    var inputType = interaction.FindPropertyRelative("inputType");
                    inputType.enumValueIndex = 0;
                    var action            = interaction.FindPropertyRelative("inputAction");
                    var actionId          = action.FindPropertyRelative("id");
                    var actionDescription = action.FindPropertyRelative("description");
                    actionDescription.stringValue = "None";
                    actionId.intValue             = 0;
                }

                if (noInteractions)
                {
                    EditorGUILayout.HelpBox("Create an Interaction Mapping.", MessageType.Warning);
                    EditorGUILayout.EndScrollView();
                    GUILayout.EndVertical();
                    return;
                }
            }
            else if (EnableWysiwyg)
            {
                EditorGUI.BeginChangeCheck();
                editInputActionPositions = EditorGUILayout.Toggle("Edit Input Action Positions", editInputActionPositions);

                if (EditorGUI.EndChangeCheck())
                {
                    if (!editInputActionPositions)
                    {
                        File.WriteAllText(Path.GetFullPath(EditorWindowOptionsPath), JsonUtility.ToJson(controllerInputActionOptions, true));
                        AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
                    }
                    else
                    {
                        if (!controllerInputActionOptions.Controllers.Any(option => option.Controller == currentControllerType && option.Handedness == currentHandedness))
                        {
                            currentControllerOption = new ControllerInputActionOption
                            {
                                Controller          = currentControllerType,
                                Handedness          = currentHandedness,
                                InputLabelPositions = new Vector2[currentInteractionList.arraySize],
                                IsLabelFlipped      = new bool[currentInteractionList.arraySize]
                            };

                            controllerInputActionOptions.Controllers.Add(currentControllerOption);
                            isMouseInRects = new bool[currentInteractionList.arraySize];

                            if (controllerInputActionOptions.Controllers.Any(option => option.Controller == SupportedControllerType.None))
                            {
                                controllerInputActionOptions.Controllers.Remove(
                                    controllerInputActionOptions.Controllers.Find(option =>
                                                                                  option.Controller == SupportedControllerType.None));
                            }

                            AssetDatabase.DeleteAsset(EditorWindowOptionsPath);
                            File.WriteAllText(Path.GetFullPath(EditorWindowOptionsPath), JsonUtility.ToJson(controllerInputActionOptions, true));
                            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
                        }
                    }
                }
            }

            GUILayout.BeginHorizontal();

            if (useCustomInteractionMapping)
            {
                EditorGUILayout.LabelField("Id", GUILayout.Width(32f));
                EditorGUIUtility.labelWidth = 24f;
                EditorGUIUtility.fieldWidth = 24f;
                EditorGUILayout.LabelField(ControllerInputTypeContent, GUILayout.Width(InputActionLabelWidth));
                EditorGUILayout.LabelField(AxisTypeContent, GUILayout.Width(InputActionLabelWidth));
                EditorGUILayout.LabelField(ActionContent, GUILayout.Width(InputActionLabelWidth));
                EditorGUILayout.LabelField(KeyCodeContent, GUILayout.Width(InputActionLabelWidth));
                EditorGUILayout.LabelField(XAxisContent, GUILayout.Width(InputActionLabelWidth));
                EditorGUILayout.LabelField(YAxisContent, GUILayout.Width(InputActionLabelWidth));
                GUILayout.FlexibleSpace();
                EditorGUILayout.LabelField(string.Empty, GUILayout.Width(24f));

                EditorGUIUtility.labelWidth = defaultLabelWidth;
                EditorGUIUtility.fieldWidth = defaultFieldWidth;
            }

            GUILayout.EndHorizontal();

            for (int i = 0; i < interactionList.arraySize; i++)
            {
                EditorGUILayout.BeginHorizontal();
                var interaction = interactionList.GetArrayElementAtIndex(i);

                if (useCustomInteractionMapping)
                {
                    EditorGUILayout.LabelField($"{i + 1}", GUILayout.Width(32f));
                    var inputType = interaction.FindPropertyRelative("inputType");
                    EditorGUILayout.PropertyField(inputType, GUIContent.none, GUILayout.Width(InputActionLabelWidth));
                    var axisType = interaction.FindPropertyRelative("axisType");
                    EditorGUILayout.PropertyField(axisType, GUIContent.none, GUILayout.Width(InputActionLabelWidth));
                    var invertXAxis = interaction.FindPropertyRelative("invertXAxis");
                    var invertYAxis = interaction.FindPropertyRelative("invertYAxis");
                    var interactionAxisConstraint = interaction.FindPropertyRelative("axisType");

                    var action            = interaction.FindPropertyRelative("inputAction");
                    var actionId          = action.FindPropertyRelative("id");
                    var actionDescription = action.FindPropertyRelative("description");
                    var actionConstraint  = action.FindPropertyRelative("axisConstraint");

                    GUIContent[] labels;
                    int[]        ids;

                    switch ((AxisType)interactionAxisConstraint.intValue)
                    {
                    // case AxisType.None:
                    default:
                        labels = actionLabels;
                        ids    = actionIds;
                        break;

                    case AxisType.Raw:
                        labels = rawActionLabels;
                        ids    = rawActionIds;
                        break;

                    case AxisType.Digital:
                        labels = digitalActionLabels;
                        ids    = digitalActionIds;
                        break;

                    case AxisType.SingleAxis:
                        labels = singleAxisActionLabels;
                        ids    = singleAxisActionIds;
                        break;

                    case AxisType.DualAxis:
                        labels = dualAxisActionLabels;
                        ids    = dualAxisActionIds;
                        break;

                    case AxisType.ThreeDofPosition:
                        labels = threeDofPositionActionLabels;
                        ids    = threeDofPositionActionIds;
                        break;

                    case AxisType.ThreeDofRotation:
                        labels = threeDofRotationActionLabels;
                        ids    = threeDofRotationActionIds;
                        break;

                    case AxisType.SixDof:
                        labels = sixDofActionLabels;
                        ids    = sixDofActionIds;
                        break;
                    }

                    EditorGUI.BeginChangeCheck();
                    actionId.intValue = EditorGUILayout.IntPopup(GUIContent.none, actionId.intValue, labels, ids, GUILayout.Width(InputActionLabelWidth));

                    if (EditorGUI.EndChangeCheck())
                    {
                        var inputAction = actionId.intValue == 0 ? MixedRealityInputAction.None : inputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1];
                        actionDescription.stringValue   = inputAction.Description;
                        actionConstraint.enumValueIndex = (int)inputAction.AxisConstraint;
                    }

                    if ((AxisType)axisType.intValue == AxisType.Digital)
                    {
                        var keyCode = interaction.FindPropertyRelative("keyCode");
                        EditorGUILayout.PropertyField(keyCode, GUIContent.none, GUILayout.Width(InputActionLabelWidth));
                    }
                    else
                    {
                        if ((AxisType)axisType.intValue == AxisType.DualAxis)
                        {
                            EditorGUIUtility.labelWidth = InputActionLabelWidth * 0.5f;
                            EditorGUIUtility.fieldWidth = InputActionLabelWidth * 0.5f;

                            int currentAxisSetting = 0;

                            if (invertXAxis.boolValue)
                            {
                                currentAxisSetting += 1;
                            }

                            if (invertYAxis.boolValue)
                            {
                                currentAxisSetting += 2;
                            }

                            EditorGUI.BeginChangeCheck();
                            currentAxisSetting = EditorGUILayout.IntPopup(InvertContent, currentAxisSetting, InvertAxisContent, InvertAxisValues, GUILayout.Width(InputActionLabelWidth));

                            if (EditorGUI.EndChangeCheck())
                            {
                                switch (currentAxisSetting)
                                {
                                case 0:
                                    invertXAxis.boolValue = false;
                                    invertYAxis.boolValue = false;
                                    break;

                                case 1:
                                    invertXAxis.boolValue = true;
                                    invertYAxis.boolValue = false;
                                    break;

                                case 2:
                                    invertXAxis.boolValue = false;
                                    invertYAxis.boolValue = true;
                                    break;

                                case 3:
                                    invertXAxis.boolValue = true;
                                    invertYAxis.boolValue = true;
                                    break;
                                }
                            }

                            EditorGUIUtility.labelWidth = defaultLabelWidth;
                            EditorGUIUtility.fieldWidth = defaultFieldWidth;
                        }
                        else if ((AxisType)axisType.intValue == AxisType.SingleAxis)
                        {
                            invertXAxis.boolValue       = EditorGUILayout.ToggleLeft("Invert X", invertXAxis.boolValue, GUILayout.Width(InputActionLabelWidth));
                            EditorGUIUtility.labelWidth = defaultLabelWidth;
                        }
                        else
                        {
                            EditorGUILayout.LabelField(GUIContent.none, GUILayout.Width(InputActionLabelWidth));
                        }
                    }

                    if ((AxisType)axisType.intValue == AxisType.SingleAxis ||
                        (AxisType)axisType.intValue == AxisType.DualAxis)
                    {
                        var axisCodeX = interaction.FindPropertyRelative("axisCodeX");
                        RenderAxisPopup(axisCodeX, InputActionLabelWidth);
                    }
                    else
                    {
                        EditorGUILayout.LabelField(GUIContent.none, GUILayout.Width(InputActionLabelWidth));
                    }

                    if ((AxisType)axisType.intValue == AxisType.DualAxis)
                    {
                        var axisCodeY = interaction.FindPropertyRelative("axisCodeY");
                        RenderAxisPopup(axisCodeY, InputActionLabelWidth);
                    }
                    else
                    {
                        EditorGUILayout.LabelField(GUIContent.none, GUILayout.Width(InputActionLabelWidth));
                    }

                    if (GUILayout.Button(InteractionMinusButtonContent, EditorStyles.miniButtonRight, GUILayout.ExpandWidth(true)))
                    {
                        interactionList.DeleteArrayElementAtIndex(i);
                    }
                }
                else
                {
                    var interactionDescription    = interaction.FindPropertyRelative("description");
                    var interactionAxisConstraint = interaction.FindPropertyRelative("axisType");
                    var action            = interaction.FindPropertyRelative("inputAction");
                    var actionId          = action.FindPropertyRelative("id");
                    var actionDescription = action.FindPropertyRelative("description");
                    var actionConstraint  = action.FindPropertyRelative("axisConstraint");
                    var invertXAxis       = interaction.FindPropertyRelative("invertXAxis");
                    var invertYAxis       = interaction.FindPropertyRelative("invertYAxis");

                    int[]        ids;
                    GUIContent[] labels;
                    var          axisConstraint = (AxisType)interactionAxisConstraint.intValue;

                    switch (axisConstraint)
                    {
                    // case AxisType.None:
                    default:
                        labels = actionLabels;
                        ids    = actionIds;
                        break;

                    case AxisType.Raw:
                        labels = rawActionLabels;
                        ids    = rawActionIds;
                        break;

                    case AxisType.Digital:
                        labels = digitalActionLabels;
                        ids    = digitalActionIds;
                        break;

                    case AxisType.SingleAxis:
                        labels = singleAxisActionLabels;
                        ids    = singleAxisActionIds;
                        break;

                    case AxisType.DualAxis:
                        labels = dualAxisActionLabels;
                        ids    = dualAxisActionIds;
                        break;

                    case AxisType.ThreeDofPosition:
                        labels = threeDofPositionActionLabels;
                        ids    = threeDofPositionActionIds;
                        break;

                    case AxisType.ThreeDofRotation:
                        labels = threeDofRotationActionLabels;
                        ids    = threeDofRotationActionIds;
                        break;

                    case AxisType.SixDof:
                        labels = sixDofActionLabels;
                        ids    = sixDofActionIds;
                        break;
                    }

                    EditorGUI.BeginChangeCheck();

                    if (currentControllerTexture == null)
                    {
                        bool skip        = false;
                        var  description = interactionDescription.stringValue;

                        if (currentControllerType == SupportedControllerType.WindowsMixedReality && currentHandedness == Handedness.None)
                        {
                            switch (description)
                            {
                            case "Grip Press":
                            case "Trigger Position":
                            case "Trigger Touched":
                            case "Touchpad Position":
                            case "Touchpad Touch":
                            case "Touchpad Press":
                            case "Menu Press":
                            case "Thumbstick Position":
                            case "Thumbstick Press":
                                skip = true;
                                break;

                            case "Trigger Press (Select)":
                                description = "Air Tap (Select)";
                                break;
                            }
                        }

                        if (!skip)
                        {
                            var currentLabelWidth = EditorGUIUtility.labelWidth;

                            if (axisConstraint == AxisType.SingleAxis ||
                                axisConstraint == AxisType.DualAxis)
                            {
                                EditorGUIUtility.labelWidth = 12f;
                                EditorGUILayout.LabelField("Invert:");
                                invertXAxis.boolValue = EditorGUILayout.Toggle("X", invertXAxis.boolValue);
                            }

                            if (axisConstraint == AxisType.DualAxis)
                            {
                                invertYAxis.boolValue = EditorGUILayout.Toggle("Y", invertYAxis.boolValue);
                            }

                            EditorGUIUtility.labelWidth = currentLabelWidth;
                            actionId.intValue           = EditorGUILayout.IntPopup(GUIContent.none, actionId.intValue, labels, ids, GUILayout.Width(80f));
                            EditorGUILayout.LabelField(description, GUILayout.ExpandWidth(true));
                            GUILayout.FlexibleSpace();
                        }
                    }
                    else
                    {
                        var flipped      = currentControllerOption.IsLabelFlipped[i];
                        var rectPosition = currentControllerOption.InputLabelPositions[i];
                        var rectSize     = InputActionLabelPosition + InputActionDropdownPosition + new Vector2(flipped ? 0f : 8f, EditorGUIUtility.singleLineHeight);

                        GUI.Box(new Rect(rectPosition, rectSize), GUIContent.none, EditorGUIUtility.isProSkin ? "ObjectPickerBackground" : "ObjectPickerResultsEven");

                        var offset    = flipped ? InputActionLabelPosition : Vector2.zero;
                        var popupRect = new Rect(rectPosition + offset, new Vector2(InputActionDropdownPosition.x, EditorGUIUtility.singleLineHeight));

                        actionId.intValue = EditorGUI.IntPopup(popupRect, actionId.intValue, labels, ids);
                        offset            = flipped ? Vector2.zero : InputActionDropdownPosition;
                        var labelRect = new Rect(rectPosition + offset, new Vector2(InputActionLabelPosition.x, EditorGUIUtility.singleLineHeight));
                        EditorGUI.LabelField(labelRect, interactionDescription.stringValue, flipped ? flippedLabelStyle : EditorStyles.label);

                        if (!editInputActionPositions)
                        {
                            offset = flipped
                                ? InputActionLabelPosition + InputActionDropdownPosition + HorizontalSpace
                                : Vector2.zero;

                            if (axisConstraint == AxisType.SingleAxis ||
                                axisConstraint == AxisType.DualAxis)
                            {
                                if (!flipped)
                                {
                                    if (axisConstraint == AxisType.DualAxis)
                                    {
                                        offset += new Vector2(-112f, 0f);
                                    }
                                    else
                                    {
                                        offset += new Vector2(-76f, 0f);
                                    }
                                }

                                var boxSize = axisConstraint == AxisType.DualAxis ? new Vector2(112f, EditorGUIUtility.singleLineHeight) : new Vector2(76f, EditorGUIUtility.singleLineHeight);

                                GUI.Box(new Rect(rectPosition + offset, boxSize), GUIContent.none, EditorGUIUtility.isProSkin ? "ObjectPickerBackground" : "ObjectPickerResultsEven");

                                labelRect = new Rect(rectPosition + offset, new Vector2(48f, EditorGUIUtility.singleLineHeight));
                                EditorGUI.LabelField(labelRect, "Invert X", flipped ? flippedLabelStyle : EditorStyles.label);
                                offset += new Vector2(52f, 0f);
                                var toggleXAxisRect = new Rect(rectPosition + offset, new Vector2(12f, EditorGUIUtility.singleLineHeight));
                                invertXAxis.boolValue = EditorGUI.Toggle(toggleXAxisRect, invertXAxis.boolValue);
                            }

                            if (axisConstraint == AxisType.DualAxis)
                            {
                                offset   += new Vector2(24f, 0f);
                                labelRect = new Rect(rectPosition + offset, new Vector2(8f, EditorGUIUtility.singleLineHeight));
                                EditorGUI.LabelField(labelRect, "Y", flipped ? flippedLabelStyle : EditorStyles.label);
                                offset += new Vector2(12f, 0f);
                                var toggleYAxisRect = new Rect(rectPosition + offset, new Vector2(12f, EditorGUIUtility.singleLineHeight));
                                invertYAxis.boolValue = EditorGUI.Toggle(toggleYAxisRect, invertYAxis.boolValue);
                            }
                        }
                        else
                        {
                            offset = flipped
                                ? InputActionLabelPosition + InputActionDropdownPosition + HorizontalSpace
                                : InputActionFlipTogglePosition;

                            var toggleRect = new Rect(rectPosition + offset, new Vector2(-InputActionFlipTogglePosition.x, EditorGUIUtility.singleLineHeight));

                            EditorGUI.BeginChangeCheck();

                            currentControllerOption.IsLabelFlipped[i] = EditorGUI.Toggle(toggleRect, flipped);

                            if (EditorGUI.EndChangeCheck())
                            {
                                if (currentControllerOption.IsLabelFlipped[i])
                                {
                                    currentControllerOption.InputLabelPositions[i] -= InputActionLabelPosition;
                                }
                                else
                                {
                                    currentControllerOption.InputLabelPositions[i] += InputActionLabelPosition;
                                }
                            }

                            if (!isMouseInRects.Any(value => value) || isMouseInRects[i])
                            {
                                switch (Event.current.type)
                                {
                                case EventType.MouseDrag when labelRect.Contains(Event.current.mousePosition) && !isMouseInRects[i]:
                                    isMouseInRects[i] = true;

                                    mouseDragOffset = Event.current.mousePosition - currentControllerOption.InputLabelPositions[i];
                                    break;

                                case EventType.Repaint when isMouseInRects[i]:
Beispiel #25
0
        private void RenderControllerList(SerializedProperty controllerList)
        {
            if (thisProfile.ControllerVisualizationSettings.Length != controllerList.arraySize)
            {
                return;
            }

            EditorGUILayout.Space();

            if (InspectorUIUtility.RenderIndentedButton(ControllerAddButtonContent, EditorStyles.miniButton))
            {
                controllerList.InsertArrayElementAtIndex(controllerList.arraySize);
                var index             = controllerList.arraySize - 1;
                var controllerSetting = controllerList.GetArrayElementAtIndex(index);

                var mixedRealityControllerMappingDescription = controllerSetting.FindPropertyRelative("description");
                mixedRealityControllerMappingDescription.stringValue = typeof(GenericJoystickController).Name;

                var mixedRealityControllerHandedness = controllerSetting.FindPropertyRelative("handedness");
                mixedRealityControllerHandedness.intValue = 1;

                serializedObject.ApplyModifiedProperties();

                thisProfile.ControllerVisualizationSettings[index].ControllerType.Type = typeof(GenericJoystickController);
                return;
            }

#if UNITY_2019
            xrPipelineUtility.RenderXRPipelineTabs();
#endif // UNITY_2019

            for (int i = 0; i < controllerList.arraySize; i++)
            {
                var        controllerSetting = controllerList.GetArrayElementAtIndex(i);
                var        mixedRealityControllerMappingDescription = controllerSetting.FindPropertyRelative("description");
                SystemType controllerType = thisProfile.ControllerVisualizationSettings[i].ControllerType;
                bool       hasValidType   = controllerType != null &&
                                            controllerType.Type != null;

                if (hasValidType)
                {
                    MixedRealityControllerAttribute controllerAttribute = MixedRealityControllerAttribute.Find(controllerType.Type);
                    if (controllerAttribute != null && !controllerAttribute.SupportedUnityXRPipelines.IsMaskSet(xrPipelineUtility.SelectedPipeline))
                    {
                        continue;
                    }
                }
                else if (!MixedRealityProjectPreferences.ShowNullDataProviders)
                {
                    continue;
                }

                EditorGUILayout.Space();

                mixedRealityControllerMappingDescription.stringValue = hasValidType
                    ? controllerType.Type.Name.ToProperCase()
                    : "Undefined Controller";

                serializedObject.ApplyModifiedProperties();
                SerializedProperty mixedRealityControllerHandedness = controllerSetting.FindPropertyRelative("handedness");

                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUILayout.LabelField($"{mixedRealityControllerMappingDescription.stringValue} {((Handedness)mixedRealityControllerHandedness.intValue).ToString().ToProperCase()} Hand{(mixedRealityControllerHandedness.intValue == (int)(Handedness.Both) ? "s" : "")}", EditorStyles.boldLabel);

                    if (GUILayout.Button(ControllerMinusButtonContent, EditorStyles.miniButtonRight, GUILayout.Width(24f)))
                    {
                        controllerList.DeleteArrayElementAtIndex(i);
                        return;
                    }
                }

                EditorGUILayout.PropertyField(controllerSetting.FindPropertyRelative("controllerType"));
                EditorGUILayout.PropertyField(controllerSetting.FindPropertyRelative("controllerVisualizationType"));

                if (!hasValidType)
                {
                    EditorGUILayout.HelpBox("A controller type must be defined!", MessageType.Error);
                }

                var handednessValue = mixedRealityControllerHandedness.intValue - 1;

                // Reset in case it was set to something other than left, right, or both.
                if (handednessValue < 0 || handednessValue > 2)
                {
                    handednessValue = 0;
                }

                EditorGUI.BeginChangeCheck();
                handednessValue = EditorGUILayout.IntPopup(new GUIContent(mixedRealityControllerHandedness.displayName, mixedRealityControllerHandedness.tooltip), handednessValue, HandednessSelections, null);
                if (EditorGUI.EndChangeCheck())
                {
                    mixedRealityControllerHandedness.intValue = handednessValue + 1;
                }

                var overrideModel       = controllerSetting.FindPropertyRelative("overrideModel");
                var overrideModelPrefab = overrideModel.objectReferenceValue as GameObject;

                var controllerUsePlatformModelOverride = controllerSetting.FindPropertyRelative("usePlatformModels");
                EditorGUILayout.PropertyField(controllerUsePlatformModelOverride);
                if (controllerUsePlatformModelOverride.boolValue)
                {
                    var platformModelMaterial = controllerSetting.FindPropertyRelative("platformModelMaterial");
                    EditorGUILayout.PropertyField(platformModelMaterial);
                }

                if (controllerUsePlatformModelOverride.boolValue && overrideModelPrefab != null)
                {
                    EditorGUILayout.HelpBox("When platform model is used, the override model will only be used if the default model cannot be loaded from the driver.", MessageType.Warning);
                }

                EditorGUI.BeginChangeCheck();
                overrideModelPrefab = EditorGUILayout.ObjectField(new GUIContent(overrideModel.displayName, "If no override model is set, the global model is used."), overrideModelPrefab, typeof(GameObject), false) as GameObject;
                if (overrideModelPrefab == null && !controllerUsePlatformModelOverride.boolValue)
                {
                    EditorGUILayout.HelpBox("No override model was assigned and this controller will not attempt to use the platform's model, the global model will be used instead", MessageType.Warning);
                }

                if (EditorGUI.EndChangeCheck() && CheckVisualizer(overrideModelPrefab))
                {
                    overrideModel.objectReferenceValue = overrideModelPrefab;
                }
            }
        }
Beispiel #26
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            EditorGUI.BeginChangeCheck();

            TerrainHLOD hlod = target as TerrainHLOD;

            if (hlod == null)
            {
                EditorGUILayout.LabelField("TerrainHLOD is null.");
                return;
            }
            isShowCommon = EditorGUILayout.BeginFoldoutHeaderGroup(isShowCommon, "Common");
            if (isShowCommon == true)
            {
                EditorGUILayout.PropertyField(m_TerrainDataProperty, Styles.SourceText);
                EditorGUILayout.PropertyField(m_DestoryTerrainProperty, Styles.DestoryTerrainText);
                EditorGUILayout.PropertyField(m_ChunkSizeProperty);

                m_ChunkSizeProperty.floatValue = HLODUtils.GetChunkSizePropertyValue(m_ChunkSizeProperty.floatValue);

                var bounds = hlod.GetBounds();
                int depth  = m_splitter.CalculateTreeDepth(bounds, m_ChunkSizeProperty.floatValue);
                EditorGUILayout.LabelField($"The HLOD tree will be created with {depth} levels.");
                if (depth > 5)
                {
                    EditorGUILayout.LabelField($"Node Level Count greater than 5 may cause a frozen Editor.", Styles.RedTextColor);
                    EditorGUILayout.LabelField($"Use a value less than 5.", Styles.RedTextColor);
                }


                EditorGUILayout.PropertyField(m_BorderVertexCountProperty);
                m_LODSlider.Draw();
            }
            EditorGUILayout.EndFoldoutHeaderGroup();

            isShowSimplifier = EditorGUILayout.BeginFoldoutHeaderGroup(isShowSimplifier, "Simplifier");
            if (isShowSimplifier == true)
            {
                if (m_SimplifierTypes.Length > 0)
                {
                    int simplifierIndex = Math.Max(Array.IndexOf(m_SimplifierTypes, hlod.SimplifierType), 0);
                    simplifierIndex     = EditorGUILayout.Popup("Simplifier", simplifierIndex, m_SimplifierNames);
                    hlod.SimplifierType = m_SimplifierTypes[simplifierIndex];

                    var info = m_SimplifierTypes[simplifierIndex].GetMethod("OnGUI");
                    if (info != null)
                    {
                        if (info.IsStatic == true)
                        {
                            info.Invoke(null, new object[] { hlod.SimplifierOptions });
                        }
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("Can not find Simplifiers.");
                }
            }
            EditorGUILayout.EndFoldoutHeaderGroup();

            isShowMaterial = EditorGUILayout.BeginFoldoutHeaderGroup(isShowMaterial, "Material");
            if (isShowMaterial == true)
            {
                Material mat     = null;
                string   matGUID = hlod.MaterialGUID;
                if (string.IsNullOrEmpty(matGUID) == false)
                {
                    string path = AssetDatabase.GUIDToAssetPath(matGUID);
                    mat = AssetDatabase.LoadAssetAtPath <Material>(path);
                }

                mat = EditorGUILayout.ObjectField("Material", mat, typeof(Material), false) as Material;
                if (mat != null)
                {
                    string path = AssetDatabase.GetAssetPath(mat);
                    hlod.MaterialGUID = AssetDatabase.AssetPathToGUID(path);
                }
                hlod.TextureSize = EditorGUILayout.IntPopup("Size", hlod.TextureSize, Styles.TextureSizeStrings,
                                                            Styles.TextureSizes);
                //Output Property name
                //EditorGUILayout.
                if (mat == null)
                {
                    mat = new Material(Shader.Find("Standard"));
                }

                string[] outputTexturePropertyNames = mat.GetTexturePropertyNames();
                int      index = 0;
                isShowTexturePropertices = EditorGUILayout.Foldout(isShowTexturePropertices, "Texture propertices");

                if (isShowTexturePropertices == true)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.Toggle(true, GUILayout.Width(20));
                    index = Array.IndexOf(outputTexturePropertyNames, hlod.AlbedoPropertyName);
                    index = EditorGUILayout.Popup("Albedo", index, outputTexturePropertyNames);
                    index = (index < 0) ? 0 : index;
                    hlod.AlbedoPropertyName = outputTexturePropertyNames[index];
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    hlod.UseNormal          = EditorGUILayout.Toggle(hlod.UseNormal, GUILayout.Width(20));
                    index                   = Array.IndexOf(outputTexturePropertyNames, hlod.NormalPropertyName);
                    index                   = EditorGUILayout.Popup("Normal", index, outputTexturePropertyNames);
                    index                   = (index < 0) ? 0 : index;
                    hlod.NormalPropertyName = outputTexturePropertyNames[index];
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    hlod.UseMask          = EditorGUILayout.Toggle(hlod.UseMask, GUILayout.Width(20));
                    index                 = Array.IndexOf(outputTexturePropertyNames, hlod.MaskPropertyName);
                    index                 = EditorGUILayout.Popup("Mask", index, outputTexturePropertyNames);
                    index                 = (index < 0) ? 0 : index;
                    hlod.MaskPropertyName = outputTexturePropertyNames[index];
                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndFoldoutHeaderGroup();

            isShowStreaming = EditorGUILayout.BeginFoldoutHeaderGroup(isShowStreaming, "Streaming");
            if (isShowStreaming == true)
            {
                if (m_StreamingTypes.Length > 0)
                {
                    int streamingIndex = Math.Max(Array.IndexOf(m_StreamingTypes, hlod.StreamingType), 0);
                    streamingIndex     = EditorGUILayout.Popup("Streaming", streamingIndex, m_StreamingNames);
                    hlod.StreamingType = m_StreamingTypes[streamingIndex];

                    var info = m_StreamingTypes[streamingIndex].GetMethod("OnGUI");
                    if (info != null)
                    {
                        if (info.IsStatic == true)
                        {
                            info.Invoke(null, new object[] { hlod.StreamingOptions });
                        }
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("Can not find StreamingSetters.");
                }
            }
            EditorGUILayout.EndFoldoutHeaderGroup();

            GUIContent generateButton = Styles.GenerateButtonEnable;
            GUIContent destroyButton  = Styles.DestroyButtonNotExists;

            if (hlod.GetComponent <HLODControllerBase>() != null)
            {
                generateButton = Styles.GenerateButtonExists;
                destroyButton  = Styles.DestroyButtonEnable;
            }



            EditorGUILayout.Space();

            GUI.enabled = generateButton == Styles.GenerateButtonEnable;
            if (GUILayout.Button(generateButton))
            {
                CoroutineRunner.RunCoroutine(TerrainHLODCreator.Create(hlod));
            }

            GUI.enabled = destroyButton == Styles.DestroyButtonEnable;
            if (GUILayout.Button(destroyButton))
            {
                CoroutineRunner.RunCoroutine(TerrainHLODCreator.Destroy(hlod));
            }

            GUI.enabled = true;

            serializedObject.ApplyModifiedProperties();
        }
Beispiel #27
0
    /// <summary>
    /// 绘制窗口
    /// </summary>
    public void OnGUI()
    {
        if (GUILayout.Button("关闭"))
        {//关闭按钮
            Close();
        }
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("显示通知"))
        {
            GUIContent content = new GUIContent();
            content.text    = "通知";
            content.tooltip = "ShowNotification";
            ShowNotification(new GUIContent(content));
        }
        if (GUILayout.Button("关闭通知"))
        {
            RemoveNotification();
        }
        EditorGUILayout.EndHorizontal();

        //滚动视图分组↓
        scrollViewPos = EditorGUILayout.BeginScrollView(scrollViewPos);

        //Label
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("文本");
        EditorGUILayout.SelectableLabel("可选文本");
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        //水平分组↓
        EditorGUILayout.BeginHorizontal();
        //数值输入
        intField   = EditorGUILayout.IntField("整数", intField);
        floatField = EditorGUILayout.FloatField("浮点数", floatField);
        EditorGUILayout.EndHorizontal();
        //水平分组↑

        EditorGUILayout.Space();

        //文本输入
        EditorGUILayout.BeginHorizontal();
        textField     = EditorGUILayout.TextField("文本输入框", textField);
        passwordField = EditorGUILayout.PasswordField("密码输入框", passwordField);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("可换行的文本输入框");
        textArea = EditorGUILayout.TextArea(textArea);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        //颜色
        colorField = EditorGUILayout.ColorField("取色器", colorField);

        EditorGUILayout.Space();

        //垂直分组
        EditorGUILayout.BeginVertical();
        //滑动条
        sliderVal = EditorGUILayout.Slider("浮点数滚动条", sliderVal, 0, 1);
        intSlider = EditorGUILayout.IntSlider("整数滚动条", intSlider, 0, 10);
        EditorGUILayout.MinMaxSlider("区间滚动条", ref v2MinMax.x, ref v2MinMax.y, 0, 1);
        EditorGUILayout.EndVertical();

        EditorGUILayout.Space();

        //多元数
        vector2Field = EditorGUILayout.Vector2Field("二维向量", vector2Field);
        vector3Field = EditorGUILayout.Vector3Field("三维向量", vector3Field);
        vector4Field = EditorGUILayout.Vector4Field("四维向量", vector4Field);
        rectField    = EditorGUILayout.RectField("矩形", rectField);
        boundsField  = EditorGUILayout.BoundsField("边界", boundsField);

        EditorGUILayout.Space();

        //下拉列表
        popupVal     = EditorGUILayout.Popup("返回选项数组下标", popupVal, new string[] { "A", "B" });
        intPopupVal  = EditorGUILayout.IntPopup("返回选项数组下标对应的整数数组值", intPopupVal, new string[] { "A", "B" }, new int[] { 1, 2 });
        enumPopupVal = (Condition)EditorGUILayout.EnumPopup("返回枚举", enumPopupVal);

        EditorGUILayout.Space();

        //
        tagField   = EditorGUILayout.TagField("TagField", tagField);
        layerField = EditorGUILayout.LayerField("LayerField", layerField);

        EditorGUILayout.Space();

        foldout = EditorGUILayout.Foldout(foldout, "折叠");
        if (foldout)
        {
            EditorGUILayout.LabelField("折叠内容1");
            EditorGUILayout.LabelField("折叠内容2");
        }

        EditorGUILayout.Space();

        toggle = EditorGUILayout.Toggle("复选框", toggle);

        EditorGUILayout.Space();

        //启用/禁用分组中的内容
        toggleGroup = EditorGUILayout.BeginToggleGroup("启用/禁用分组中的内容", toggleGroup);
        EditorGUILayout.TextField("sdk");
        EditorGUILayout.EndToggleGroup();

        EditorGUILayout.Space();

        curveField        = EditorGUILayout.CurveField("动画片段", curveField);
        inspectorTitlebar = EditorGUILayout.InspectorTitlebar(inspectorTitlebar, objectField);    //将选择的物体放在面板上
        objectField       = EditorGUILayout.ObjectField("ObjectField", objectField, typeof(RectTransform), true);

        EditorGUILayout.EndScrollView();
        //滚动视图分组↑

        #region Mask
        //_enumValue0 = (EnumValue0)EditorGUILayout.EnumMaskField("EnumMaskField", _enumValue0);
        //EditorGUILayout.EnumMaskPopup();
        _enumCustom = (EnumCustom)EditorGUILayout.EnumFlagsField(_enumCustom);
        #endregion
    }
        void OnGUI()
        {
            GUILayout.BeginHorizontal();
            textureconfig.TextureType = (TextureImporterType)EditorGUILayout.EnumPopup("TextureType", textureconfig.TextureType);
            bTextureType = GUILayout.Toggle(bTextureType, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            textureconfig.mFilterMode = (FilterMode)EditorGUILayout.EnumPopup("FilterMode", textureconfig.mFilterMode);
            bFilterMode = GUILayout.Toggle(bFilterMode, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            textureconfig.mTextureWrapMode = (TextureWrapMode)EditorGUILayout.EnumPopup("WrapMode", textureconfig.mTextureWrapMode);
            bTextureWrapMode = GUILayout.Toggle(bTextureWrapMode, "");
            GUILayout.EndHorizontal();
#if UNITY_5_5_OR_NEWER
            GUILayout.BeginHorizontal();
            textureconfig.mCompression = (TextureImporterCompression)EditorGUILayout.EnumPopup("Compression", textureconfig.mCompression);
            bCompression = GUILayout.Toggle(bCompression, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            textureconfig.alphasource = (TextureImporterAlphaSource)EditorGUILayout.EnumPopup("AlphaSource", textureconfig.alphasource);
            bAlphaSource = GUILayout.Toggle(bAlphaSource, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            textureconfig.sRGB = GUILayout.Toggle(textureconfig.sRGB, "sRGB");
            bsRGB = GUILayout.Toggle(bsRGB, "");
            GUILayout.EndHorizontal();
#else
            GUILayout.BeginHorizontal();
            textureconfig.alphaFromGrayScale = GUILayout.Toggle(textureconfig.alphaFromGrayScale, "Alpha From GrayScale");
            bAlphaFromGray = GUILayout.Toggle(bAlphaFromGray, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            textureconfig.alphaIsTransparency = GUILayout.Toggle(textureconfig.alphaIsTransparency, "AlphaIsTransparency");
            bAlphaIsTransparency = GUILayout.Toggle(bAlphaIsTransparency, "");
            GUILayout.EndHorizontal();
#endif

            GUILayout.BeginHorizontal();
            textureconfig.ReadAndWrite = GUILayout.Toggle(textureconfig.ReadAndWrite, "Read/Write Enable");
            bReadAndWrite = GUILayout.Toggle(bReadAndWrite, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            textureconfig.Mipmaps = GUILayout.Toggle(textureconfig.Mipmaps, "GenMipMap");
            bMipmaps = GUILayout.Toggle(bMipmaps, "");
            GUILayout.EndHorizontal();

            if (textureconfig.Mipmaps)
            {
                GUILayout.BeginHorizontal();
                textureconfig.BorderMipMaps = GUILayout.Toggle(textureconfig.BorderMipMaps, "Border Mip Maps");
                bBorderMipMaps = GUILayout.Toggle(bBorderMipMaps, "");
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                textureconfig.mTextureImporterMipFilter = (TextureImporterMipFilter)EditorGUILayout.EnumPopup("Mip Map Filtering", textureconfig.mTextureImporterMipFilter);
                bTextureImporterMipFilter = GUILayout.Toggle(bTextureImporterMipFilter, "");
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                textureconfig.FadeoutMipMaps = GUILayout.Toggle(textureconfig.FadeoutMipMaps, "In Linear Space");
                bFadeoutMipMaps = GUILayout.Toggle(bFadeoutMipMaps, "");
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            GUILayout.Label("Aniso Level ");
            textureconfig.AnisoLevel = EditorGUILayout.IntSlider(textureconfig.AnisoLevel, 0, 9);
            bAnisoLevel = GUILayout.Toggle(bAnisoLevel, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            MaxSizeIndex = EditorGUILayout.IntPopup("Max Size ", MaxSizeIndex, MaxSizeString, IntArray);
            int.TryParse(MaxSizeString[MaxSizeIndex], out textureconfig.MaxSizeInt);
            Debug.Log(textureconfig.MaxSizeInt);
            bMaxSizeInt = GUILayout.Toggle(bMaxSizeInt, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Set Texture Batch"))
            {
                SetTextureBatch();
            }
            GUILayout.EndHorizontal();
            ShowList();
        }
Beispiel #29
0
        static void PreferencesGUI()
        {
            EditorGUILayout.BeginVertical();
            EditorGUILayout.Space();

#if HAS_MINIMUM_REQUIRED_VERSION
            // Max execution time
            {
                var label = new GUIContent("Max Execution Time (ms)",
                                           "One of the features of AutoLOD is to keep the editor running responsively, so it’s possible to set"
                                           + "the max execution time for coroutines that run. AutLOD will spawn LOD generators on separate "
                                           + "threads, however, some generators may require main thread usage for accessing non thread-safe "
                                           + "Unity data structures and classes.");

                if (maxExecutionTime == 0)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (!EditorGUILayout.Toggle(label, true))
                    {
                        maxExecutionTime = 1;
                    }
                    GUILayout.Label("Infinity");
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    EditorGUI.BeginChangeCheck();
                    var maxTime = EditorGUILayout.IntSlider(label, maxExecutionTime, 0, 15);
                    if (EditorGUI.EndChangeCheck())
                    {
                        maxExecutionTime = maxTime;
                    }
                }
            }

            // Mesh simplifier
            {
                var type = meshSimplifierType;
                if (type != null)
                {
                    var label = new GUIContent("Default Mesh Simplifier", "All simplifiers (IMeshSimplifier) are "
                                               + "enumerated and provided here for selection. By allowing for multiple implementations, "
                                               + "different approaches can be compared. The default mesh simplifier is used to generate LODs "
                                               + "on import and when explicitly called.");

                    var displayedOptions = meshSimplifiers.Select(t => t.Name).ToArray();
                    EditorGUI.BeginChangeCheck();
                    var selected = EditorGUILayout.Popup(label, Array.IndexOf(displayedOptions, type.Name), displayedOptions);
                    if (EditorGUI.EndChangeCheck())
                    {
                        meshSimplifierType = meshSimplifiers[selected];
                    }

                    if (meshSimplifierType != null && typeof(IMeshSimplifier).IsAssignableFrom(meshSimplifierType))
                    {
                        if (s_SimplifierPreferences == null || s_SimplifierPreferences.GetType() != meshSimplifierType)
                        {
                            s_SimplifierPreferences = (IPreferences)Activator.CreateInstance(meshSimplifierType);
                        }

                        if (s_SimplifierPreferences != null)
                        {
                            EditorGUI.indentLevel++;
                            s_SimplifierPreferences.OnPreferencesGUI();
                            EditorGUI.indentLevel--;
                        }
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("No IMeshSimplifiers found!", MessageType.Warning);
                }
            }

            // Batcher
            {
                var type = batcherType;
                if (type != null)
                {
                    var label = new GUIContent("Default Batcher", "All simplifiers (IMeshSimplifier) are "
                                               + "enumerated and provided here for selection. By allowing for multiple implementations, "
                                               + "different approaches can be compared. The default batcher is used in HLOD generation when "
                                               + "combining objects that are located within the same LODVolume.");

                    var displayedOptions = batchers.Select(t => t.Name).ToArray();
                    EditorGUI.BeginChangeCheck();
                    var selected = EditorGUILayout.Popup(label, Array.IndexOf(displayedOptions, type.Name), displayedOptions);
                    if (EditorGUI.EndChangeCheck())
                    {
                        batcherType = batchers[selected];
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("No IBatchers found!", MessageType.Warning);
                }
            }

            // Max LOD
            {
                var label = new GUIContent("Maximum LOD Generated", "Controls the depth of the generated LOD chain");

                var maxLODValues = Enumerable.Range(0, LODData.MaxLOD + 1).ToArray();
                EditorGUI.BeginChangeCheck();
                int maxLODGenerated = EditorGUILayout.IntPopup(label, maxLOD,
                                                               maxLODValues.Select(v => new GUIContent(v.ToString())).ToArray(), maxLODValues);
                if (EditorGUI.EndChangeCheck())
                {
                    maxLOD = maxLODGenerated;
                }
            }

            // Control LOD0 maximum poly count
            {
                var label = new GUIContent("Initial LOD Max Poly Count", "In the case where non realtime-ready assets "
                                           + "are brought into Unity these would normally perform poorly. Being able to set a max poly count "
                                           + "for LOD0 allows even the largest of meshes to import with performance-minded defaults.");

                EditorGUI.BeginChangeCheck();
                var maxPolyCount = EditorGUILayout.IntField(label, initialLODMaxPolyCount);
                if (EditorGUI.EndChangeCheck())
                {
                    initialLODMaxPolyCount = maxPolyCount;
                }
            }

            // Generate LODs on import
            {
                var label = new GUIContent("Generate on Import", "Controls whether automatic LOD generation will happen "
                                           + "on import. Even if this option is disabled it is still possible to generate LOD chains "
                                           + "individually on individual files.");

                EditorGUI.BeginChangeCheck();
                var generateLODsOnImport = EditorGUILayout.Toggle(label, generateOnImport);
                if (EditorGUI.EndChangeCheck())
                {
                    generateOnImport = generateLODsOnImport;
                }
            }

            // Turn off/on saving assets (performance feature
            {
                var label = new GUIContent("Save Assets",
                                           "This can speed up performance, but may cause errors with some simplifiers");
                EditorGUI.BeginChangeCheck();
                var saveAssetsOnImport = EditorGUILayout.Toggle(label, saveAssets);
                if (EditorGUI.EndChangeCheck())
                {
                    saveAssets = saveAssetsOnImport;
                }
            }


            // Use SceneLOD?
            {
                var label = new GUIContent("Scene LOD", "Enable Hierarchical LOD (HLOD) support for scenes, "
                                           + "which will automatically generate and stay updated in the background.");

                EditorGUI.BeginChangeCheck();
                var enabled = EditorGUILayout.Toggle(label, sceneLODEnabled);
                if (EditorGUI.EndChangeCheck())
                {
                    sceneLODEnabled = enabled;
                }

                if (sceneLODEnabled)
                {
                    label = new GUIContent("Show Volume Bounds", "This will display the bounds visually of the bounding "
                                           + "volume hierarchy (currently an Octree)");

                    EditorGUI.indentLevel++;
                    EditorGUI.BeginChangeCheck();
                    var showBounds = EditorGUILayout.Toggle(label, showVolumeBounds);
                    if (EditorGUI.EndChangeCheck())
                    {
                        showVolumeBounds = showBounds;
                    }

                    var sceneLOD = SceneLOD.instance;
                    EditorGUILayout.HelpBox(string.Format("Coroutine Queue: {0}\nCurrent Execution Time: {1:0.00} s", sceneLOD.coroutineQueueRemaining, sceneLOD.coroutineCurrentExecutionTime * 0.001f), MessageType.None);

                    // Force more frequent updating
                    var mouseOverWindow = EditorWindow.mouseOverWindow;
                    if (mouseOverWindow)
                    {
                        mouseOverWindow.Repaint();
                    }

                    EditorGUI.indentLevel--;
                }
            }
#else
            EditorGUILayout.HelpBox(k_MinimumRequiredVersion, MessageType.Warning);
#endif

            EditorGUILayout.EndVertical();
        }
Beispiel #30
0
        private void Tab_DrawSetup()
        {
            FGUI_Inspector.VSpace(-2, -4);
            GUILayout.BeginVertical(FGUI_Resources.ViewBoxStyle);
            GUILayout.BeginVertical(FGUI_Resources.BGInBoxBlankStyle);
            GUILayout.Space(7f);

            Transform startField = Get.StartBone;

            if (Get.StartBone == null)
            {
                startField = Get.transform; GUI.color = new Color(1f, 1f, 1f, 0.7f);
            }


            if (topWarningAlpha > 0f)
            {
                if (topWarning != "")
                {
                    GUI.color = new Color(c.r, c.g, c.b, c.a * Mathf.Min(1f, topWarningAlpha));
                    //EditorGUILayout.HelpBox(topWarning, MessageType.Info);
                    if (GUILayout.Button(topWarning, FGUI_Inspector.Style(new Color(0.8f, 0.8f, 0f, 0.1f), 0), GUILayout.ExpandWidth(true)))
                    {
                        topWarningAlpha = 0f;
                    }
                    GUI.color        = c;
                    topWarningAlpha -= 0.05f;
                }
            }


            EditorGUI.BeginChangeCheck();
            EditorGUIUtility.labelWidth = 82;

            Transform preStart = Get.StartBone;

            if (Application.isPlaying)
            {
                GUI.enabled = false;
            }

            try
            {
                GUILayout.BeginHorizontal();
            }
            catch (System.Exception)
            {
                GUILayout.BeginHorizontal();
            }

            Transform startB = (Transform)EditorGUILayout.ObjectField(new GUIContent(sp_StartBone.displayName), startField, typeof(Transform), true);

            if (startB != preStart)
            {
                Get.EndBone = null;
                serializedObject.ApplyModifiedProperties();
            }

            if (Application.isPlaying)
            {
                GUI.enabled = true;
            }

            //bool canInclude = false;
            //if (startB) if (startB.parent) canInclude = true;

            bool boneInSkin = true; if (skins.Count != 0)

            {
                boneInSkin = false; for (int s = 0; s < skins.Count; s++)
                {
                    if (boneInSkin)
                    {
                        break;
                    }
                    for (int i = 0; i < skins[s].bones.Length; i++)
                    {
                        if (startB == skins[s].bones[i])
                        {
                            boneInSkin = true; break;
                        }
                    }
                }
            }

            if (!boneInSkin)
            {
                GUILayout.Space(4);
                EditorGUILayout.LabelField(new GUIContent(FGUI_Resources.Tex_Warning, "'Start Bone' was not found in mesh renderer of this object, are you sure you assigned correct 'Start Bone'?"), new GUILayoutOption[] { GUILayout.Height(18), GUILayout.Width(20) });
            }

            {
                EditorGUI.BeginChangeCheck();
                Get.IncludeParent = EditorGUILayout.IntPopup(new GUIContent("", "If start bone should be included in tail motion or just be anchor for rest of the bones"), Get.IncludeParent ? 1 : 0, setp_includeParentNames, setp_includeParent, GUILayout.Width(64)) == 1;

                if (EditorGUI.EndChangeCheck())
                {
                    GetSelectedTailAnimators();
                    for (int i = 0; i < lastSelected.Count; i++)
                    {
                        lastSelected[i].IncludeParent = Get.IncludeParent; new SerializedObject(lastSelected[i]).ApplyModifiedProperties();
                    }
                }

                //if (Get.IncludeParent)
                //    if (!canInclude)
                //    {
                //        GUILayout.Space(4);
                //        EditorGUILayout.LabelField(new GUIContent(FGUI_Resources.Tex_Info, "Start bone need to have parent in order to be included in chain.\nAfter entering playmode this parameter will be set to 'Excluded'"), new GUILayoutOption[] { GUILayout.Height(18), GUILayout.Width(20) });
                //    }
            }

            GUILayout.EndHorizontal();


            EditorGUIUtility.labelWidth = 0;
            if (EditorGUI.EndChangeCheck())
            {
                Get.StartBone = startB; serializedObject.ApplyModifiedProperties(); Get.GetGhostChain(); serializedObject.Update();
            }

            GUI.color = c;

            GUILayout.Space(4f);
            GUILayout.EndVertical();

            GUILayout.BeginVertical(FGUI_Resources.BGInBoxStyle);
            Fold_TailChainSetup();

            GUILayout.Space(-5f);

            GUILayout.EndVertical();

            //Fold_DrawCoreAnimatorSetup();
            Fold_DrawAdditionalSetup();

            GUILayout.EndVertical();
        }