示例#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];
        }
示例#2
0
//	[MenuItem("Assets/Create/OpenCog/Delegates")]
        public static void CreateAssets()
        {
            List <OCDelegate> delegates = new List <OCDelegate>();

            MethodInfo[] delegateMethods = typeof(OCAction).GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);

            foreach (MethodInfo dmi in delegateMethods)
            {
                ParameterInfo[] paramInfo = dmi.GetParameters();
                if (paramInfo != null && paramInfo.Length == 2 && paramInfo[0].ParameterType == typeof(OCAction))
                {
                    OCDelegate del = ScriptableObject.CreateInstance <OCDelegate>()
                                     .Initialize(Delegate.CreateDelegate(typeof(OCAction.OCActionCondition), dmi));
                    delegates.Add(del);
                }
            }

            //OCScriptableObjectAssetFactory.CreateAsset<OCDelegate>();

            OCScriptableObjectAssetFactory.CreateAssets(delegates.ToArray());
        }