public static void Show(Action <IFerr2DTMaterial> aOnPickMaterial)
    {
        Ferr2DT_MaterialSelector wiz = ScriptableWizard.DisplayWizard <Ferr2DT_MaterialSelector>("Select Terrain Material");

        wiz._onPickMaterial = aOnPickMaterial;
        wiz._selectedObject = null;
    }
    private void ShowMaterialSelector()
    {
        EditorGUILayout.LabelField("TERRAIN MATERIAL");

        Ferr.EditorTools.Box(4, () => {
            EditorGUILayout.BeginHorizontal();
            IFerr2DTMaterial material = terrain.TerrainMaterial;
            GUIContent button         = material != null && material.edgeMaterial != null && material.edgeMaterial.mainTexture != null ? new GUIContent(material.edgeMaterial.mainTexture) : new GUIContent("Pick");
            if (GUILayout.Button(button, GUILayout.Width(64f), GUILayout.Height(64f)))
            {
                Ferr2DT_MaterialSelector.Show((mat) => {
                    if (mat != terrain.TerrainMaterial)
                    {
                        SelectMaterial((UnityEngine.Object)mat);
                    }
                    materialChanged = true;
                });
            }

            UnityEngine.Object obj = EditorGUILayout.ObjectField((UnityEngine.Object)terrain.TerrainMaterial, typeof(Ferr2DT_Material), false, GUILayout.Height(64f));
            if (obj != (UnityEngine.Object)terrain.TerrainMaterial)
            {
                SelectMaterial(obj);
                materialChanged = true;
            }
            EditorGUILayout.EndHorizontal();
        });
    }
    public static void Show(Action <IFerr2DTMaterial> aOnPickMaterial)
    {
        Ferr2DT_MaterialSelector wiz = ScriptableWizard.DisplayWizard <Ferr2DT_MaterialSelector>("Select Terrain Material");

        wiz.materials      = new List <IFerr2DTMaterial>();
        wiz.onPickMaterial = aOnPickMaterial;
        wiz.materials      = Ferr.ComponentTracker.GetComponents <IFerr2DTMaterial>();
    }
