Example #1
0
        private void OnEnable()
        {
            m_AsepriteObjects = new CAsepriteObject[targets.Length];
            for (int i = 0; i < targets.Length; i++)
            {
                AssetImporter tImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(targets[i]));
                if (tImporter == null)
                {
                    continue;
                }
                JSONNode tData = JSON.Parse(tImporter.userData);
                if (tData == null)
                {
                    tData = new JSONObject();
                }
                JSONNode tID = tData["assetID"];

                if (tID != null)
                {
                    m_AsepriteObjects[i] = CAsepritePostProcesor.GetAssetByID <CAsepriteObject>(tID.Value);
                    if (m_AsepriteObjects[i] == null)
                    {
                        m_AsepriteObjects[i] = CAsepritePostProcesor.FindAsepriteObject(targets[i]);
                    }
                    //Debug.Log(tID.Value);
                }

                if (m_AsepriteObjects[i] != null)
                {
                    tID.Value          = CAsepritePostProcesor.GetIDByAsset(m_AsepriteObjects[i]);
                    tImporter.userData = tData.ToString();
                }
            }
        }
Example #2
0
        public override void OnInspectorGUI()
        {
            int tNotImported = 0;

            foreach (CAsepriteObject tObj in m_AsepriteObjects)
            {
                if (tObj == null)
                {
                    tNotImported++;
                }
            }

            if (tNotImported > 0)
            {
                GUILayout.Label("No imported asset found for " + tNotImported
                                + " file" + (tNotImported > 1 ? "s" : ""));
                if (GUILayout.Button(ButtonContentImport, GUILayout.MaxHeight(60)))
                {
                    for (int i = 0; i < targets.Length; i++)
                    {
                        if (m_AsepriteObjects[i] == null)
                        {
                            Object tTarget = targets[i];
                            string tPath   = AssetDatabase.GetAssetPath(tTarget);
                            m_AsepriteObjects[i] = CAsepriteObjectEditor.CreateAsset(tPath);
                            m_AsepriteObjects[i].asepriteAsset = tTarget;
                            CAsepriteObjectEditor.Import(tPath, m_AsepriteObjects[i]);

                            AssetImporter tImporter = AssetImporter.GetAtPath(tPath);
                            JSONNode      tData     = JSON.Parse(tImporter.userData);
                            if (tData == null)
                            {
                                tData = new JSONObject();
                            }
                            tData["assetID"] =
                                CAsepritePostProcesor.GetIDByAsset(m_AsepriteObjects[i]);
                            tImporter.userData = tData.ToString();
                            EditorUtility.SetDirty(tTarget);
                            EditorUtility.SetDirty(m_AsepriteObjects[i]);
                            AssetDatabase.WriteImportSettingsIfDirty(tPath);
                        }
                    }
                }
            }
            else
            {
                if (GUILayout.Button("Select imported asset", GUILayout.MaxHeight(60)))
                {
                    for (int i = 0; i < targets.Length; i++)
                    {
                        m_AsepriteObjects[i].asepriteAsset = targets[i];
                        EditorUtility.SetDirty(m_AsepriteObjects[i]);
                    }
                    Selection.objects = m_AsepriteObjects;
                }
            }
        }