Example #1
0
    //保存预设时 自动挂载离线数据
    public static void BindOfflineData(GameObject go)
    {
        string     path = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(go);
        PrefabType type = PrefabType.None;

        if (path.Contains(PrefabStageListener.UIPrefabsPath))
        {
            type = PrefabType.UI;
        }
        else if (path.Contains(PrefabStageListener.EffectPrefabsPath))
        {
            type = PrefabType.Effect;
        }
        else if (path.Contains(PrefabStageListener.ModelPrefabsPath))
        {
            type = PrefabType.Default;
        }
        if (type != PrefabType.None)
        {
            OfflineData data = null;
            switch (type)
            {
            case PrefabType.UI:
                data = go.GetComponent <UIOfflineData>();
                if (data == null)
                {
                    data = go.AddComponent <UIOfflineData>();
                }
                break;

            case PrefabType.Effect:
                data = go.GetComponent <EffectOfflineData>();
                if (data == null)
                {
                    data = go.AddComponent <EffectOfflineData>();
                }
                break;

            case PrefabType.Default:
                data = go.GetComponent <OfflineData>();
                if (data == null)
                {
                    data = go.AddComponent <OfflineData>();
                }
                break;
            }
            data.BindData();
            EditorUtility.SetDirty(go);
            Resources.UnloadUnusedAssets();
        }
        LogTool.Log("预设以保存 prefab:", go.name);
    }
    public static void CreateOfflineData(GameObject obj)
    {
        OfflineData offlineData = obj.GetComponent <OfflineData>();

        if (offlineData == null)
        {
            offlineData = obj.AddComponent <OfflineData>();
            offlineData.BindData();
            EditorUtility.SetDirty(obj);
            Debug.Log("修改了" + obj.name + " Prefab!");
            Resources.UnloadUnusedAssets();
            AssetDatabase.Refresh();
        }
    }
        public static void CreateOfflineData(GameObject gameObject)
        {
            OfflineData offlineData = gameObject.GetComponent <OfflineData>();

            if (offlineData == null)
            {
                offlineData = gameObject.AddComponent <OfflineData>();
            }

            offlineData.BindData();
            EditorUtility.SetDirty(gameObject);
            Debug.Log($"修改了{gameObject.name} Prefab");
            Resources.UnloadUnusedAssets();
            AssetDatabase.Refresh();
        }
Example #4
0
    private static void BindOfflineData <T>(GameObject obj) where T : OfflineData
    {
        OfflineData offlineData = obj.GetComponent <T>();

        if (offlineData == null)
        {
            offlineData = obj.AddComponent <T>();
        }
        offlineData.BindData();
        //保存当前预制体
        EditorUtility.SetDirty(obj);
        Debug.Log("修改了:" + obj.name + " prefab!");
        Resources.UnloadUnusedAssets(); //卸载未使用的资源
        AssetDatabase.Refresh();        //更新编辑器
    }
        public static void CreateOfflineData(string path)
        {
            GameObject obj = PrefabUtility.LoadPrefabContents(path);

            OfflineData offlineData = obj.GetComponent <OfflineData>();

            if (offlineData == null)
            {
                offlineData = obj.AddComponent <OfflineData>();
            }
            offlineData.BindData();
            EditorUtility.SetDirty(obj);
            Debug.Log("修改了" + obj.name + "prefab!");
            if (PrefabUtility.SaveAsPrefabAsset(obj, path))
            {
                PrefabUtility.UnloadPrefabContents(obj);
            }
            Resources.UnloadUnusedAssets();
            AssetDatabase.Refresh();
        }