Quaternions

1 Like

Don’t like inverting the localscale of sprites in unity2d to flip them, messes with the rotations to much, so going to write a small editor extension that flips sprite sheets. Will post code here when it’s done for anyone who is interested.

To use it the texture needs to be flagged Read/Write in the inspector as an Advanced Texture

using UnityEngine;
using System.Collections;
using System.IO;
using UnityEditor;

public class flipImage : ScriptableWizard {
   public Texture2D[] inputTexture = new Texture2D[1];
   public string filenameInsert="-flipped";
   private Texture2D outputTexture;
   private Color[] textureData;
   private Color[] outputData;

   // Use this for initialization
   [MenuItem("Window/Flip Texture")]
   public static void ShowWindow()
   {
     ScriptableWizard.DisplayWizard("Flip Texture(s)", typeof(flipImage), "Flip Texture(s)");
   }

   void OnWizardCreate()
   {

     for(int d=0; d<inputTexture.Length;d++)
     {
       // Get Texture data
       textureData = inputTexture[d].GetPixels();
       outputData = new Color[textureData.Length];

       // Flip the Texture
       for(int y=0; y< inputTexture[d].height; y++)
       {
         for(int x=inputTexture[d].width-1; x > 1; x--)
         {
           outputData[((y*inputTexture[d].width)+(inputTexture[d].width-x))]=textureData[((y*inputTexture[d].width)+x)];
         }
       }

       // Write to a new Texture
       outputTexture =  new Texture2D(inputTexture[d].width, inputTexture[d].height, inputTexture[d].format,false);
       outputTexture.SetPixels(outputData);
       outputTexture.Apply();
       byte[] bytes = outputTexture.EncodeToPNG();
       string infile=AssetDatabase.GetAssetPath(inputTexture[d]);
       string outfile=infile.Insert(infile.Length-4,filenameInsert);
       File.WriteAllBytes(outfile, bytes);
     }

     AssetDatabase.Refresh();

   }
}

Now I’ve run into this issue, Changing Animation Sprites - Unity Engine - Unity Discussions … currently going to try a swap the filenames of the spritesheets at run-time, just hoping unity’s animation system references to the the individual sprites by name and not position… or I’ll have to modify the about asset to reorder the sprites within the spritesheet.

That isn’t going to work… FileUtils is a unityEditor function, and I don’t know about moving files around in an android built…

This section is for scripting support, not for posting scripts. I believe you are looking for the Assets & Asset Store section.

If you are asking a question I am unclear of what is being asked.

Bit of a wasted effort… Going to write a shader with a flip bool… not the best shader programmer but should be able to mange it… will be my 3rd modified shader based on unity2D’s spriterenderer shader

Sorry… wasn’t sure where to put it…

Basically trying to figure out a way to flip a sprite without using the inverted localScale trick as It makes the rotations/movement code too tedious to program.

would you not just rotate the gameobject…

1 Like

Unity2D, rotating the sprite would show it upside down… anyway posted my solution in the assets section of the forums, ended up modifying the unity2D’s Sprite shader to include a flip option…