unity编辑器在运行状态时,prefab的apply按钮就消失了,其实此时代码访问的话是有效的。

代码如下,将会给transform的右键增加一个save prefab的选项。

using UnityEngine;
using UnityEditor;
using System.Collections;

static public class PrefabExtendTools
{

    [MenuItem("CONTEXT/Transform/SavePrefab")]
    static public void SavePrefab()
    {
        GameObject source = PrefabUtility.GetPrefabParent (Selection.activeGameObject) as GameObject;
        if(source == null) return;
        string prefabPath = AssetDatabase.GetAssetPath (source).ToLower ();
        if(prefabPath.EndsWith(".prefab") == false) return;
        PrefabUtility.ReplacePrefab (Selection.activeGameObject, source, ReplacePrefabOptions.ConnectToPrefab | ReplacePrefabOptions.ReplaceNameBased);
    }
}

 

 

Unity运行时保存prefab的方法一则

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2021-07-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
  • 2021-10-27
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
相关资源
相似解决方案