Esempio n. 1
0
        /// <summary>
        //	This makes it easy to create, name and place unique new ScriptableObject asset files.
        /// </summary>
        public static void CreateAssets(OCDelegate[] assets)
        {
            string path = AssetDatabase.GetAssetPath(Selection.activeObject);

            if (path == "")
            {
                path = "Assets";
            }
            else
            if (Path.GetExtension(path) != "")
            {
                path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
            }

            path += "/OpenCog Assets/OtherAssets/ActionConditions/";

            foreach (OCDelegate asset in assets)
            {
                string     basePath      = path + asset.Name + " " + typeof(OCDelegate).Name + ".asset";
                OCDelegate existingAsset = (OCDelegate)AssetDatabase.LoadAssetAtPath(basePath, typeof(OCDelegate));

                if (existingAsset != null)
                {
                    AssetDatabase.DeleteAsset(basePath);
                }

                string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(basePath);
                AssetDatabase.CreateAsset(asset, assetPathAndName);
            }


            AssetDatabase.SaveAssets();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = assets[0];
        }
Esempio n. 2
0
        /// <summary>
        //	This makes it easy to create, name and place unique new ScriptableObject asset files.
        /// </summary>
        public static void CreateAsset <T>(T asset) where T : ScriptableObject
        {
            string path = AssetDatabase.GetAssetPath(Selection.activeObject);

            if (path == "")
            {
                path = "Assets";
            }
            else
            if (Path.GetExtension(path) != "")
            {
                path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
            }

            string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/New " + typeof(T).ToString() + ".asset");

            AssetDatabase.CreateAsset(asset, assetPathAndName);

            AssetDatabase.SaveAssets();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = asset;
        }