void CopyParameters(IEnumerable <EditorProp> aos, EditorProp aoCopy, int paramIndex) { foreach (var ao in aos) { if (ao != null) { CustomParameterEditor.CopyParameter(ao[AOStateMachineEditor.paramsField][paramIndex], aoCopy[AOStateMachineEditor.paramsField][paramIndex]); } } }
static void UpdateParametersIfDifferentFromDefaults(EditorProp parameters, EditorProp defaultParams, bool debug) { int aoParametersCount = parameters.arraySize; int defParametersCount = defaultParams.arraySize; Func <EditorProp, string> GetParamName = (EditorProp parameter) => parameter[CustomParameterEditor.nameField].stringValue; //check for parameters to delete for (int i = aoParametersCount - 1; i >= 0; i--) { string name = GetParamName(parameters[i]); bool inDefParams = false; for (int d = 0; d < defParametersCount; d++) { if (GetParamName(defaultParams[d]) == name) { inDefParams = true; break; } } if (!inDefParams) { if (debug) { Debug.Log("Deleting param: " + name); } parameters.DeleteAt(i, "deleting different params"); } } // Debug.Log("finished deletes"); aoParametersCount = parameters.arraySize; //check for parameters that need adding for (int i = 0; i < defParametersCount; i++) { var defParam = defaultParams[i]; string defParamName = GetParamName(defParam); bool inParams = false; for (int p = 0; p < aoParametersCount; p++) { if (GetParamName(parameters[p]) == defParamName) { inParams = true; break; } } if (!inParams) { if (debug) { Debug.Log("adding param: " + defParamName); } CustomParameterEditor.CopyParameter(parameters.AddNew(), defParam); } } aoParametersCount = parameters.arraySize; // Debug.Log("finished Adds"); //reorder to same order EditorProp temp = null; for (int d = 0; d < defParametersCount; d++) { string defParamName = GetParamName(defaultParams[d]); var parameter = parameters[d]; if (GetParamName(parameter) == defParamName) { continue; } if (debug) { Debug.Log("moving param: " + GetParamName(parameter)); } EditorProp trueParam = null; //for (int p = d + 1; p < c_p; p++) { for (int p = 0; p < aoParametersCount; p++) { trueParam = parameters[p]; if (GetParamName(trueParam) == defParamName) { break; } } if (trueParam == null) { if (debug) { Debug.LogError("couldnt find: " + defParamName); } } //put the current one in temp if (temp == null) { //make extra temp parameeter temp = parameters.AddNew(); } // Debug.Log("put in temp"); CustomParameterEditor.CopyParameter(temp, parameter); //place the real param in the current // Debug.Log("put in current"); CustomParameterEditor.CopyParameter(parameter, trueParam); //place temp in old param that was moved // Debug.Log("put in temp 2"); CustomParameterEditor.CopyParameter(trueParam, temp); } if (temp != null) { //delete temp parameter parameters.DeleteAt(parameters.arraySize - 1, "deleting temp param"); } //check type changes Func <EditorProp, int> GetParamType = (EditorProp parameter) => parameter[CustomParameterEditor.typeField].intValue; for (int i = 0; i < defParametersCount; i++) { if (GetParamType(parameters[i]) != GetParamType(defaultParams[i])) { if (debug) { Debug.Log("changing: " + GetParamName(parameters[i]) + " from " + GetParamType(parameters[i]) + " to " + GetParamType(defaultParams[i])); } CustomParameterEditor.CopyParameter(parameters[i], defaultParams[i]); } } }