private void Awake()
        {
            if (targetObject == null)
            {
                targetObject = gameObject;
            }

            // ensure we have a default configuration in case there's none set by the user
            scaleHandlesConfiguration          = EnsureScriptable(scaleHandlesConfiguration);
            rotationHandlesConfiguration       = EnsureScriptable(rotationHandlesConfiguration);
            boxDisplayConfiguration            = EnsureScriptable(boxDisplayConfiguration);
            linksConfiguration                 = EnsureScriptable(linksConfiguration);
            handleProximityEffectConfiguration = EnsureScriptable(handleProximityEffectConfiguration);

            // instantiate runtime classes for visuals
            scaleHandles    = new ScaleHandles(scaleHandlesConfiguration);
            rotationHandles = new RotationHandles(rotationHandlesConfiguration);
            boxDisplay      = new BoxDisplay(boxDisplayConfiguration);
            links           = new Links(linksConfiguration);
            proximityEffect = new ProximityEffect(handleProximityEffectConfiguration);

            // subscribe to visual changes
            scaleHandlesConfiguration.configurationChanged.AddListener(CreateRig);
            scaleHandlesConfiguration.visibilityChanged.AddListener(ResetVisuals);
            rotationHandlesConfiguration.configurationChanged.AddListener(CreateRig);
            boxDisplayConfiguration.configurationChanged.AddListener(CreateRig);
            linksConfiguration.configurationChanged.AddListener(CreateRig);
        }
Esempio n. 2
0
        internal void CreateLinks(RotationHandles rotationHandles, Transform parent, Vector3 currentBoundsExtents)
        {
            // create links
            if (links != null)
            {
                GameObject link;
                Vector3    linkDimensions = GetLinkDimensions(currentBoundsExtents);
                for (int i = 0; i < RotationHandles.NumEdges; ++i)
                {
                    if (config.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();

                    CardinalAxisType axisType            = rotationHandles.GetAxisType(i);
                    float            wireframeEdgeRadius = config.WireframeEdgeRadius;
                    if (axisType == CardinalAxisType.Y)
                    {
                        link.transform.localScale = new Vector3(wireframeEdgeRadius, linkDimensions.y, wireframeEdgeRadius);
                        link.transform.Rotate(new Vector3(0.0f, 90.0f, 0.0f));
                    }
                    else if (axisType == 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 (config.WireframeMaterial != null)
                    {
                        linkRenderer.material = config.WireframeMaterial;
                    }

                    links.Add(new Link(link.transform, axisType));
                }
            }
        }