Ejemplo n.º 4
0
    public static void Show(Action <Ferr2DT_TerrainMaterial> aOnPickMaterial)
    {
        Ferr2DT_MaterialSelector wiz = ScriptableWizard.DisplayWizard <Ferr2DT_MaterialSelector>("Select Terrain Material");

        wiz.materials      = new List <Ferr2DT_TerrainMaterial>();
        wiz.onPickMaterial = aOnPickMaterial;

        string[] fileNames  = System.IO.Directory.GetFiles(Application.dataPath, "*.prefab", System.IO.SearchOption.AllDirectories);
        int      pathLength = Application.dataPath.Length + 1;

        for (int i = fileNames.Length; i > 0; i--)
        {
            fileNames [i - 1] = "Assets\\" + fileNames[i - 1].Substring(pathLength);
            GameObject go = UnityEditor.AssetDatabase.LoadAssetAtPath(fileNames[i - 1], typeof(GameObject)) as GameObject;
            if (go != null)
            {
                Ferr2DT_TerrainMaterial source = go.GetComponent <Ferr2DT_TerrainMaterial>();
                if (source)
                {
                    wiz.materials.Add(source);
                }
            }
        }
    }
    public override void OnInspectorGUI()
    {
        Undo.RecordObject(target, "Modified Path Terrain");

        Ferr2DT_PathTerrain sprite = (Ferr2DT_PathTerrain)target;

        multiSelect = targets.Length > 1;

        // render the material selector!
        Ferr.EditorTools.Box(4, () => {
            IFerr2DTMaterial material = sprite.TerrainMaterial;

            EditorGUILayout.BeginHorizontal();
            GUIContent button = material != null && material.edgeMaterial != null && material.edgeMaterial.mainTexture != null ? new GUIContent(material.edgeMaterial.mainTexture) : new GUIContent("Pick");
            if (GUILayout.Button(button, GUILayout.Width(48f), GUILayout.Height(48f)))
            {
                Action <IFerr2DTMaterial> callback = null;
                for (int i = 0; i < targets.Length; i += 1)
                {
                    Ferr2DT_PathTerrain curr = (Ferr2DT_PathTerrain)targets[i];
                    callback += (mat) => {
                        Undo.RecordObject(curr, "Changed Terrain Material");
                        curr.SetMaterial(mat);
                        EditorUtility.SetDirty(curr);
                    };
                }
                Ferr2DT_MaterialSelector.Show(callback);
            }

            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Terrain Material:");
            EditorGUI.indentLevel = 2;
            EditorGUILayout.LabelField(sprite.TerrainMaterial == null ? "None" : sprite.TerrainMaterial.name);
            EditorGUI.indentLevel = 0;
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
        });


        showVisuals = EditorGUILayout.Foldout(showVisuals, "VISUALS");

        if (showVisuals)
        {
            EditorGUI.indentLevel = 2;
            Ferr.EditorTools.Box(4, () => {
                // other visual data
                EditorGUILayout.PropertyField(vertexColorType);
                EditorGUI.indentLevel = 3;
                if (!vertexColorType.hasMultipleDifferentValues && vertexColorType.enumValueIndex == (int)Ferr2DT_ColorType.SolidColor)
                {
                    EditorGUILayout.PropertyField(vertexColor);
                }
                else if (!vertexColorType.hasMultipleDifferentValues && vertexColorType.enumValueIndex == (int)Ferr2DT_ColorType.Gradient)
                {
                    EditorGUILayout.PropertyField(vertexGradientAngle);
                    EditorGUILayout.PropertyField(vertexGradient);
                }
                else if (!vertexColorType.hasMultipleDifferentValues && vertexColorType.enumValueIndex == (int)Ferr2DT_ColorType.DistanceGradient)
                {
                    EditorGUILayout.PropertyField(vertexGradientDistance);
                    EditorGUILayout.PropertyField(vertexGradient);
                }
                EditorGUI.indentLevel = 2;

                EditorGUILayout.PropertyField(pixelsPerUnit);
                EditorGUILayout.PropertyField(slantAmount);
                EditorGUILayout.PropertyField(splitMiddle);
                EditorGUILayout.PropertyField(createTangents);
                EditorGUILayout.PropertyField(randomByWorldCoordinates, new GUIContent("Randomize Edge by World Coordinates"));
                EditorGUILayout.PropertyField(uvOffset, new GUIContent("Fill UV Offset"));

                if (!serializedObject.isEditingMultipleObjects)
                {
                    Renderer renderCom     = sprite.GetComponent <Renderer>();
                    string[] sortingLayers = Ferr.LayerUtil.GetSortingLayerNames();
                    if (sortingLayers != null)
                    {
                        string currName = renderCom.sortingLayerName == "" ? "Default" : renderCom.sortingLayerName;
                        int nameID      = EditorGUILayout.Popup("Sorting Layer", Array.IndexOf(sortingLayers, currName), sortingLayers);

                        renderCom.sortingLayerName = sortingLayers[nameID];
                    }
                    else
                    {
                        renderCom.sortingLayerID = EditorGUILayout.IntField("Sorting Layer", renderCom.sortingLayerID);
                    }
                    renderCom.sortingOrder = EditorGUILayout.IntField("Order in Layer", renderCom.sortingOrder);

                    // warn if the shader's aren't likely to work with the settings provided!
                    if (renderCom.sortingOrder != 0 || (renderCom.sortingLayerName != "Default" && renderCom.sortingLayerName != ""))
                    {
                        bool opaque = false;
                        for (int i = 0; i < renderCom.sharedMaterials.Length; ++i)
                        {
                            Material mat = renderCom.sharedMaterials[i];
                            if (mat != null && mat.GetTag("RenderType", false, "") == "Opaque")
                            {
                                opaque = true;
                            }
                        }
                        if (opaque)
                        {
                            EditorGUILayout.HelpBox("Layer properties won't work properly unless your shaders are all 'transparent'!", MessageType.Warning);
                        }
                    }
                }
            });
        }
        EditorGUI.indentLevel = 0;

        showTerrainType = EditorGUILayout.Foldout(showTerrainType, "TERRAIN TYPE");
        if (showTerrainType)
        {
            EditorGUI.indentLevel = 2;
            Ferr.EditorTools.Box(4, () => {
                EditorGUILayout.PropertyField(fill, new GUIContent("Fill Type"));
                if (fill.enumValueIndex == (int)Ferr2DT_FillMode.Closed || fill.enumValueIndex == (int)Ferr2DT_FillMode.InvertedClosed || fill.enumValueIndex == (int)Ferr2DT_FillMode.FillOnlyClosed && sprite.GetComponent <Ferr2D_Path>() != null)
                {
                    sprite.GetComponent <Ferr2D_Path>().closed = true;
                }
                if (fill.enumValueIndex != (int)Ferr2DT_FillMode.None && (sprite.TerrainMaterial != null && sprite.TerrainMaterial.fillMaterial == null))
                {
                    fill.enumValueIndex = (int)Ferr2DT_FillMode.None;
                }
                if (fill.enumValueIndex != (int)Ferr2DT_FillMode.None)
                {
                    EditorGUILayout.PropertyField(fillZ, new GUIContent("Fill Z Offset"));
                }
                if (fill.enumValueIndex == (int)Ferr2DT_FillMode.Skirt)
                {
                    EditorGUILayout.PropertyField(fillY, new GUIContent("Skirt Y Value"));
                }

                EditorGUILayout.PropertyField(splitCorners);
                EditorGUILayout.PropertyField(smoothPath);
                EditorGUI.indentLevel = 3;
                if (smoothPath.boolValue)
                {
                    EditorGUILayout.PropertyField(splitCount, new GUIContent("Edge Splits"));
                    EditorGUILayout.PropertyField(splitDist, new GUIContent("Fill Split"));
                    if (splitCount.intValue < 1)
                    {
                        splitCount.intValue = 2;
                    }
                }
                else
                {
                    splitCount.intValue  = 0;
                    splitDist.floatValue = 1;
                }
                EditorGUI.indentLevel = 2;

                EditorGUILayout.PropertyField(fillSplit, new GUIContent("Split fill mesh"));
                if (fillSplit.boolValue)
                {
                    EditorGUI.indentLevel = 3;
                    EditorGUILayout.PropertyField(fillSplitDistance, new GUIContent("Split Distance"));
                    EditorGUI.indentLevel = 2;
                }
            });
        }
        EditorGUI.indentLevel = 0;


        showCollider = EditorGUILayout.Foldout(showCollider, "COLLIDER");
        // render collider options
        if (showCollider)
        {
            EditorGUI.indentLevel = 2;
            Ferr.EditorTools.Box(4, () => {
                EditorGUILayout.PropertyField(createCollider);
                if (createCollider.boolValue)
                {
                    EditorGUILayout.PropertyField(sharpCorners);
                    if (sharpCorners.boolValue)
                    {
                        EditorGUI.indentLevel = 3;
                        EditorGUILayout.PropertyField(sharpCornerDistance, new GUIContent("Corner Distance"));
                        EditorGUI.indentLevel = 2;
                    }

                    EditorGUILayout.PropertyField(create3DCollider, new GUIContent("Use 3D Collider"));
                    if (sprite.create3DCollider)
                    {
                        EditorGUI.indentLevel = 3;
                        EditorGUILayout.PropertyField(depth, new GUIContent("Collider Width"));
                        EditorGUILayout.PropertyField(smoothSphereCollisions);
                        EditorGUI.indentLevel = 2;
                        EditorGUILayout.PropertyField(isTrigger);
                        EditorGUILayout.PropertyField(physicsMaterial);
                    }
                    else
                    {
                        EditorGUILayout.PropertyField(useEdgeCollider);
                        EditorGUILayout.PropertyField(usedByEffector);
                        EditorGUILayout.PropertyField(isTrigger);
                        EditorGUILayout.PropertyField(physicsMaterial2D);
                    }

                    if (sprite.fill == Ferr2DT_FillMode.None)
                    {
                        EditorGUILayout.PropertyField(surfaceOffset.GetArrayElementAtIndex((int)Ferr2DT_TerrainDirection.Top), new GUIContent("Thickness Top"));
                        EditorGUILayout.PropertyField(surfaceOffset.GetArrayElementAtIndex((int)Ferr2DT_TerrainDirection.Bottom), new GUIContent("Thickness Bottom"));
                    }
                    else
                    {
                        EditorGUILayout.PropertyField(surfaceOffset.GetArrayElementAtIndex((int)Ferr2DT_TerrainDirection.Top), new GUIContent("Offset Top"));
                        EditorGUILayout.PropertyField(surfaceOffset.GetArrayElementAtIndex((int)Ferr2DT_TerrainDirection.Left), new GUIContent("Offset Left"));
                        EditorGUILayout.PropertyField(surfaceOffset.GetArrayElementAtIndex((int)Ferr2DT_TerrainDirection.Right), new GUIContent("Offset Right"));
                        EditorGUILayout.PropertyField(surfaceOffset.GetArrayElementAtIndex((int)Ferr2DT_TerrainDirection.Bottom), new GUIContent("Offset Bottom"));
                    }

                    //EditorGUI.indentLevel = 0;
                    EditorGUILayout.LabelField("Generate colliders along:");
                    EditorGUILayout.PropertyField(collidersTop, new GUIContent("Top"));
                    EditorGUILayout.PropertyField(collidersLeft, new GUIContent("Left"));
                    EditorGUILayout.PropertyField(collidersRight, new GUIContent("Right"));
                    EditorGUILayout.PropertyField(collidersBottom, new GUIContent("Bottom"));

                    if (!collidersBottom.boolValue || !collidersLeft.boolValue || !collidersRight.boolValue || !collidersTop.boolValue)
                    {
                        EditorGUI.indentLevel = 2;
                        EditorGUILayout.PropertyField(colliderThickness);
                        EditorGUI.indentLevel = 0;
                    }
                }
            });
        }
        EditorGUI.indentLevel = 0;

        if (serializedObject.ApplyModifiedProperties() || GUI.changed)
        {
            for (int i = 0; i < targets.Length; i++)
            {
                EditorUtility.SetDirty(targets[i]);
                ((Ferr2DT_PathTerrain)targets[i]).Build(true);
            }

            cachedColliders = sprite.GetColliderVerts();
        }
        if (Event.current.type == EventType.ValidateCommand)
        {
            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":
                sprite.ForceMaterial(sprite.TerrainMaterial, true);
                sprite.Build(true);
                cachedColliders = sprite.GetColliderVerts();
                break;
            }
        }
    }
    public override void OnInspectorGUI()
    {
                #if !(UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0)
        Undo.RecordObject(target, "Modified Path Terrain");
                #else
        Undo.SetSnapshotTarget(target, "Modified Path Terrain");
                #endif

        Ferr2DT_PathTerrain sprite = (Ferr2DT_PathTerrain)target;

        // render the material selector!
        Ferr_EditorTools.Box(4, () => {
            EditorGUILayout.BeginHorizontal();
            GUIContent button = sprite.TerrainMaterial != null && sprite.TerrainMaterial.edgeMaterial != null && sprite.TerrainMaterial.edgeMaterial.mainTexture != null ? new GUIContent(sprite.TerrainMaterial.edgeMaterial.mainTexture) : new GUIContent("Pick");
            if (GUILayout.Button(button, GUILayout.Width(48f), GUILayout.Height(48f)))
            {
                Ferr2DT_MaterialSelector.Show(sprite.SetMaterial);
            }
            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Terrain Material:");
            EditorGUI.indentLevel = 2;
            EditorGUILayout.LabelField(sprite.TerrainMaterial == null ? "None" : sprite.TerrainMaterial.name);
            EditorGUI.indentLevel = 0;
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
        });


        showVisuals = EditorGUILayout.Foldout(showVisuals, "VISUALS");

        if (showVisuals)
        {
            EditorGUI.indentLevel = 2;
            Ferr_EditorTools.Box(4, () => {
                // other visual data
                sprite.vertexColor              = EditorGUILayout.ColorField("Vertex Color", sprite.vertexColor);
                sprite.pixelsPerUnit            = Mathf.Clamp(EditorGUILayout.FloatField("Pixels Per Unit", sprite.pixelsPerUnit), 1, 768);
                sprite.stretchThreshold         = EditorGUILayout.Slider("Stretch Threshold", sprite.stretchThreshold, 0f, 1f);
                sprite.slantAmount              = EditorGUILayout.Slider("Slant Amount", sprite.slantAmount, -2, 2);
                sprite.splitMiddle              = EditorGUILayout.Toggle("Split Middle", sprite.splitMiddle);
                sprite.createTangents           = EditorGUILayout.Toggle("Create Tangents", sprite.createTangents);
                sprite.randomByWorldCoordinates = EditorGUILayout.Toggle("Randomize Edge by World Coordinates", sprite.randomByWorldCoordinates);
                sprite.uvOffset = EditorGUILayout.Vector2Field("Fill UV Offset", sprite.uvOffset);
#if !(UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0)
                Type utility = Type.GetType("UnityEditorInternal.InternalEditorUtility, UnityEditor");
                if (utility != null)
                {
                    PropertyInfo sortingLayerNames = utility.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
                    if (sortingLayerNames != null)
                    {
                        string[]     layerNames = sortingLayerNames.GetValue(null, null) as string[];
                        int current             = 0;

                        if (layerNames != null)
                        {
                            current = Array.IndexOf(layerNames, sprite.GetComponent <Renderer>().sortingLayerName);
                        }
                        if (current <= -1)
                        {
                            current = 0;
                        }

                        if (current != sprite.GetComponent <Renderer>().sortingLayerID || sprite.GetComponent <Renderer>().sortingLayerID < 0 || sprite.GetComponent <Renderer>().sortingLayerID >= layerNames.Length)
                        {
                            sprite.GetComponent <Renderer>().sortingLayerID = EditorGUILayout.IntField("Sorting Layer", sprite.GetComponent <Renderer>().sortingLayerID);
                        }
                        else
                        {
                            sprite.GetComponent <Renderer>().sortingLayerName = layerNames[EditorGUILayout.Popup("Sorting Layer", current, layerNames)];
                        }
                    }
                    else
                    {
                        sprite.GetComponent <Renderer>().sortingLayerID = EditorGUILayout.IntField("Sorting Layer", sprite.GetComponent <Renderer>().sortingLayerID);
                    }
                }
                else
                {
                    sprite.GetComponent <Renderer>().sortingLayerID = EditorGUILayout.IntField("Sorting Layer", sprite.GetComponent <Renderer>().sortingLayerID);
                }
                sprite.GetComponent <Renderer>().sortingOrder = EditorGUILayout.IntField("Order in Layer", sprite.GetComponent <Renderer>().sortingOrder);
#endif
            });
        }
        EditorGUI.indentLevel = 0;

        showTerrainType = EditorGUILayout.Foldout(showTerrainType, "TERRAIN TYPE");
        if (showTerrainType)
        {
            EditorGUI.indentLevel = 2;
            Ferr_EditorTools.Box(4, () => {
                sprite.fill = (Ferr2DT_FillMode)EditorGUILayout.EnumPopup("Fill Type", sprite.fill);
                if (sprite.fill == Ferr2DT_FillMode.Closed || sprite.fill == Ferr2DT_FillMode.InvertedClosed || sprite.fill == Ferr2DT_FillMode.FillOnlyClosed && sprite.GetComponent <Ferr2D_Path>() != null)
                {
                    sprite.GetComponent <Ferr2D_Path>().closed = true;
                }
                if (sprite.fill != Ferr2DT_FillMode.None && (sprite.TerrainMaterial != null && sprite.TerrainMaterial.fillMaterial == null))
                {
                    sprite.fill = Ferr2DT_FillMode.None;
                }
                if (sprite.fill != Ferr2DT_FillMode.None)
                {
                    sprite.fillZ = EditorGUILayout.FloatField("Fill Z Offset", sprite.fillZ);
                }
                if (sprite.fill == Ferr2DT_FillMode.Skirt)
                {
                    sprite.fillY = EditorGUILayout.FloatField("Skirt Y Value", sprite.fillY);
                }

                sprite.splitCorners   = EditorGUILayout.Toggle("Split Corners", sprite.splitCorners);
                sprite.smoothPath     = EditorGUILayout.Toggle("Smooth Path", sprite.smoothPath);
                EditorGUI.indentLevel = 3;
                if (sprite.smoothPath)
                {
                    sprite.splitCount = EditorGUILayout.IntField("Edge Splits", sprite.splitCount);
                    sprite.splitDist  = EditorGUILayout.Slider("Fill Split", sprite.splitDist, 0.1f, 4);
                    if (sprite.splitCount < 1)
                    {
                        sprite.splitCount = 2;
                    }
                }
                else
                {
                    sprite.splitCount = 0;
                    sprite.splitDist  = 1;
                }
                EditorGUI.indentLevel = 2;
            });
        }
        EditorGUI.indentLevel = 0;


        showCollider = EditorGUILayout.Foldout(showCollider, "COLLIDER");
        // render collider options
        if (showCollider)
        {
            EditorGUI.indentLevel = 2;
            Ferr_EditorTools.Box(4, () => {
                sprite.createCollider = EditorGUILayout.Toggle("Create Collider", sprite.createCollider);
                if (sprite.createCollider)
                {
                    sprite.sharpCorners = EditorGUILayout.Toggle("Sharp Corners", sprite.sharpCorners);
                    if (sprite.sharpCorners)
                    {
                        EditorGUI.indentLevel      = 3;
                        sprite.sharpCornerDistance = Mathf.Max(0, EditorGUILayout.FloatField("Corner Distance", sprite.sharpCornerDistance));
                        EditorGUI.indentLevel      = 2;
                    }


                                #if !(UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0)
                    sprite.create3DCollider = EditorGUILayout.Toggle("Use 3D Collider", sprite.create3DCollider);
                    if (sprite.create3DCollider)
                    {
                        EditorGUI.indentLevel         = 3;
                        sprite.depth                  = EditorGUILayout.FloatField("Collider Width", sprite.depth);
                        sprite.smoothSphereCollisions = EditorGUILayout.Toggle("Smooth Sphere Collisions", sprite.smoothSphereCollisions);
                        EditorGUI.indentLevel         = 2;
                        sprite.isTrigger              = EditorGUILayout.Toggle("Is Trigger", sprite.isTrigger);
                        sprite.physicsMaterial        = (PhysicMaterial)EditorGUILayout.ObjectField("Physics Material", sprite.physicsMaterial, typeof(PhysicMaterial), true);
                    }
                    else
                    {
                        sprite.isTrigger         = EditorGUILayout.Toggle("Is Trigger", sprite.isTrigger);
                        sprite.physicsMaterial2D = (PhysicsMaterial2D)EditorGUILayout.ObjectField("Physics Material", sprite.physicsMaterial2D, typeof(PhysicsMaterial2D), true);
                    }
                                #else
                    sprite.depth           = EditorGUILayout.FloatField("Collider Width", sprite.depth);
                    sprite.physicsMaterial = (PhysicMaterial)EditorGUILayout.ObjectField("Physics Material", sprite.physicsMaterial, typeof(PhysicMaterial), true);
                                #endif


                    if (sprite.fill == Ferr2DT_FillMode.None)
                    {
                        sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Top]    = EditorGUILayout.FloatField("Thickness Top", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Top]);
                        sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Bottom] = EditorGUILayout.FloatField("Thickness Bottom", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Bottom]);
                    }
                    else
                    {
                        sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Top]    = EditorGUILayout.FloatField("Offset Top", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Top]);
                        sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Left]   = EditorGUILayout.FloatField("Offset Left", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Left]);
                        sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Right]  = EditorGUILayout.FloatField("Offset Right", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Right]);
                        sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Bottom] = EditorGUILayout.FloatField("Offset Bottom", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Bottom]);
                    }

                    //EditorGUI.indentLevel = 0;
                    EditorGUILayout.LabelField("Generate colliders along:");
                    sprite.collidersTop    = EditorGUILayout.Toggle("Top", sprite.collidersTop);
                    sprite.collidersLeft   = EditorGUILayout.Toggle("Left", sprite.collidersLeft);
                    sprite.collidersRight  = EditorGUILayout.Toggle("Right", sprite.collidersRight);
                    sprite.collidersBottom = EditorGUILayout.Toggle("Bottom", sprite.collidersBottom);

                                #if !(UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0)
                    if (!sprite.collidersBottom || !sprite.collidersLeft || !sprite.collidersRight || !sprite.collidersTop)
                    {
                        EditorGUI.indentLevel    = 2;
                        sprite.colliderThickness = EditorGUILayout.FloatField("Collider Thickness", sprite.colliderThickness);
                        EditorGUI.indentLevel    = 0;
                    }
                                #endif
                }
            });
        }
        EditorGUI.indentLevel = 0;

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
            sprite.RecreatePath(true);
            cachedColliders = sprite.GetColliderVerts();
        }
        if (Event.current.type == EventType.ValidateCommand)
        {
            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":
                sprite.ForceMaterial(sprite.TerrainMaterial, true);
                sprite.RecreatePath(true);
                cachedColliders = sprite.GetColliderVerts();
                break;
            }
        }
    }
