public static string GetPrefabBuilderGUIName(IPrefabBuilder builder)
        {
            CustomPrefabBuilder attr =
                builder.GetType().GetCustomAttributes(typeof(CustomPrefabBuilder), false).FirstOrDefault() as CustomPrefabBuilder;

            return(attr.Name);
        }
Exemple #2
0
 public static T BuildEmergencyFallback <T>(this IPrefabBuilder <T> builder)
     where T : PrefabInfo
 {
     return(Prefabs
            .Find <T>(builder.BasedPrefabName)
            .Clone(builder.Name));
 }
Exemple #3
0
        public static T Build <T>(this IPrefabBuilder <T> builder)
            where T : PrefabInfo
        {
            var info = Prefabs
                       .Find <T>(builder.BasedPrefabName)
                       .Clone(builder.Name);

            builder.BuildUp(info);

            return(info);
        }
        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();
                                        }
                                    }
                                }
                                                          );
                            }
                        }
                    }
                }
                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);
                        }
                    }
                }
            }
        }
        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();
                                            }
                                        }
                                    }
                                );
                            }
                        }
                    }
                } 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);
                        }
                    }
                }
            }
        }
 public static string GetPrefabBuilderGUIName(IPrefabBuilder builder)
 {
     CustomPrefabBuilder attr =
         builder.GetType().GetCustomAttributes(typeof(CustomPrefabBuilder), false).FirstOrDefault() as CustomPrefabBuilder;
     return attr.Name;
 }