CreateAsset() public static method

public static CreateAsset ( Object asset, string pathName ) : void
asset Object
pathName string
return void
Esempio n. 1
0
        public void OnGUI()
        {
            EditorGUIUtility.hierarchyMode = true;

            lightmapSettings.Update();

            m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition);

            EditorGUILayout.PropertyField(m_LightingSettingsAsset);

            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (GUILayout.Button(Styles.newLightingSettings, GUILayout.Width(170)))
            {
                var ls = new LightingSettings();
                ls.name = "New Lighting Settings";
                Undo.RecordObject(m_LightmapSettings.targetObject, "New Lighting Settings");
                Lightmapping.lightingSettingsInternal = ls;
                ProjectWindowUtil.CreateAsset(ls, (ls.name + ".lighting"));
            }

            GUILayout.EndHorizontal();
            EditorGUILayout.Space();

            m_BakeSettings.OnGUI();
            WorkflowSettingsGUI();

            EditorGUILayout.EndScrollView();
            EditorGUILayout.Space();

            lightmapSettings.ApplyModifiedProperties();
        }
        void LightingSettingsGUI()
        {
            m_ShowLightingSettings.value = EditorGUILayout.FoldoutTitlebar(m_ShowLightingSettings.value, Styles.lightingSettings, true);

            if (m_ShowLightingSettings.value)
            {
                ++EditorGUI.indentLevel;

                EditorGUILayout.PropertyField(m_LightingSettingsAsset, GUIContent.Temp("Lighting Settings Asset"));

                EditorGUILayout.Space();
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();

                if (GUILayout.Button(Styles.newLightingSettings, GUILayout.Width(170)))
                {
                    var ls = new LightingSettings();
                    ls.name = "New Lighting Settings";
                    Undo.RecordObject(m_LightmapSettings.targetObject, "New Lighting Settings");
                    Lightmapping.lightingSettingsInternal = ls;
                    ProjectWindowUtil.CreateAsset(ls, (ls.name + ".lighting"));
                }

                GUILayout.EndHorizontal();
                EditorGUILayout.Space();

                --EditorGUI.indentLevel;
            }
        }
        internal void CreateAsset()
        {
            if (string.IsNullOrEmpty(name))
            {
                name = "New Lighting Settings";
            }

            ProjectWindowUtil.CreateAsset(this, (name + ".lighting"));
        }
Esempio n. 4
0
        private static void ShowAssetsPopupMenu <T>(Rect buttonRect, string typeName, SerializedProperty serializedProperty, string fileExtension, string defaultFieldName) where T : UnityEngine.Object, new()
        {
            GenericMenu genericMenu = new GenericMenu();
            int         num         = (!(serializedProperty.objectReferenceValue != null)) ? 0 : serializedProperty.objectReferenceValue.GetInstanceID();

            genericMenu.AddItem(new GUIContent(defaultFieldName), num == 0, new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback), new object[]
            {
                0,
                serializedProperty
            });
            HierarchyProperty hierarchyProperty = new HierarchyProperty(HierarchyType.Assets);
            SearchFilter      searchFilter      = new SearchFilter
            {
                classNames = new string[]
                {
                    typeName
                }
            };

            hierarchyProperty.SetSearchFilter(searchFilter);
            hierarchyProperty.Reset();
            while (hierarchyProperty.Next(null))
            {
                genericMenu.AddItem(new GUIContent(hierarchyProperty.name), hierarchyProperty.instanceID == num, new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback), new object[]
                {
                    hierarchyProperty.instanceID,
                    serializedProperty
                });
            }
            int num2 = BaseObjectTools.StringToClassID(typeName);

            if (num2 > 0)
            {
                BuiltinResource[] builtinResourceList = EditorGUIUtility.GetBuiltinResourceList(num2);
                BuiltinResource[] array = builtinResourceList;
                for (int i = 0; i < array.Length; i++)
                {
                    BuiltinResource builtinResource = array[i];
                    genericMenu.AddItem(new GUIContent(builtinResource.m_Name), builtinResource.m_InstanceID == num, new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback), new object[]
                    {
                        builtinResource.m_InstanceID,
                        serializedProperty
                    });
                }
            }
            genericMenu.AddSeparator(string.Empty);
            genericMenu.AddItem(new GUIContent("Create New..."), false, delegate
            {
                T t = Activator.CreateInstance <T>();
                ProjectWindowUtil.CreateAsset(t, "New " + typeName + "." + fileExtension);
                serializedProperty.objectReferenceValue = t;
                serializedProperty.m_SerializedObject.ApplyModifiedProperties();
            });
            genericMenu.DropDown(buttonRect);
        }
