1
Support / Re: Screen Rotation Problem
« on: November 02, 2012, 05:50:52 pm »
I think the black boarders are now my problem with some pillarboxing/letterboxing I am doing. Completely forgot about that. Thanks for your help
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
The resolution stuff will be correct on the device.
public static void SwitchCameraTo(Orientation orientation)
{
// If the orientation is already correct, return early
if (orientation == GameController.CameraOrientation)
return;
GameController.CameraOrientation = orientation;
if (orientation == Orientation.Horizontal)
{
GameController.Camera.nativeResolutionWidth = 960;
GameController.Camera.nativeResolutionHeight = 640;
GameController.Camera.forceResolution = new Vector2(960, 640);
Screen.orientation = ScreenOrientation.LandscapeLeft;
}
else
{
GameController.Camera.nativeResolutionWidth = 640;
GameController.Camera.nativeResolutionHeight = 960;
GameController.Camera.forceResolution = new Vector2(640, 960);
Screen.orientation = ScreenOrientation.Portrait;
}
}
EditorUtility.SetDirty(sprite);
straight after the call to SwitchCollectionAndSprite() seems to have worked!
public void Transfer()
{
// Load the two collections
tk2dSpriteCollection sourceCol = AssetDatabase.LoadAssetAtPath(
"Assets/Main/Sprites/" + m_atlasNames[m_sourceAtlasIndex],
typeof(tk2dSpriteCollection)) as tk2dSpriteCollection;
tk2dSpriteCollection destCol = AssetDatabase.LoadAssetAtPath(
"Assets/Main/Sprites/" + m_atlasNames[m_destAtlasIndex],
typeof(tk2dSpriteCollection)) as tk2dSpriteCollection;
// ===============================
// Make a copy of the dest texture refs with a extra slot for the new one
Texture2D[] temp = new Texture2D[destCol.textureRefs.Length + 1];
for (int i = 0; i < destCol.textureRefs.Length; ++i)
temp[i] = destCol.textureRefs[i];
// The new sprite we are adding to the dest col
temp[temp.Length - 1] = sourceCol.textureRefs[m_sourceSpriteIndex];
// Set the copy
destCol.textureRefs = temp;
// Ensure the dest col is updated
tk2dSpriteCollectionBuilder.ResetCurrentBuild();
tk2dSpriteCollectionBuilder.Rebuild(destCol);
// =============================
// Make a copy of the texture params of the sprite that we are moving
tk2dSpriteCollectionDefinition defToCopy = sourceCol.textureParams[m_sourceSpriteIndex];
// Find the moved sprite in the dest col and then copy across the source params
for (int i = 0; i < destCol.textureParams.Length; ++i)
{
if (destCol.textureParams[i] == null)
continue;
if (destCol.textureParams[i].name == defToCopy.name)
destCol.textureParams[i].CopyFrom(defToCopy);
}
// Update the dest col
tk2dSpriteCollectionBuilder.ResetCurrentBuild();
tk2dSpriteCollectionBuilder.Rebuild(destCol);
// Now we need to go through the level and update any uses of the source sprite
FixupReferences();
// =============================
// Now that the sprite has been moved we need to null the reference in the source col
for (int i = 0; i < sourceCol.textureRefs.Length; ++i)
if (i == m_sourceSpriteIndex)
sourceCol.textureRefs[i] = null;
// Update the source col
tk2dSpriteCollectionBuilder.ResetCurrentBuild();
tk2dSpriteCollectionBuilder.Rebuild(sourceCol);
// Refresh sprite list
m_sourceSpriteIndex = 0;
PopulateSourceSprites();
}
public void FixupReferences()
{
// Get the collection name we want to replace (used to search with)
string collectionNameToFind = "";
string[] split = m_atlasNames[m_sourceAtlasIndex].Split(new char[] { '/' });
collectionNameToFind = split[split.Length - 1].Split(new char[] { '.' })[0];
// Load the dest col
tk2dSpriteCollection destCol = AssetDatabase.LoadAssetAtPath(
"Assets/Main/Sprites/" + m_atlasNames[m_destAtlasIndex],
typeof(tk2dSpriteCollection)) as tk2dSpriteCollection;
// Load the scene to alter
if (EditorApplication.OpenScene("SCENE_NAME"))
{
// Read the contents of the hierarchy
object[] hierarchy = GameObject.FindSceneObjectsOfType(typeof(GameObject));
foreach (object o in hierarchy)
{
GameObject go = (GameObject)o;
// Try and get the sprite component
tk2dSprite sprite = go.GetComponent<tk2dSprite>();
// No sprite component so return
if (sprite == null)
continue;
// The sprites collection name isn't the one we want to alter so return
if (sprite.collection.spriteCollectionName != collectionNameToFind)
continue;
// If the sprite names match, switch the collection and the sprite
if (sprite.collection.spriteDefinitions[sprite.spriteId].name == m_sourceSpriteNames[m_sourceSpriteIndex])
sprite.SwitchCollectionAndSprite(destCol.spriteCollection, destCol.spriteCollection.spriteDefinitions.Length - 1);
}
// Save the scene
EditorApplication.SaveScene();
EditorApplication.SaveAssets();
}
else
{
Debug.LogError("Failed to find " + "World1Level1");
}
}