Пример #1
0
    private void Awake()
    {
        _currentPosition  = Position.Idle;
        _previousPosition = Position.Idle;

        _anglePositions = GetComponent <AnglePositions>();
        _lever          = GetComponent <BNG.Lever>();
        _alreadyWaiting = false;
    }
Пример #2
0
        public override void OnInspectorGUI()
        {
            Lever lever = (Lever)target;

            float initialMin = lever.MinimumXRotation;
            float initialMax = lever.MaximumXRotation;

            GUILayout.Label("Min / Max Angle Settings ", EditorStyles.boldLabel);

            EditorGUILayout.PropertyField(minimumXRotation);
            EditorGUILayout.PropertyField(maximumXRotation);

            GUILayout.BeginHorizontal();

            EditorGUILayout.MinMaxSlider(ref lever.MinimumXRotation, ref lever.MaximumXRotation, -180, 180);

            GUILayout.EndHorizontal();

            GUILayout.Label("Starting Value", EditorStyles.boldLabel);
            EditorGUILayout.Slider(serializedObject.FindProperty("InitialXRotation"), lever.MinimumXRotation, lever.MaximumXRotation);

            EditorGUILayout.PropertyField(serializedObject.FindProperty("SwitchTolerance"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("SwitchOnSound"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("SwitchOffSound"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("UseSmoothLook"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("SmoothLookSpeed"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("AllowPhysicsForces"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ReturnToCenter"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ReturnLookSpeed"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("SnapToGrabber"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("DropLeverOnActivation"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("LeverPercentage"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ShowEditorGizmos"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("onLeverDown"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("onLeverUp"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("onLeverChange"));

            serializedObject.ApplyModifiedProperties();

            if (!Application.isPlaying)
            {
                // Make Sure initial x rotation is within range
                if (lever.InitialXRotation < lever.MinimumXRotation)
                {
                    lever.InitialXRotation = lever.MinimumXRotation;
                }
                else if (lever.InitialXRotation > lever.MaximumXRotation)
                {
                    lever.InitialXRotation = lever.MaximumXRotation;
                }
            }

            bool hingeChanged = lever.MinimumXRotation != initialMin || lever.MaximumXRotation != initialMax;

            if (hingeChanged)
            {
                // Update hingeJoint if it's available
                HingeJoint hinge = lever.GetComponent <HingeJoint>();
                if (hinge != null)
                {
                    JointLimits jl = hinge.limits;
                    jl.min       = lever.MinimumXRotation;
                    jl.max       = lever.MaximumXRotation;
                    hinge.limits = jl;
                }
            }
            else
            {
                // Check that the hinge wasn't changed
                HingeJoint hinge = lever.GetComponent <HingeJoint>();
                if (hinge != null)
                {
                    JointLimits jl = hinge.limits;
                    if (lever.MinimumXRotation != jl.min)
                    {
                        lever.MinimumXRotation = jl.min;
                    }
                    if (lever.MaximumXRotation != jl.max)
                    {
                        lever.MaximumXRotation = jl.max;
                    }
                }
            }
        }
 private void Awake()
 {
     _lever = GetComponent <BNG.Lever>();
 }