public override void OnGUI(SerializedNodeProperty property, BehaviourMachine.ActionNode node, GUIContent guiContent) { // Now draw the property as a Slider or an IntSlider based on whether it’s a float or integer. if ( property.type != typeof(MinMaxRangeSO) ) Debug.LogWarning( "Use only with MinMaxRange type" ); else { var range = attribute as MinMaxRangeSAttribute; var so=(MinMaxRangeSO)property.value; //set or reset to default full range if(so.rangeStart==so.rangeEnd){ so.rangeStart=range.minLimit; so.rangeEnd=range.maxLimit; } var newMin =so.rangeStart; var newMax = so.rangeEnd; Rect position= GUILayoutUtility.GetRect(Screen.width-32f,32f); var xDivision = position.width * 0.33f; var yDivision = position.height * 0.5f; EditorGUI.LabelField( new Rect( position.x, position.y, xDivision, yDivision ) , guiContent ); EditorGUI.LabelField( new Rect( position.x, position.y + yDivision, position.width, yDivision ) , range.minLimit.ToString( "0.##" ) ); EditorGUI.LabelField( new Rect( position.x + position.width -28f, position.y + yDivision, position.width, yDivision ) , range.maxLimit.ToString( "0.##" ) ); EditorGUI.MinMaxSlider( new Rect( position.x + 24f, position.y + yDivision, position.width -48f, yDivision ) , ref newMin, ref newMax, range.minLimit, range.maxLimit ); EditorGUI.LabelField( new Rect( position.x + xDivision, position.y, xDivision, yDivision ) , "From: " ); newMin = Mathf.Clamp( EditorGUI.FloatField( new Rect( position.x + xDivision + 30, position.y, xDivision -30, yDivision ) , newMin ) , range.minLimit, newMax ); EditorGUI.LabelField( new Rect( position.x + xDivision * 2f, position.y, xDivision, yDivision ) , "To: " ); newMax = Mathf.Clamp( EditorGUI.FloatField( new Rect( position.x + xDivision * 2f + 24, position.y, xDivision -24, yDivision ) , newMax ) , newMin, range.maxLimit ); so.rangeStart = newMin; so.rangeEnd = newMax; property.ValueChanged(); property.ApplyModifiedValue(); property.serializedNode.ApplyModifiedProperties(); } }
// // Methods // public override void OnGUI(SerializedNodeProperty property, ActionNode node, GUIContent guiContent) { Enum @enum; if (Enum.IsDefined (this.attribute.GetEnumType (), property.value)) { @enum = (Enum)Enum.ToObject (this.attribute.GetEnumType (), property.value); } else { @enum = this.attribute.GetEnumValue (); } @enum=EditorGUILayout.EnumPopup (@enum); property.value= ((int)Convert.ChangeType (@enum, @enum.GetTypeCode ())); property.ApplyModifiedValue (); }
// // Methods // public override void OnGUI(SerializedNodeProperty property, ActionNode node, GUIContent guiContent) { attribute.serializedObject = node; GUILayout.BeginHorizontal (); if (attribute.Min < attribute.Max) { if (attribute.HasEnableToggle) attribute.Enabled = GUILayout.Toggle (attribute.Enabled, property.label); if (attribute.Enabled) { GUILayout.Label (attribute.Min.ToString ()); _valueCurrent = GUILayout.HorizontalSlider (_valueCurrent, attribute.Min, attribute.Max); property.value = _valueCurrent; GUILayout.Label (attribute.Max.ToString ()); property.ApplyModifiedValue (); } } GUILayout.EndHorizontal (); }
// // Methods // /// <summary> /// Handles the onGUI event. /// </summary> /// <param name="property">Property.</param> /// <param name="node">Node.</param> /// <param name="guiContent">GUI content.</param> public override void OnGUI(SerializedNodeProperty property, ActionNode node, GUIContent guiContent) { //if (animatorSerialized == null || aniController == null) { if(aniController == null) { //!!! Serialization never serialized Animator cos its initialized in Reset after // NodePropertyIterator iter= property.serializedNode.GetIterator(); // iter.Find(attribute.animatorFieldName); // animatorSerialized=iter.current; // // if(animatorSerialized==null || animatorSerialized.value==null){ // Debug.LogError("AnimatorStateNodePropertyDrawer> No Animator component set on node parent GameObject"); // return; // } //runtimeContoller =( (Animator)animatorSerialized.value).runtimeAnimatorController; Animator animator = node.GetType ().GetField (attribute.animatorFieldName).GetValue (node) as Animator; RuntimeAnimatorController runtimeContoller; runtimeContoller = animator.runtimeAnimatorController; if (runtimeContoller is AnimatorOverrideController) aniController = ((AnimatorOverrideController)runtimeContoller).runtimeAnimatorController as UnityEditor.Animations.AnimatorController; else aniController = runtimeContoller as UnityEditor.Animations.AnimatorController; } animatorStateDisplayOptions = MecanimUtility.GetDisplayOptions (aniController); animatorStateValues = MecanimUtility.GetAnimatorStates (aniController); if(property.value!=null){ if(animatorStateValues.Length>0){ animatorStateSelectedPrev=animatorStateSelected=animatorStateValues.FirstOrDefault((itm)=>itm.nameHash==((ws.winx.unity.AnimatorState)property.value).nameHash); } } animatorStateSelected = EditorGUILayoutEx.CustomObjectPopup (guiContent, animatorStateSelected, animatorStateDisplayOptions, animatorStateValues);//,compare); //TODO try Begin/End Check if (animatorStateSelectedPrev != animatorStateSelected) { NodePropertyIterator iter = property.serializedNode.GetIterator (); iter.Find (attribute.layerIndexFieldName); SerializedNodeProperty layerIndexSerialized = iter.current; layerIndexSerialized.value = MecanimUtility.GetLayerIndex (aniController, animatorStateSelected); layerIndexSerialized.ApplyModifiedValue (); ws.winx.unity.AnimatorState state=property.value as ws.winx.unity.AnimatorState; if(state==null) state=ScriptableObject.CreateInstance<ws.winx.unity.AnimatorState>(); state.motion=animatorStateSelected.motion; state.nameHash=animatorStateSelected.nameHash; state.layer=(int)layerIndexSerialized.value; if(state.motion is UnityEditor.Animations.BlendTree){ BlendTree tree =(BlendTree)state.motion; int blendParamsNum= tree.GetRecursiveBlendParamCount(); state.blendParamsHashes=new int[blendParamsNum]; for(int i=0;i<blendParamsNum;i++) state.blendParamsHashes[i]=Animator.StringToHash(tree.GetRecursiveBlendParam(i)); }else{ state.blendParamsHashes=null; } //property.value=state; property.ValueChanged(); property.ApplyModifiedValue (); animatorStateSelectedPrev = animatorStateSelected; } if (animatorStateSelected.motion == null) Debug.LogError ("Selected state doesn't have Motion set"); }