Пример #1
0
        public static UnityObject CreatePrefab(string folderPath,
                                               GameObject obj = null,
                                               ReplacePrefabOptions options = ReplacePrefabOptions.ConnectToPrefab) {
            //Create Folder if it doesn't already exist
            AssetUtil.CreateFolder(folderPath);

            folderPath = "Assets/" + folderPath;

            if (obj == null)
                return PrefabUtility.CreateEmptyPrefab(folderPath + "New Prefab.prefab");
            return PrefabUtility.CreatePrefab(folderPath + "/" + obj.name + ".prefab", obj, options);
        }
Пример #2
0
        public static GameObject ReplacePrefab(GameObject go, Object targetPrefab, HEU_ReplacePrefabOptions heuOptions)
        {
#if UNITY_EDITOR
            ReplacePrefabOptions unityOptions = ReplacePrefabOptions.Default;
            switch (heuOptions)
            {
            case HEU_ReplacePrefabOptions.Default:                  unityOptions = ReplacePrefabOptions.Default; break;

            case HEU_ReplacePrefabOptions.ConnectToPrefab:  unityOptions = ReplacePrefabOptions.ConnectToPrefab; break;

            case HEU_ReplacePrefabOptions.ReplaceNameBased: unityOptions = ReplacePrefabOptions.ReplaceNameBased; break;

            default: Debug.LogFormat("Unsupported replace prefab option: {0}", heuOptions); break;
            }

            return(PrefabUtility.ReplacePrefab(go, targetPrefab, unityOptions));
#else
            Debug.LogWarning(HEU_Defines.HEU_USERMSG_NONEDITOR_NOT_SUPPORTED);
            return(null);
#endif
        }
Пример #3
0
 //Revert
 static void RevertToSelectedPrefabs(GameObject _goCurrentGo, Object _ObjPrefabParent, ReplacePrefabOptions _eReplaceOptions)
 {
     PrefabUtility.ReconnectToLastPrefab(_goCurrentGo);
     PrefabUtility.RevertPrefabInstance(_goCurrentGo);
 }
Пример #4
0
        public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged)
        {
            EditorGUILayout.HelpBox("Create Prefab From Group: Create prefab from incoming group of assets, using assigned script.", MessageType.Info);
            editor.UpdateNodeName(node);

            var builder = m_instance.Get <IPrefabBuilder>(editor.CurrentEditingGroup);

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var map = PrefabBuilderUtility.GetAttributeAssemblyQualifiedNameMap();
                if (map.Count > 0)
                {
                    using (new GUILayout.HorizontalScope()) {
                        GUILayout.Label("PrefabBuilder");
                        var guiName = PrefabBuilderUtility.GetPrefabBuilderGUIName(m_instance.ClassName);

                        if (GUILayout.Button(guiName, "Popup", GUILayout.MinWidth(150f)))
                        {
                            var builders = map.Keys.ToList();

                            if (builders.Count > 0)
                            {
                                NodeGUI.ShowTypeNamesMenu(guiName, builders, (string selectedGUIName) =>
                                {
                                    using (new RecordUndoScope("Change PrefabBuilder class", node, true)) {
                                        builder = PrefabBuilderUtility.CreatePrefabBuilder(selectedGUIName);
                                        m_instance.Set(editor.CurrentEditingGroup, builder);
                                        onValueChanged();
                                    }
                                }
                                                          );
                            }
                        }

                        MonoScript s = TypeUtility.LoadMonoScript(m_instance.ClassName);

                        using (new EditorGUI.DisabledScope(s == null)) {
                            if (GUILayout.Button("Edit", GUILayout.Width(50)))
                            {
                                AssetDatabase.OpenAsset(s, 0);
                            }
                        }
                    }
                    ReplacePrefabOptions opt = (ReplacePrefabOptions)EditorGUILayout.EnumPopup("Prefab Replace Option", m_replacePrefabOptions, GUILayout.MinWidth(150f));
                    if (m_replacePrefabOptions != opt)
                    {
                        using (new RecordUndoScope("Change Prefab Replace Option", node, true)) {
                            m_replacePrefabOptions = opt;
                            onValueChanged();
                        }
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(m_instance.ClassName))
                    {
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "Your PrefabBuilder script {0} is missing from assembly. Did you delete script?", m_instance.ClassName), MessageType.Info);
                    }
                    else
                    {
                        string[] menuNames = Model.Settings.GUI_TEXT_MENU_GENERATE_PREFABBUILDER.Split('/');
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "You need to create at least one PrefabBuilder script to use this node. To start, select {0}>{1}>{2} menu and create new script from template.",
                                menuNames[1], menuNames[2], menuNames[3]
                                ), MessageType.Info);
                    }
                }

                GUILayout.Space(10f);

                editor.DrawPlatformSelector(node);
                using (new EditorGUILayout.VerticalScope()) {
                    var disabledScope = editor.DrawOverrideTargetToggle(node, m_instance.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => {
                        if (enabled)
                        {
                            m_instance.CopyDefaultValueTo(editor.CurrentEditingGroup);
                        }
                        else
                        {
                            m_instance.Remove(editor.CurrentEditingGroup);
                        }
                        onValueChanged();
                    });

                    using (disabledScope) {
                        if (builder != null)
                        {
                            Action onChangedAction = () => {
                                using (new RecordUndoScope("Change PrefabBuilder Setting", node)) {
                                    m_instance.Set(editor.CurrentEditingGroup, builder);
                                    onValueChanged();
                                }
                            };

                            builder.OnInspectorGUI(onChangedAction);
                        }
                    }
                }
            }
        }
