/// <summary> /// Draws all of the added abilities. /// </summary> private void OnAbilityListDraw(Rect rect, int index, bool isActive, bool isFocused) { var ability = m_Abilities.GetArrayElementAtIndex(index).objectReferenceValue as Ability; // Remove the ability if it no longer exists. if (ReferenceEquals(ability, null)) { m_Abilities.DeleteArrayElementAtIndex(index); m_ReorderableAbilityList.index = m_Controller.SelectedAbility = -1; m_Abilities.serializedObject.ApplyModifiedProperties(); InspectorUtility.SetObjectDirty(m_Controller); // It's not easy removing a null component. var components = m_Controller.GetComponents <Component>(); for (int i = components.Length - 1; i > -1; --i) { if (ReferenceEquals(components[i], null)) { var serializedObject = new SerializedObject(m_Controller.gameObject); var componentProperty = serializedObject.FindProperty("m_Component"); componentProperty.DeleteArrayElementAtIndex(i); serializedObject.ApplyModifiedProperties(); } } return; } if (ability.hideFlags != HideFlags.HideInInspector) { ability.hideFlags = HideFlags.HideInInspector; } var label = SplitCamelCase(ability.GetType().Name); if (ability.IsActive) { label += " (Active)"; } var activeRect = rect; activeRect.width -= 20; EditorGUI.LabelField(activeRect, label); EditorGUI.BeginChangeCheck(); activeRect = rect; activeRect.x += activeRect.width - 34; activeRect.width = 20; ability.enabled = EditorGUI.Toggle(activeRect, ability.enabled); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(ability, "Inspector"); InspectorUtility.SetObjectDirty(ability); } }
public override TaskStatus OnUpdate() { var target = GetDefaultGameObject(targetGameObject.Value); if (target != prevTarget) { controller = target.GetComponentInParent <RigidbodyCharacterController>(); controllerHandler = target.GetComponentInParent <ControllerHandler>(); var abilities = controller.GetComponents(TaskUtility.GetTypeWithinAssembly(abilityType.Value)); if (abilities.Length > 1) { if (priorityIndex.Value != -1) { for (int i = 0; i < abilities.Length; ++i) { var localAbility = abilities[i] as Ability; if (localAbility.Index == priorityIndex.Value) { ability = localAbility; break; } } } else { ability = abilities[0] as Ability; } } else if (abilities.Length == 1) { ability = abilities[0] as Ability; } prevTarget = target; } if (ability == null) { return(TaskStatus.Failure); } controllerHandler.TryStartAbility(ability); return(TaskStatus.Success); }