/// <summary> /// Load Data using reflection /// </summary> /// <param name="iData"></param> virtual protected internal void LoadData(UCL_TC_Data iData) { iData.UpdateVersion(UpdateVersionAct); var aDataType = iData.GetType(); Dictionary <System.Type, List <FieldInfo> > aInfos = GetFieldInfosDic(); System.Action <string, List <FieldInfo> > aLoadData = delegate(string iTypeName, List <FieldInfo> iFieldInfos) { FieldInfo aFieldInfo = aDataType.GetField("m_" + iTypeName); if (aFieldInfo == null) { return; } IList aDatas = aFieldInfo.GetValue(iData) as IList; //sdata.FindPropertyRelative("m_" + type_name); if (aDatas == null) { Debug.LogWarning("LoadData:" + iTypeName + " not support by UCL_TC_Data yet!!"); return; } for (int i = 0, count = iFieldInfos.Count < aDatas.Count ? iFieldInfos.Count : aDatas.Count; i < count; i++) { var aData = aDatas[i]; var aInfo = iFieldInfos[i]; aInfo.SetValue(this, aData); } }; foreach (var aTypeName in aInfos) { aLoadData(aTypeName.Key.Name, aTypeName.Value); } }
/// <summary> /// return true if data altered /// </summary> /// <param name="data"></param> /// <returns></returns> virtual public bool OnInspectorGUI(UCL_TC_Data iTC_Data, UnityEditor.SerializedProperty iSerializedProperty) { bool aIsDirty = false; Dictionary <Type, List <FieldInfo> > aFieldInfosDic = GetFieldInfosDic(); if (iTC_Data.UpdateVersion(UpdateVersionAct)) { aIsDirty = true; } Action <Type, List <FieldInfo> > aDrawData = delegate(Type iType, List <FieldInfo> iFieldInfos) { string aTypeName = iType.Name; var aDatas = iSerializedProperty.FindPropertyRelative("m_" + aTypeName); if (aDatas == null) { //if (typeof(Component).IsAssignableFrom(iType)) //{ // aDatas = iSerializedProperty.FindPropertyRelative("m_Component"); //} //else { if (GUILayout.Button(new GUIContent(aTypeName + " not supported by UCL_TC_Data", "Click this button to open UCL_TC_Data script."))) { //Assets/UCL/UCL_Modules/UCL_Tween/UCL_TweenScript/UCL_TweenBehaviors/UCL_TweenComponentDatas/UCL_TC_Data.cs string sc_path = Core.FileLib.EditorLib.GetLibFolderPath(Core.FileLib.LibName.UCL_TweenLib) + "/UCL_TweenScript/UCL_TweenBehaviors/UCL_TweenComponentDatas/UCL_TC_Data.cs"; //Debug.Log("EaseScript:" + sc_path); var aObj = UCL.Core.EditorLib.AssetDatabaseMapper.LoadMainAssetAtPath(sc_path); if (aObj != null) { UnityEditor.Selection.activeObject = aObj; } } //GUILayout.Box(type_name + " not support by UCL_TC_Data yet!!"); return; } } while (iFieldInfos.Count > aDatas.arraySize) { aDatas.InsertArrayElementAtIndex(aDatas.arraySize); var aFieldInfo = iFieldInfos[aDatas.arraySize - 1]; if (aFieldInfo.FieldType.IsBool()) { bool aNewVal = (bool)iFieldInfos[aDatas.arraySize - 1].GetValue(this); //Debug.LogError("aNewVal:" + aNewVal+ ",aFieldInfo.Name:" + aFieldInfo.Name); aDatas.GetArrayElementAtIndex(aDatas.arraySize - 1).boolValue = aNewVal; } } while (iFieldInfos.Count < aDatas.arraySize) { aDatas.DeleteArrayElementAtIndex(aDatas.arraySize - 1); } for (int i = 0; i < iFieldInfos.Count && i < aDatas.arraySize; i++) { var aInfo = iFieldInfos[i]; var aFieldName = aInfo.Name; string aDisplayName = aFieldName.StartsWith("m_") ? aFieldName.Remove(0, 2) : aFieldName; var aHeaderAttr = aInfo.GetCustomAttribute <HeaderAttribute>(); if (aHeaderAttr != null) { GUILayout.Box(aHeaderAttr.header); } UnityEditor.EditorGUILayout.PropertyField(aDatas.GetArrayElementAtIndex(i), new GUIContent(aDisplayName), true); } }; foreach (var aType in aFieldInfosDic) { aDrawData(aType.Key, aType.Value); } return(aIsDirty); }