Пример #5
0
 public static extern GameObject ReplacePrefab(GameObject go, UnityEngine.Object targetPrefab, [DefaultValue("ReplacePrefabOptions.Default")] ReplacePrefabOptions options);
Пример #6
0
 public static extern GameObject CreatePrefab(string path, GameObject go, [DefaultValue("ReplacePrefabOptions.Default")] ReplacePrefabOptions options);
Пример #7
0
        private void DoInspectorPrefabBuilderGUI(NodeGUI node)
        {
            EditorGUILayout.HelpBox("PrefabBuilder: Create prefab with given assets and script.", MessageType.Info);
            UpdateNodeName(node);

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var map = PrefabBuilderUtility.GetAttributeClassNameMap();
                if (map.Count > 0)
                {
                    using (new GUILayout.HorizontalScope()) {
                        GUILayout.Label("PrefabBuilder");
                        var guiName = PrefabBuilderUtility.GetPrefabBuilderGUIName(node.Data.ScriptClassName);

                        if (GUILayout.Button(guiName, "Popup", GUILayout.MinWidth(150f)))
                        {
                            var builders = map.Keys.ToList();

                            if (builders.Count > 0)
                            {
                                NodeGUI.ShowTypeNamesMenu(guiName, builders, (string selectedGUIName) =>
                                {
                                    using (new RecordUndoScope("Change PrefabBuilder class", node, true)) {
                                        m_prefabBuilder = PrefabBuilderUtility.CreatePrefabBuilder(selectedGUIName);
                                        if (m_prefabBuilder != null)
                                        {
                                            node.Data.ScriptClassName           = PrefabBuilderUtility.GUINameToClassName(selectedGUIName);
                                            node.Data.InstanceData.DefaultValue = m_prefabBuilder.Serialize();
                                        }
                                    }
                                }
                                                          );
                            }
                        }

                        MonoScript s = TypeUtility.LoadMonoScript(node.Data.ScriptClassName);

                        using (new EditorGUI.DisabledScope(s == null)) {
                            if (GUILayout.Button("Edit", GUILayout.Width(50)))
                            {
                                AssetDatabase.OpenAsset(s, 0);
                            }
                        }
                    }
                    ReplacePrefabOptions opt = (ReplacePrefabOptions)EditorGUILayout.EnumPopup("Prefab Replace Option", node.Data.ReplacePrefabOptions, GUILayout.MinWidth(150f));
                    if (node.Data.ReplacePrefabOptions != opt)
                    {
                        using (new RecordUndoScope("Change Prefab Replace Option", node, true)) {
                            node.Data.ReplacePrefabOptions = opt;
                        }
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(node.Data.ScriptClassName))
                    {
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "Your PrefabBuilder script {0} is missing from assembly. Did you delete script?", node.Data.ScriptClassName), MessageType.Info);
                    }
                    else
                    {
                        string[] menuNames = AssetBundleGraphSettings.GUI_TEXT_MENU_GENERATE_PREFABBUILDER.Split('/');
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "You need to create at least one PrefabBuilder script to use PrefabBuilder node. To start, select {0}>{1}>{2} menu and create new script from template.",
                                menuNames[1], menuNames[2], menuNames[3]
                                ), MessageType.Info);
                    }
                }

                GUILayout.Space(10f);

                if (DrawPlatformSelector(node))
                {
                    // if platform tab is changed, renew prefabBuilder for that tab.
                    m_prefabBuilder = null;
                }
                using (new EditorGUILayout.VerticalScope()) {
                    var disabledScope = DrawOverrideTargetToggle(node, node.Data.InstanceData.ContainsValueOf(currentEditingGroup), (bool enabled) => {
                        if (enabled)
                        {
                            node.Data.InstanceData[currentEditingGroup] = node.Data.InstanceData.DefaultValue;
                        }
                        else
                        {
                            node.Data.InstanceData.Remove(currentEditingGroup);
                        }
                        m_prefabBuilder = null;
                    });

                    using (disabledScope) {
                        //reload prefabBuilder instance from saved instance data.
                        if (m_prefabBuilder == null)
                        {
                            m_prefabBuilder = PrefabBuilderUtility.CreatePrefabBuilder(node.Data, currentEditingGroup);
                            if (m_prefabBuilder != null)
                            {
                                node.Data.ScriptClassName = m_prefabBuilder.GetType().FullName;
                                if (node.Data.InstanceData.ContainsValueOf(currentEditingGroup))
                                {
                                    node.Data.InstanceData[currentEditingGroup] = m_prefabBuilder.Serialize();
                                }
                            }
                        }

                        if (m_prefabBuilder != null)
                        {
                            Action onChangedAction = () => {
                                using (new RecordUndoScope("Change PrefabBuilder Setting", node)) {
                                    node.Data.ScriptClassName = m_prefabBuilder.GetType().FullName;
                                    if (node.Data.InstanceData.ContainsValueOf(currentEditingGroup))
                                    {
                                        node.Data.InstanceData[currentEditingGroup] = m_prefabBuilder.Serialize();
                                    }
                                }
                            };

                            m_prefabBuilder.OnInspectorGUI(onChangedAction);
                        }
                    }
                }
            }
        }