Ejemplo n.º 7
0
    public override void OnInspectorGUI()
    {
        Undo.RecordObject(target, "Modified Path Terrain");

        Ferr2DT_PathTerrain sprite = (Ferr2DT_PathTerrain)target;

        // render the material selector!
        Ferr.EditorTools.Box(4, () => {
            EditorGUILayout.BeginHorizontal();
            GUIContent button = sprite.TerrainMaterial != null && sprite.TerrainMaterial.edgeMaterial != null && sprite.TerrainMaterial.edgeMaterial.mainTexture != null ? new GUIContent(sprite.TerrainMaterial.edgeMaterial.mainTexture) : new GUIContent("Pick");
            if (GUILayout.Button(button, GUILayout.Width(48f), GUILayout.Height(48f)))
            {
                Ferr2DT_MaterialSelector.Show(sprite.SetMaterial);
            }
            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Terrain Material:");
            EditorGUI.indentLevel = 2;
            EditorGUILayout.LabelField(sprite.TerrainMaterial == null ? "None" : sprite.TerrainMaterial.name);
            EditorGUI.indentLevel = 0;
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
        });


        showVisuals = EditorGUILayout.Foldout(showVisuals, "VISUALS");

        if (showVisuals)
        {
            EditorGUI.indentLevel = 2;
            Ferr.EditorTools.Box(4, () => {
                // other visual data
                sprite.vertexColor              = EditorGUILayout.ColorField("Vertex Color", sprite.vertexColor);
                sprite.pixelsPerUnit            = Mathf.Clamp(EditorGUILayout.FloatField("Pixels Per Unit", sprite.pixelsPerUnit), 1, 768);
                sprite.stretchThreshold         = EditorGUILayout.Slider("Stretch Threshold", sprite.stretchThreshold, 0f, 1f);
                sprite.slantAmount              = EditorGUILayout.Slider("Slant Amount", sprite.slantAmount, -2, 2);
                sprite.splitMiddle              = EditorGUILayout.Toggle("Split Middle", sprite.splitMiddle);
                sprite.createTangents           = EditorGUILayout.Toggle("Create Tangents", sprite.createTangents);
                sprite.randomByWorldCoordinates = EditorGUILayout.Toggle("Randomize Edge by World Coordinates", sprite.randomByWorldCoordinates);
                sprite.uvOffset = EditorGUILayout.Vector2Field("Fill UV Offset", sprite.uvOffset);

                Type utility       = Type.GetType("UnityEditorInternal.InternalEditorUtility, UnityEditor");
                Renderer renderCom = sprite.GetComponent <Renderer>();
                if (utility != null)
                {
                    PropertyInfo sortingLayerNames = utility.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
                    if (sortingLayerNames != null)
                    {
                        string[] layerNames = sortingLayerNames.GetValue(null, null) as string[];
                        string currName     = renderCom.sortingLayerName == "" ? "Default" : renderCom.sortingLayerName;
                        int nameID          = EditorGUILayout.Popup("Sorting Layer", Array.IndexOf(layerNames, currName), layerNames);

                        renderCom.sortingLayerName = layerNames[nameID];
                    }
                    else
                    {
                        renderCom.sortingLayerID = EditorGUILayout.IntField("Sorting Layer", renderCom.sortingLayerID);
                    }
                }
                else
                {
                    renderCom.sortingLayerID = EditorGUILayout.IntField("Sorting Layer", renderCom.sortingLayerID);
                }
                renderCom.sortingOrder = EditorGUILayout.IntField("Order in Layer", renderCom.sortingOrder);

                // warn if the shader's aren't likely to work with the settings provided!
                if (renderCom.sortingOrder != 0 || (renderCom.sortingLayerName != "Default" && renderCom.sortingLayerName != ""))
                {
                    bool opaque = false;
                    for (int i = 0; i < renderCom.sharedMaterials.Length; ++i)
                    {
                        Material mat = renderCom.sharedMaterials[i];
                        if (mat != null && mat.GetTag("RenderType", false, "") == "Opaque")
                        {
                            opaque = true;
                        }
                    }
                    if (opaque)
                    {
                        EditorGUILayout.HelpBox("Layer properties won't work properly unless your shaders are all 'transparent'!", MessageType.Warning);
                    }
                }
            });
        }
        EditorGUI.indentLevel = 0;

        showTerrainType = EditorGUILayout.Foldout(showTerrainType, "TERRAIN TYPE");
        if (showTerrainType)
        {
            EditorGUI.indentLevel = 2;
            Ferr.EditorTools.Box(4, () => {
                sprite.fill = (Ferr2DT_FillMode)EditorGUILayout.EnumPopup("Fill Type", sprite.fill);
                if (sprite.fill == Ferr2DT_FillMode.Closed || sprite.fill == Ferr2DT_FillMode.InvertedClosed || sprite.fill == Ferr2DT_FillMode.FillOnlyClosed && sprite.GetComponent <Ferr2D_Path>() != null)
                {
                    sprite.GetComponent <Ferr2D_Path>().closed = true;
                }
                if (sprite.fill != Ferr2DT_FillMode.None && (sprite.TerrainMaterial != null && sprite.TerrainMaterial.fillMaterial == null))
                {
                    sprite.fill = Ferr2DT_FillMode.None;
                }
                if (sprite.fill != Ferr2DT_FillMode.None)
                {
                    sprite.fillZ = EditorGUILayout.FloatField("Fill Z Offset", sprite.fillZ);
                }
                if (sprite.fill == Ferr2DT_FillMode.Skirt)
                {
                    sprite.fillY = EditorGUILayout.FloatField("Skirt Y Value", sprite.fillY);
                }

                sprite.splitCorners   = EditorGUILayout.Toggle("Split Corners", sprite.splitCorners);
                sprite.smoothPath     = EditorGUILayout.Toggle("Smooth Path", sprite.smoothPath);
                EditorGUI.indentLevel = 3;
                if (sprite.smoothPath)
                {
                    sprite.splitCount = EditorGUILayout.IntField("Edge Splits", sprite.splitCount);
                    sprite.splitDist  = EditorGUILayout.Slider("Fill Split", sprite.splitDist, 0.1f, 4);
                    if (sprite.splitCount < 1)
                    {
                        sprite.splitCount = 2;
                    }
                }
                else
                {
                    sprite.splitCount = 0;
                    sprite.splitDist  = 1;
                }
                EditorGUI.indentLevel = 2;

                sprite.fillSplit      = EditorGUILayout.Toggle("Split fill mesh", sprite.fillSplit);
                EditorGUI.indentLevel = 3;
                if (sprite.fillSplit)
                {
                    sprite.fillSplitDistance = EditorGUILayout.Slider("Split distance", sprite.fillSplitDistance, 0.25f, 10);
                }
                EditorGUI.indentLevel = 2;
            });
        }
        EditorGUI.indentLevel = 0;


        showCollider = EditorGUILayout.Foldout(showCollider, "COLLIDER");
        // render collider options
        if (showCollider)
        {
            EditorGUI.indentLevel = 2;
            Ferr.EditorTools.Box(4, () => {
                sprite.createCollider = EditorGUILayout.Toggle("Create Collider", sprite.createCollider);
                if (sprite.createCollider)
                {
                    sprite.sharpCorners = EditorGUILayout.Toggle("Sharp Corners", sprite.sharpCorners);
                    if (sprite.sharpCorners)
                    {
                        EditorGUI.indentLevel      = 3;
                        sprite.sharpCornerDistance = Mathf.Max(0, EditorGUILayout.FloatField("Corner Distance", sprite.sharpCornerDistance));
                        EditorGUI.indentLevel      = 2;
                    }

                    sprite.create3DCollider = EditorGUILayout.Toggle("Use 3D Collider", sprite.create3DCollider);
                    if (sprite.create3DCollider)
                    {
                        EditorGUI.indentLevel         = 3;
                        sprite.depth                  = EditorGUILayout.FloatField("Collider Width", sprite.depth);
                        sprite.smoothSphereCollisions = EditorGUILayout.Toggle("Smooth Sphere Collisions", sprite.smoothSphereCollisions);
                        EditorGUI.indentLevel         = 2;
                        sprite.isTrigger              = EditorGUILayout.Toggle("Is Trigger", sprite.isTrigger);
                        sprite.physicsMaterial        = (PhysicMaterial)EditorGUILayout.ObjectField("Physics Material", sprite.physicsMaterial, typeof(PhysicMaterial), true);
                    }
                    else
                    {
                        sprite.useEdgeCollider   = EditorGUILayout.Toggle("Use Edge Collider", sprite.useEdgeCollider);
                        sprite.usedByEffector    = EditorGUILayout.Toggle("Used by Effector", sprite.usedByEffector);
                        sprite.isTrigger         = EditorGUILayout.Toggle("Is Trigger", sprite.isTrigger);
                        sprite.physicsMaterial2D = (PhysicsMaterial2D)EditorGUILayout.ObjectField("Physics Material", sprite.physicsMaterial2D, typeof(PhysicsMaterial2D), true);
                    }

                    if (sprite.fill == Ferr2DT_FillMode.None)
                    {
                        sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Top]    = EditorGUILayout.FloatField("Thickness Top", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Top]);
                        sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Bottom] = EditorGUILayout.FloatField("Thickness Bottom", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Bottom]);
                    }
                    else
                    {
                        sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Top]    = EditorGUILayout.FloatField("Offset Top", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Top]);
                        sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Left]   = EditorGUILayout.FloatField("Offset Left", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Left]);
                        sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Right]  = EditorGUILayout.FloatField("Offset Right", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Right]);
                        sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Bottom] = EditorGUILayout.FloatField("Offset Bottom", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Bottom]);
                    }

                    //EditorGUI.indentLevel = 0;
                    EditorGUILayout.LabelField("Generate colliders along:");
                    sprite.collidersTop    = EditorGUILayout.Toggle("Top", sprite.collidersTop);
                    sprite.collidersLeft   = EditorGUILayout.Toggle("Left", sprite.collidersLeft);
                    sprite.collidersRight  = EditorGUILayout.Toggle("Right", sprite.collidersRight);
                    sprite.collidersBottom = EditorGUILayout.Toggle("Bottom", sprite.collidersBottom);

                    if (!sprite.collidersBottom || !sprite.collidersLeft || !sprite.collidersRight || !sprite.collidersTop)
                    {
                        EditorGUI.indentLevel    = 2;
                        sprite.colliderThickness = EditorGUILayout.FloatField("Collider Thickness", sprite.colliderThickness);
                        EditorGUI.indentLevel    = 0;
                    }
                }
            });
        }
        EditorGUI.indentLevel = 0;

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
            sprite.Build(true);
            cachedColliders = sprite.GetColliderVerts();
        }
        if (Event.current.type == EventType.ValidateCommand)
        {
            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":
                sprite.ForceMaterial(sprite.TerrainMaterial, true);
                sprite.Build(true);
                cachedColliders = sprite.GetColliderVerts();
                break;
            }
        }
    }
