void Awake()
 {
     if (!ssdb)
     {
         ssdb = SsAssetDatabase.Instance;
     }
 }
示例#2
0
    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();
    }
    public override void OnInspectorGUI()
    {
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Reimort"))
        {
            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();
    }
示例#4
0
    static SsAssetPostProcessor()
    {
        var go = GetDatabaseGo();

        if (!go)
        {
            go = CreateDatabaseGo();
            // get replaced database go.
            go = SaveDatabase(go);
        }
        _database = go.GetComponent <SsAssetDatabase>();
    }
示例#5
0
    void OnEnable()
    {
        if (!Instance)
        {
            // cannot find with this function
//			Instance = GameObject.FindObjectOfType(typeof(SsAssetDatabase)) as SsAssetDatabase;
            GameObject go = GameObject.Find(fileName);
            Instance = go.GetComponent <SsAssetDatabase>();
            if (!Instance)
            {
                Debug.Log("Not found " + fileName + " in this scene");
                return;
            }
        }
        animeList = Instance.animeList;
    }
示例#6
0
 void OnEnable()
 {
     if (!Instance)
     {
         // cannot find with this function
     //			Instance = GameObject.FindObjectOfType(typeof(SsAssetDatabase)) as SsAssetDatabase;
         GameObject go = GameObject.Find(fileName);
         Instance = go.GetComponent<SsAssetDatabase>();
         if (!Instance)
         {
             Debug.Log("Not found " + fileName + " in this scene");
             return;
         }
     }
     animeList = Instance.animeList;
 }
    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
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("* Needs Reimport animations to apply these settings.");
            EditorGUILayout.EndHorizontal();

            _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();

            EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Refers to individual inheritance value for Root part.", GUILayout.Width(300));
                _database.RefersToIndividualInheritValueForRootPart = EditorGUILayout.Toggle(_database.RefersToIndividualInheritValueForRootPart);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("  * OPTPiX SpriteStudio 5 compatible if checked.");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Not integerize interpolated X/Y position values.", GUILayout.Width(300));
            _database.NotIntegerizeInterpolatotedXYValues = EditorGUILayout.Toggle(_database.NotIntegerizeInterpolatotedXYValues);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("  * OPTPiX SpriteStudio 5 compatible if checked.");
            EditorGUILayout.EndHorizontal();
        }
        GUILayout.Space(12);
        if (GUILayout.Button("Close"))
        {
            Close();
        }
    }
示例#8
0
    GetDatabase()
    {
#if false
        // ensure the database is present
        if (!_database)
        {
            // get or create game object of database
            GameObject databaseGo = GetDatabaseGo();
            if (databaseGo == null)
            {
                databaseGo = CreateDatabaseGo();
                RebuildDatabase(databaseGo);
                SaveDatabase(databaseGo);
            }
            _database = databaseGo.GetComponent <SsAssetDatabase>();
        }
#endif
        return(_database);
    }
示例#9
0
    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);
        }
        GUILayout.Space(12);
        if (GUILayout.Button("Close"))
        {
            Close();
        }
    }
示例#10
0
	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();
		}
    }
示例#11
0
    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();
        }
    }
示例#12
0
 static public void Init()
 {
     EditorWindow.GetWindowWithRect <SsEditorWindow>(new Rect(0, 0, 400, 100), true, "SpriteStudio Settings");
     // get current settings from database.
     _database = SsAssetPostProcessor.GetDatabase();
 }
示例#13
0
    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()");
    }
 void OnEnable()
 {
     _target = target as SsAssetDatabase;
 }
 public static void Init()
 {
     EditorWindow.GetWindowWithRect<SsEditorWindow>(new Rect(0,0,400,300), true, "SpriteStudio Settings");
     // get current settings from database.
     _database = SsAssetPostProcessor.GetDatabase();
 }
示例#16
0
 GameObject_CreateDatabase(MenuCommand command)
 {
     SsAssetDatabase.CreateNewObject();
 }
 void OnEnable()
 {
     _target = target as SsAssetDatabase;
 }
