Beispiel #1
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            string      text  = System.IO.File.ReadAllText(ctx.assetPath);
            SetterAsset asset = ScriptableObject.CreateInstance <SetterAsset>();

            asset.m_XML = text;
            Serializer.Deserialize(asset, text);
            ctx.AddObjectToAsset("MainAsset", asset);
            ctx.SetMainObject(asset);
            SetterAssetCache.SetDirty();
        }
Beispiel #2
0
        void AddMenu()
        {
            GenericMenu menu = new GenericMenu();

            foreach (var type in Util.ContextTypes)
            {
                menu.AddItem(new GUIContent(type.Name), false, () =>
                {
                    var ctx = System.Activator.CreateInstance(type) as SetterContext;
                    m_Asset.m_Contexts.Add(ctx);
                    SetterAssetCache.SetDirty();
                });
            }
            menu.ShowAsContext();
        }
Beispiel #3
0
        void OnPreprocessAsset()
        {
            string path = assetImporter.assetPath;

            if (!System.IO.Path.HasExtension(path))
            {
                return;
            }
            if (!path.StartsWith("Assets"))
            {
                return;
            }
            foreach (var root in SetterAssetCache.GetRootSetters <IImportContext>(path))
            {
                root.Import(path, assetImporter);
            }
        }
Beispiel #4
0
        public override void OnInspectorGUI()
        {
            GUI.enabled = true;
            using (new GUILayout.HorizontalScope())
            {
                if (GUILayout.Button("戻す", GUILayout.ExpandWidth(false), GUILayout.MinWidth(100)))
                {
                    m_Asset.Load();
                    SetterAssetCache.SetDirty();
                }
                if (GUILayout.Button("保存", GUILayout.ExpandWidth(false), GUILayout.MinWidth(100)))
                {
                    m_Asset.Save();
                    SetterAssetCache.SetDirty();
                }
                if (GUILayout.Button("追加", GUILayout.ExpandWidth(false), GUILayout.MinWidth(100)))
                {
                    AddMenu();
                }
            }

            for (int i = 0; i < m_Asset.m_Contexts.Count; i++)
            {
                using (new GUILayout.VerticalScope("box", GUILayout.MinHeight(100f)))
                {
                    var ctx  = m_Asset.m_Contexts[i];
                    var path = AssetDatabase.GetAssetPath(m_Asset);
                    var dir  = path.Substring(0, path.LastIndexOf('/'));
                    ctx.SetDirectory(dir);
                    using (new GUILayout.HorizontalScope())
                    {
                        GUILayout.Label(ctx.GetType().Name);
                        if (GUILayout.Button("削除", GUILayout.ExpandWidth(false)))
                        {
                            m_Asset.m_Contexts.Remove(ctx);
                            break;
                        }
                    }
                    GUILayout.Label(ctx.Description);
                    ctx.OnGUI();
                }
            }
        }
Beispiel #5
0
 void IImportContext.Import(string path, AssetImporter importer)
 {
     Import(path, importer, SetterAssetCache.GetSetters <T>(path).Where(x => x != this));
 }