How to make handles in a line editor rotate by rot

2019-03-01 07:14发布

enter image description here

I have been trying to make the handles (from the nodes) in GoKit rotate by rotating the game object. Basically I added GoKit to my project and made a game object with the GoDummyPath script attached. I only used two nodes (or handles) to create a straight line. The image above shows what I want to achieve. From an original position A, I would want to rotate the game object to affect the positions of the handles (the line) to say B. The small circle represents the position of the game object.

I couldn't rotate the line by rotating the game object in the inspector, so I added the following code to the GoDummyPathEditor:

Two variables:

private Quaternion handleRotation;
private Transform handleTransform;

to OnEnable()

handleTransform = _target.transform;
    handleRotation = Tools.pivotRotation == PivotRotation.Local ?
        handleTransform.rotation : Quaternion.identity;

    for (var i = 0; i < _target.nodes.Count; i++)
        _target.nodes [i] = handleTransform.TransformPoint (_target.nodes [i]);

if( GUI.changed ) of OnInspectorGUI():

for (var i = 0; i < _target.nodes.Count; i++)
            _target.nodes [i] = handleTransform.InverseTransformPoint(_target.nodes [i]);

I replaced:

Handles.Label( _target.nodes[i] + new Vector3( 3f, 0, 1.5f ), i.ToString(), _indexStyle );

with:

_target.nodes[i] = Handles.DoPositionHandle(_target.nodes[i], handleRotation); 

The full changed GoDummyPathEditor

I still cannot move the handles. I don't know what I'm missing here. How can I rotate the handles by rotating the game object through the inspector rotation property?

0条回答
登录 后发表回答