Exemplo n.º 1
0
    static void Initialize()
    {
        YuME_tileConverter tileConverterWindow = EditorWindow.GetWindow <YuME_tileConverter>(false, "Tile Converter");

        tileConverterWindow.titleContent.text = "Tile Converter";
    }
Exemplo n.º 2
0
    void OnGUI()
    {
        // ----------------------------------------------------------------------------------------------------
        // ------ Tile Import Data
        // ----------------------------------------------------------------------------------------------------

        EditorGUILayout.Space();
        GUILayout.Label(editorData.tileImporterHeader);

        _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);

        EditorGUILayout.LabelField("Tile Import Settings", EditorStyles.boldLabel);

        EditorGUILayout.BeginVertical("box");

        if (userSettings.sourceTiles == null)
        {
            userSettings.sourceTiles = (GameObject)EditorGUILayout.ObjectField("Source Tiles Object", null, typeof(GameObject), false);
        }
        else
        {
            userSettings.sourceTiles = (GameObject)EditorGUILayout.ObjectField("Source Tiles Object", userSettings.sourceTiles, typeof(GameObject), false);
        }

        if (userSettings.sourceMaterial == null)
        {
            userSettings.sourceMaterial = (Material)EditorGUILayout.ObjectField("Source Tile Material", null, typeof(Material), false);
        }
        else
        {
            userSettings.sourceMaterial = (Material)EditorGUILayout.ObjectField("Source Tile Material", userSettings.sourceMaterial, typeof(Material), false);
        }

        if (userSettings.sourceTexture == null)
        {
            userSettings.sourceTexture = (Texture)EditorGUILayout.ObjectField("Source Tile Texture", null, typeof(Texture), false);
        }
        else
        {
            userSettings.sourceTexture = (Texture)EditorGUILayout.ObjectField("Source Tile Texture", userSettings.sourceTexture, typeof(Texture), false);
        }

        EditorGUILayout.EndVertical();

        // ----------------------------------------------------------------------------------------------------
        // ------ Static Settings
        // ----------------------------------------------------------------------------------------------------

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Prefab Static Setting", EditorStyles.boldLabel);

        EditorGUILayout.BeginVertical("box");

        userSettings.tileStatic = EditorGUILayout.Toggle("Set Tiles as Static", userSettings.tileStatic);

        EditorGUILayout.EndVertical();

        // ----------------------------------------------------------------------------------------------------
        // ------ Alt Settings
        // ----------------------------------------------------------------------------------------------------

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("ALT Tile Setting", EditorStyles.boldLabel);

        EditorGUILayout.BeginVertical("box");

        userSettings.altIdentifier = EditorGUILayout.TextField("Alternative Tile Identifier", userSettings.altIdentifier);

        EditorGUILayout.EndVertical();

        // ----------------------------------------------------------------------------------------------------
        // ------ Shadow Settings
        // ----------------------------------------------------------------------------------------------------

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Prefab Shadow Setup", EditorStyles.boldLabel);

        EditorGUILayout.BeginVertical("box");

        userSettings.shadowCastingMode = EditorGUILayout.Popup("Cast Shadows", userSettings.shadowCastingMode, new string[] { "Off", "On", "ShadowsOnly", "TwoSided" });

        userSettings.receiveShadows = EditorGUILayout.Toggle("Receive Shadows", userSettings.receiveShadows);

        EditorGUILayout.EndVertical();

        // ----------------------------------------------------------------------------------------------------
        // ------ Collision Settings
        // ----------------------------------------------------------------------------------------------------

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Tile Collision Setup", EditorStyles.boldLabel);

        EditorGUILayout.BeginVertical("box");

        userSettings.bypassCollisionSetup = EditorGUILayout.Toggle("Bypass Collision Setup", userSettings.bypassCollisionSetup);

        if (!userSettings.bypassCollisionSetup)
        {
            userSettings.importCollision = EditorGUILayout.Toggle("Custom Collision Mesh", userSettings.importCollision);

            if (userSettings.importCollision)
            {
                userSettings.collisionIdentifier = EditorGUILayout.TextField("Collision Mesh Identifier", userSettings.collisionIdentifier);
            }
        }

        EditorGUILayout.EndVertical();

        // ----------------------------------------------------------------------------------------------------
        // ------ Bounding Box Settings
        // ----------------------------------------------------------------------------------------------------

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Tile Bounding Setup", EditorStyles.boldLabel);

        EditorGUILayout.BeginVertical("box");

        userSettings.importCustomBounds = EditorGUILayout.Toggle("Custom Bounds Mesh", userSettings.importCustomBounds);

        if (userSettings.importCustomBounds)
        {
            userSettings.customBoundsIdentifier = EditorGUILayout.TextField("Custom Bounds Identifier", userSettings.customBoundsIdentifier);
        }

        EditorGUILayout.EndVertical();

        //data.userSettings.splitByType = EditorGUI.Toggle(new Rect(3, 295, position.width - 3, 20),
        //    new GUIContent("Split Tiles by Type", "Checks the tile name for keywords such as 'wall', 'floor', 'corner' and puts them in seperate folders for easy navigation"),
        //    data.userSettings.splitByType);

        // ----------------------------------------------------------------------------------------------------
        // ------ Append Settings
        // ----------------------------------------------------------------------------------------------------

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Custom Append Label", EditorStyles.boldLabel);

        EditorGUILayout.BeginVertical("box");

        userSettings.appendName = EditorGUILayout.TextField("Append to Tile Name", userSettings.appendName);

        EditorGUILayout.EndVertical();

        // ----------------------------------------------------------------------------------------------------
        // ------ Folder Settings
        // ----------------------------------------------------------------------------------------------------

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Select Tile Prefab Destination Folder", EditorStyles.boldLabel);

        EditorGUILayout.BeginVertical("box");

        EditorGUILayout.LabelField("Set Destination Folders");

        if (GUILayout.Button("Tile Destination", GUILayout.Height(30)))
        {
            userSettings.destinationFolder = EditorUtility.OpenFolderPanel("Tile Prefab Destination Folder", "", "");

            if (userSettings.destinationFolder == "")
            {
                userSettings.destinationFolder = "Assets/";
            }
        }

        userSettings.destinationFolder = YuTools_Utils.shortenAssetPath(userSettings.destinationFolder);

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Select Mesh Destination Folder");

        if (GUILayout.Button("Mesh Destination", GUILayout.Height(30)))
        {
            userSettings.meshFolder = EditorUtility.OpenFolderPanel("Tile Mesh Destination Folder", "", "");

            if (userSettings.meshFolder == "")
            {
                userSettings.meshFolder = "Assets/";
            }
        }

        EditorGUILayout.Space();

        EditorGUILayout.EndVertical();

        userSettings.meshFolder = YuTools_Utils.shortenAssetPath(userSettings.meshFolder);

        // ----------------------------------------------------------------------------------------------------
        // ------ Import Button
        // ----------------------------------------------------------------------------------------------------

        EditorGUILayout.Space();

        if (userSettings.sourceTiles != null)
        {
            if (GUILayout.Button("Import Tileset", GUILayout.Height(40)))
            {
                bool tileDestinationFolderWarning = true;
                bool meshDestinationFolderWarning = true;

                if (userSettings.destinationFolder == "Assets/")
                {
                    tileDestinationFolderWarning = EditorUtility.DisplayDialog("Tile Prefabs will be created in the root Assets Folder",
                                                                               "Are you sure you want create the tile prefabs in the root Asset/ folder?", "OK", "Cancel");
                }

                if (userSettings.meshFolder == "Assets/")
                {
                    meshDestinationFolderWarning = EditorUtility.DisplayDialog("New mesh data will be created in the root Assets Folder",
                                                                               "Are you sure you want create the new mesh data in the root Asset/ folder?", "OK", "Cancel");
                }

                if (tileDestinationFolderWarning && meshDestinationFolderWarning)
                {
                    refreshSourceTileObject();
                    createTemplateMaterial();
                    createTemplateTileObject();
                    setTileShadowOptions();
                    createTileSet();
                    revertScenePrefabs();
                    YuME_tileConverter.recreateCustomBrushes(userSettings.destinationFolder);
                    cleanUpImport();
                }
            }
        }
        else
        {
            EditorGUILayout.HelpBox("Set a Source Tile Object To Create Tile Set", MessageType.Warning);
        }

        // ----------------------------------------------------------------------------------------------------
        // ------ Output Folder Information
        // ----------------------------------------------------------------------------------------------------

        EditorGUILayout.Space();

        EditorGUILayout.BeginVertical("box");

        EditorGUILayout.LabelField("Tile Output Folder:", EditorStyles.boldLabel);
        EditorGUILayout.LabelField(userSettings.destinationFolder);

        EditorGUILayout.LabelField("Mesh Output Folder:", EditorStyles.boldLabel);
        EditorGUILayout.LabelField(userSettings.meshFolder);

        EditorGUILayout.EndVertical();

        EditorGUILayout.EndScrollView();

        // ----------------------------------------------------------------------------------------------------
        // ------ GUI Changed
        // ----------------------------------------------------------------------------------------------------

        if (GUI.changed)
        {
            if (userSettings.sourceMaterial != null)
            {
                userSettings.sourceTexture = userSettings.sourceMaterial.mainTexture;
            }

            EditorUtility.SetDirty(userSettings);
        }
    }