Esempio n. 5
0
        public static void CreateNewGUISkin()
        {
            GUISkin gUISkin  = ScriptableObject.CreateInstance <GUISkin>();
            GUISkin gUISkin2 = Resources.GetBuiltinResource(typeof(GUISkin), "GameSkin/GameSkin.guiskin") as GUISkin;

            if (gUISkin2)
            {
                EditorUtility.CopySerialized(gUISkin2, gUISkin);
            }
            else
            {
                Debug.LogError("Internal error: unable to load builtin GUIskin");
            }
            ProjectWindowUtil.CreateAsset(gUISkin, "New GUISkin.guiskin");
        }
        public static void CreateNewGUISkin()
        {
            GUISkin instance        = ScriptableObject.CreateInstance <GUISkin>();
            GUISkin builtinResource = Resources.GetBuiltinResource(typeof(GUISkin), "GameSkin/GameSkin.guiskin") as GUISkin;

            if ((bool)((UnityEngine.Object)builtinResource))
            {
                EditorUtility.CopySerialized((UnityEngine.Object)builtinResource, (UnityEngine.Object)instance);
            }
            else
            {
                Debug.LogError((object)"Internal error: unable to load builtin GUIskin");
            }
            ProjectWindowUtil.CreateAsset((UnityEngine.Object)instance, "New GUISkin.guiskin");
        }
Esempio n. 7
0
        public static void CreateNewDefaultBrush()
        {
            Brush b = CreateInstance(DefaultMask(), AnimationCurve.Linear(0, 0, 1, 1), 1.0f, false);

            ProjectWindowUtil.CreateAsset(b, "New Brush.brush");
        }
Esempio n. 8
0
        private static void ShowAssetsPopupMenu <T>(Rect buttonRect, string typeName, SerializedProperty serializedProperty, string fileExtension, string defaultFieldName) where T : UnityEngine.Object, new()
        {
            GenericMenu genericMenu = new GenericMenu();
            int         num         = (!(serializedProperty.objectReferenceValue != null)) ? 0 : serializedProperty.objectReferenceValue.GetInstanceID();
            bool        flag        = false;
            UnityType   unityType   = UnityType.FindTypeByName(typeName);
            int         num2        = (unityType == null) ? 0 : unityType.persistentTypeID;

            BuiltinResource[] array = null;
            if (num2 > 0)
            {
                array = EditorGUIUtility.GetBuiltinResourceList(num2);
                BuiltinResource[] array2 = array;
                for (int i = 0; i < array2.Length; i++)
                {
                    BuiltinResource resource = array2[i];
                    if (resource.m_Name == defaultFieldName)
                    {
                        GenericMenu arg_124_0 = genericMenu;
                        GUIContent  arg_124_1 = new GUIContent(resource.m_Name);
                        bool        arg_124_2 = resource.m_InstanceID == num;
                        if (AssetPopupBackend.< > f__mg$cache0 == null)
                        {
                            AssetPopupBackend.< > f__mg$cache0 = new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback);
                        }
                        arg_124_0.AddItem(arg_124_1, arg_124_2, AssetPopupBackend.< > f__mg$cache0, new object[]
                        {
                            resource.m_InstanceID,
                            serializedProperty
                        });
                        array = (from x in array
                                 where x != resource
                                 select x).ToArray <BuiltinResource>();
                        flag = true;
                        break;
                    }
                }
            }
            if (!flag)
            {
                GenericMenu arg_1A6_0 = genericMenu;
                GUIContent  arg_1A6_1 = new GUIContent(defaultFieldName);
                bool        arg_1A6_2 = num == 0;
                if (AssetPopupBackend.< > f__mg$cache1 == null)
                {
                    AssetPopupBackend.< > f__mg$cache1 = new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback);
                }
                arg_1A6_0.AddItem(arg_1A6_1, arg_1A6_2, AssetPopupBackend.< > f__mg$cache1, new object[]
                {
                    0,
                    serializedProperty
                });
            }
            HierarchyProperty hierarchyProperty = new HierarchyProperty(HierarchyType.Assets);
            SearchFilter      searchFilter      = new SearchFilter
            {
                classNames = new string[]
                {
                    typeName
                }
            };

            hierarchyProperty.SetSearchFilter(searchFilter);
            hierarchyProperty.Reset();
            while (hierarchyProperty.Next(null))
            {
                GenericMenu arg_23D_0 = genericMenu;
                GUIContent  arg_23D_1 = new GUIContent(hierarchyProperty.name);
                bool        arg_23D_2 = hierarchyProperty.instanceID == num;
                if (AssetPopupBackend.< > f__mg$cache2 == null)
                {
                    AssetPopupBackend.< > f__mg$cache2 = new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback);
                }
                arg_23D_0.AddItem(arg_23D_1, arg_23D_2, AssetPopupBackend.< > f__mg$cache2, new object[]
                {
                    hierarchyProperty.instanceID,
                    serializedProperty
                });
            }
            if (num2 > 0 && array != null)
            {
                BuiltinResource[] array3 = array;
                for (int j = 0; j < array3.Length; j++)
                {
                    BuiltinResource builtinResource = array3[j];
                    GenericMenu     arg_2C7_0       = genericMenu;
                    GUIContent      arg_2C7_1       = new GUIContent(builtinResource.m_Name);
                    bool            arg_2C7_2       = builtinResource.m_InstanceID == num;
                    if (AssetPopupBackend.< > f__mg$cache3 == null)
                    {
                        AssetPopupBackend.< > f__mg$cache3 = new GenericMenu.MenuFunction2(AssetPopupBackend.AssetPopupMenuCallback);
                    }
                    arg_2C7_0.AddItem(arg_2C7_1, arg_2C7_2, AssetPopupBackend.< > f__mg$cache3, new object[]
                    {
                        builtinResource.m_InstanceID,
                        serializedProperty
                    });
                }
            }
            genericMenu.AddSeparator("");
            genericMenu.AddItem(new GUIContent("Create New..."), false, delegate
            {
                T t = Activator.CreateInstance <T>();
                ProjectWindowUtil.CreateAsset(t, "New " + typeName + "." + fileExtension);
                serializedProperty.objectReferenceValue = t;
                serializedProperty.m_SerializedObject.ApplyModifiedProperties();
            });
            genericMenu.DropDown(buttonRect);
        }