Пример #8
0
 private static extern GameObject Internal_CreatePrefab(string path, GameObject go, [DefaultValue("ReplacePrefabOptions.Default")] ReplacePrefabOptions options);
Пример #9
0
        public void Initialize(string groupKey, string className, string instanceData, string version, ReplacePrefabOptions opt, List <AssetReference> assets)
        {
            m_groupKey             = groupKey;
            m_builderClass         = className;
            m_instanceData         = instanceData;
            m_prefabBuilderVersion = version;
            m_replacePrefabOptions = (int)opt;

            m_usedAssets = new List <UsedAsset> ();
            assets.ForEach(a => m_usedAssets.Add(new UsedAsset(a.importFrom)));
        }
Пример #10
0
 public static GameObject ReplacePrefab(GameObject go, UnityEngine.Object targetPrefab, ReplacePrefabOptions options) =>
 PrefabUtility.ReplacePrefab(go, targetPrefab, options);
Пример #11
0
        public static GameObject ReplacePrefab(GameObject go, Object targetPrefab)
        {
            ReplacePrefabOptions options = ReplacePrefabOptions.Default;

            return(ReplacePrefab(go, targetPrefab, options));
        }
Пример #12
0
        private static GameObject SavePrefab(GameObject inputObject, string path, ReplacePrefabOptions replaceOptions, PrefabCreationFlags creationFlags)
        {
            bool success;

            return(SavePrefab(inputObject, path, replaceOptions, creationFlags, out success));
        }
Пример #13
0
 extern public static GameObject ReplacePrefab(GameObject go, Object targetPrefab, [uei.DefaultValue("ReplacePrefabOptions.Default")]  ReplacePrefabOptions options);
Пример #14
0
    public override void OnInspectorGUI()
    {

        base.OnInspectorGUI();

        MonoDelegateView mview = (MonoDelegateView)this.target;
        BaseView bview = mview.m_view;

		if(bview == null)
			return;

        EditorGUILayout.PrefixLabel(new GUIContent("View Public Field", "use fewer Public fields will Be fine "));
		if (fields == null && bview != null)
        {
            fields = bview.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
        }



        for (int i = 0; i < fields.Length; ++i)
        {
            KbEditorUtils.UnkownTypeEditorShow(fields[i], bview);
        }

        PrefabType prefabtype = PrefabUtility.GetPrefabType(mview);
        //		LogMgr.LogError (prefabtype.ToString());
        if (prefabtype == PrefabType.PrefabInstance || prefabtype == PrefabType.None)
        {
            bview.AutoPos = EditorGUILayout.Toggle("Auto Pos", bview.AutoPos);
            if (bview.AutoPos)
            {
                bview.Pos = EditorGUILayout.Vector3Field("World Pos", mview.gameObject.transform.position);
            }

        }

        GUILayout.Space(10);
        GUI.skin.label.alignment = TextAnchor.MiddleCenter;

        GUILayout.Label("Create Trans  Target ");
        GUILayout.Space(10);
        selected = GUILayout.Toolbar(selected, RegisterTrans.mIns.ToStringArray(""));


        if (bview.Trans == null)
        {

            GUILayout.Space(5);
            GUILayout.BeginHorizontal();

            GUILayout.Label("Author: Kubility ", GUILayout.Width(120));


            if (GUILayout.Button(new GUIContent("+", "it Will Create an Trans"), EditorStyles.toolbarButton))
            {
                Type transType = RegisterTrans.TransTypes[selected];
                var trans = Activator.CreateInstance(transType, new System.Object[] { null });//ScriptableObject.CreateInstance (transType);
                var field = bview.GetType().GetField("_Trans", BindingFlags.Instance | BindingFlags.NonPublic);

                field.SetValue(bview, trans);

            }

            GUILayout.EndHorizontal();
        }

        if (bview.Trans != null)
        {
            Type transType = RegisterTrans.TransTypes[selected];
            GUILayout.Space(10);
            DyNamicCreate(transType, bview);
        }
		string filepath=string.IsNullOrEmpty(prefabPath)? defaultPath +mview.gameObject.name:prefabPath;
		EditorGUILayout.Space();

		filepath =EditorGUILayout.TextField("PrefabPath",filepath);

		EditorGUILayout.Space();
		EditorGUILayout.BeginHorizontal();

		if(GUILayout.Button("Convert To Prefab "))
		{
			prefab = PrefabUtility.CreateEmptyPrefab("Assets/"+filepath+".prefab") ;
			AssetDatabase.Refresh();
			int retryTimes =0;
			
			while( AssetDatabase.LoadAssetAtPath<GameObject>("Assets/"+filepath+".prefab") == null && retryTimes <100)
			{
				retryTimes++;
			}
			PrefabUtility.ReplacePrefab(mview.gameObject, prefab,ReplaceOptions);


		}

		ReplaceOptions = (ReplacePrefabOptions)EditorGUILayout.EnumPopup(ReplaceOptions);
        EditorGUILayout.EndHorizontal();

		EditorGUILayout.Space();
        if (GUI.changed)
            EditorUtility.SetDirty(target);
        serializedObject.ApplyModifiedProperties();
    }
