Search Unity

Can not use the AxisState with AxisStateProperty in my custom code.

Discussion in 'Cinemachine' started by watsonsong, Mar 13, 2018.

  1. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I want to use AxisState as the Z axis input for camera distance, as the free look camera does not supply.
    When I add the AxisStateProperty tag to the AxisState SerializeField, the error as follow is report:

    Cinemachine.Editor.AxisStatePropertyDrawer.ValueRangeIsLocked (UnityEditor.SerializedProperty property) (at C:/ProgramData/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.1.12/Editor/PropertyDrawers/AxisStatePropertyDrawer.cs:72)
    Cinemachine.Editor.AxisStatePropertyDrawer.GetPropertyHeight (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at C:/ProgramData/Unity/cache/packages/packages.unity.com/com.unity.cinemachine@2.1.12/Editor/PropertyDrawers/AxisStatePropertyDrawer.cs:62)
    UnityEditor.PropertyDrawer.GetPropertyHeightSafe (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at C:/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyDrawer.cs:36)
    UnityEditor.PropertyHandler.GetHeight (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label, System.Boolean includeChildren) (at C:/buildslave/unity/build/Editor/Mono/ScriptAttributeGUI/PropertyHandler.cs:216)
    ...


    This happened in the AxisStatePropertyDrawer class and GetPropertyHeight method, which use reflect to find a property:

    bool ValueRangeIsLocked(SerializedProperty property)
    {
    bool locked = false;
    PropertyInfo pi = typeof(AxisState).GetProperty(
    "ValueRangeLocked", BindingFlags.NonPublic | BindingFlags.Instance);
    if (pi != null)
    locked = bool.Equals(true, pi.GetValue(SerializedPropertyHelper.GetPropertyValue(property), null));
    return locked;
    }


    BTW, could the free look camera support a input to control the camera distance. So I can use the mouse wheel or the guesture on mobile phone the control the camera distance to the target.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I tried it with an empty project and the following test and got no errors. Could it be that you have a naming conflict in your project, possibly SerializedPropertyHelper?

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using Cinemachine;
    4.  
    5. public class AxisTest : MonoBehaviour
    6. {
    7.     [AxisStateProperty]
    8.     public AxisState m_VerticalAxis = new AxisState(-90, 90, false, false, 300f, 0.1f, 0.1f, "Mouse Y", true);
    9.  
    10.     // Use this for initialization
    11.     void Start () {
    12.      
    13.     }
    14.  
    15.     // Update is called once per frame
    16.     void Update () {
    17.      
    18.     }
    19. }
    upload_2018-3-13_10-25-40.png
     
    Last edited: Mar 13, 2018
  3. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I am using the Unity2018.1beta10, and I reference the Cinemachine by the PackageManager.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Yes that is what I did too.