示例#18
0
    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);
    }
    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()");
    }
示例#20
0
 void Awake()
 {
     if (!ssdb)
         ssdb = SsAssetDatabase.Instance;
 }
示例#21
0
    OnPostprocessAllAssets(
        string[]        importedAssets,
        string[]        deletedAssets,
        string[]        movedAssets,
        string[]        movedFromAssetPaths)
    {
        // reject re-entering for files unnecessary to import during an another file is created internally.
        if (_s_rejectReenter)
        {
//			Debug.LogError("REJECT ->" + importedAssets[0]);
            return;
        }

        string dbFilename = Path.GetFileName(SsAssetDatabase.filePath);

        // ignore database import
        if (importedAssets.Length == 1 &&
            importedAssets[0].EndsWith(dbFilename, _pathComparison))
        {
#if _RELINK_DB_OBJECT_TO_PREFAB
            UpdateDatabaseObjectInHierarchy();
#endif
//			Debug.LogWarning("IGNORE Database");
            return;
        }

//		if (importedAssets.Length > 0)
//			Debug.Log("ENTER importing " + importedAssets[0] + " count: " + importedAssets.Length);

        // reject reenter this function while importing new generated files.
        _s_rejectReenter = true;

        try
        {
            AssetDatabase.Refresh();

            // get game object contains database
            GameObject databaseGo = GetDatabaseGo();

            bool createDatabase = false;
            // make database first to assure the existing.
            if (databaseGo == null)
            {
                createDatabase = true;
            }
            else
            {
                // ignore database delete and re-create it
                if (deletedAssets.Length > 0 &&
                    deletedAssets[0].EndsWith(dbFilename, _pathComparison))
                {
                    createDatabase = true;
                }
            }

            if (createDatabase)
            {
                // create database
//				Debug.LogWarning("Create Database: " + databaseGo);
                var go = CreateDatabaseGo();
                RebuildDatabase(go);
                databaseGo = SaveDatabase(go);
            }

            _database = databaseGo.GetComponent <SsAssetDatabase>();

            int prevAnimeListCount = _database.animeList.Count;

            // filter imported files and create assets as needed
            foreach (var name in importedAssets)
            {
                // ignore database file in filename list
                if (name.EndsWith(dbFilename, _pathComparison))
                {
                    continue;
                }

#if _GENERATE_SHADERS
                if (name.EndsWith(_shaderTemplateFilename, _pathComparison))
                {
                    BuildShaders(name);
                }
#endif

                if (name.EndsWith(".ssax", _pathComparison))
                {
                    SsaxImporter v = SsaxImporter.Create(name);
                    if (v != null)
                    {
                        var anm = v.AnimeRes;
                        CreateSpritePrefab(anm);
                        _database.AddAnime(anm);
                    }
                }
            }

            // assets will be deleted
            foreach (var name in deletedAssets)
            {
                if (!name.EndsWith(".asset", _pathComparison))
                {
                    continue;
                }
                Object asset = AssetDatabase.LoadAssetAtPath(name, typeof(SsAnimation));
                // remove animation element from list
                SsAnimation anim = asset as SsAnimation;
                if (anim == null)
                {
                    continue;
                }
                _database.animeList.Remove(anim);
            }
            // cleanup null elements in the database
            _database.CleanupAnimeList();

            if (_database.animeList.Count != prevAnimeListCount)
            {
                // apply modification of database to actual file
                EditorUtility.SetDirty(databaseGo);
            }
            AssetDatabase.SaveAssets();

#if _RELINK_DB_OBJECT_TO_PREFAB
            // update game object refers to the database prefab
            UpdateDatabaseObjectInHierarchy();
#endif
        }
        catch
        {
//			Debug.LogWarning("ABORT importing");
            throw;
        }
        finally
        {
            _s_rejectReenter = false;
//			Debug.Log("LEAVE importing");
        }
    }