Hey, so I’m trying to set up a 2D animation editor in Unity but I’m not able to get my texture to scroll using the code below. The scrollbars show up and can be scrolled, but not the entire span of the texture. I’m probably doing something dumb, but I’m not very familiar with all of these different gui types and using them in conjunction.
I am trying to just pull the texture from the current Sprite Object’s material, which may change, but I’m just dipping my toes into this tool as an educational experience for myself. I know some people will point to the documentation, which I have read, but I’m either missing something or its just not clicking.
Any help would be greatly appreciated! I apologize in advance if my code formatting is poor and/or unreadable.
using UnityEditor;
using UnityEngine;
using System.Collections;
public class AnimationWindow : EditorWindow {
CAnimation animation;
Texture2D texture;
Vector2 scrollPos;
int currentFrame;
public void Init(CAnimation cAnimation)
{
SetAnimation(cAnimation);
}
public void SetAnimation(CAnimation cAnimation)
{
animation = cAnimation;
texture = (Texture2D)cAnimation.renderer.material.mainTexture;
if (animation == null)
{
currentFrame = 0;
texture = null;
}
}
void OnGUI()
{
////////////////////////////////current frame
GUILayout.BeginHorizontal();
GUILayout.Label(" Current Frame ");
currentFrame = (int)EditorGUILayout.Slider((float)currentFrame, (float)0, (float)animation.m_nNumberOfFrames);
GUILayout.EndHorizontal();
///// end sprite sheet
////////////////////////////////sprite sheet
EditorGUILayout.BeginHorizontal();
GUILayout.Label(" Sprite Sheet ");
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
scrollPos = EditorGUILayout.BeginScrollView(scrollPos, true, true, GUILayout.Width(400), GUILayout.Height(400));
EditorGUI.DrawPreviewTexture(new Rect(0, 0, 1000, 1000), texture);
EditorGUILayout.EndScrollView();
EditorGUILayout.EndHorizontal();
///// end sprite sheet
}
}