protected virtual void DrawImpl(Rect position, GUIContent label) { var rowHeight = GUI.skin.font.lineHeight; rowHeight += GUI.skin.label.margin.vertical + GUI.skin.label.padding.vertical; var pos = new GUILayoutPosition(position, rowHeight); if (Target.CurrentType == SerializedTarget.Type.SerializedProperty) { using (var scope = new EditorGUI.ChangeCheckScope()) { var foldoutPos = pos.GetSplitPos(3f, 0); _foldout = EditorGUI.Foldout(foldoutPos, _foldout, label); var objFieldPos = pos.GetSplitPos(3f, 1, 2); var newObj = EditorGUI.ObjectField(objFieldPos, Target.ObjectReference, typeof(TDictionary), false); if (scope.changed) { Target.ObjectReference = newObj; } } if (!_foldout || Target.ObjectReference == null) { return; } } else { EditorGUI.LabelField(pos.Pos, label); } var assetInstance = Dictionary; if (assetInstance == null) { pos.IncrementRow(); var labelPos = pos.Pos; EditorGUI.LabelField(labelPos, "Don't Found Reference..."); return; } var SO = new SerializedObject(assetInstance); var(doApply, nextPos) = OnDrawElementsBefore(pos, SO, rowHeight); pos = nextPos; if (doApply) { return; } using (var indent1 = new EditorGUI.IndentLevelScope()) { var indentPos = pos.Indent(true); DrawElements(indentPos, SO, rowHeight); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var divideCount = 6; var pos = new GUILayoutPosition(position); var labelPos = pos.GetSplitPos(divideCount, 0, 2); EditorGUI.LabelField(labelPos, label); var popUpPos = pos.GetSplitPos(divideCount, 2, 4); var selectingSceneIndex = FindIndex(property.stringValue); var index = EditorGUI.Popup(popUpPos, selectingSceneIndex, ScenePathList); if (selectingSceneIndex != index) { property.stringValue = index >= 0 ? EditorBuildSettings.scenes[index].path : ""; } }
/// <summary> /// Targetと引数SOが参照しているものは同じですが、場合によってTargetがポインタ型の場合があるためプロパティを変更したい場合はSOの方を使用してください。 /// </summary> /// <param name="SO"></param> /// <param name="position"></param> /// <returns></returns> bool DrawTypePopUp(SerializedObject SO, GUILayoutPosition position, bool enableUpdate) { bool doApply = false; var typeCache = GetOrCreateTypeCahce(SO, out var isNew); if (isNew) { doApply = true; } var newAsmIndex = EditorGUI.Popup(position.GetSplitPos(layoutPosDivideCount, 1), typeCache.AssemblyIndex, typeCache.AssemblyNameList); var newTypeIndex = EditorGUI.Popup(position.GetSplitPos(layoutPosDivideCount, 2), typeCache.TypeIndex, typeCache.TypeNameList); doApply |= newAsmIndex != typeCache.AssemblyIndex; doApply |= newTypeIndex != typeCache.TypeIndex; if (doApply && enableUpdate) { typeCache.AssemblyIndex = newAsmIndex; typeCache.TypeIndex = newTypeIndex; } return(doApply); }
/// <summary> /// Targetと引数SOが参照しているものは同じだが、場合によってTargetがポインタ型の場合があるためプロパティを変更したい場合はSOの方を使用してください。 /// </summary> /// <param name="position"></param> /// <param name="SO"></param> /// <param name="rowHeight"></param> /// <returns></returns> protected override (bool doApply, GUILayoutPosition nextPos) OnDrawElementsBefore(GUILayoutPosition position, SerializedObject SO, float rowHeight) { position.IncrementRow(); var labelPos = position.GetSplitPos(layoutPosDivideCount, 0); RectOffset offset = new RectOffset((int)(labelPos.width * -0.1f), 0, 0, 0); labelPos = offset.Add(labelPos); EditorGUI.LabelField(labelPos, "Used Type"); bool doApply = false; bool enableUpdateType = true; //UsedUnityObjectAttributeが指定されていたら型は固定し、そうでなければ選択できるようにする var instance = SO.targetObject as TDictionary; if (Target.CurrentType == SerializedTarget.Type.SerializedProperty && UsedTypeAttribute.SetTypeFromFieldInfo(Target.SerializedProperty.GetFieldInfo(), instance)) { var typeNameProp = SO.FindProperty("_typeName"); Assert.IsNotNull(typeNameProp, $"{Target.SerializedProperty.propertyPath}"); if (typeNameProp.stringValue != instance.HasType.FullName) { typeNameProp.stringValue = instance.HasType.FullName; var typeCache = GetOrCreateTypeCahce(SO, out bool _); typeCache.CurrentType = instance.HasType; doApply = true; } enableUpdateType = false; } doApply |= DrawTypePopUp(SO, position, enableUpdateType); if (doApply) { var typeNameProp = SO.FindProperty("_typeName"); if (typeNameProp.stringValue != _typeCache.CurrentType.FullName) { typeNameProp.stringValue = _typeCache.CurrentType.FullName; SO.FindProperty("_values").ClearArray(); SO.ApplyModifiedProperties(); } var inst = SO.targetObject as TDictionary; inst.Refresh(); } return(doApply, position); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var textTemplateEngine = GetTargetTextTemplateEngine(property); var keywordProp = property.FindPropertyRelative("keyword"); var valueProp = property.FindPropertyRelative("value"); int selectedKeywordIndex = textTemplateEngine.Keywords .Zip(Enumerable.Range(0, textTemplateEngine.Keywords.Count()), (_k, _i) => (_k, _i)) .Where(_t => _t._k.key == keywordProp.stringValue) .Select(_t => _t._i).FirstOrDefault(); int selectedValueIndex = 0; if (textTemplateEngine.Keywords.Any()) { selectedValueIndex = textTemplateEngine.Keywords .ElementAt(selectedKeywordIndex) .values.FindIndex(_i => _i == valueProp.stringValue); } var pos = new GUILayoutPosition(position); pos.Indent(false, 0.3f); var posWidth = 6; var popupWidth = 2; bool isUpdated = false; using (var horizontalScope = new GUILayout.HorizontalScope()) { EditorGUI.LabelField(pos.GetSplitPos(posWidth, 0, 1), "Key"); var keywordList = textTemplateEngine.Keywords.Select(_k => _k.key); if (!keywordList.Any()) { keywordList = Enumerable.Repeat("", 1); } selectedKeywordIndex = Mathf.Clamp(selectedKeywordIndex, 0, keywordList.Count() - 1); var newSelectedKeywordIndex = EditorGUI.Popup(pos.GetSplitPos(posWidth, 1, popupWidth), selectedKeywordIndex, keywordList.ToArray()); if (newSelectedKeywordIndex != selectedKeywordIndex) { isUpdated = true; selectedKeywordIndex = newSelectedKeywordIndex; selectedValueIndex = 0; } EditorGUI.LabelField(pos.GetSplitPos(posWidth, 3, 1), "Val"); var valueList = (selectedKeywordIndex < textTemplateEngine.Keywords.Count()) ? textTemplateEngine.Keywords.ElementAt(selectedKeywordIndex).values.AsEnumerable() : Enumerable.Repeat("", 1); var newSelectedValueIndex = EditorGUI.Popup(pos.GetSplitPos(posWidth, 4, popupWidth), selectedValueIndex, valueList.ToArray()); if (newSelectedValueIndex != selectedValueIndex) { isUpdated = true; selectedValueIndex = newSelectedValueIndex; } } if (isUpdated) { var keyword = textTemplateEngine.Keywords.ElementAt(selectedKeywordIndex); property.FindPropertyRelative("keyword").stringValue = keyword.key; property.FindPropertyRelative("value").stringValue = keyword.values[selectedValueIndex]; } }