예제 #1
0
    static public void DrawKeyFrame(Vector3 tPosition1, Vector3 tinTangent1, Vector3 toutTangent1, int j, AnimationCurve Curve1, AnimationCurve Curve2, AnimationCurve Curve3)
    {
        float handleSize = HandlesUtility.GetHandleSize(tPosition1);

        Handles.Label(tPosition1 + new Vector3(0.25f * handleSize, 0.0f * handleSize, 0.0f * handleSize), "key" + j.ToString());
        Vector3 nPosition    = HandlesUtility.PositionHandle(tPosition1, Quaternion.identity);
        Vector3 ninTangent1  = HandlesUtility.TangentHandle(tinTangent1 + tPosition1);
        Vector3 noutTangent1 = HandlesUtility.TangentHandle(toutTangent1 + tPosition1);

        //Handles.DrawLine(tPosition1, tinTangent1 + tPosition1);
        //Handles.Label(tinTangent1 + tPosition1 + new Vector3(0.25f * handleSize, 0.0f * handleSize, 0.0f * handleSize), "iT" + j.ToString());
        Handles.DrawLine(tPosition1, toutTangent1 + tPosition1);
        Handles.Label(toutTangent1 + tPosition1 + new Vector3(0.25f * handleSize, 0.0f * handleSize, 0.0f * handleSize), "oT" + j.ToString());

        Vector3 newTin1  = (ninTangent1 - tPosition1);
        Vector3 newTout1 = (noutTangent1 - tPosition1);

        if (tPosition1 != nPosition || ninTangent1 != newTin1 || noutTangent1 != newTout1)
        {
            Keyframe nkey1 = new Keyframe(Curve1.keys[j].time, nPosition.x, newTout1.x, newTout1.x);
            Curve1.MoveKey(j, nkey1);
            Keyframe nkey2 = new Keyframe(Curve2.keys[j].time, nPosition.y, newTout1.y, newTout1.y);
            Curve2.MoveKey(j, nkey2);
            Keyframe nkey3 = new Keyframe(Curve3.keys[j].time, nPosition.z, newTout1.z, newTout1.z);
            Curve3.MoveKey(j, nkey3);
        }
    }
예제 #2
0
        private void DrawBlock()
        {
            if (currentGridBlock == null)
            {
                return;
            }

            HandlesUtility.HandlesGUI
                (() => DrawBlock(currentGridBlock));
        }
