Exemplo n.º 1
0
        //void ShowValueEvent(ValueListener Valuelistener, int i)
        //{

        //	EditorGUILayout.BeginHorizontal();

        //	drive.ValueEventsBools[i] = EditorGUILayout.BeginFoldoutHeaderGroup(drive.ValueEventsBools[i], "Positive Bounds");
        //	EditorGUILayout.EndFoldoutHeaderGroup();

        //	ShowRangeArea(ref valueEvent);

        //	if (ShowRemoveButton(valueEvent))
        //		return null;

        //	EditorGUILayout.EndHorizontal();

        //	if (drive.ValueEventsBools[i])
        //		ShowValueEvents(valueEvent.booleanAction);

        //	return valueEvent;
        //}

        //private void ShowValueEvents(BooleanAction booleanAction)
        //{
        //	var serializedAction = new SerializedObject(booleanAction);

        //	var activated = serializedAction.FindProperty("Activated");
        //	var valueChanged = serializedAction.FindProperty("ValueChanged");
        //	var deactivated = serializedAction.FindProperty("Deactivated");

        //	EditorGUILayout.PropertyField(activated);
        //	EditorGUILayout.PropertyField(valueChanged);
        //	EditorGUILayout.PropertyField(deactivated);

        //	serializedAction.ApplyModifiedProperties();
        //}

        //void ShowRangeArea(ref FloatRangeListener rangeListener)
        //{
        //	MyEditorTools.BeginHorizontal();

        //	FloatRange tempRange = rangeListener;

        //	tempRange.minimum = EditorGUILayout.FloatField(tempRange.minimum, EditorStyles.numberField, miniFeildWidth);

        //	EditorGUILayout.MinMaxSlider(ref tempRange.minimum, ref tempRange.maximum, 0, 1);

        //	tempRange.maximum = EditorGUILayout.FloatField(tempRange.maximum, EditorStyles.numberField, miniFeildWidth);

        //	if (tempRange.maximum > 1)
        //		tempRange.maximum = 1;

        //	valueEvent.floatToBoolean.SetActivationRange(tempRange);

        //	MyEditorTools.EndHorizontal();
        //}

        //bool ShowRemoveButton(ValueListener listener)
        //{
        //	if (GUILayout.Button("-", EditorStyles.miniButtonLeft, miniButtonWidth))
        //	{
        //		//RemoveMap(mapping);
        //		return true;
        //	}

        //	return false;
        //}
        private void OnSceneGUI()
        {
            drive = (DrivePort)target;

            if (drive.driveType == DrivePort.DriveTypes.Directional)
            {
                Vector3    center = drive.transform.position;
                Quaternion rot    = drive.transform.localRotation;

                dirHandle.axes = drive.axis;

                EditorGUI.BeginChangeCheck();

                driveBounds = new Bounds(drive.transform.position, drive.range);

                var newBounds = dirHandle.DrawHandle(drive.transform.position, rot, drive.range, drive.axis);

                if (!newBounds.Equals(driveBounds))
                {
                    Undo.RecordObject(drive, "Update Center and Range");
                    Undo.RecordObject(drive.transform, "Update Center and Range");
                    drive.transform.position =
                        drive.transform.localToWorldMatrix.MultiplyPoint3x4(newBounds.center);
                    drive.range = newBounds.size;
                }
            }
            else if (drive.driveType == DrivePort.DriveTypes.Rotational)
            {
                RotationalDriveHandle.QuanternionViewer(drive.transform.position, drive.transform.rotation, drive.targetIndex);
            }

            //RotationalDriveHandle.QuanternionViewer(drive.globalStart, drive.transform.rotation, Vector3.zero);
        }
        //public override void OnInspectorGUI()
        //{
        //	base.OnInspectorGUI();
        //	drive = (DriveInteractable)target;


        //}

        private void OnSceneGUI()
        {
            drive = (DriveInteractable)target;
            //SerializedProperty size = serializedObject.FindProperty("range");
            //rotHandle.Draw(20, drive.transform.position, drive.transform.rotation, drive.transform.up, .5f);
            if (drive.driveType == DriveInteractable.DriveTypes.Directional)
            {
                Vector3    center = Application.isPlaying ? drive.middlePos : drive.transform.position;
                Quaternion rot    = Application.isPlaying ? drive.middleRot : drive.transform.localRotation;
                //DirectionalDriveHandle.DrawRange(center, rot, drive.range);
                Vector3 glboalLocal = drive.transform.InverseTransformPoint(drive.globalStart);
                Vector3 localPos    = drive.transform.localPosition - glboalLocal;

                Handles.Label(center, $"({-glboalLocal.x},{-glboalLocal.y},{-glboalLocal.z})");

                dirHandle.axes = drive.axis;

                EditorGUI.BeginChangeCheck();

                dirHandle.DrawHandle(drive.globalStart, rot, drive.range, drive.axis);
                drive.range = dirHandle.liveBounds.size;
                //using (new Handles.DrawingScope(Matrix4x4.TRS(center, rot, Vector3.one)))
                //{
                //	box.size = drive.range / 2;
                //	box.DrawHandle();
                //	drive.range = box.size * 2;

                //}



//				drive.startMatrix = drive.transform.localToWorldMatrix;
//				drive.inStartMatrix = drive.transform.worldToLocalMatrix;

                //dirHandle.range = size.vector3Value * 2;
                //size.vector3Value = dirHandle.range / 2;
                if (EditorGUI.EndChangeCheck())
                {
                }
            }
            else if (drive.driveType == DriveInteractable.DriveTypes.Rotational)
            {
                RotationalDriveHandle.QuanternionViewer(drive.transform.position, drive.transform.rotation, drive.targetIndex);
            }

            //RotationalDriveHandle.QuanternionViewer(drive.globalStart, drive.transform.rotation, Vector3.zero);
        }