static public UCL_TC_Data Create() { var data = new UCL_TC_Data(); data.m_Foldout = true; return(data); }
/// <summary> /// override to avoid using reflection on IOS /// </summary> /// <param name="data"></param> protected internal override void LoadData(UCL_TC_Data data) { if (data.m_UCL_TC_Event.Count > 0) { m_Event = data.m_UCL_TC_Event[0]; } }
/// <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); } }
public override bool OnInspectorGUI(UCL_TC_Data tc_data, UnityEditor.SerializedProperty sdata) { { var data = sdata.FindPropertyRelative("m_UCL_Path"); if (data.arraySize == 0) { data.InsertArrayElementAtIndex(0); } UnityEditor.EditorGUILayout.PropertyField(data.GetArrayElementAtIndex(0), new GUIContent("Path")); } { var data = sdata.FindPropertyRelative("m_Transform"); if (data.arraySize == 0) { data.InsertArrayElementAtIndex(0); } UnityEditor.EditorGUILayout.PropertyField(data.GetArrayElementAtIndex(0), new GUIContent("Target")); } { var data = sdata.FindPropertyRelative("m_LookAtFront"); if (data.arraySize == 0) { data.InsertArrayElementAtIndex(0); } UnityEditor.EditorGUILayout.PropertyField(data.GetArrayElementAtIndex(0), new GUIContent("LookAtFront")); } return(true); }
public override bool OnInspectorGUI(UCL_TC_Data tc_data, UnityEditor.SerializedProperty sdata) { var event_data = sdata.FindPropertyRelative("m_UCL_TC_Event"); if (event_data.arraySize == 0) { event_data.InsertArrayElementAtIndex(0); } UnityEditor.EditorGUILayout.PropertyField(event_data.GetArrayElementAtIndex(0)); return(true); }
override public void OnInspectorGUIBasic(UCL_TC_Data iTcData, UnityEditor.SerializedProperty iSerializedProperty, Transform iTransform) { base.OnInspectorGUIBasic(iTcData, iSerializedProperty, iTransform); UnityEditor.SerializedProperty aTransformDatas = iSerializedProperty.FindPropertyRelative("m_Transform"); if (iTransform != null && aTransformDatas != null) { if (aTransformDatas.arraySize == 0) {//Init aTransformDatas.InsertArrayElementAtIndex(0); aTransformDatas.InsertArrayElementAtIndex(1); aTransformDatas.GetArrayElementAtIndex(0).objectReferenceValue = iTransform; } } }
/// <summary> /// override to avoid using reflection on IOS /// </summary> /// <param name="data"></param> protected internal override void LoadData(UCL_TC_Data data) { if (data.m_UCL_Path.Count > 0) { m_Path = data.m_UCL_Path[0]; } if (data.m_Transform.Count > 0) { m_Target = data.m_Transform[0]; } if (data.m_LookAtFront.Count > 0) { m_LookAtFront = data.m_LookAtFront[0]; } }
virtual public void OnInspectorGUIBasic(UCL_TC_Data tc_data, UnityEditor.SerializedProperty iSerializedProperty, Transform TB_transform) { string aTips = OnInspectorGUITips(); if (!string.IsNullOrEmpty(aTips)) { var aTip = aTips.Split('\n'); foreach (string aStr in aTip) { if (!string.IsNullOrEmpty(aStr)) { GUILayout.Box(aStr); } } } }
override protected void UpdateVersionAct(UCL_TC_Data.DataVersion iCurVersion, UCL_TC_Data iData) { switch (iCurVersion) { case UCL_TC_Data.DataVersion.Ver1: { //Add bool m_UseStartValue; so ReOrder the bool list iData.m_Boolean.Insert(0, false); break; } } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); UCL_TB_Tweener aTB = target as UCL_TB_Tweener; GUILayout.BeginVertical(); var aSerializedComponents = serializedObject.FindProperty("m_TweenerComponents"); var aComponents = aTB.m_TweenerComponents; int add_at = -1; int delete_at = -1; bool aIsModified = false; int aChangeTypeAt = -1; EditorGUI.BeginChangeCheck(); if (aComponents != null) { for (int i = 0; i < aComponents.Count; i++) { var aTC_Data = aComponents[i]; var aSerializedData = aSerializedComponents.GetArrayElementAtIndex(i); var aTweenComponent = UCL_TweenerComponent.Create(aTC_Data.m_Type); var aType = aTweenComponent.GetType(); /* * if(GUILayout.Button("Insert TweenerComponent")) { * add_at = i; * break; * } */ UnityEditor.EditorGUILayout.BeginHorizontal(); aTC_Data.m_Foldout = UnityEditor.EditorGUILayout.Foldout(aTC_Data.m_Foldout, aType.Name, true); if (GUILayout.Button("Delete", UCL.Core.UI.UCL_GUIStyle.ButtonTextRed)) { delete_at = i; break; } UnityEditor.EditorGUILayout.EndHorizontal(); if (aTC_Data.m_Foldout) { aIsModified = true; var aTypeData = aSerializedData.FindPropertyRelative("m_Type"); var aTypeEnum = aTypeData.enumValueIndex; UnityEditor.EditorGUILayout.PropertyField(aTypeData); if (aTypeEnum != aTypeData.enumValueIndex)//Change Type { aChangeTypeAt = i; } else { aTweenComponent.OnInspectorGUIBasic(aTC_Data, aSerializedData, aTB.transform); if (aTweenComponent.OnInspectorGUI(aTC_Data, aSerializedData)) {//serializedObject UCL.Core.EditorLib.EditorUtilityMapper.SetDirty(aTB); } } } } } if (aIsModified) { if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "serializedObject.ApplyModifiedProperties()"); serializedObject.ApplyModifiedProperties(); } //Undo.RecordObject(target, "serializedObject.ApplyModifiedProperties()"); //if(EditorGUI.EndChangeCheck()) Undo.RecordObject(target, "serializedObject.ApplyModifiedProperties()"); } if (aChangeTypeAt >= 0) { Undo.RecordObject(aTB, "m_TweenerComponents.Init()" + aChangeTypeAt); aComponents[aChangeTypeAt].Init(); UCL.Core.EditorLib.EditorUtilityMapper.SetDirty(aTB); //serializedObject.Update(); } if (aTB.m_TweenerComponents == null) { aTB.m_TweenerComponents = new List <UCL_TC_Data>(); } if (GUILayout.Button("Add TweenerComponent")) { add_at = aTB.m_TweenerComponents.Count; } if (add_at >= 0) { //EditorGUI.BeginChangeCheck(); Undo.RecordObject(aTB, "m_TweenerComponents.Insert_" + add_at); aTB.m_TweenerComponents.Insert(add_at, UCL_TC_Data.Create()); } else if (delete_at >= 0) { //EditorGUI.BeginChangeCheck(); Undo.RecordObject(target, "m_TweenerComponents.RemoveAt_" + delete_at); aTB.m_TweenerComponents.RemoveAt(delete_at); //if(EditorGUI.EndChangeCheck()) Undo.RecordObject(target, "m_TweenerComponents.RemoveAt_"+delete_at); } GUILayout.EndVertical(); }
/// <summary> /// Update if the data is older version /// </summary> /// <param name="iCurVersion"></param> virtual protected void UpdateVersionAct(UCL_TC_Data.DataVersion iCurVersion, UCL_TC_Data iData) { }
/// <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); }