Example #1
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();
    }
Example #2
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();
        }
    }
Example #3
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();
 }
Example #4
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);
    }