예제 #3
0
    public void OnSceneGUI()
    {
        CinemaActorClipCurve clipCurveGameObject = (target as CinemaActorClipCurve);

        for (int i = 0; i < clipCurveGameObject.CurveData.Count; i++)
        {
            MemberClipCurveData data = clipCurveGameObject.CurveData[i];
            if (data.Type == "Transform" && data.PropertyName == "localPosition")
            {
                HandlesUtility.DrawCurvePath(data.Curve1, data.Curve2, data.Curve3);

                /* for (int j = 0; j < data.Curve1.keys.Length - 1; j++)
                 * {
                 *   //AnimationUtility.SetKeyLeftTangentMode(data.Curve1, j, AnimationUtility.TangentMode.Linear);
                 *   Keyframe key1x = data.Curve1.keys[j];
                 *   Keyframe key1y = data.Curve2.keys[j];
                 *   Keyframe key1z = data.Curve3.keys[j];
                 *   Keyframe key2x = data.Curve1.keys[j + 1];
                 *   Keyframe key2y = data.Curve2.keys[j + 1];
                 *   Keyframe key2z = data.Curve3.keys[j + 1];
                 *
                 *   Vector3 position = new Vector3(key1x.value, key1y.value, key1z.value);
                 *   Vector3 inTangent1 = new Vector3(key1x.inTangent, key1y.inTangent, key1z.inTangent);
                 *   Vector3 outTangent1 = new Vector3(key1x.outTangent, key1y.outTangent, key1z.outTangent);
                 *
                 *   Vector3 position2 = new Vector3(key2x.value, key2y.value, key2z.value);
                 *   Vector3 inTangent2 = new Vector3(key2x.inTangent, key2y.inTangent, key2z.inTangent);
                 *   Vector3 outTangent2 = new Vector3(key2x.outTangent, key2y.outTangent, key2z.outTangent);
                 *
                 *   float handleSize = HandlesUtility.GetHandleSize(position);
                 *   Handles.Label(position + new Vector3(0.25f * handleSize, 0.0f * handleSize, 0.0f * handleSize), j.ToString());
                 *
                 *   Vector3 nPosition = HandlesUtility.PositionHandle(position, Quaternion.identity);
                 *   if (position != nPosition)
                 *   {
                 *       Keyframe nkey1 = new Keyframe(data.Curve1.keys[j].time, nPosition.x);
                 *       data.Curve1.MoveKey(j, nkey1);
                 *       Keyframe nkey2 = new Keyframe(data.Curve2.keys[j].time, nPosition.y);
                 *       data.Curve2.MoveKey(j, nkey2);
                 *       Keyframe nkey3 = new Keyframe(data.Curve3.keys[j].time, nPosition.z);
                 *       data.Curve3.MoveKey(j, nkey3);
                 *   }
                 *   if (j == data.Curve1.length - 2)
                 *   {
                 *       Vector3 nPosition2 = HandlesUtility.PositionHandle(position2, Quaternion.identity);
                 *       float handleSize2 = HandlesUtility.GetHandleSize(position2);
                 *       Handles.Label(position2 + new Vector3(0.25f * handleSize2, 0.0f * handleSize2, 0.0f * handleSize2), (j+1).ToString());
                 *
                 *       if (position2 != nPosition2)
                 *       {
                 *           Keyframe nkey1 = new Keyframe(data.Curve1.keys[j+1].time, nPosition2.x);
                 *           data.Curve1.MoveKey(j + 1, nkey1);
                 *           Keyframe nkey2 = new Keyframe(data.Curve2.keys[j + 1].time, nPosition2.y);
                 *           data.Curve2.MoveKey(j + 1, nkey2);
                 *           Keyframe nkey3 = new Keyframe(data.Curve3.keys[j + 1].time, nPosition2.z);
                 *           data.Curve3.MoveKey(j + 1, nkey3);
                 *       }
                 *   }
                 *
                 *   Vector3 ninTangent1 = HandlesUtility.TangentHandle(inTangent1 + position);
                 *   if (inTangent1 != ninTangent1)
                 *   {
                 *       Keyframe ok1= data.Curve1.keys[j];
                 *       Keyframe nkey1 = new Keyframe(ok1.time, ok1.value, ninTangent1.x - ok1.value, ok1.outTangent);
                 *       data.Curve1.MoveKey(j, nkey1);
                 *       Keyframe ok2 = data.Curve2.keys[j];
                 *       Keyframe nkey2 = new Keyframe(ok2.time, ok2.value, ninTangent1.y - ok2.value, ok2.outTangent);
                 *       data.Curve2.MoveKey(j, nkey2);
                 *       Keyframe ok3 = data.Curve3.keys[j];
                 *       Keyframe nkey3 = new Keyframe(ok3.time, ok3.value, ninTangent1.z - ok3.value, ok3.outTangent);
                 *       data.Curve3.MoveKey(j, nkey3);
                 *   }
                 *
                 *   float time1 = data.Curve1.keys[j].time;
                 *   float time2 = data.Curve1.keys[j +1].time;
                 *   int N = 20;
                 *   float gap = (time2 - time1) / N;
                 *
                 *   for (float t = time1; t < time2; t += gap)
                 *   {
                 *       Vector3 dposition = new Vector3(data.Curve1.Evaluate(t), data.Curve2.Evaluate(t), data.Curve3.Evaluate(t));
                 *       Vector3 dposition2 = new Vector3(data.Curve1.Evaluate(t + gap), data.Curve2.Evaluate(t + gap), data.Curve3.Evaluate(t + gap));
                 *       Handles.color = Color.red;
                 *       Handles.DrawLine(dposition, dposition2);
                 *       Handles.color = Color.white;
                 *   }
                 *
                 * }*/
            }
        }
    }
