public void Rebind(RebindOption bindOpt) { if (Application.isPlaying) { Transform tr = bindOpt.FindTr(m_trPath); m_runtimeCp = null; if (tr != null) { Type type = RCall.GetTypeFromString(m_compType, true); m_runtimeCp = tr.GetComponent(type); if (m_runtimeCp == null) { Dbg.LogWarn("RebindCp.Rebind: failed to get cp \"{0}\" on \"{1}\"", m_compType, m_trPath); } } else { Dbg.LogWarn("RebindCp.Rebind: failed to find \"{0}\"", m_trPath); } } else { Transform tr = bindOpt.FindTr(m_trPath); //even editTimeTr not null, it could be stale if (tr != null) { Type type = RCall.GetTypeFromString(m_compType, true); m_editTimeCp = tr.GetComponent(type); } } }
private void _GUI_AddNewCurve() { EditorWindow uaw = (EditorWindow)EUtil.GetUnityAnimationWindow(); object uawstate = EUtil.GetUnityAnimationWindowState(uaw); m_CurClip = RCall.GetField("UnityEditorInternal.AnimationWindowState", "m_ActiveAnimationClip", uawstate) as AnimationClip; if (m_CurClip == null) { EditorGUILayout.LabelField("Need an animation clip first..."); return; } m_NewPath = EditorGUILayout.TextField("Path:", m_NewPath); m_NewProperty = EditorGUILayout.TextField("Property:", m_NewProperty); m_TypeFullName = EditorGUILayout.TextField("TypeFullName:", m_TypeFullName); m_bIsPPtrCurve = EditorGUILayout.Toggle("IsPPtrCurve:", m_bIsPPtrCurve); EditorGUILayout.Separator(); bool bOK = true; EUtil.PushGUIColor(Color.red); if (string.IsNullOrEmpty(m_NewProperty)) { bOK = false; EditorGUILayout.LabelField("Property is not specified"); } if (string.IsNullOrEmpty(m_TypeFullName) || RCall.GetTypeFromString(m_TypeFullName, true) == null) { bOK = false; EditorGUILayout.LabelField(string.Format("No type is found for name: {0}", m_TypeFullName)); } EUtil.PopGUIColor(); EUtil.PushGUIEnable(bOK); { if (EUtil.Button("Add New Curve", Color.green)) { Type tp = RCall.GetTypeFromString(m_TypeFullName); if (m_bIsPPtrCurve) { EditorCurveBinding newBinding = EditorCurveBinding.PPtrCurve(m_NewPath, tp, m_NewProperty); AnimationUtility.SetObjectReferenceCurve(m_CurClip, newBinding, new ObjectReferenceKeyframe[0]); } else { EditorCurveBinding newBinding = EditorCurveBinding.FloatCurve(m_NewPath, tp, m_NewProperty); AnimationUtility.SetEditorCurve(m_CurClip, newBinding, new AnimationCurve()); } } } EUtil.PopGUIEnable(); }
private void _GUI_EditSingleCurve() { EditorWindow uaw = (EditorWindow)EUtil.GetUnityAnimationWindow(); object uawstate = EUtil.GetUnityAnimationWindowState(uaw); m_CurClip = RCall.GetField("UnityEditorInternal.AnimationWindowState", "m_ActiveAnimationClip", uawstate) as AnimationClip; IList curves = (IList)RCall.GetProp("UnityEditorInternal.AnimationWindowState", "activeCurves", uawstate); if (curves.Count != 1) { EditorGUILayout.LabelField(string.Format("Please select ONE curve, you have currently selected {0} curves", curves.Count)); return; } object oneCurve = curves[0]; //AnimationWindowCurve EditorCurveBinding oneBinding = (EditorCurveBinding)RCall.GetProp("UnityEditorInternal.AnimationWindowCurve", "binding", oneCurve); EditorGUILayout.LabelField("Path:"); EUtil.PushContentColor(Color.yellow); EditorGUILayout.SelectableLabel(oneBinding.path); EUtil.PopContentColor(); EditorGUILayout.LabelField("Property:"); EUtil.PushContentColor(Color.green); EditorGUILayout.SelectableLabel(oneBinding.propertyName); EUtil.PopContentColor(); EditorGUILayout.LabelField("IsPPtrCurve: " + oneBinding.isPPtrCurve.ToString()); EditorGUILayout.Separator(); m_NewType = EditorGUILayout.TextField("Type:", m_NewType); if (m_NewType.Length == 0) { m_NewType = oneBinding.type.ToString(); } m_NewPath = EditorGUILayout.TextField("New Path:", m_NewPath); m_NewProperty = EditorGUILayout.TextField("New Property:", m_NewProperty); Type newTp = RCall.GetTypeFromString(m_NewType, true); EUtil.PushGUIEnable(m_NewProperty.Length > 0 && newTp != null); if (EUtil.Button("Apply Change", Color.green)) { Undo.RegisterCompleteObjectUndo(m_CurClip, "Apply Curve Change"); _ModifyCurveBinding(oneBinding, m_NewPath, m_NewProperty, newTp); } EUtil.PopGUIEnable(); }