private void UpdateGameActionSettingsList() { if (_hasUpdatedListOfGameActionSettings) { return; } var gameAction = GameActionBank.GetAction(Value); var requiredSettingAuths = GameActionSettingAuthBase.GetRequiredSettingAuthTypes(gameAction.GetType()); GameActionSettings.RemoveAll(authInstance => authInstance == null || !requiredSettingAuths.Contains(authInstance.GetType())); foreach (var authType in requiredSettingAuths) { if (!GameActionSettings.Any(x => x.GetType() == authType)) { GameActionSettings.Add(Activator.CreateInstance(authType) as GameActionSettingAuthBase); } } _hasUpdatedListOfGameActionSettings = true; }
public override void OnInspectorGUI() { var castedTarget = (GameActionAuth)target; EditorGUI.BeginChangeCheck(); DrawPrimaryTitle("Simulation"); GUIContent label = EditorGUIUtilityX.TempContent("Game Action Type"); EditorGUILayoutX.SearchablePopupString(_gameActionProp, label, s_availableTypeNames); if (_gameActionProp.stringValue != "") { Type gameActionType = TypeUtility.FindType(_gameActionProp.stringValue, false); if (gameActionType != null) { Type[] settingAuthTypes = GameActionSettingAuthBase.GetRequiredSettingAuthTypes(gameActionType); // Remove extra setting in property list for (int i = _gameActionSettingsProp.arraySize - 1; i >= 0; i--) { if (castedTarget.GameActionSettings[i] == null || !settingAuthTypes.Contains(castedTarget.GameActionSettings[i].GetType())) { _gameActionSettingsProp.DeleteArrayElementAtIndex(i); castedTarget.GameActionSettings.RemoveAt(i); } } // Add missing setting to property list for (int i = 0; i < settingAuthTypes.Length; i++) { Type currentAuthSettingType = settingAuthTypes[i]; if (currentAuthSettingType == null) { continue; } if (!castedTarget.GameActionSettings.Any((x) => x.GetType() == currentAuthSettingType)) { _gameActionSettingsProp.InsertArrayElementAtIndex(_gameActionSettingsProp.arraySize); SerializedProperty currentGameActionSetting = _gameActionSettingsProp.GetArrayElementAtIndex(_gameActionSettingsProp.arraySize - 1); var newAuthSetting = Activator.CreateInstance(currentAuthSettingType); currentGameActionSetting.managedReferenceValue = newAuthSetting; castedTarget.GameActionSettings.Add((GameActionSettingAuthBase)newAuthSetting); } } for (int i = 0; i < _gameActionSettingsProp.arraySize; i++) { EditorGUILayout.PropertyField(_gameActionSettingsProp.GetArrayElementAtIndex(i)); } } } DrawLine(10); DrawPrimaryTitle("Presentation"); EditorGUILayout.PropertyField(_sfxProp); EditorGUILayout.PropertyField(_animationProp); EditorGUILayout.PropertyField(_surveyProp); EditorGUILayout.PropertyField(_instigatorVFXProp); EditorGUILayout.PropertyField(_targetsVFXProp); if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } }