private void playingModeDrawElementCallBack(FYFY.FSystem system, Rect rect) { float buttonSize = EditorGUIUtility.singleLineHeight; Color baseColor = GUI.color; GUI.color = (system.Pause == true) ? Color.red : Color.green; if (GUI.Button(new Rect(rect.x, rect.y + 1.35f, buttonSize, buttonSize), "")) { system.Pause = !system.Pause; } GUI.color = baseColor; string typeFullName = system.GetType().FullName + string.Format(" avg: {0:00.000}", system.avgExecDuration / 1000) + string.Format(" max: {0:00.000}", system.maxExecDuration / 1000); Rect textArea = new Rect(rect.x + buttonSize + 5, rect.y + 1.35f, rect.width - (buttonSize + 5), buttonSize); EditorGUI.LabelField(textArea, findFittableString(typeFullName, textArea)); }
/// <summary>Set field "fieldName" defined inside "system" system with "parameter" parameter </summary> public static void initAppropriateSystemField(FSystem system, string fieldName, object parameter) { if (system != null) { Type systemType = system.GetType(); // We found the system, now found the target field FieldInfo fieldInfo = systemType.GetField(fieldName); if (fieldInfo != null) { fieldInfo.SetValue(system, parameter); } else { UnityEngine.Debug.LogError(fieldName + " is not available in " + systemType.FullName); } } else { UnityEngine.Debug.LogError("initAppropriateSystemField aborted because first parameter is null"); } }
/// <summary>Call function "functionName" defined inside "system" system with "parameter" parameter </summary> public static void callAppropriateSystemMethod(FSystem system, string functionName, object parameter) { if (system != null) { Type systemType = system.GetType(); // Found the target funcion MethodInfo systemMethod; if (parameter != null) { systemMethod = systemType.GetMethod(functionName, new Type[] { parameter.GetType() }); } else { systemMethod = systemType.GetMethod(functionName, new Type[] { }); } if (systemMethod != null) { // We found the function, then we invoke it if (parameter != null) { systemMethod.Invoke(system, new object[] { parameter }); } else { systemMethod.Invoke(system, new object[] { }); } } else { UnityEngine.Debug.LogError(functionName + " is not available in " + systemType.FullName); } } else { UnityEngine.Debug.LogError("callAppropriateSystemMethod aborted because first parameter is null"); } }