private void OnGUI() { if (monsterConfig == null) { ReadMonsterConfig(); } // EditorGUIUtility.labelWidth = 300; if (challengePresetAsset == null) { challengePresetAsset = Resources.Load <ChallengePresetAsset>(pathToFile); challengePresetAsset.Deserialize(); } if (challengePresetAsset.data == null || challengePresetAsset.data.Length < 1) { challengePresetAsset.data = new JsonSerializationOperation(new DungeonSpawnConfig.Challenge()).ActToStringArray(); challengePresetAsset.Deserialize(); } if (challengePresetAsset.challenge == null) { challengePresetAsset.Deserialize(); } if (challengePresetAsset.monsterConfig == null) { challengePresetAsset.SetMonsterConfig(monsterConfig); } EditorGUILayout.Space(); if (GUILayout.Button("Refresh Config")) { ReadMonsterConfig(); } EditorGUILayout.Space(); DrawHeader(); EditorGUI.BeginChangeCheck(); using (new EditorHelper.ScrollView(scrollPosition)) { challengePresetAsset.OnGUI(); } bool changed = EditorGUI.EndChangeCheck(); if (changed) { challengePresetAsset.Serialize(); EditorUtility.SetDirty(challengePresetAsset); } }
public static void Open(ChallengePresetAsset asset, string fileName) { if (asset != null) { ChallengePresetEditor editor = CreateInstance <ChallengePresetEditor>(); editor.pathToFile = new AssetFile(AssetDatabase.GetAssetPath(asset)).ShowResourcePath(); if (string.IsNullOrEmpty(editor.pathToFile)) { return; } editor.Show(); editor.position = new Rect(100, 200, 640, 480); GUIContent editorTitleContent = new GUIContent(editor.titleContent); editorTitleContent.text = asset.name; editor.titleContent = editorTitleContent; } }
public static bool OnOpenAsset(int instanceID, int line) { ChallengePresetAsset challengePresetAsset = Selection.activeObject as ChallengePresetAsset; if (!mouseOverWindow.titleContent.text.Contains("Project")) { return(false); } if (challengePresetAsset != null) { ChallengePresetEditor editor = CreateInstance <ChallengePresetEditor>(); editor.pathToFile = new AssetFile(AssetDatabase.GetAssetPath(instanceID)).ShowResourcePath(); editor.Show(); editor.position = new Rect(100, 400, 640, 480); GUIContent editorTitleContent = new GUIContent(editor.titleContent); editorTitleContent.text = challengePresetAsset.name; editor.titleContent = editorTitleContent; } return(false); }
private void DrawIconOfCharacterOfSpawner() { if (Spawn.ShowCacheOfTextureByMonsterId() == null) { return; } if (onGuiCount % 13 == 0) { onGuiCount = 0; if (!string.IsNullOrEmpty(path)) { resourceRequest = Resources.LoadAsync <ChallengePresetAsset>(path); } } if (resourceRequest != null) { if (resourceRequest.isDone) { if (resourceRequest.asset == null) { resourceRequest = null; return; } ChallengePresetAsset challengePresetAsset = (ChallengePresetAsset)resourceRequest.asset; Challenge challenge = challengePresetAsset.DeserializeToObject(); CharacterId characterId = new CharacterId(challenge.spawn.monsterId); bool found = Spawn.ShowCacheOfTextureByMonsterId().TryGetValue(characterId.ToString(), out icon); if (!found) { string pathToIcon = string.Format(Config.characterIconPathFormat, characterId.GroupId, characterId.SubId); icon = EditorGUIUtility.Load(pathToIcon) as Texture; Spawn.ShowCacheOfTextureByMonsterId()[characterId.StringValue] = icon; } resourceRequest = null; } } if (icon != null) { /*EditorGUILayout.LabelField("", GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(false), * GUILayout.Height(89), GUILayout.Width(89));*/ Rect lastRect = GUILayoutUtility.GetLastRect(); Rect rectForIcon = new Rect(lastRect.position + new Vector2(lastRect.width, 0), new Vector2(89, 89)); GUIStyle gs = new GUIStyle(EditorStyles.label); gs.normal.background = Texture2D.grayTexture; Rect positionOfBackground = new Rect(rectForIcon.position - new Vector2(34, 0), rectForIcon.size); EditorGUI.LabelField(positionOfBackground, "", gs); EditorGUI.LabelField(positionOfBackground, "", gs); EditorGUI.LabelField(positionOfBackground, "", gs); if (materialForIcon == null) { materialForIcon = new Material(Shader.Find("Sprites/Default")); } EditorGUI.DrawPreviewTexture(rectForIcon, icon, materialForIcon); } }