private void _targetList_DrawElement(Rect area, int index, bool isActive, bool isFocused) { var element = _targetList.serializedProperty.GetArrayElementAtIndex(index); var targProp = element.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_TRIGGERABLETARG); const float MARGIN = 1.0f; const float WEIGHT_FIELD_WIDTH = 60f; const float PERC_FIELD_WIDTH = 45f; const float FULLWEIGHT_WIDTH = WEIGHT_FIELD_WIDTH + PERC_FIELD_WIDTH; EditorGUI.BeginProperty(area, GUIContent.none, targProp); Rect trigRect; var actInfo = TriggerTargetPropertyDrawer.GetTriggerActivationInfo(element); GUIContent labelContent = EditorHelper.TempContent(index.ToString("00: ") + actInfo.ActivationTypeDisplayName); if (this.CustomizeEntryLabel != null) { this.CustomizeEntryLabel(labelContent, index); } if (_drawWeight && area.width > FULLWEIGHT_WIDTH) { var top = area.yMin + MARGIN; var labelRect = new Rect(area.xMin, top, EditorGUIUtility.labelWidth - FULLWEIGHT_WIDTH, EditorGUIUtility.singleLineHeight); var weightRect = new Rect(area.xMin + EditorGUIUtility.labelWidth - FULLWEIGHT_WIDTH, top, WEIGHT_FIELD_WIDTH, EditorGUIUtility.singleLineHeight); var percRect = new Rect(area.xMin + EditorGUIUtility.labelWidth - PERC_FIELD_WIDTH, top, PERC_FIELD_WIDTH, EditorGUIUtility.singleLineHeight); trigRect = new Rect(area.xMin + EditorGUIUtility.labelWidth, top, area.width - EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight); var weightProp = element.FindPropertyRelative(PROP_WEIGHT); float weight = weightProp.floatValue; EditorGUI.LabelField(labelRect, labelContent); weightProp.floatValue = EditorGUI.FloatField(weightRect, weight); float p = (_totalWeight > 0f) ? (100f * weight / _totalWeight) : ((index == 0) ? 100f : 0f); EditorGUI.LabelField(percRect, string.Format("{0:0.#}%", p)); } else { //Draw Triggerable - this is the simple case to make a clean designer set up for newbs var top = area.yMin + MARGIN; var labelRect = new Rect(area.xMin, top, area.width, EditorGUIUtility.singleLineHeight); trigRect = EditorGUI.PrefixLabel(labelRect, labelContent); } //Draw Triggerable - this is the simple case to make a clean designer set up for newbs EditorGUI.BeginChangeCheck(); var targObj = TriggerTargetPropertyDrawer.TargetObjectField(trigRect, GUIContent.none, targProp.objectReferenceValue); if (EditorGUI.EndChangeCheck()) { targProp.objectReferenceValue = TriggerTargetPropertyDrawer.IsValidTriggerTarget(targObj, actInfo.ActivationType) ? targObj : null; } EditorGUI.EndProperty(); ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_targetList, area, index, isActive, isFocused); }
private void _targetList_DrawElement(Rect area, int index, bool isActive, bool isFocused) { var element = _targetList.serializedProperty.GetArrayElementAtIndex(index); var targProp = element.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_TRIGGERABLETARG); var actProp = element.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_ACTIVATIONTYPE); //var act = (TriggerActivationType)actProp.enumValueIndex; var act = actProp.GetEnumValue <TriggerActivationType>(); const float MARGIN = 1.0f; const float WEIGHT_FIELD_WIDTH = 60f; const float PERC_FIELD_WIDTH = 45f; const float FULLWEIGHT_WIDTH = WEIGHT_FIELD_WIDTH + PERC_FIELD_WIDTH; EditorGUI.BeginProperty(area, GUIContent.none, targProp); Rect trigRect; GUIContent labelContent = EditorHelper.TempContent(index.ToString("00: ") + act.ToString()); //(act == TriggerActivationType.TriggerAllOnTarget) ? EditorHelper.TempContent("Target") : EditorHelper.TempContent(string.Format("Target ({0})", act)); if (_drawWeight && area.width > FULLWEIGHT_WIDTH) { var top = area.yMin + MARGIN; var labelRect = new Rect(area.xMin, top, EditorGUIUtility.labelWidth - FULLWEIGHT_WIDTH, EditorGUIUtility.singleLineHeight); var weightRect = new Rect(area.xMin + EditorGUIUtility.labelWidth - FULLWEIGHT_WIDTH, top, WEIGHT_FIELD_WIDTH, EditorGUIUtility.singleLineHeight); var percRect = new Rect(area.xMin + EditorGUIUtility.labelWidth - PERC_FIELD_WIDTH, top, PERC_FIELD_WIDTH, EditorGUIUtility.singleLineHeight); trigRect = new Rect(area.xMin + EditorGUIUtility.labelWidth, top, area.width - EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight); var weightProp = element.FindPropertyRelative(PROP_WEIGHT); float weight = weightProp.floatValue; EditorGUI.LabelField(labelRect, labelContent); weightProp.floatValue = EditorGUI.FloatField(weightRect, weight); float p = (_totalWeight > 0f) ? (100f * weight / _totalWeight) : ((index == 0) ? 100f : 0f); EditorGUI.LabelField(percRect, string.Format("{0:0.#}%", p)); } else { //Draw Triggerable - this is the simple case to make a clean designer set up for newbs var top = area.yMin + MARGIN; var labelRect = new Rect(area.xMin, top, area.width, EditorGUIUtility.singleLineHeight); trigRect = EditorGUI.PrefixLabel(labelRect, labelContent); } //Draw Triggerable - this is the simple case to make a clean designer set up for newbs /* * var targGo = GameObjectUtil.GetGameObjectFromSource(targProp.objectReferenceValue); * var newTargGo = EditorGUI.ObjectField(trigRect, GUIContent.none, targGo, typeof(GameObject), true) as GameObject; * if (newTargGo != targGo) * { * targGo = newTargGo; * targProp.objectReferenceValue = (targGo != null) ? targGo.transform : null; * } */ EditorGUI.BeginChangeCheck(); var targObj = TriggerTargetPropertyDrawer.TargetObjectField(trigRect, GUIContent.none, targProp.objectReferenceValue); if (EditorGUI.EndChangeCheck()) { targProp.objectReferenceValue = TriggerTargetPropertyDrawer.IsValidTriggerTarget(targObj, act) ? targObj : null; } EditorGUI.EndProperty(); ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_targetList, area, index, isActive, isFocused); }