Ejemplo n.º 8
0
 static void MenuAddPhysicalTerrain()
 {
     Ferr2DT_MaterialSelector.Show(AddPhysicalTerrain);
 }
Ejemplo n.º 9
0
 static void MenuAddDecoTerrain()
 {
     Ferr2DT_MaterialSelector.Show(AddDecoTerrain);
 }
    public override void OnInspectorGUI()
    {
                #if !(UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0)
        Undo.RecordObject(target, "Modified Path Terrain");
                #else
        Undo.SetSnapshotTarget(target, "Modified Path Terrain");
                #endif

        Ferr2DT_PathTerrain sprite = (Ferr2DT_PathTerrain)target;

        // render the material selector!
        EditorGUILayout.BeginHorizontal();
        GUIContent button = sprite.TerrainMaterial != null && sprite.TerrainMaterial.edgeMaterial != null && sprite.TerrainMaterial.edgeMaterial.mainTexture != null ? new GUIContent(sprite.TerrainMaterial.edgeMaterial.mainTexture) : new GUIContent("Pick");
        if (GUILayout.Button(button, GUILayout.Width(48f), GUILayout.Height(48f)))
        {
            Ferr2DT_MaterialSelector.Show(sprite.SetMaterial);
        }
        EditorGUILayout.BeginVertical();
        EditorGUILayout.LabelField("Terrain Material:");
        EditorGUI.indentLevel = 2;
        EditorGUILayout.LabelField(sprite.TerrainMaterial == null ? "None" : sprite.TerrainMaterial.name);
        EditorGUI.indentLevel = 0;
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndHorizontal();

        showVisuals = EditorGUILayout.Foldout(showVisuals, "VISUALS");


        if (showVisuals)
        {
            EditorGUI.indentLevel = 2;
            // other visual data
            sprite.vertexColor      = EditorGUILayout.ColorField("Vertex Color", sprite.vertexColor);
            sprite.pixelsPerUnit    = EditorGUILayout.FloatField("Pixels Per Unit", sprite.pixelsPerUnit);
            sprite.stretchThreshold = EditorGUILayout.Slider("Stretch Threshold", sprite.stretchThreshold, 0f, 1f);
        }
        EditorGUI.indentLevel = 0;


        showTerrainType = EditorGUILayout.Foldout(showTerrainType, "TERRAIN TYPE");
        if (showTerrainType)
        {
            EditorGUI.indentLevel = 2;
            sprite.fill           = (Ferr2DT_FillMode)EditorGUILayout.EnumPopup("Fill Type", sprite.fill);
            if (sprite.fill == Ferr2DT_FillMode.Closed || sprite.fill == Ferr2DT_FillMode.InvertedClosed || sprite.fill == Ferr2DT_FillMode.FillOnlyClosed && sprite.GetComponent <Ferr2D_Path>() != null)
            {
                sprite.GetComponent <Ferr2D_Path>().closed = true;
            }
            if (sprite.fill != Ferr2DT_FillMode.None && (sprite.TerrainMaterial != null && sprite.TerrainMaterial.fillMaterial == null))
            {
                sprite.fill = Ferr2DT_FillMode.None;
            }
            if (sprite.fill != Ferr2DT_FillMode.None)
            {
                sprite.fillZ = EditorGUILayout.FloatField("Fill Z Offset", sprite.fillZ);
            }
            if (sprite.fill == Ferr2DT_FillMode.Skirt)
            {
                sprite.fillY = EditorGUILayout.FloatField("Skirt Y Value", sprite.fillY);
            }

            sprite.splitCorners = EditorGUILayout.Toggle("Split Corners", sprite.splitCorners);
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("Smooth Path", GUILayout.Width(122f));
            sprite.smoothPath = EditorGUILayout.Toggle(sprite.smoothPath, GUILayout.Width(48f));
            if (sprite.smoothPath)
            {
                EditorGUILayout.LabelField("Splits", GUILayout.Width(64f));
                sprite.splitDist = EditorGUILayout.FloatField(sprite.splitDist, GUILayout.Width(64f));
            }
            EditorGUILayout.EndHorizontal();
            if (sprite.smoothPath)
            {
                EditorGUILayout.HelpBox("Edge overrides do not currently work with smoothed terrain! Look for this in a coming update =D", MessageType.Info);
            }
        }
        EditorGUI.indentLevel = 0;


        showCollider = EditorGUILayout.Foldout(showCollider, "COLLIDER");
        // render collider options
        if (showCollider)
        {
            EditorGUI.indentLevel = 2;
            sprite.createCollider = EditorGUILayout.Toggle("Create Collider", sprite.createCollider);
            if (sprite.createCollider)
            {
                                #if !(UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0)
                sprite.create3DCollider = EditorGUILayout.Toggle("Use 3D Collider", sprite.create3DCollider);

                if (sprite.create3DCollider)
                {
                    sprite.physicsMaterial = (PhysicMaterial)EditorGUILayout.ObjectField("Physics Material", sprite.physicsMaterial, typeof(PhysicMaterial), true);
                    sprite.depth           = EditorGUILayout.FloatField("Collider Width", sprite.depth);
                }
                else
                {
                    sprite.physicsMaterial2D = (PhysicsMaterial2D)EditorGUILayout.ObjectField("Physics Material", sprite.physicsMaterial2D, typeof(PhysicsMaterial2D), true);
                }
                                #else
                sprite.physicsMaterial = (PhysicMaterial)EditorGUILayout.ObjectField("Physics Material", sprite.physicsMaterial, typeof(PhysicMaterial), true);
                sprite.depth           = EditorGUILayout.FloatField("Collider Width", sprite.depth);
                                #endif
                if (sprite.fill == Ferr2DT_FillMode.None)
                {
                    sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Top]    = EditorGUILayout.FloatField("Thickness Top", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Top]);
                    sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Bottom] = EditorGUILayout.FloatField("Thickness Bottom", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Bottom]);
                }
                else
                {
                    sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Top]    = EditorGUILayout.FloatField("Offset Top", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Top]);
                    sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Left]   = EditorGUILayout.FloatField("Offset Left", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Left]);
                    sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Right]  = EditorGUILayout.FloatField("Offset Right", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Right]);
                    sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Bottom] = EditorGUILayout.FloatField("Offset Bottom", sprite.surfaceOffset[(int)Ferr2DT_TerrainDirection.Bottom]);
                }

                EditorGUI.indentLevel = 0;
                EditorGUILayout.LabelField("Generate colliders along:");
                EditorGUILayout.BeginHorizontal();

                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField("Top", GUILayout.Width(25));
                sprite.collidersTop = EditorGUILayout.Toggle(sprite.collidersTop, GUILayout.Width(25));
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField("Left", GUILayout.Width(25));
                sprite.collidersLeft = EditorGUILayout.Toggle(sprite.collidersLeft, GUILayout.Width(25));
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField("Right", GUILayout.Width(35));
                sprite.collidersRight = EditorGUILayout.Toggle(sprite.collidersRight, GUILayout.Width(35));
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField("Bottom", GUILayout.Width(45));
                sprite.collidersBottom = EditorGUILayout.Toggle(sprite.collidersBottom, GUILayout.Width(45));
                EditorGUILayout.EndVertical();

                EditorGUILayout.EndHorizontal();

                                #if !(UNITY_4_2 || UNITY_4_1 || UNITY_4_1 || UNITY_4_0 || UNITY_3_5 || UNITY_3_4 || UNITY_3_3 || UNITY_3_1 || UNITY_3_0)
                if (!sprite.collidersBottom || !sprite.collidersLeft || !sprite.collidersRight || !sprite.collidersTop)
                {
                    EditorGUI.indentLevel    = 2;
                    sprite.colliderThickness = EditorGUILayout.FloatField("Collider Thickness", sprite.colliderThickness);
                    EditorGUI.indentLevel    = 0;
                }
                                #endif
            }
        }
        EditorGUI.indentLevel = 0;

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
            sprite.RecreatePath();
        }
        if (Event.current.type == EventType.ValidateCommand)
        {
            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":
                sprite.ForceMaterial(sprite.TerrainMaterial, true);
                sprite.RecreatePath();
                break;
            }
        }
    }