private void DrawInspector() { GUILayout.Space(5f); EditorGUI.BeginChangeCheck(); var raycastTarget = EditorGUILayout.Toggle("RaycastTarget", instance.raycastTarget); if (EditorGUI.EndChangeCheck()) { UnityEditorUtility.RegisterUndo("GraphicGroupInspector Undo", instance); instance.raycastTarget = raycastTarget; } GUILayout.Space(2f); EditorGUI.BeginChangeCheck(); var colorTint = EditorGUILayout.ColorField("ColorTint", instance.ColorTint); if (EditorGUI.EndChangeCheck()) { UnityEditorUtility.RegisterUndo("GraphicGroupInspector Undo", instance); instance.ColorTint = colorTint; } }
private static void SetMeshImporterMat(Material mat) { var mainDir = UnityEditorUtility.GetSelectDir(); var dirs = IOUtility.GetAllDir(mainDir); if (dirs != null) { foreach (var dir in dirs) { var fullDir = UnityIOUtility.GetFullPath(dir); //Debug.LogError(dir); var fullpaths = Directory.GetFiles(fullDir); foreach (var item in fullpaths) { SetMeshImporterMat(item, mat); } } } //var objs = AssetDatabase.LoadAllAssetsAtPath(dir); //Debug.LogError(objs.Length); //foreach (var item in objs) //{ // Debug.LogError(item.name); //} }
void OnDisable() { if (changed) { UnityEditorUtility.SaveAsset(instance); } }
public IEnumerable <AssetInfo> GetAssetInfos(string assetPath) { var assetInfos = new List <AssetInfo>(); var assetPaths = new string[0]; if (AssetDatabase.IsValidFolder(assetPath)) { assetPaths = UnityEditorUtility.GetAllAssetPathInFolder(assetPath); } else { assetPaths = new string[] { assetPath }; } foreach (var path in assetPaths) { var assetInfo = GetAssetInfo(path); if (assetInfo != null) { assetInfos.Add(assetInfo); } } return(assetInfos); }
private static StateMachine[] FindFsms() { StateMachine[] fsms = UnityEditorUtility.GetAssetsOfType <StateMachine> (".asset"); ICodeBehaviour[] behaviours = UnityEditorUtility.FindInScene <ICodeBehaviour>().ToArray(); fsms = ArrayUtility.AddRange <StateMachine>(fsms, behaviours.Where(x => !EditorUtility.IsPersistent(x.stateMachine)).Select(y => y.stateMachine).ToArray()); return(fsms); }
private static void CleanAllSonDir() { locAppId = UnityEditorUtility.GetLocAppIdAtSelectDir(); locU3DApp = ProjectInfoDati.GetActualInstance(); if (string.IsNullOrEmpty(locAppId)) { UnityEditorUtility.DisplayError("所选择的目录不是一个应用下的有效目录!"); return; } var assetbundleEditor = AssetBundleEditorDati.GetActualInstance(); if (assetbundleEditor == null) { UnityEditorUtility.DisplayError($"应用{locAppId}没有AssetBundle打包配置!"); throw new Exception($"应用{locAppId}没有AssetBundle打包配置!"); } foreach (var dir in AllSonDirs) { if (!dir.StartsWith(locU3DApp.ProjectAssetDatabaseDir)) // dir.StartsWith(appHelper.StreamingAssetsDir)) { Debug.LogError($"目标目录不是一个有效的AssetBundle打包目录!"); continue; } assetbundleEditor.CleanBuildSettingAtDir(dir); } AssetBundleEditorDati.GetSingleDati().Save(); }
// オプションの描画. protected virtual void DrawBuildOptions() { var originLabelWidth = EditorLayoutTools.SetLabelWidth(130f); if (selectionBuildParam != null && selectionBuildParam.buildParam != null) { var buildParam = selectionBuildParam.buildParam; EditorGUI.BeginChangeCheck(); // Version. buildParam.Version = EditorGUILayout.DelayedTextField("Version", buildParam.Version); GUILayout.Space(2f); // BuildVersion. buildParam.BuildVersion = EditorGUILayout.DelayedIntField("BuildVersion", buildParam.BuildVersion); if (EditorGUI.EndChangeCheck()) { UnityEditorUtility.SaveAsset(buildParam); } } GUILayout.Space(2f); EditorLayoutTools.SetLabelWidth(originLabelWidth); }
public void Optimisation() { Reload(); var change = false; if (groupInfos != null) { foreach (var groupInfo in groupInfos) { var delete = groupInfo.manageTargetAssets.RemoveAll(x => x == null); change |= delete != 0; } } if (manageInfos != null) { var delete = manageInfos.RemoveAll(x => x.assetObject == null); change |= delete != 0; } change |= ignoreInfo.Optimisation(); if (change) { Debug.LogError("AssetManageConfig invalid data removed."); UnityEditorUtility.SaveAsset(this); Reload(); } }
private void DrawTabView(string _propertyName) { SerializedProperty _property = serializedObject.FindProperty(_propertyName); // Draw child properties UnityEditorUtility.DrawChildPropertyFields(_property); }
protected override void Save() { var saveData = new List <SaveData>(); foreach (var item in pinning) { if (item == null || item.target == null) { continue; } var guid = UnityEditorUtility.GetAssetGUID(item.target); var data = new SaveData() { guid = guid, comment = item.comment, }; saveData.Add(data); } if (saveData.Any()) { ProjectPrefs.Set(PinnedPrefsKey, saveData); } else { if (ProjectPrefs.HasKey(PinnedPrefsKey)) { ProjectPrefs.DeleteKey(PinnedPrefsKey); } } }
public override void OnInspectorGUI() { var instance = target as UIRawImage; var rawImage = instance.RawImage; if (rawImage == null) { return; } GUILayout.Space(4f); DrawDefaultScriptlessInspector(); using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.PrefixLabel("Dummy Texture"); EditorGUI.BeginChangeCheck(); textureAsset = EditorGUILayout.ObjectField(textureAsset, typeof(Texture), false) as Texture; if (EditorGUI.EndChangeCheck()) { UnityEditorUtility.RegisterUndo("UIRawImageInspector-Undo", instance); var assetGuid = textureAsset != null?UnityEditorUtility.GetAssetGUID(textureAsset) : string.Empty; Reflection.SetPrivateField(instance, "assetGuid", assetGuid); if (textureAsset == null) { if (rawImage.texture != null && rawImage.texture.name == UIRawImage.DummyAssetName) { rawImage.texture = null; } } else { Reflection.InvokePrivateMethod(instance, "ApplyDummyAsset"); } } } if (dummyTexture != null) { if (rawImage.texture != dummyTexture) { UnityUtility.SafeDelete(dummyTexture); dummyTexture = null; } } if (rawImage.texture != null && rawImage.texture.name == UIRawImage.DummyAssetName) { dummyTexture = rawImage.texture; } }
//----- property ----- //----- method ----- private static string[] OnWillSaveAssets(string[] paths) { if (!onApplyPrefab.HasObservers) { return(paths); } foreach (var path in paths) { var prefab = AssetDatabase.LoadMainAssetAtPath(path) as GameObject; if (prefab == null) { continue; } var isPrefab = UnityEditorUtility.IsPrefab(prefab); if (!isPrefab) { continue; } onApplyPrefab.OnNext(prefab); } return(paths); }
//----- params ----- //----- field ----- //----- property ----- //----- method ----- public static string[] OnWillSaveAssets(string[] paths) { if (paths.IsEmpty()) { return(paths); } GameObject[] hierarchyGameObjects = null; foreach (string path in paths) { var atlasTexture = AssetDatabase.LoadMainAssetAtPath(path) as AtlasTexture; if (atlasTexture != null) { // 必要になった時に一回だけ取得して使いまわす. if (hierarchyGameObjects == null) { hierarchyGameObjects = UnityEditorUtility.FindAllObjectsInHierarchy(); } // AtlasTextureImage. UpdateAtlasTextureImage(hierarchyGameObjects, atlasTexture); } } return(paths); }
protected override bool ValidatePinned(Object[] items) { if (Application.isPlaying) { return(false); } foreach (var item in items) { var localIdentifierInFile = UnityEditorUtility.GetLocalIdentifierInFile(item); // Sceneに保存されていないGameObjectは登録不可. if (localIdentifierInFile <= 0) { return(false); } // Hierarchyのオブジェクト以外が登録不可. if (EditorUtility.IsPersistent(item)) { return(false); } } return(true); }
protected void RequestCompile() { // コンパイル中は予約だけして実行しない. if (EditorApplication.isCompiling) { Prefs.RequestCompile = true; return; } Prefs.RequestCompile = false; // コンパイル要求. UnityEditorUtility.RequestScriptCompilation(); CompilationPipeline.assemblyCompilationStarted -= OnAssemblyCompilationStarted; CompilationPipeline.assemblyCompilationStarted += OnAssemblyCompilationStarted; CompilationPipeline.assemblyCompilationFinished -= OnAssemblyCompilationFinished; CompilationPipeline.assemblyCompilationFinished += OnAssemblyCompilationFinished; AssemblyReloadEvents.beforeAssemblyReload -= BeforeAssemblyReload; AssemblyReloadEvents.beforeAssemblyReload += BeforeAssemblyReload; timeStamps = new Dictionary <string, double>(); compileResults = new Dictionary <string, CompileResult>(); }
//----- params ----- //----- field ----- //----- property ----- //----- method ----- public override void OnInspectorGUI() { var instance = target as PatternImageAnimation; serializedObject.Update(); var setNativeSizeProperty = serializedObject.FindProperty("setNativeSize"); DrawDefaultScriptlessInspector(); GUILayout.Space(2f); EditorGUI.BeginChangeCheck(); var index = Reflection.GetPrivateField <PatternImageAnimation, int>(instance, "patternIndex"); var labels = instance.GetPatternNames(); index = EditorGUILayout.Popup("PatternName", index, labels.ToArray()); if (EditorGUI.EndChangeCheck()) { UnityEditorUtility.RegisterUndo("PatternImageAnimationInspector-Undo", instance); if (index == -1) { index = 0; } Reflection.SetPrivateField(instance, "patternIndex", index); } EditorGUILayout.PropertyField(setNativeSizeProperty); }
private List <SpriteEntry> CreateSprites(List <Texture> textures) { var list = new List <SpriteEntry>(); foreach (var item in textures) { var texture = item as Texture2D; if (texture == null) { continue; } var sprite = new SpriteEntry(); sprite.SetRect(0, 0, texture.width, texture.height); sprite.texture = texture; sprite.name = texture.name; sprite.guid = UnityEditorUtility.GetAssetGUID(texture); sprite.temporaryTexture = false; list.Add(sprite); } return(list); }
protected override void OnGUIWindow() { GUIStyle _subTitleStyle = new GUIStyle("BoldLabel"); _subTitleStyle.wordWrap = true; GUILayout.BeginVertical(UnityEditorUtility.kOuterContainerStyle); { UnityEditorUtility.DrawLabel("Registration Status", _subTitleStyle, UnityEditorUtility.Alignment.Center); GUILayout.Space(2f); DrawProperty("m_authorizationStatus", GUIStyle.none); GUILayout.Space(2f); } GUILayout.EndVertical(); GUILayout.Space(5f); GUILayout.BeginVertical(UnityEditorUtility.kOuterContainerStyle); { UnityEditorUtility.DrawLabel("Contacts", _subTitleStyle, UnityEditorUtility.Alignment.Center); GUILayout.Space(2f); DrawChildProperties("m_contactsList", GUIStyle.none); GUILayout.Space(2f); } GUILayout.EndVertical(); }
void OnDisable() { if (isChanged) { UnityEditorUtility.SaveAsset(target); } }
//----- method ----- protected override void DrawContent(int index, SelectionInfo content) { var highlight = Setter.TextGuid == content.TextGuid; var originBackgroundColor = GUI.backgroundColor; using (new BackgroundColorScope(highlight ? new Color(0.6f, 0.8f, 0.85f) : new Color(0.95f, 0.95f, 0.95f))) { var size = EditorStyles.label.CalcSize(new GUIContent(content.Text)); size.y += 6f; using (new EditorGUILayout.HorizontalScope(EditorStyles.textArea, GUILayout.Height(size.y))) { var labelStyle = new GUIStyle("IN TextField") { alignment = TextAnchor.MiddleLeft, }; GUILayout.Space(10f); GUILayout.Label(content.Name, labelStyle, GUILayout.MinWidth(220f), GUILayout.Height(size.y)); GUILayout.Label(content.Text, labelStyle, GUILayout.MaxWidth(500f), GUILayout.Height(size.y)); GUILayout.FlexibleSpace(); using (new EditorGUILayout.VerticalScope()) { var buttonHeight = 18f; GUILayout.Space((size.y - buttonHeight) * 0.5f); using (new BackgroundColorScope(originBackgroundColor)) { if (GUILayout.Button("Select", GUILayout.Width(75f), GUILayout.Height(buttonHeight))) { UnityEditorUtility.RegisterUndo("TextDataSelector-Select", Setter); if (!string.IsNullOrEmpty(content.TextGuid)) { Reflection.InvokePrivateMethod(Setter, "SetTextGuid", new object[] { content.TextGuid }); SetterInspector.Repaint(); if (onSelect != null) { onSelect.OnNext(Unit.Default); } } } } GUILayout.Space((size.y - buttonHeight) * 0.5f); } GUILayout.Space(8f); } } }
private void OnPreprocessTexture() { var assetTuner = AssetTuner.Instance; try { if (!UnityEditorUtility.IsEditAsset(assetPath)) { foreach (var tuner in assetTuner.AssetTuners) { var textureTuner = tuner as ITextureAssetTuner; if (textureTuner == null) { continue; } if (textureTuner.Validate(assetPath)) { textureTuner.OnPreprocessTexture(assetPath, assetTuner.IsFirstImport(assetPath)); } } } } catch (Exception ex) { Debug.LogException(ex); } }
protected override void OnGUIWindow() { // draw inspector properties GUILayout.BeginVertical(UnityEditorUtility.kOuterContainerStyle); { base.OnGUIWindow(); // disable inspector when its compiling GUI.enabled = !EditorApplication.isCompiling; UnityEditorUtility.DrawSplitter(new Color(0.35f, 0.35f, 0.35f), 1, 10); DrawTopBar(); GUILayout.Space(10f); if (m_activeType == eSettingsType.NONE) { DrawMainMenu(_options: GetAvailableTabs()); } else { DrawDetailedView(); } GUILayout.Space(10f); DrawFooter(); GUILayout.Space(10f); } GUILayout.EndVertical(); // reset GUI state GUI.enabled = true; }
public static void Reload() { if (!GameText.Exists) { GameText.CreateInstance(); } var gameTextInfo = GameTextLanguage.GameTextInfos.ElementAtOrDefault(GameTextLanguage.Prefs.selection); if (gameTextInfo != null) { GameText.Instance.LoadFromResources(gameTextInfo.AssetPath); } var gameObjects = UnityEditorUtility.FindAllObjectsInHierarchy(); foreach (var gameObject in gameObjects) { var setter = gameObject.GetComponent <GameTextSetter>(); if (setter != null) { setter.ImportText(); } } IsLoaded = true; }
/// <summary> /// アセットバンドル名でアセットをグループ化. /// </summary> /// <returns></returns> private ILookup <string, string> GetAllAssetPathByAssetBundleName() { var title = "Build AssetBundle Info"; EditorUtility.DisplayProgressBar(title, "Find AllAssets", 0); var allAssetGuids = AssetDatabase.FindAssets("", new string[] { UnityPathUtility.AssetsFolder }); var allAssetPaths = new List <Tuple <string, string> >(); for (var i = 0; i < allAssetGuids.Length; i++) { var guid = allAssetGuids[i]; EditorUtility.DisplayProgressBar(title, guid, (float)i / allAssetGuids.Length); var assetPath = AssetDatabase.GUIDToAssetPath(guid); var assetBundleName = UnityEditorUtility.GetAssetBundleName(assetPath); if (string.IsNullOrEmpty(assetBundleName)) { continue; } allAssetPaths.Add(Tuple.Create(assetBundleName, assetPath)); } EditorUtility.ClearProgressBar(); return(allAssetPaths.ToLookup(x => x.Item1, x => x.Item2)); }
//------ fields ------ //------ property ------ //------ methods ------ public static bool Generate() { var directory = string.Empty; var assetPath = string.Empty; var selectionObject = Selection.activeObject; if (selectionObject != null) { var path = AssetDatabase.GetAssetPath(selectionObject); directory = AssetDatabase.IsValidFolder(path) ? path : Path.GetDirectoryName(path); var assetName = Path.GetFileName(DefaultAssetPath); assetPath = PathUtility.Combine(directory, assetName); } else { assetPath = DefaultAssetPath; } var instance = GenerateScriptableObject(typeof(ScriptableObject), assetPath); UnityEditorUtility.SelectAsset(instance); return(instance); }
private void SetValue <TValue>(TextShadow instance, string fieldName, TValue value) { UnityEditorUtility.RegisterUndo("TextShadowInspector Undo", instance); Reflection.SetPrivateField(instance, fieldName, value); update = true; }
protected static void TuneAsset(string path) { var asset = AssetDatabase.LoadMainAssetAtPath(path); var controller = asset as AnimatorController; if (controller == null) { return; } var rootStateMachine = controller.layers[0].stateMachine; // Add DefaultState. var defaultState = rootStateMachine.AddState("Default"); var state = rootStateMachine.states.FirstOrDefault(x => x.state == defaultState); state.position = new Vector2(50f, 50f); // Set EntryTransition. rootStateMachine.AddEntryTransition(defaultState); // Set Position. rootStateMachine.entryPosition = new Vector2(0f, 0f); rootStateMachine.anyStatePosition = new Vector2(0f, 50f); rootStateMachine.exitPosition = new Vector2(0f, 100f); UnityEditorUtility.SaveAsset(controller); }
private void DrawTextSelectGUI(TextData textData, ContentType contentType) { var categoryChanged = false; using (new EditorGUILayout.HorizontalScope()) { var categories = textData.Categories.Where(x => x.ContentType == contentType).ToArray(); // Noneが入るので1ずれる. var categoryIndex = categories.IndexOf(x => x.Guid == SelectionCategoryGuid) + 1; var categoryLabels = categories.Select(x => x.DisplayName).ToArray(); var labels = new List <string> { "None" }; labels.AddRange(categoryLabels); EditorGUI.BeginChangeCheck(); categoryIndex = EditorGUILayout.Popup("TextData", categoryIndex, labels.ToArray()); if (EditorGUI.EndChangeCheck()) { UnityEditorUtility.RegisterUndo("TextDataSetterInspector-Undo", instance); var newCategory = 1 <= categoryIndex ? categories[categoryIndex - 1] : null; var newCategoryGuid = newCategory != null ? newCategory.Guid : string.Empty; if (currentCategoryGuid != newCategoryGuid) { SetTextGuid(null); UpdateCurrentInfo(textData); currentCategoryGuid = newCategoryGuid; categoryChanged = true; } } using (new DisableScope(categoryIndex == 0 || TextData.Instance.Texts == null)) { GUILayout.Space(2f); if (GUILayout.Button("select", EditorStyles.miniButton, GUILayout.Width(75f))) { TextDataSelector.Open(); } } } if (categoryChanged && string.IsNullOrEmpty(currentCategoryGuid)) { SetDevelopmentText(string.Empty); } }
//------ fields ------ //------ property ------ //------ methods ------ public static bool Generate() { var instance = Generate <ScriptableObject>(); UnityEditorUtility.SelectAsset(instance); return(instance); }
private void LoadSceneAsset() { var sceneGuid = Prefs.targetSceneGuid; sceneAsset = UnityEditorUtility.FindMainAsset(sceneGuid) as SceneAsset; isSceneLoaded = true; }