public void SetupSelection() { bool somethingChanged = false; // See if something changed: if (sprite != null) { if (sprite.gameObject != Selection.activeGameObject) somethingChanged = true; else if (sprite.States.Length != animList.Length) somethingChanged = true; else if (sprite.States.Length < 1) somethingChanged = true; else if (selectedAnim >= sprite.States.Length || selectedAnim < 0) somethingChanged = true; else if (sprite.States[selectedAnim].frameGUIDs.Length != frames.Count) somethingChanged = true; } else somethingChanged = true; if (somethingChanged) { if (Selection.activeGameObject != null) { sprite = (ISpriteAnimatable)Selection.activeGameObject.GetComponent(typeof(ISpriteAnimatable)); selGO = Selection.activeGameObject; zoomCoef = 1f; } else { // If another GameObject wasn't selected, // don't change anything so we can drag // textures in, etc. // So only change if there is no activeObject // (as opposed to activeGameObject): if(Selection.activeObject == null) { selGO = null; sprite = null; } } // Select a safe value for our selected frame: if (sprite != null) { if (sprite.States.Length > 0) { selectedAnim = Mathf.Clamp(selectedAnim, 0, sprite.States.Length - 1); animSettingsTracker.Synch(sprite.States[selectedAnim]); } // Commented out because two different sprites with // the same number of frames in their selected anim // would cause the list not to be updated: //if (sprite.States.Length != animList.Length) BuildAnimList(); if (sprite.States.Length > 0) { selectedAnim = Mathf.Clamp(selectedAnim, 0, sprite.States.Length - 1); if (sprite.States[selectedAnim].frameGUIDs.Length != frames.Count) RebuildFrameList(); // Only change the selected frame if it is not valid: if (selectedFrame != null) if (selectedFrame.index >= sprite.States[selectedAnim].frameGUIDs.Length) { selectedFrame = null; } } else selectedFrame = null; } else { selectedFrame = null; } if (m_editor != null) m_editor.Repaint(); } }
int IComparer.Compare(object a, object b) { t1 = (DraggableTexture)a; t2 = (DraggableTexture)b; if (t1.Position.x > t2.Position.x) return 1; else if (t1.Position.x < t2.Position.x) return -1; else return 0; }
void RebuildFrameList() { frames.Clear(); float leftEdge = 0; bool matchedSelection = false; Texture2D frameTex; if (sprite.States.Length < 1) return; selectedAnim = Mathf.Clamp(selectedAnim, 0, sprite.States.Length - 1); for (int i = 0; i < sprite.States[selectedAnim].frameGUIDs.Length; ++i) { frameTex = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(sprite.States[selectedAnim].frameGUIDs[i]), typeof(Texture2D)); DraggableTexture tex = new DraggableTexture(frameTex, i, new Vector2(leftEdge, 0)); if (tex.texture != null) leftEdge += (tex.texture.width * zoomCoef) + spaceBetweenFrames; else leftEdge += DraggableTexture.NULL_SIZE + spaceBetweenFrames; frames.Add(tex); // Attempt to preserve our selection: if (selectedFrame != null) if (tex.index == selectedFrame.index && tex.texture == selectedFrame.texture) { selectedFrame = tex; matchedSelection = true; } } if (!matchedSelection) selectedFrame = null; }
void DeleteSelectedFrame() { // Now move each frame after the one we're removing down one slot: for (int i = selectedFrame.index; i < sprite.States[selectedAnim].frameGUIDs.Length - 1; ++i) { sprite.States[selectedAnim].frameGUIDs[i] = sprite.States[selectedAnim].frameGUIDs[i + 1]; } selectedFrame = null; // Save our old list: string[] temp = sprite.States[selectedAnim].frameGUIDs; // Create a new one that is one shorter: sprite.States[selectedAnim].frameGUIDs = new string[temp.Length - 1]; if (sprite.States[selectedAnim].frameGUIDs.Length > 0) { // Copy the old contents back, sans the last element: System.Array.Copy(temp, sprite.States[selectedAnim].frameGUIDs, temp.Length - 1); } RebuildFrameList(); EditorUtility.SetDirty(sprite.gameObject); }
void ChangeSelectedFrame(DraggableTexture tex) { // Deselect the previous frame: if (selectedFrame != null) { selectedFrame.selected = false; } selectedFrame = tex; tex.selected = true; // If we aren't previewing, use this // frame as our preview frame: if (!previewing) curPreviewTexture = selectedFrame.index; }