testss
This commit is contained in:
@@ -0,0 +1,227 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AnimationImporter
|
||||
{
|
||||
public class AnimationImporterSharedConfig : ScriptableObject
|
||||
{
|
||||
private const string PREFS_PREFIX = "ANIMATION_IMPORTER_";
|
||||
|
||||
[SerializeField]
|
||||
private List<string> _animationNamesThatDoNotLoop = new List<string>() { "death" };
|
||||
public List<string> animationNamesThatDoNotLoop { get { return _animationNamesThatDoNotLoop; } }
|
||||
|
||||
[SerializeField]
|
||||
private bool _automaticImporting = false;
|
||||
|
||||
public bool automaticImporting
|
||||
{
|
||||
get
|
||||
{
|
||||
return _automaticImporting;
|
||||
}
|
||||
set
|
||||
{
|
||||
_automaticImporting = value;
|
||||
}
|
||||
}
|
||||
|
||||
// sprite import values
|
||||
[SerializeField]
|
||||
private float _spritePixelsPerUnit = 100f;
|
||||
public float spritePixelsPerUnit
|
||||
{
|
||||
get
|
||||
{
|
||||
return _spritePixelsPerUnit;
|
||||
}
|
||||
set
|
||||
{
|
||||
_spritePixelsPerUnit = value;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private AnimationTargetObjectType _targetObjectType = AnimationTargetObjectType.SpriteRenderer;
|
||||
public AnimationTargetObjectType targetObjectType
|
||||
{
|
||||
get
|
||||
{
|
||||
return _targetObjectType;
|
||||
}
|
||||
set
|
||||
{
|
||||
_targetObjectType = value;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private SpriteAlignment _spriteAlignment = SpriteAlignment.BottomCenter;
|
||||
public SpriteAlignment spriteAlignment
|
||||
{
|
||||
get
|
||||
{
|
||||
return _spriteAlignment;
|
||||
}
|
||||
set
|
||||
{
|
||||
_spriteAlignment = value;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private float _spriteAlignmentCustomX = 0;
|
||||
public float spriteAlignmentCustomX
|
||||
{
|
||||
get
|
||||
{
|
||||
return _spriteAlignmentCustomX;
|
||||
}
|
||||
set
|
||||
{
|
||||
_spriteAlignmentCustomX = value;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private float _spriteAlignmentCustomY = 0;
|
||||
public float spriteAlignmentCustomY
|
||||
{
|
||||
get
|
||||
{
|
||||
return _spriteAlignmentCustomY;
|
||||
}
|
||||
set
|
||||
{
|
||||
_spriteAlignmentCustomY = value;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private AssetTargetLocation _spritesTargetLocation = new AssetTargetLocation(AssetTargetLocationType.SubDirectory, "Sprites");
|
||||
public AssetTargetLocation spritesTargetLocation
|
||||
{
|
||||
get { return _spritesTargetLocation; }
|
||||
set { _spritesTargetLocation = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private AssetTargetLocation _animationsTargetLocation = new AssetTargetLocation(AssetTargetLocationType.SubDirectory, "Animations");
|
||||
public AssetTargetLocation animationsTargetLocation
|
||||
{
|
||||
get { return _animationsTargetLocation; }
|
||||
set { _animationsTargetLocation = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private AssetTargetLocation _animationControllersTargetLocation = new AssetTargetLocation(AssetTargetLocationType.SameDirectory, "Animations");
|
||||
public AssetTargetLocation animationControllersTargetLocation
|
||||
{
|
||||
get { return _animationControllersTargetLocation; }
|
||||
set { _animationControllersTargetLocation = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private SpriteNamingScheme _spriteNamingScheme = SpriteNamingScheme.Classic;
|
||||
public SpriteNamingScheme spriteNamingScheme
|
||||
{
|
||||
get { return _spriteNamingScheme; }
|
||||
set { _spriteNamingScheme = value; }
|
||||
}
|
||||
|
||||
public void RemoveAnimationThatDoesNotLoop(int index)
|
||||
{
|
||||
animationNamesThatDoNotLoop.RemoveAt(index);
|
||||
}
|
||||
|
||||
public bool AddAnimationThatDoesNotLoop(string animationName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(animationName) || animationNamesThatDoNotLoop.Contains(animationName))
|
||||
return false;
|
||||
|
||||
animationNamesThatDoNotLoop.Add(animationName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specify if the Unity user has preferences for an older version of AnimationImporter
|
||||
/// </summary>
|
||||
/// <returns><c>true</c>, if the user has old preferences, <c>false</c> otherwise.</returns>
|
||||
public bool UserHasOldPreferences()
|
||||
{
|
||||
var pixelsPerUnityKey = PREFS_PREFIX + "spritePixelsPerUnit";
|
||||
return PlayerPrefs.HasKey(pixelsPerUnityKey) || EditorPrefs.HasKey(pixelsPerUnityKey);
|
||||
}
|
||||
|
||||
private bool HasKeyInPreferences(string key)
|
||||
{
|
||||
return PlayerPrefs.HasKey(key) || EditorPrefs.HasKey(key);
|
||||
}
|
||||
|
||||
private int GetIntFromPreferences(string intKey)
|
||||
{
|
||||
if (PlayerPrefs.HasKey(intKey))
|
||||
{
|
||||
return PlayerPrefs.GetInt(intKey);
|
||||
}
|
||||
else if (EditorPrefs.HasKey(intKey))
|
||||
{
|
||||
return EditorPrefs.GetInt(intKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
return int.MinValue;
|
||||
}
|
||||
}
|
||||
|
||||
private float GetFloatFromPreferences(string floatKey)
|
||||
{
|
||||
if (PlayerPrefs.HasKey(floatKey))
|
||||
{
|
||||
return PlayerPrefs.GetFloat(floatKey);
|
||||
}
|
||||
else if (EditorPrefs.HasKey(floatKey))
|
||||
{
|
||||
return EditorPrefs.GetFloat(floatKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
return float.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
private bool GetBoolFromPreferences(string boolKey)
|
||||
{
|
||||
if (PlayerPrefs.HasKey(boolKey))
|
||||
{
|
||||
return System.Convert.ToBoolean(PlayerPrefs.GetInt(boolKey));
|
||||
}
|
||||
else if (EditorPrefs.HasKey(boolKey))
|
||||
{
|
||||
return EditorPrefs.GetBool(boolKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetStringFromPreferences(string stringKey)
|
||||
{
|
||||
if (PlayerPrefs.HasKey(stringKey))
|
||||
{
|
||||
return PlayerPrefs.GetString(stringKey);
|
||||
}
|
||||
else if (EditorPrefs.HasKey(stringKey))
|
||||
{
|
||||
return EditorPrefs.GetString(stringKey);
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
|
||||
public enum AnimationTargetObjectType : int
|
||||
{
|
||||
SpriteRenderer,
|
||||
Image,
|
||||
SpriteRendererAndImage
|
||||
}
|
@@ -0,0 +1,75 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AnimationImporter
|
||||
{
|
||||
[System.Serializable]
|
||||
public class AssetTargetLocation
|
||||
{
|
||||
[SerializeField]
|
||||
private AssetTargetLocationType _locationType;
|
||||
public AssetTargetLocationType locationType
|
||||
{
|
||||
get { return _locationType; }
|
||||
set { _locationType = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private string _globalDirectory = "Assets";
|
||||
public string globalDirectory
|
||||
{
|
||||
get { return _globalDirectory; }
|
||||
set { _globalDirectory = value; }
|
||||
}
|
||||
|
||||
private string _subDirectoryName;
|
||||
public string subDirectoryName
|
||||
{
|
||||
get {return _subDirectoryName; }
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
// constructor
|
||||
// --------------------------------------------------------------------------------
|
||||
|
||||
public AssetTargetLocation(AssetTargetLocationType type, string subFolderName) : this(type)
|
||||
{
|
||||
_subDirectoryName = subFolderName;
|
||||
}
|
||||
|
||||
public AssetTargetLocation(AssetTargetLocationType type)
|
||||
{
|
||||
locationType = type;
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
// public methods
|
||||
// --------------------------------------------------------------------------------
|
||||
|
||||
public string GetAndEnsureTargetDirectory(string assetDirectory)
|
||||
{
|
||||
string directory = GetTargetDirectory(assetDirectory);
|
||||
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
return directory;
|
||||
}
|
||||
|
||||
public string GetTargetDirectory(string assetDirectory)
|
||||
{
|
||||
if (locationType == AssetTargetLocationType.GlobalDirectory)
|
||||
{
|
||||
return globalDirectory;
|
||||
}
|
||||
else if (locationType == AssetTargetLocationType.SubDirectory)
|
||||
{
|
||||
return Path.Combine(assetDirectory, subDirectoryName);
|
||||
}
|
||||
|
||||
return assetDirectory;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
|
||||
namespace AnimationImporter
|
||||
{
|
||||
public enum AssetTargetLocationType : int
|
||||
{
|
||||
SameDirectory,
|
||||
SubDirectory,
|
||||
GlobalDirectory
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
|
||||
namespace AnimationImporter
|
||||
{
|
||||
public enum ImportAnimatorController
|
||||
{
|
||||
None,
|
||||
AnimatorController,
|
||||
AnimatorOverrideController
|
||||
}
|
||||
}
|
102
Assets/AnimationImporter/Editor/Config/PreviousImportSettings.cs
Normal file
102
Assets/AnimationImporter/Editor/Config/PreviousImportSettings.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Random = UnityEngine.Random;
|
||||
using UnityEditor;
|
||||
|
||||
namespace AnimationImporter
|
||||
{
|
||||
public class PreviousImportSettings
|
||||
{
|
||||
private SpriteMetaData? _previousFirstSprite = null;
|
||||
|
||||
private bool _hasPreviousTextureImportSettings = false;
|
||||
public bool hasPreviousTextureImportSettings
|
||||
{
|
||||
get
|
||||
{
|
||||
return _hasPreviousTextureImportSettings;
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
// public methods
|
||||
// --------------------------------------------------------------------------------
|
||||
|
||||
public void GetTextureImportSettings(string filename)
|
||||
{
|
||||
TextureImporter importer = AssetImporter.GetAtPath(filename) as TextureImporter;
|
||||
|
||||
if (importer != null)
|
||||
{
|
||||
_hasPreviousTextureImportSettings = true;
|
||||
|
||||
if (importer.spritesheet != null && importer.spritesheet.Length > 0)
|
||||
{
|
||||
_previousFirstSprite = importer.spritesheet[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyPreviousTextureImportSettings(TextureImporter importer)
|
||||
{
|
||||
if (!_hasPreviousTextureImportSettings|| importer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// apply old pivot point settings
|
||||
// we assume every sprite should have the same pivot point
|
||||
if (_previousFirstSprite.HasValue)
|
||||
{
|
||||
var spritesheet = importer.spritesheet; // read values
|
||||
|
||||
for (int i = 0; i < spritesheet.Length; i++)
|
||||
{
|
||||
spritesheet[i].alignment = _previousFirstSprite.Value.alignment;
|
||||
spritesheet[i].pivot = _previousFirstSprite.Value.pivot;
|
||||
}
|
||||
|
||||
importer.spritesheet = spritesheet; // write values
|
||||
}
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
// analyzing animations
|
||||
// --------------------------------------------------------------------------------
|
||||
|
||||
public static AnimationTargetObjectType GetAnimationTargetFromExistingClip(AnimationClip clip)
|
||||
{
|
||||
var curveBindings = AnimationUtility.GetObjectReferenceCurveBindings(clip);
|
||||
|
||||
bool targetingSpriteRenderer = false;
|
||||
bool targetingImage = false;
|
||||
|
||||
for (int i = 0; i < curveBindings.Length; i++)
|
||||
{
|
||||
if (curveBindings[i].type == typeof(SpriteRenderer))
|
||||
{
|
||||
targetingSpriteRenderer = true;
|
||||
}
|
||||
else if (curveBindings[i].type == typeof(UnityEngine.UI.Image))
|
||||
{
|
||||
targetingImage = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetingSpriteRenderer && targetingImage)
|
||||
{
|
||||
return AnimationTargetObjectType.SpriteRendererAndImage;
|
||||
}
|
||||
else if (targetingImage)
|
||||
{
|
||||
return AnimationTargetObjectType.Image;
|
||||
}
|
||||
else
|
||||
{
|
||||
return AnimationTargetObjectType.SpriteRenderer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
79
Assets/AnimationImporter/Editor/Config/SpriteNaming.cs
Normal file
79
Assets/AnimationImporter/Editor/Config/SpriteNaming.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AnimationImporter
|
||||
{
|
||||
public enum SpriteNamingScheme : int
|
||||
{
|
||||
Classic, // hero 0
|
||||
FileAnimationZero, // hero_idle_0, ...
|
||||
FileAnimationOne, // hero_idle_1, ...
|
||||
AnimationZero, // idle_0, ...
|
||||
AnimationOne // idle_1, ...
|
||||
}
|
||||
|
||||
public static class SpriteNaming
|
||||
{
|
||||
private static int[] _namingSchemesValues = null;
|
||||
public static int[] namingSchemesValues
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_namingSchemesValues == null)
|
||||
{
|
||||
InitNamingLists();
|
||||
}
|
||||
|
||||
return _namingSchemesValues;
|
||||
}
|
||||
}
|
||||
|
||||
private static string[] _namingSchemesDisplayValues = null;
|
||||
public static string[] namingSchemesDisplayValues
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_namingSchemesDisplayValues == null)
|
||||
{
|
||||
InitNamingLists();
|
||||
}
|
||||
|
||||
return _namingSchemesDisplayValues;
|
||||
}
|
||||
}
|
||||
|
||||
private static void InitNamingLists()
|
||||
{
|
||||
var allNamingSchemes = Enum.GetValues(typeof(SpriteNamingScheme));
|
||||
|
||||
_namingSchemesValues = new int[allNamingSchemes.Length];
|
||||
_namingSchemesDisplayValues = new string[allNamingSchemes.Length];
|
||||
|
||||
for (int i = 0; i < allNamingSchemes.Length; i++)
|
||||
{
|
||||
SpriteNamingScheme namingScheme = (SpriteNamingScheme)allNamingSchemes.GetValue(i);
|
||||
_namingSchemesValues[i] = (int)namingScheme;
|
||||
_namingSchemesDisplayValues[i] = namingScheme.ToDisplayString();
|
||||
}
|
||||
}
|
||||
|
||||
private static string ToDisplayString(this SpriteNamingScheme namingScheme)
|
||||
{
|
||||
switch (namingScheme)
|
||||
{
|
||||
case SpriteNamingScheme.Classic:
|
||||
return "hero 0, hero 1, ... (Default)";
|
||||
case SpriteNamingScheme.FileAnimationZero:
|
||||
return "hero_idle_0, hero_idle_1, ...";
|
||||
case SpriteNamingScheme.FileAnimationOne:
|
||||
return "hero_idle_1, hero_idle_2, ...";
|
||||
case SpriteNamingScheme.AnimationZero:
|
||||
return "idle_0, idle_1, ...";
|
||||
case SpriteNamingScheme.AnimationOne:
|
||||
return "idle_1, idle_2, ...";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user