public static void conditionChangedCB(object sender, MStateFunctionArgs args) { // Client data isn't supported in Maya.NET, therefore we have to maintain an original // copy of the condition states and manually compare the states here in order to find // which state is being changed. for (int i = 0; i < conditionNames.length; ++i) { if (conditionCallbacks[i]) { bool newState = MConditionMessage.getConditionState(conditionNames[i]); if (newState != conditionStates[i]) { displayInfo("condition " + conditionNames[i] + " changed to " + (newState ? "true" : "false")); conditionStates[i] = newState; } } } }
public override void doIt(MArgList args) { parseArgs(args); // Allocate an array of indices. conditions[n] is a user provided // condition name. Look it up in the static conditionNames array // and set indices[n] to the index of the entry in conditionNames. // // This maps the user specified conditions to the global conditions // so we can track callback adds and removes globally. // int[] indices = new int[conditions.length]; for (int i = 0; i < conditions.length; ++i) { // Initialize the entry to "not found". // indices[i] = -1; // Search condition names for a match. // for (int j = 0; j < conditionNames.length; ++j) { if (conditions[i] == conditionNames[j]) { // Found a match. Store the index and stop looking for // indices[i] = (int)j; break; } } } for (int i = 0; i < conditions.length; ++i) { int j = indices[i]; if (j == -1) { displayWarning(conditions[i] + "is not a valid condition name"); break; } if (addMessage) { try { MConditionMessage.Condition[conditions[i]] += conditionChangedCB; conditionCallbacks[j] = true; } catch (Exception) { displayError("failed to add callback for " + conditions[i]); conditionCallbacks[j] = false; } } else if (delMessage) { try { MConditionMessage.Condition[conditions[i]] -= conditionChangedCB; conditionCallbacks[j] = false; } catch (Exception) { displayError("failed to remove callback for " + conditions[i]); conditionCallbacks[j] = true; } } } // Ok, we've made all the necessary changes. Now show the status. // displayInfo("Condition Name State Msgs On"); displayInfo("-------------------- ----- -------"); for (int i = 0; i < conditions.length; ++i) { int j = indices[i]; if (j == -1) { continue; } try { conditionStates[j] = MConditionMessage.getConditionState(conditions[i]); } catch (Exception) { displayError("failed to get status for " + conditions[i]); conditionStates[j] = false; } string tmpStr = string.Format("{0,-20} {1,-5} {2, -5}", conditions[i], conditionStates[j], conditionCallbacks[j] ? "yes" : "no"); displayInfo(tmpStr); } return; }