コード例 #1
0
    public static void ApplyGraphChange(GraphOwner go, GameObject instance)
    {
        //--------------------- 同步更新prefab资源
        bool isBound = go.graphIsBound;

        if (!isBound)
        {
            return;
        }

        var prefabType = UnityEditor.PrefabUtility.GetPrefabType(go.gameObject);

        if (prefabType == UnityEditor.PrefabType.PrefabInstance)
        {
            if (!Application.isPlaying)
            {
                GameObject prefab = (GameObject)PrefabUtility.GetCorrespondingObjectFromSource(instance);

                List <Graph> allNestGraphs = go.graph.GetAllNestedGraphs <Graph>(true);

                foreach (var v in allNestGraphs)
                {
                    if (!NestedUtility.CheckHasThisAsset(v, prefab))
                    {
                        UnityEditor.AssetDatabase.AddObjectToAsset(v, prefab);
                    }
                }

                UnityEditor.EditorApplication.delayCall +=
                    () => { AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(prefab)); };
                AssetDatabase.Refresh();
            }
        }
    }
コード例 #2
0
ファイル: NestedUtility.cs プロジェクト: coollemen/FishHunter
    public static void ApplyGraphChange(GraphOwner go, GameObject instance)
    {
        //--------------------- 同步更新prefab资源
        bool isBound = go.graphIsBound;

        if (!isBound)
        {
            return;
        }

#if UNITY_2018_3_OR_NEWER
        var prefabType = UnityEditor.PrefabUtility.GetPrefabInstanceStatus(go.gameObject);
        //Debug.Log("start to add child graph");
        if (prefabType != UnityEditor.PrefabInstanceStatus.MissingAsset || prefabType != UnityEditor.PrefabInstanceStatus.NotAPrefab)
        {
            //Debug.Log("check prefab type");
            if (!Application.isPlaying)
            {
                GameObject prefab = (GameObject)PrefabUtility.GetCorrespondingObjectFromSource(instance);
                //Debug.Log("Prefab name:" + prefab.name);
                List <Graph> allNestGraphs = new List <Graph>();
                allNestGraphs.Add(go.graph);
                allNestGraphs = go.graph.GetAllNestedGraphs <Graph>(true);

                foreach (var v in allNestGraphs)
                {
                    if (!NestedUtility.CheckHasThisAsset(v, prefab))
                    {
                        //Debug.Log(" add child graph");
                        UnityEditor.AssetDatabase.AddObjectToAsset(v, prefab);
                        AssetDatabase.SaveAssets();
                        EditorUtility.SetDirty(go);
                    }
                }

                UnityEditor.EditorApplication.delayCall += () => { UnityEditor.AssetDatabase.ImportAsset(UnityEditor.AssetDatabase.GetAssetPath(prefab)); };
            }
        }
#else
        var prefabType = UnityEditor.PrefabUtility.GetPrefabType(go.gameObject);

        if (prefabType == UnityEditor.PrefabType.PrefabInstance)
        {
            if (!Application.isPlaying)
            {
                GameObject prefab = (GameObject)PrefabUtility.GetPrefabParent(instance);

                List <Graph> allNestGraphs = go.graph.GetAllNestedGraphs <Graph>(true);

                foreach (var v in allNestGraphs)
                {
                    if (!NestedUtility.CheckHasThisAsset(v, prefab))
                    {
                        UnityEditor.AssetDatabase.AddObjectToAsset(v, prefab);
                    }
                }

                UnityEditor.EditorApplication.delayCall +=
                    () => { AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(prefab)); };
                AssetDatabase.Refresh();
            }
        }
#endif
    }