Exemplo n.º 1
0
        internal void Update(BoundsControlRotationHandles rotationHandles, Transform parent, Vector3 currentBoundsExtents)
        {
            for (int i = 0; i < BoundsControlRotationHandles.NumEdges; ++i)
            {
                if (links != null)
                {
                    links[i].position = rotationHandles.GetEdgeCenter(i);

                    Vector3 rootScale    = parent.lossyScale;
                    Vector3 invRootScale = new Vector3(1.0f / rootScale[0], 1.0f / rootScale[1], 1.0f / rootScale[2]);
                    // Compute the local scale that produces the desired world space dimensions
                    Vector3 linkDimensions = Vector3.Scale(GetLinkDimensions(currentBoundsExtents), invRootScale);

                    if (rotationHandles.GetAxisType(i) == CardinalAxisType.X)
                    {
                        links[i].localScale = new Vector3(wireframeEdgeRadius, linkDimensions.x, wireframeEdgeRadius);
                    }
                    else if (rotationHandles.GetAxisType(i) == CardinalAxisType.Y)
                    {
                        links[i].localScale = new Vector3(wireframeEdgeRadius, linkDimensions.y, wireframeEdgeRadius);
                    }
                    else//Z
                    {
                        links[i].localScale = new Vector3(wireframeEdgeRadius, linkDimensions.z, wireframeEdgeRadius);
                    }
                }
            }
        }
Exemplo n.º 2
0
        internal void CreateLinks(BoundsControlRotationHandles rotationHandles, Transform parent, Vector3 currentBoundsExtents)
        {
            // ensure materials exist
            SetMaterials();

            // create links
            if (links != null)
            {
                GameObject link;
                Vector3    linkDimensions = GetLinkDimensions(currentBoundsExtents);
                for (int i = 0; i < BoundsControlRotationHandles.NumEdges; ++i)
                {
                    if (wireframeShape == WireframeType.Cubic)
                    {
                        link = GameObject.CreatePrimitive(PrimitiveType.Cube);
                        GameObject.Destroy(link.GetComponent <BoxCollider>());
                    }
                    else
                    {
                        link = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
                        GameObject.Destroy(link.GetComponent <CapsuleCollider>());
                    }
                    link.name = "link_" + i.ToString();


                    if (rotationHandles.GetAxisType(i) == CardinalAxisType.Y)
                    {
                        link.transform.localScale = new Vector3(wireframeEdgeRadius, linkDimensions.y, wireframeEdgeRadius);
                        link.transform.Rotate(new Vector3(0.0f, 90.0f, 0.0f));
                    }
                    else if (rotationHandles.GetAxisType(i) == CardinalAxisType.Z)
                    {
                        link.transform.localScale = new Vector3(wireframeEdgeRadius, linkDimensions.z, wireframeEdgeRadius);
                        link.transform.Rotate(new Vector3(90.0f, 0.0f, 0.0f));
                    }
                    else//X
                    {
                        link.transform.localScale = new Vector3(wireframeEdgeRadius, linkDimensions.x, wireframeEdgeRadius);
                        link.transform.Rotate(new Vector3(0.0f, 0.0f, 90.0f));
                    }

                    link.transform.position = rotationHandles.GetEdgeCenter(i);
                    link.transform.parent   = parent;
                    Renderer linkRenderer = link.GetComponent <Renderer>();
                    linkRenderers.Add(linkRenderer);

                    if (wireframeMaterial != null)
                    {
                        linkRenderer.material = wireframeMaterial;
                    }

                    links.Add(link.transform);
                }
            }
        }