Пример #1
0
        public void Subscribe(string topic, GameObject parent)
        {
            if (!this.attachables.ContainsKey(topic))
            {
                Debug.Log($"Subscribing {parent.name} to topic {topic}");

                var visuals = parent.transform.Find("Visuals");
                if (visuals != null)
                {
                    var c = visuals.GetComponentsInChildren <Renderer>();
                    parent = c[0].gameObject;
                }
                ;

                // modify the parent's interactability (collision with the pointer)
                parent.GetComponent <Renderer>().material = activeMaterial;
                NearInteractionTouchable touchable = parent.AddComponent <NearInteractionTouchable>();
                BoxCollider collider = parent.AddComponent <BoxCollider>();
                touchable.SetTouchableCollider(collider);

                // instanciate an interactable that processes all kinds of events to the respective function.
                Interactable    interactable = attachInteractible(topic, parent);
                PressableButton button       = parent.AddComponent <PressableButton>();

                // route physical presses to the interactable
                PhysicalPressEventRouter physicalEvents = parent.AddComponent <PhysicalPressEventRouter>();
                physicalEvents.routingTarget = interactable;

                // create the 3d component
                GameObject attachable = Instantiate <GameObject>(this.externalPlotPrefab);

                ToolTipController toolTipController = attachable.GetComponent <ToolTipController>();
                toolTipController.Topic = topic;
                var texture = attachable.AddComponent <TextureProvider>();
                texture.InitRosSource(topic, toolTipController.ImageRenderer);
                ExternalPlot eplot = attachable.GetComponent <ExternalPlot>();
                eplot.ToolTipText = topic;
                eplot.FontSize    = 20;

                ExternalPlotConnector con = attachable.GetComponent <ExternalPlotConnector>();
                con.Target = parent;
                attachable.transform.SetParent(this.attachablesRoot.transform);

                Vector3 offset = new Vector3(0.0f, 0.1f, 0.0f);
                attachable.transform.position = parent.transform.position + offset;

                // create the reference object
                AttachableReference aref;
                aref.attachable = attachable;
                aref.parent     = parent;
                aref.active     = true;
                aref.following  = false;

                this.attachables.Add(topic, aref);
            }
            else
            {
                this.Show(topic);
            }
        }