ActivateToolButton add_tool_button(Cockpit cockpit, string sName,
                                           float fHUDRadius, float dx, float dy,
                                           float fButtonRadius, toolInfo info)
        {
            ActivateToolButton button = new ActivateToolButton()
            {
                TargetScene = cockpit.Scene,
                ToolType    = info.identifier
            };

            button.CreateMeshIconButton(fButtonRadius, info.sMeshPath, defaultMaterial, info.fMeshScaleFudge);
            HUDUtil.PlaceInSphere(button, fHUDRadius, dx, dy);
            button.Name = sName;

            if (info.identifier == "cancel")
            {
                button.OnClicked += (s, e) => {
                    bool bIsSpatial = InputState.IsDevice(e.device, InputDevice.AnySpatialDevice);
                    int  nSide      = bIsSpatial ? (int)e.side : 1;
                    cockpit.Context.ToolManager.DeactivateTool((ToolSide)nSide);

                    // remove icon from hand
                    if (bIsSpatial)
                    {
                        cockpit.Context.SpatialController.ClearHandIcon(nSide);
                    }

                    // hide indicator
                    remove_indicator(nSide);
                };
            }
            else
            {
                button.OnClicked += (s, e) => {
                    bool bIsSpatial = InputState.IsDevice(e.device, InputDevice.AnySpatialDevice);
                    int  nSide      = bIsSpatial ? (int)e.side : 1;
                    remove_indicator(nSide);

                    cockpit.Context.ToolManager.SetActiveToolType(info.identifier, (ToolSide)nSide);
                    if (cockpit.Context.ToolManager.ActivateTool((ToolSide)nSide))
                    {
                        if (bIsSpatial)
                        {
                            Mesh iconmesh = Resources.Load <Mesh>(info.sMeshPath);
                            if (iconmesh != null)
                            {
                                cockpit.Context.SpatialController.SetHandIcon(iconmesh, nSide);
                            }
                        }

                        add_indicator(button, nSide);
                    }
                };
            }
            return(button);
        }
 void add_indicator(ActivateToolButton button, int nSide)
 {
     indicatorButton[nSide] = button;
     indicatorButton[nSide].StandardMaterial   = activeMaterial;
     indicator[nSide].transform.position       = Vector3.zero;
     indicator[nSide].transform.rotation       = Quaternion.identity;
     indicator[nSide].transform.localScale     = fIndicatorSize * Vector3.one;
     indicator[nSide].transform.localPosition +=
         fIndicatorShiftXY * (Vector3.up + Vector3.right * ((nSide == 0) ? -1 : 1)) - fIndicatorShiftZ * Vector3.forward;
     indicatorButton[nSide].AppendNewGO(indicator[nSide], button.RootGameObject, false);
     indicator[nSide].Show();
 }