Пример #15
0
 //Revert
 static void RevertToSelectedPrefabs(GameObject _goCurrentGo, Object _ObjPrefabParent, ReplacePrefabOptions _eReplaceOptions)
 {
     PrefabUtility.ReconnectToLastPrefab(_goCurrentGo);
     PrefabUtility.RevertPrefabInstance(_goCurrentGo);
 }
Пример #16
0
    /// <summary>
    /// Unity Editor function
    /// </summary>
    /// <param name="resourcesRelPath">Path to a folder inside of the Resources folder and relative to it</param>
    /// <param name="prefabName">Name of the prefab, omitting '.prefab'</param>
    /// <param name="orig">Transform in the scene on which to base a new prefab if none is found</param>
    /// <param name="rpos">Replace prefab options</param>
    /// <returns></returns>
    public static T GetOrCreatePrefabInstance <T>(string resourcesRelPath, string prefabName, T orig, ReplacePrefabOptions rpos) where T : MonoBehaviour
    {
        string resourcesLocalName = string.Format("{0}/{1}", resourcesRelPath, prefabName);
        T      result             = Resources.Load <T>(resourcesLocalName);

        if (result)
        {
            return(Object.Instantiate(result));
        }
#if UNITY_EDITOR
        if (!result)
        {
            Assert.IsFalse(orig == null, "Whoops. we need an original of this transform at this point");
            if (orig == null)
            {
                return(null);
            }

            string     localPath = string.Format("{0}/{1}{2}", PathMaster.ResourcesLocal, resourcesLocalName, ".prefab");
            GameObject go        = PrefabUtility.CreatePrefab(localPath, orig.gameObject, rpos);
            if (go)
            {
                result = Object.Instantiate(go.GetComponent <T>());
            }
        }
#endif
        return(result);
    }
    // Save prefab
    private static void ReplaceSpritePrefab(GameObject a_rPrefabInstance, GameObject a_rPrefab, ReplacePrefabOptions a_eReplacePrefabOption = ReplacePrefabOptions.Default)
    {
        Uni2DSprite[] oSpritesPrefabInstance = a_rPrefabInstance.GetComponentsInChildren<Uni2DSprite>();

            // Save its resources
            string oPrefabPath;
            string oPrefabResourcesName;
            string oPrefabResourcesPath;
            string oPrefabResourcesPathAbsolute;
            GetPrefabResourcesDirectoryPaths(a_rPrefab, out oPrefabPath, out oPrefabResourcesName, out oPrefabResourcesPath, out oPrefabResourcesPathAbsolute);

            // Create the resources folder
            if(Directory.Exists(oPrefabResourcesPathAbsolute))
            {
                AssetDatabase.DeleteAsset(oPrefabResourcesPath);
            }
            string oPrefabResourcesFolderPathGUID = AssetDatabase.CreateFolder(oPrefabPath, oPrefabResourcesName);
            oPrefabResourcesPath = AssetDatabase.GUIDToAssetPath(oPrefabResourcesFolderPathGUID);

            foreach(Uni2DSprite rSpritePrefabInstance in oSpritesPrefabInstance)
            {
                rSpritePrefabInstance.SaveSpriteAsPartOfAPrefab(oPrefabResourcesPath);
            }

            // Replace prefab
            PrefabUtility.ReplacePrefab(a_rPrefabInstance, a_rPrefab, a_eReplacePrefabOption);
    }
    // Save prefab
    private static void ReplaceSpritePrefab(GameObject a_rPrefabInstance, GameObject a_rPrefab, ReplacePrefabOptions a_eReplacePrefabOption = ReplacePrefabOptions.Default)
    {
        Uni2DSprite[ ] rSpritePrefabInstances = a_rPrefabInstance.GetComponentsInChildren<Uni2DSprite>();

        // Save its resources
        string oPrefabPath;
        string oPrefabResourcesName;
        string oPrefabResourcesPath;
        string oPrefabResourcesPathAbsolute;
        GetPrefabResourcesDirectoryPaths(a_rPrefab, out oPrefabPath, out oPrefabResourcesName, out oPrefabResourcesPath, out oPrefabResourcesPathAbsolute);

        // Create the resources folder
        if( Directory.Exists( oPrefabResourcesPathAbsolute ) )
        {
            AssetDatabase.DeleteAsset(oPrefabResourcesPath);
        }

        try
        {
            string oPrefabResourcesFolderPathGUID = AssetDatabase.CreateFolder(oPrefabPath, oPrefabResourcesName);
            oPrefabResourcesPath = AssetDatabase.GUIDToAssetPath(oPrefabResourcesFolderPathGUID);
        }
        catch( Exception e )
        {
            Debug.LogError( "Uni2D can't create prefab folder: " + e.Message );
        }

        int iSpriteCount = rSpritePrefabInstances.Length;
        string[ ] oTextureGUIDs = new string[ iSpriteCount ];
        string[ ] oAtlasGUIDs   = new string[ iSpriteCount ];
        for( int iSpriteIndex = 0; iSpriteIndex < iSpriteCount; ++iSpriteIndex )
        {
            Uni2DSprite rSpritePrefabInstance = rSpritePrefabInstances[ iSpriteIndex ];
            Uni2DEditorSpriteSettings rSpriteSettings = rSpritePrefabInstance.SpriteSettings;

            rSpritePrefabInstance.SaveSpriteAsPartOfAPrefab( oPrefabResourcesPath );

            // Save texture/atlas dependencies
            oTextureGUIDs[ iSpriteIndex ] = rSpriteSettings.textureContainer.GUID;
            oAtlasGUIDs[ iSpriteIndex   ] = rSpriteSettings.atlas != null
                ? Uni2DEditorUtils.GetUnityAssetGUID( rSpriteSettings.atlas )
                : null;
        }

        // Replace prefab
        GameObject rNewPrefab = PrefabUtility.ReplacePrefab(a_rPrefabInstance, a_rPrefab, a_eReplacePrefabOption);

        // Update asset table with sprite prefabs dependencies
        string rPrefabGUID = Uni2DEditorUtils.GetUnityAssetGUID( rNewPrefab );
        Uni2DEditorAssetTable rAssetTable = Uni2DEditorAssetTable.Instance;

        for( int iSpriteIndex = 0; iSpriteIndex < iSpriteCount; ++iSpriteIndex )
        {
            rAssetTable.AddSpritePrefabUsingTexture( rPrefabGUID, oTextureGUIDs[ iSpriteIndex ] );

            if( !string.IsNullOrEmpty( oAtlasGUIDs[ iSpriteIndex ] ) )
            {
                rAssetTable.AddSpritePrefabUsingAtlas( rPrefabGUID, oAtlasGUIDs[ iSpriteIndex ] );
            }
        }
        rAssetTable.Save( );
    }
	// Save prefab
	private static void ReplaceSpritePrefab(GameObject a_rPrefabInstance, GameObject a_rPrefab, ReplacePrefabOptions a_eReplacePrefabOption = ReplacePrefabOptions.Default)
	{		
		Uni2DSprite[ ] rSpritePrefabInstances = a_rPrefabInstance.GetComponentsInChildren<Uni2DSprite>();
	
		// Save its resources
		string oPrefabPath;
		string oPrefabResourcesName;
		string oPrefabResourcesPath;
		string oPrefabResourcesPath_Absolute;
		GetPrefabResourcesDirectoryPaths(a_rPrefab, out oPrefabPath, out oPrefabResourcesName, out oPrefabResourcesPath, out oPrefabResourcesPath_Absolute);
	
		// Create the resources folder
		if(Directory.Exists(oPrefabResourcesPath_Absolute) == false)
		{
			try
			{
				string oPrefabResourcesFolderPathGUID = AssetDatabase.CreateFolder(oPrefabPath, oPrefabResourcesName);
				oPrefabResourcesPath = AssetDatabase.GUIDToAssetPath(oPrefabResourcesFolderPathGUID);
			}
			catch( Exception e )
			{
				Debug.LogError( "Uni2D can't create prefab folder: " + e.Message );
			}
		}

		int iSpriteCount = rSpritePrefabInstances.Length;
		string[ ] oTextureGUIDs = new string[ iSpriteCount ];
		string[ ] oAtlasGUIDs   = new string[ iSpriteCount ];
		Dictionary<string, int> oSubfolderNameOccurences = new Dictionary<string, int>();
		HashSet<string> oCreatedSubfolderNames = new HashSet<string>();
		for( int iSpriteIndex = 0; iSpriteIndex < iSpriteCount; ++iSpriteIndex )
		{
			Uni2DSprite rSpritePrefabInstance = rSpritePrefabInstances[ iSpriteIndex ];
			Uni2DEditorSpriteSettings rSpriteSettings = rSpritePrefabInstance.SpriteSettings;
			
			// Select a unique subfolder name
			string oGameObjectName = rSpritePrefabInstance.gameObject.name.Replace("(Clone)", "");
			string oSubfolderName = oGameObjectName;
			int iOccurenceCount = 0;
			if(oSubfolderNameOccurences.TryGetValue(oSubfolderName, out iOccurenceCount))
			{
				oSubfolderNameOccurences[oSubfolderName] = iOccurenceCount + 1;
				oSubfolderName += " " + iOccurenceCount;
			}
			else
			{
				oSubfolderNameOccurences.Add(oSubfolderName, 1);
			}
			
			// Save the created subfolder name in order to be able to clean the useless subfolders
			oCreatedSubfolderNames.Add(oSubfolderName);
			
			rSpritePrefabInstance.SaveSpriteAsPartOfAPrefab(oPrefabResourcesPath, oPrefabResourcesPath_Absolute, oSubfolderName);

			// Save texture/atlas dependencies
			oTextureGUIDs[ iSpriteIndex ] = rSpriteSettings.textureContainer.GUID;
			oAtlasGUIDs[ iSpriteIndex   ] = rSpriteSettings.atlas != null
				? Uni2DEditorUtils.GetUnityAssetGUID( rSpriteSettings.atlas )
				: null;
		}
		
		// Remove all the unused assets in the folder
		string[] oFiles = Directory.GetFiles(oPrefabResourcesPath_Absolute);
		string[] oDirectory = Directory.GetDirectories(oPrefabResourcesPath_Absolute);
		List<string> oAssets = new List<string>();
		oAssets.AddRange(oFiles);
		foreach(string oDirectoryPath in oDirectory)
		{
			string oDirectoryName = oDirectoryPath.Replace(oPrefabResourcesPath_Absolute + "/", "");
			
			// Don't remove the subdirectory we created
			if(oCreatedSubfolderNames.Contains(oDirectoryName) == false)
			{
				oAssets.Add(oDirectoryPath);
			}
		}
		foreach(string oAssetPath in oAssets)
		{
			string oAssetName = oAssetPath.Replace(oPrefabResourcesPath_Absolute + "/", "");
			AssetDatabase.DeleteAsset(oPrefabResourcesPath + "/" + oAssetName);
		}
		
		// Replace prefab
		GameObject rNewPrefab = PrefabUtility.ReplacePrefab(a_rPrefabInstance, a_rPrefab, a_eReplacePrefabOption);
		
		// Update asset table with sprite prefabs dependencies
		string rPrefabGUID = Uni2DEditorUtils.GetUnityAssetGUID( rNewPrefab );
		Uni2DEditorAssetTable rAssetTable = Uni2DEditorAssetTable.Instance;
		
		for( int iSpriteIndex = 0; iSpriteIndex < iSpriteCount; ++iSpriteIndex )
		{
			rAssetTable.AddSpritePrefabUsingTexture( rPrefabGUID, oTextureGUIDs[ iSpriteIndex ] );

			if( !string.IsNullOrEmpty( oAtlasGUIDs[ iSpriteIndex ] ) )
			{
				rAssetTable.AddSpritePrefabUsingAtlas( rPrefabGUID, oAtlasGUIDs[ iSpriteIndex ] );
			}
		}
		rAssetTable.Save( );
		
		AssetDatabase.SaveAssets();
	}
