コード例 #1
0
ファイル: NestedUtility.cs プロジェクト: coollemen/FishHunter
    public static T CreateBoundNested <T>(IGraphAssignable parent, Graph owner) where T : Graph
    {
        T newGraph;

        newGraph = ScriptableObject.CreateInstance <T>();
        (newGraph as UnityEngine.Object).name = owner.name;
        newGraph.Validate();

        if (newGraph != null)
        {
            //newGraph.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy;
            Undo.RegisterCreatedObjectUndo(newGraph, "CreateBoundNested");
            parent.nestedGraph = newGraph;
            //设置graph归属
            if (parent.GetType().IsSubclassOf(typeof(Graph)))
            {
                newGraph.agent = ((Graph)parent).agent;
            }
            if (AssetDatabase.IsMainAsset(owner))
            {
                //Debug.Log("Create main aseet: "+owner);
                AssetDatabase.AddObjectToAsset(newGraph, owner);

                EditorApplication.delayCall += () => { AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(owner)); };
                owner.Validate();
//#if UNITY_2018_3_OR_NEWER
//                AssetDatabase.SaveAssets();
//                EditorUtility.SetDirty(owner);
//#endif
            }
            else if (AssetDatabase.IsSubAsset(owner))
            {
                //Debug.Log("Create sub aseet: " + owner);

                AssetDatabase.AddObjectToAsset(newGraph, GetMainAssetBySubAsset(owner));

                EditorApplication.delayCall += () => { AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(owner)); };
                owner.Validate();
//#if UNITY_2018_3_OR_NEWER
//                AssetDatabase.SaveAssets();
//                EditorUtility.SetDirty(owner);
//#endif
            }
        }
#if UNITY_2018_3_OR_NEWER
        AssetDatabase.SaveAssets();
        EditorUtility.SetDirty(owner);
#endif
        return(newGraph);
    }