Beispiel #1
0
    public Ferr2DT_Material CreateNewFormatMaterial()
    {
        Ferr2DT_Material result = ScriptableObject.CreateInstance <Ferr2DT_Material>();

        result.edgeMaterial = _edgeMaterial;
        result.fillMaterial = _fillMaterial;

        for (int i = 0; i < 4; i += 1)
        {
            Ferr2DT_TerrainDirection dir = (Ferr2DT_TerrainDirection)i;
            if (!Has(dir))
            {
                continue;
            }
            result.Set(dir, true);
            Ferr2DT_SegmentDescription dest = result.GetDescriptor(dir);
            Ferr2DT_SegmentDescription src  = GetDescriptor(dir);
            dest.applyTo       = src.applyTo;
            dest.body          = src.body;
            dest.capOffset     = src.capOffset;
            dest.innerLeftCap  = src.innerLeftCap;
            dest.innerRightCap = src.innerRightCap;
            dest.leftCap       = src.leftCap;
            dest.rightCap      = src.rightCap;
            dest.yOffset       = src.yOffset;
            dest.zOffset       = src.zOffset;
        }

        return(result);
    }
Beispiel #2
0
    public static void CreateAsset()
    {
        Ferr2DT_Material mat = (Ferr2DT_Material)Ferr.SOUtil.CreateAsset(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, editorMenuName);

        // top
        mat.Set(Ferr2DT_TerrainDirection.Top, true);
        Ferr2DT_SegmentDescription curr = mat._descriptors[0];

        curr.SingleColliderCapType = Ferr2D_CapColliderType.Connected;

        // left
        mat.Set(Ferr2DT_TerrainDirection.Left, true);
        curr         = mat._descriptors[1];
        curr.ZOffset = 2f / 1000f;
        curr.SingleColliderCapType = Ferr2D_CapColliderType.Rectangle;

        // right
        mat.Set(Ferr2DT_TerrainDirection.Right, true);
        curr         = mat._descriptors[2];
        curr.ZOffset = 2f / 1000f;
        curr.SingleColliderCapType = Ferr2D_CapColliderType.Rectangle;

        // right
        mat.Set(Ferr2DT_TerrainDirection.Bottom, true);
        curr         = mat._descriptors[3];
        curr.ZOffset = 1f / 1000f;
        curr.SingleColliderCapType = Ferr2D_CapColliderType.Connected;
    }
    static void UpdateTerrainAssets(bool aCreateNewAssets)
    {
        Ferr2DT_PathTerrain[] terrain          = GameObject.FindObjectsOfType <Ferr2DT_PathTerrain>();
        List <string>         missing          = new List <string>();
        List <string>         updatedMaterials = new List <string>();
        int updated = 0;
        int created = 0;
        int skipped = 0;
        int good    = 0;

        for (int i = 0; i < terrain.Length; i++)
        {
            IFerr2DTMaterial mat = terrain[i].TerrainMaterial;
            if (mat is Ferr2DT_TerrainMaterial)
            {
                string path           = AssetDatabase.GetAssetPath(mat as UnityEngine.Object);
                bool   newAssetExists = true;

                path = Path.ChangeExtension(path, "asset");
                if (!File.Exists(path))
                {
                    string name = Path.GetFileNameWithoutExtension(path);

                    if (aCreateNewAssets)
                    {
                        updatedMaterials.Add(name + ".prefab");
                        ScriptableObject newAsset = ((Ferr2DT_TerrainMaterial)mat).CreateNewFormatMaterial();
                        AssetDatabase.CreateAsset(newAsset, path);
                        AssetDatabase.SaveAssets();
                        created += 1;
                    }
                    else
                    {
                        if (!missing.Contains(name))
                        {
                            missing.Add(name);
                        }
                        skipped       += 1;
                        newAssetExists = false;
                    }
                }

                if (newAssetExists)
                {
                    Ferr2DT_Material newMat = AssetDatabase.LoadAssetAtPath <Ferr2DT_Material>(path);
                    if (newMat == null)
                    {
                        Debug.Log("Error attempting to load asset: " + path);
                    }
                    else
                    {
                        Undo.RecordObject(terrain[i], "Updating terrain material");
                        updated += 1;
                        terrain[i].TerrainMaterial = newMat;
                        terrain[i].Build(true);
                    }
                }
            }
            else
            {
                good += 1;
            }
        }
        Debug.LogFormat("Ferr2D scene update done - {0} materials created, {1} objs updated, {2} already good, {3} objs skipped.", created, updated, good, skipped);
        if (missing.Count > 0)
        {
            Debug.LogFormat("Missing updated assets for these materials: {0}", string.Join(", ", missing.ToArray()));
        }
        if (updatedMaterials.Count > 0)
        {
            Debug.LogFormat("Consider deleting these old materials once all scenes have been upgraded: {0}", string.Join(", ", updatedMaterials.ToArray()));
        }

        if (updated > 0 || created > 0)
        {
            EditorSceneManager.MarkAllScenesDirty();
        }
    }