Пример #20
0
#pragma warning disable 0618 // Type or member is obsolete
        extern private static GameObject CreateVariant_Internal([NotNull] GameObject original, string path, ReplacePrefabOptions replaceOptions);
Пример #21
0
        private static GameObject Internal_CreatePrefab(string path, GameObject go)
        {
            ReplacePrefabOptions options = ReplacePrefabOptions.Default;

            return(PrefabUtility.Internal_CreatePrefab(path, go, options));
        }
Пример #22
0
#pragma warning disable 0618 // Type or member is obsolete
        extern private static GameObject SavePrefab_Internal([NotNull] GameObject root, string path, ReplacePrefabOptions replaceOptions, PrefabCreationFlags createOptions);
Пример #23
0
 public static GameObject ReplacePrefab(GameObject go, UnityEngine.Object targetPrefab, ReplacePrefabOptions options)
 {
   return PrefabUtility.ReplacePrefab(go, targetPrefab, options);
 }
Пример #24
0
 extern static private GameObject CreatePrefab_internal(string path, GameObject go, ReplacePrefabOptions options);
Пример #25
0
        public static GameObject CreatePrefab(string path, GameObject go)
        {
            ReplacePrefabOptions options = ReplacePrefabOptions.Default;

            return(PrefabUtility.CreatePrefab(path, go, options));
        }
