public override void OnInspectorGUI() { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Reimport")) { AssetDatabase.ImportAsset(_anime.OriginalPath); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { _anime.UseScaleFactor = EditorGUILayout.BeginToggleGroup("ScaleFactor", _anime.UseScaleFactor); if (_anime.UseScaleFactor) { _anime.ScaleFactor = EditorGUILayout.FloatField(_anime.ScaleFactor); } else { if (!_database) { _database = SsAssetPostProcessor.GetDatabase(); } EditorGUILayout.FloatField(_database.ScaleFactor); } EditorGUILayout.EndToggleGroup(); } EditorGUILayout.EndHorizontal(); DrawDefaultInspector(); }
CreateSprite() { var go = new GameObject("New Sprite"); go.AddComponent <SsSprite>(); // add shader keeper to current scene if it doesn't exist. SsAssetPostProcessor.AddShaderKeeperToCurrentScene(); return(go); }
// public void OnHierarchyChange() // { // Debug.LogWarning("OnHierarchyChange()"); // AddShaderKeeper(); // } // public void OnSelectionChange() // { // Debug.LogWarning("OnSelectionChange()"); // AddShaderKeeper(); // } static public void AddShaderKeeper() { // if null or not changed or prefab is ignored. if (!SsSpriteEditor.LastSprite) { return; } if (SsSpriteEditor.LastSprite == _lastSprite) { return; } if (PrefabUtility.GetPrefabType(SsSpriteEditor.LastSprite.gameObject) == PrefabType.Prefab) { return; } // it seems to be added new sprite possibly... _lastSprite = SsSpriteEditor.LastSprite; //Debug.Log("sprite added to this scene!!" + _lastSprite); // add shader keeper to current scene if it doesn't exist. SsAssetPostProcessor.AddShaderKeeperToCurrentScene(); }
public void OnGUI() { if (!_database) { _database = SsAssetPostProcessor.GetDatabase(); } GUILayout.Label("Import Settings", EditorStyles.boldLabel); { #if _BUILD_UNIFIED_SHADERS _database.UseUnifiedShader = EditorGUILayout.Toggle("Use UnifiedShader", _database.UseUnifiedShader); #endif _database.ScaleFactor = EditorGUILayout.FloatField("Scale Factor", _database.ScaleFactor); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Interpret angle curve parameter as radian", GUILayout.Width(250)); _database.AngleCurveParamAsRadian = EditorGUILayout.Toggle(_database.AngleCurveParamAsRadian); EditorGUILayout.EndHorizontal(); } GUILayout.Space(12); if (GUILayout.Button("Close")) { Close(); } }
static public void Init() { EditorWindow.GetWindowWithRect <SsEditorWindow>(new Rect(0, 0, 400, 100), true, "SpriteStudio Settings"); // get current settings from database. _database = SsAssetPostProcessor.GetDatabase(); }
void OnEnable() { // SsTimer.StartTimer(); _sprite = target as SsSprite; // add shader keeper if it doesn't exist during show the sprite object substance. PrefabType prefabType = PrefabUtility.GetPrefabType(_sprite); if (_sprite != LastSprite && prefabType != PrefabType.Prefab) { //SsTimer.StartTimer(); SsEditorWindow.AddShaderKeeper(); //SsTimer.EndTimer("checking or add shader keeper"); } _animeFrame = _sprite._animeFrame; _startAnimeFrame = _sprite._startAnimeFrame; _endAnimeFrame = _sprite._endAnimeFrame; _hFlip = _sprite.hFlip; _vFlip = _sprite.vFlip; _drawBoundingBox = _sprite.DrawBoundingBox; _subAnimations = null; //_sprite.subAnimations; // get latest animation list // SsTimer.StartTimer(); if (!databaseGo) { databaseGo = SsAssetPostProcessor.GetDatabaseGo(); } // SsTimer.EndTimer("load database asset"); if (databaseGo) { //SsTimer.StartTimer(); _database = databaseGo.GetComponent <SsAssetDatabase>(); List <SsAnimation> animeList = _database.animeList; _animeNames = new string[animeList.Count + 1]; for (int i = 0; i < animeList.Count; ++i) { _animeNames[i + 1] = animeList[i].name; } System.Array.Sort(_animeNames, 1, _animeNames.Length - 1); _animeNames[0] = "<none>"; // get the index of this animation in the list if (_sprite.Animation) { string myAnimeName = _sprite.Animation.name; for (int i = 1; i < _animeNames.Length; ++i) { if (myAnimeName == _animeNames[i]) { _selectedAnimeIndex = i; break; } } } //SsTimer.EndTimer("make anime list"); } else { Debug.LogError("Not found animation list: '" + SsAssetDatabase.filePath + "' needs to reimport animation data"); } LastSprite = _sprite; // SsTimer.EndTimer("SsSpriteEditor.OnEnable()"); }
SSMenu_CleanupPrafabs(MenuCommand command) { SsAssetPostProcessor.CleanupSpritePrefabs(); }
Load(string srcPath) { _database = SsAssetPostProcessor.GetDatabase(); string path = Path.GetDirectoryName(srcPath); // new path name of ss anime asset string newPath = path + "/assets/" + Path.GetFileNameWithoutExtension(srcPath) + "_ssa.asset"; // identify the encoding which is Shift-JIS or UTF-8 Encoding encode = SsEncoding.SJIS; { StreamReader sr = File.OpenText(srcPath); string xmlHeaderText = sr.ReadLine(); // XmlDocument requires one node at least and also needs to get "encoding" attribute. string dummy = System.String.Copy(xmlHeaderText); dummy = dummy.Replace("<?xml", "<Dummy"); dummy = dummy.Replace("?>", "/>"); xmlHeaderText += dummy; sr.Close(); XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlHeaderText); XmlNode node = doc.FirstChild.NextSibling; string encStr = node.Attributes["encoding"].Value; if (encStr == "shift_jis") { encode = SsEncoding.SJIS; } else if (encStr == "utf-8") { encode = SsEncoding.UTF8; } } // to read SJIS encoded text correctly. string textAll = File.ReadAllText(srcPath, encode); // create directory if it doesn't exist. bool newAsset = false; if (!Directory.Exists(path + "/assets")) { AssetDatabase.CreateFolder(path, "assets"); } else { // try to open existing asset _anmRes = AssetDatabase.LoadAssetAtPath(newPath, typeof(SsAnimation)) as SsAnimation; } if (_anmRes == null) { // create new asset _anmRes = ScriptableObject.CreateInstance <SsAnimation>(); newAsset = true; } else { // update existing asset ClearPreviousMaterials(); _anmRes.ImageList = null; _anmRes.PartList = null; System.GC.Collect(); } // update imported time _anmRes.UpdateImportedTime(); // save original resource path _anmRes.OriginalPath = srcPath; // save scale factor at this import. if (!_anmRes.UseScaleFactor) { _anmRes.ScaleFactor = _database.ScaleFactor; } #if _BUILD_UNIFIED_SHADERS if (_anmRes._UseUnifiedShader == UseUnifiedShaderEnum.Default) { // use global setting _anmRes.UseUnifiedShader = _database.UseUnifiedShader; } else { // use own setting _anmRes.UseUnifiedShader = (_anmRes._UseUnifiedShader == UseUnifiedShaderEnum.Yes); } #endif if (!LoadXml(path, textAll)) { Debug.LogError("Failed to import animation data: " + srcPath); return(false); } if (newAsset) { AssetDatabase.CreateAsset(_anmRes, newPath); } else { // modification done internally is not applied actual file, so must make it dirty before. EditorUtility.SetDirty(_anmRes); AssetDatabase.SaveAssets(); //same as EditorApplication.SaveAssets(); } #if false // AddObjectToAsset() a_mat.mat -> hoge.ssax.asset // ↓ // hoge.ssax.mat // hoge.ssax.asset // umm... foreach (var e in _anmRes.ImageList) { if (e.material != null) { e.material.name = e.texture.name + "_Mat"; AssetDatabase.AddObjectToAsset(e.material, _anmRes); // Reimport the asset after adding an object. // Otherwise the change only shows up when saving the project AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(e.material)); } } #endif return(true); }