Inheritance: UnityEngine.PropertyAttribute
        private GUIContent[] GetFromComponent(SerializedProperty property, AnimParamsAttribute animParams, out int selectedIndex)
        {
            selectedIndex = -1;
            SerializedProperty animProp = property.serializedObject.FindProperty(animParams.animPath);
            if (animProp == null)
                return null;

            Animator targetAnim = animProp.objectReferenceValue as Animator;
            if (targetAnim == null)
                return null;

            string propVal = property.stringValue;
            return BuildParamList(targetAnim.parameters, propVal, out selectedIndex);
        }
Example #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Reject drawing this custom attribute if property wasn't a string type
            if (property.propertyType != SerializedPropertyType.String)
            {
                base.OnGUI(position, property, label);
                return;
            }

            AnimParamsAttribute animParams = (AnimParamsAttribute)attribute;

            SerializedProperty animProp = property.serializedObject.FindProperty(animParams.animatorProp);

            if (animProp == null)
            {
                base.OnGUI(position, property, label);
                return;
            }

            Animator targetAnim = animProp.objectReferenceValue as Animator;

            if (targetAnim == null)
            {
                base.OnGUI(position, property, label);
                return;
            }

            string propVal = property.stringValue;
            int    selectedIndex;

            GUIContent[] popup = BuildParamList(targetAnim, propVal, out selectedIndex);

            selectedIndex = EditorGUI.Popup(position, label, selectedIndex, popup);
            if (selectedIndex < popup.Length && selectedIndex > -1)
            {
                propVal = popup[selectedIndex].text;
            }
            else
            {
                propVal = "";
            }

            if (propVal.Equals(property.stringValue) == false)
            {
                property.stringValue = propVal;
                EditorUtility.SetDirty(property.serializedObject.targetObject);
            }
        }
        private GUIContent[] GetFromInstanceId(SerializedProperty property,
											AnimParamsAttribute animParams,
											out int selectedIndex)
        {
            selectedIndex = -1;

            SerializedProperty animParamCfgProp = property.serializedObject.FindProperty(animParams.animPath);
            if (animParamCfgProp == null)
                return null;

            SerializedProperty refPath = animParamCfgProp.FindPropertyRelative("instanceId");

            if (refPath == null)
                return null;

            AnimatorControllerParameter[] paramList = null;
            int targetId;

            // Try to get the instance id out of the path property
            if (int.TryParse(refPath.stringValue, out targetId))
            {
                AnimatorController targetController = EditorUtility.InstanceIDToObject(targetId) as AnimatorController;
                if (targetController != null)
                    paramList = targetController.parameters;
            }

            // If we got a parameter list, return the built list
            if (paramList != null)
                return BuildParamList(paramList, property.stringValue, out selectedIndex);

            // No list, just return null
            return null;
        }