Пример #26
0
 extern public static GameObject ReplacePrefab(GameObject go, Object targetPrefab, ReplacePrefabOptions options);
Пример #27
0
        public static GameObject ReplacePrefab(GameObject go, UnityEngine.Object targetPrefab)
        {
            ReplacePrefabOptions options = ReplacePrefabOptions.Default;

            return(PrefabUtility.ReplacePrefab(go, targetPrefab, options));
        }
Пример #28
0
 public static ReplacePrefabOptions GetReplacePrefabOptions(ReplacePrefabOptions replacePrefabOptions)
 {
     return(replacePrefabOptions);
 }
Пример #29
0
 //Apply
 static void ApplyToSelectedPrefabs(GameObject _goCurrentGo, Object _ObjPrefabParent, ReplacePrefabOptions _eReplaceOptions)
 {
     PrefabUtility.ReplacePrefab(_goCurrentGo, _ObjPrefabParent, _eReplaceOptions);
 }
Пример #30
0
        public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged)
        {
            EditorGUILayout.HelpBox("Create Prefab From Group: Create prefab from incoming group of assets, using assigned script.", MessageType.Info);
            editor.UpdateNodeName(node);

            var builder = m_instance.Get <IPrefabBuilder>(editor.CurrentEditingGroup);

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                var map = PrefabBuilderUtility.GetAttributeAssemblyQualifiedNameMap();
                if (map.Count > 0)
                {
                    using (new GUILayout.HorizontalScope()) {
                        GUILayout.Label("PrefabBuilder");
                        var guiName = PrefabBuilderUtility.GetPrefabBuilderGUIName(m_instance.ClassName);

                        if (GUILayout.Button(guiName, "Popup", GUILayout.MinWidth(150f)))
                        {
                            var builders = map.Keys.ToList();

                            if (builders.Count > 0)
                            {
                                NodeGUI.ShowTypeNamesMenu(guiName, builders, (string selectedGUIName) =>
                                {
                                    using (new RecordUndoScope("Change PrefabBuilder class", node, true)) {
                                        builder = PrefabBuilderUtility.CreatePrefabBuilder(selectedGUIName);
                                        m_instance.Set(editor.CurrentEditingGroup, builder);
                                        onValueChanged();
                                    }
                                }
                                                          );
                            }
                        }

                        MonoScript s = TypeUtility.LoadMonoScript(m_instance.ClassName);

                        using (new EditorGUI.DisabledScope(s == null)) {
                            if (GUILayout.Button("Edit", GUILayout.Width(50)))
                            {
                                AssetDatabase.OpenAsset(s, 0);
                            }
                        }
                    }
                    ReplacePrefabOptions opt = (ReplacePrefabOptions)EditorGUILayout.EnumPopup("Prefab Replace Option", m_replacePrefabOptions, GUILayout.MinWidth(150f));
                    if (m_replacePrefabOptions != opt)
                    {
                        using (new RecordUndoScope("Change Prefab Replace Option", node, true)) {
                            m_replacePrefabOptions = opt;
                            onValueChanged();
                        }
                        opt = m_replacePrefabOptions;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(m_instance.ClassName))
                    {
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "Your PrefabBuilder script {0} is missing from assembly. Did you delete script?", m_instance.ClassName), MessageType.Info);
                    }
                    else
                    {
                        string[] menuNames = Model.Settings.GUI_TEXT_MENU_GENERATE_PREFABBUILDER.Split('/');
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "You need to create at least one PrefabBuilder script to use this node. To start, select {0}>{1}>{2} menu and create new script from template.",
                                menuNames[1], menuNames[2], menuNames[3]
                                ), MessageType.Info);
                    }
                }

                GUILayout.Space(10f);

                editor.DrawPlatformSelector(node);
                using (new EditorGUILayout.VerticalScope()) {
                    var disabledScope = editor.DrawOverrideTargetToggle(node, m_instance.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => {
                        if (enabled)
                        {
                            m_instance.CopyDefaultValueTo(editor.CurrentEditingGroup);
                            m_outputDir[editor.CurrentEditingGroup]    = m_outputDir.DefaultValue;
                            m_outputOption[editor.CurrentEditingGroup] = m_outputOption.DefaultValue;
                        }
                        else
                        {
                            m_instance.Remove(editor.CurrentEditingGroup);
                            m_outputDir.Remove(editor.CurrentEditingGroup);
                            m_outputOption.Remove(editor.CurrentEditingGroup);
                        }
                        onValueChanged();
                    });

                    using (disabledScope) {
                        OutputOption opt       = (OutputOption)m_outputOption[editor.CurrentEditingGroup];
                        var          newOption = (OutputOption)EditorGUILayout.EnumPopup("Output Option", opt);
                        if (newOption != opt)
                        {
                            using (new RecordUndoScope("Change Output Option", node, true)){
                                m_outputOption[editor.CurrentEditingGroup] = (int)newOption;
                                onValueChanged();
                            }
                            opt = newOption;
                        }

                        using (new EditorGUI.DisabledScope(opt == OutputOption.CreateInCacheDirectory)) {
                            var newDirPath = editor.DrawFolderSelector("Output Directory", "Select Output Folder",
                                                                       m_outputDir[editor.CurrentEditingGroup],
                                                                       Application.dataPath,
                                                                       (string folderSelected) => {
                                string basePath = Application.dataPath;

                                if (basePath == folderSelected)
                                {
                                    folderSelected = string.Empty;
                                }
                                else
                                {
                                    var index = folderSelected.IndexOf(basePath);
                                    if (index >= 0)
                                    {
                                        folderSelected = folderSelected.Substring(basePath.Length + index);
                                        if (folderSelected.IndexOf('/') == 0)
                                        {
                                            folderSelected = folderSelected.Substring(1);
                                        }
                                    }
                                }
                                return(folderSelected);
                            }
                                                                       );
                            if (newDirPath != m_outputDir[editor.CurrentEditingGroup])
                            {
                                using (new RecordUndoScope("Change Output Directory", node, true)){
                                    m_outputDir[editor.CurrentEditingGroup] = newDirPath;
                                    onValueChanged();
                                }
                            }

                            var dirPath = Path.Combine(Application.dataPath, m_outputDir [editor.CurrentEditingGroup]);

                            if (opt == OutputOption.CreateInSelectedDirectory &&
                                !string.IsNullOrEmpty(m_outputDir [editor.CurrentEditingGroup]) &&
                                !Directory.Exists(dirPath))
                            {
                                using (new EditorGUILayout.HorizontalScope()) {
                                    EditorGUILayout.LabelField(m_outputDir[editor.CurrentEditingGroup] + " does not exist.");
                                    if (GUILayout.Button("Create directory"))
                                    {
                                        Directory.CreateDirectory(dirPath);
                                        AssetDatabase.Refresh();
                                    }
                                }
                                EditorGUILayout.Space();

                                string parentDir = Path.GetDirectoryName(m_outputDir[editor.CurrentEditingGroup]);
                                if (Directory.Exists(parentDir))
                                {
                                    EditorGUILayout.LabelField("Available Directories:");
                                    string[] dirs = Directory.GetDirectories(parentDir);
                                    foreach (string s in dirs)
                                    {
                                        EditorGUILayout.LabelField(s);
                                    }
                                }
                                EditorGUILayout.Space();
                            }

                            var outputDir = PrepareOutputDirectory(BuildTargetUtility.GroupToTarget(editor.CurrentEditingGroup), node.Data);

                            using (new EditorGUI.DisabledScope(!Directory.Exists(outputDir)))
                            {
                                using (new EditorGUILayout.HorizontalScope()) {
                                    GUILayout.FlexibleSpace();
                                    if (GUILayout.Button("Highlight in Project Window", GUILayout.Width(180f)))
                                    {
                                        var folder = AssetDatabase.LoadMainAssetAtPath(outputDir);
                                        EditorGUIUtility.PingObject(folder);
                                    }
                                }
                            }
                        }

                        GUILayout.Space(8f);

                        if (builder != null)
                        {
                            Action onChangedAction = () => {
                                using (new RecordUndoScope("Change PrefabBuilder Setting", node)) {
                                    m_instance.Set(editor.CurrentEditingGroup, builder);
                                    onValueChanged();
                                }
                            };

                            builder.OnInspectorGUI(onChangedAction);
                        }
                    }
                }
            }
        }
Пример #31
0
 public static GameObject ReplacePrefab(GameObject go, Object targetPrefab, ReplacePrefabOptions options)
 {
     return(PrefabUtility.ReplacePrefab(go, targetPrefab, options));
 }
Пример #32
0
 //Apply
 static void ApplyToSelectedPrefabs(GameObject _goCurrentGo, Object _ObjPrefabParent, ReplacePrefabOptions _eReplaceOptions)
 {
     PrefabUtility.ReplacePrefab(_goCurrentGo, _ObjPrefabParent, _eReplaceOptions);
 }