예제 #4
0
    private void OnSceneGUI(SceneView obj)
    {
        if (m_sceneProxy == null || m_storyboardData == null)
        {
            return;
        }

        if (Event.current.type == EventType.Repaint)
        {
            Color outerBoundsColor = Color.blue;
            Color proxyColor       = Color.red;
            Color outline          = Color.white;
            outerBoundsColor.a = 0.2f;
            proxyColor.a       = 0.2f;

            if (m_visualizeProxyBoundaries)
            {
                HandlesUtility.DrawCubeOutlined(m_sceneProxy.transform.position, m_proxyBounds, outerBoundsColor, outline);
            }

            if (m_visualizeProxyCollisions)
            {
                if (m_storyboardData.m_proxySets.Count > 0)
                {
                    for (int i = 0; i < m_storyboardData.m_proxySets[m_proxySetToDraw].m_proxies.Count; i++)
                    {
                        Proxy proxy = m_storyboardData.m_proxySets[m_proxySetToDraw].m_proxies[i];

                        if (proxy.m_collider == null)
                        {
                            continue;
                        }


                        if (proxy.m_collider.GetType() == typeof(BoxCollider))
                        {
                            BoxCollider bc = proxy.m_collider.transform.GetComponent <BoxCollider>();
                            Handles.matrix = Matrix4x4.TRS(proxy.m_collider.transform.TransformPoint(bc.center), proxy.m_collider.transform.rotation, proxy.m_collider.transform.lossyScale);
                            HandlesUtility.DrawCubeOutlined(Vector3.zero, bc.size, proxyColor, outline);
                        }
                        else if (proxy.m_collider.GetType() == typeof(SphereCollider))
                        {
                            SphereCollider cc = proxy.m_collider.transform.GetComponent <SphereCollider>();
                            Handles.color  = proxyColor;
                            Handles.matrix = Matrix4x4.TRS(proxy.m_collider.transform.TransformPoint(cc.center), proxy.m_collider.transform.rotation, Vector3.one);
                            //  Handles.matrix = Matrix4x4.identity;
                            Handles.SphereHandleCap(0, Vector3.zero, Quaternion.identity, cc.radius * proxy.m_collider.transform.localScale.MaxComponent() * 2, EventType.Repaint);
                        }
                        else if (proxy.m_collider.GetType() == typeof(CapsuleCollider))
                        {
                            CapsuleCollider cc = proxy.m_collider.transform.GetComponent <CapsuleCollider>();
                            Handles.color  = proxyColor;
                            Handles.matrix = Matrix4x4.TRS(proxy.m_collider.transform.TransformPoint(cc.center), proxy.m_collider.transform.rotation, proxy.m_collider.transform.lossyScale);
                            HandlesUtility.DrawCubeOutlined(Vector3.zero, new Vector3(1, cc.height, 1), proxyColor, outline);
                        }
                        else if (proxy.m_collider.GetType() == typeof(MeshCollider))
                        {
                            // TODO
                        }
                        else if (proxy.m_collider.GetType() == typeof(TerrainCollider))
                        {
                            // TOOD
                        }
                    }
                }
            }
        }
    }