Esempio n. 9
0
        // private

        static void ShowAssetsPopupMenu <T>(Rect buttonRect, string typeName, SerializedProperty serializedProperty, string fileExtension, string defaultFieldName) where T : Object, new()
        {
            GenericMenu gm = new GenericMenu();

            int selectedInstanceID = serializedProperty.objectReferenceValue != null?serializedProperty.objectReferenceValue.GetInstanceID() : 0;


            bool foundDefaultAsset = false;
            var  type    = UnityEditor.UnityType.FindTypeByName(typeName);
            int  classID = type != null ? type.persistentTypeID : 0;

            BuiltinResource[] resourceList = null;

            // Check the assets for one that matches the default name.
            if (classID > 0)
            {
                resourceList = EditorGUIUtility.GetBuiltinResourceList(classID);
                foreach (var resource in resourceList)
                {
                    if (resource.m_Name == defaultFieldName)
                    {
                        gm.AddItem(new GUIContent(resource.m_Name), resource.m_InstanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { resource.m_InstanceID, serializedProperty });
                        resourceList      = resourceList.Where(x => x != resource).ToArray();
                        foundDefaultAsset = true;
                        break;
                    }
                }
            }

            // If no defalut asset was found, add defualt null value.
            if (!foundDefaultAsset)
            {
                gm.AddItem(new GUIContent(defaultFieldName), selectedInstanceID == 0, AssetPopupMenuCallback, new object[] { 0, serializedProperty });
            }

            // Add items from asset database
            foreach (var property in AssetDatabase.FindAllAssets(new SearchFilter()
            {
                classNames = new[] { typeName }
            }))
            {
                gm.AddItem(new GUIContent(property.name), property.instanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { property.instanceID, serializedProperty });
            }

            // Add builtin items, except for the already added default item.
            if (classID > 0 && resourceList != null)
            {
                foreach (var resource in resourceList)
                {
                    gm.AddItem(new GUIContent(resource.m_Name), resource.m_InstanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { resource.m_InstanceID, serializedProperty });
                }
            }

            // Create item
            gm.AddSeparator("");
            gm.AddItem(EditorGUIUtility.TrTextContent("Create New..."), false, delegate
            {
                var newAsset = Activator.CreateInstance <T>();
                ProjectWindowUtil.CreateAsset(newAsset, "New " + typeName + "." + fileExtension);
                serializedProperty.objectReferenceValue = newAsset;
                serializedProperty.m_SerializedObject.ApplyModifiedProperties();
            });

            gm.DropDown(buttonRect);
        }
Esempio n. 10
0
        public static void CreateNewDefaultTerrainLayer()
        {
            TerrainLayer terrainLayer = new TerrainLayer();

            ProjectWindowUtil.CreateAsset(terrainLayer, "New Terrain Layer.terrainlayer");
        }