浏览代码

Better factorization for Creating Assets

/main
Thomas ICHÉ 6 年前
当前提交
e3952924
共有 5 个文件被更改,包括 64 次插入3 次删除
  1. 5
      Editor/EditorSceneSetup/EditorSceneSetup.cs
  2. 8
      Editor/AssetFactory.meta
  3. 43
      Editor/AssetFactory/AssetFactory.cs
  4. 11
      Editor/AssetFactory/AssetFactory.cs.meta

5
Editor/EditorSceneSetup/EditorSceneSetup.cs


return false;
}
public static void CreateAsset()
static void CreateAsset()
AssetDatabase.CreateAsset(CreateInstance<EditorSceneSetup>(), "Assets/New Editor Scene Setup.asset");
AssetFactory.CreateAssetInProjectWindow<EditorSceneSetup>("SceneSet Icon", "New SceneSetup.asset");
}
public int ActiveScene;

8
Editor/AssetFactory.meta


fileFormatVersion: 2
guid: e78d538974cc9924792b2707919e382a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

43
Editor/AssetFactory/AssetFactory.cs


using UnityEngine;
using UnityEditor.Callbacks;
using UnityEditor.ProjectWindowCallback;
using System;
using System.IO;
using UnityEditor;
namespace GameplayIngredients.Editor
{
public class AssetFactory
{
public static void CreateAssetInProjectWindow<T>(string iconName, string fileName) where T: ScriptableObject
{
var icon = EditorGUIUtility.FindTexture(iconName);
var namingInstance = new DoCreateGenericAsset();
namingInstance.type = typeof(T);
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, namingInstance, fileName, icon, null);
}
public static ScriptableObject CreateAssetAtPath(string path, Type type)
{
Debug.Log("CreateAssetAtPath (" + type.Name + ")");
ScriptableObject asset = ScriptableObject.CreateInstance(type);
asset.name = Path.GetFileName(path);
AssetDatabase.CreateAsset(asset, path);
return asset;
}
class DoCreateGenericAsset : EndNameEditAction
{
public Type type;
public override void Action(int instanceId, string pathName, string resourceFile)
{
ScriptableObject asset = AssetFactory.CreateAssetAtPath(pathName, type);
ProjectWindowUtil.ShowCreatedAsset(asset);
}
}
}
}

11
Editor/AssetFactory/AssetFactory.cs.meta


fileFormatVersion: 2
guid: 4833ee2adf8a9cd4c96cbd6dac04fe42
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存