예제 #5
0
        public void OnSceneGUI()
        {
            if (ObjectPathTimeline == null || ObjectPathTimeline.Keyframes == null)
            {
                return;
            }

            if (SelectedNodeIndex >= 0)
            {
                if (Event.current.isKey && (Event.current.keyCode == KeyCode.Delete || Event.current.keyCode == KeyCode.Backspace))
                {
                    USUndoManager.RegisterCompleteObjectUndo(this, "Remove Keyframe");
                    USUndoManager.RegisterCompleteObjectUndo(ObjectPathTimeline, "Remove Keyframe");

                    Event.current.Use();
                    RemoveKeyframeAtIndex(SelectedNodeIndex);
                    SelectedNodeIndex = -1;
                }
            }

            if (Event.current.type == EventType.MouseDown)
            {
                var nearestIndex = GetNearestNodeForMousePosition(Event.current.mousePosition);

                if (nearestIndex != -1)
                {
                    SelectedNodeIndex = nearestIndex;

                    if (Event.current.clickCount > 1)
                    {
                        USUndoManager.PropertyChange(ObjectPathTimeline, "Add Keyframe");

                        var cameraTransform = SceneView.currentDrawingSceneView.camera.transform;

                        var keyframe     = GetKeyframeAtIndex(SelectedNodeIndex);
                        var nextKeyframe = GetKeyframeAtIndex(SelectedNodeIndex + 1);

                        var newKeyframePosition = Vector3.zero;
                        if (keyframe == null)
                        {
                            newKeyframePosition = cameraTransform.position + (cameraTransform.forward * 1.0f);
                        }
                        else
                        {
                            if (SelectedNodeIndex == ObjectPathTimeline.Keyframes.Count - 1)
                            {
                                newKeyframePosition = keyframe.Position + (cameraTransform.up * Vector3.Magnitude(keyframe.Position - cameraTransform.position) * 0.1f);
                            }
                            else
                            {
                                var directionVector = nextKeyframe.Position - keyframe.Position;
                                var halfDistance    = Vector3.Magnitude(directionVector) * 0.5f;
                                directionVector.Normalize();
                                newKeyframePosition = keyframe.Position + (directionVector * halfDistance);
                            }
                        }

                        var translatedKeyframe = CreateInstance <SplineKeyframe>();
                        USUndoManager.RegisterCreatedObjectUndo(translatedKeyframe, "Add Keyframe");
                        translatedKeyframe.Position = newKeyframePosition;

                        ObjectPathTimeline.AddAfterKeyframe(translatedKeyframe, SelectedNodeIndex);
                        GUI.changed = true;
                    }
                }
            }

            if (Vector3.Distance(ObjectPathTimeline.Keyframes[0].Position, ObjectPathTimeline.Keyframes[ObjectPathTimeline.Keyframes.Count - 1].Position) == 0)
            {
                Handles.Label(ObjectPathTimeline.Keyframes[0].Position, "Start and End");
            }
            else
            {
                Handles.Label(ObjectPathTimeline.Keyframes[0].Position, "Start");
                Handles.Label(ObjectPathTimeline.Keyframes[ObjectPathTimeline.Keyframes.Count - 1].Position, "End");
            }

            for (var nodeIndex = 0; nodeIndex < ObjectPathTimeline.Keyframes.Count; nodeIndex++)
            {
                var node = ObjectPathTimeline.Keyframes[nodeIndex];

                if (node && nodeIndex > 0 && nodeIndex < ObjectPathTimeline.Keyframes.Count - 1)
                {
                    var handleSize = HandlesUtility.GetHandleSize(node.Position);
                    Handles.Label(node.Position + new Vector3(0.25f * handleSize, 0.0f * handleSize, 0.0f * handleSize), nodeIndex.ToString());
                }

                using (new HandlesChangeColor(ObjectPathTimeline.PathColor))
                {
                    USUndoManager.BeginChangeCheck();

                    var existingKeyframe = ObjectPathTimeline.Keyframes[nodeIndex];
                    var newPosition      = HandlesUtility.PositionHandle(existingKeyframe.Position, Quaternion.identity);

                    if (USUndoManager.EndChangeCheck())
                    {
                        USUndoManager.PropertyChange(ObjectPathTimeline, "Modify Keyframe");

                        foreach (var keyframe in ObjectPathTimeline.Keyframes)
                        {
                            USUndoManager.PropertyChange(keyframe, "Modify Keyframe");
                        }

                        ObjectPathTimeline.AlterKeyframe(newPosition, nodeIndex);
                        EditorUtility.SetDirty(ObjectPathTimeline);
                    }
                }
            }
        }