Пример #1
0
 ////////////////////////////////////////////////////////////////////////////////////////////////
 /*--------------------------------------------------------------------------------------------*/
 public void Awake()
 {
     if (Hoverkey == null)
     {
         Hoverkey = UnityUtil.FindNearbyComponent <HoverkeyInterface>(gameObject);
     }
 }
Пример #2
0
        /*--------------------------------------------------------------------------------------------*/
        private GameObject BuildRowItem(Transform pRowTx, HoverkeyBuilderKeyInfo pKeyInfo)
        {
            var itemGo = new GameObject(pKeyInfo.DefaultKey + "");

            itemGo.transform.SetParent(pRowTx, false);

            HoverItemBuilder build = itemGo.AddComponent <HoverItemBuilder>();

            build.ItemType             = pKeyInfo.ItemType;
            build.ButtonRendererPrefab = ButtonRendererPrefab;
            build.SliderRendererPrefab = SliderRendererPrefab;
            build.OnEditorTriggerButtonSelected();
            DestroyImmediate(build, false);

            ////

            HoverItemData data = itemGo.GetComponent <HoverItemData>();

            data.Id    = pKeyInfo.ID;
            data.Label = pKeyInfo.DefaultLabel;

            itemGo.AddComponent <HoverShapeRect>();

            HoverkeyItemLabels labels = itemGo.AddComponent <HoverkeyItemLabels>();

            labels.ActionType    = pKeyInfo.ActionType;
            labels.DefaultKey    = pKeyInfo.DefaultKey;
            labels.DefaultLabel  = pKeyInfo.DefaultLabel;
            labels.HasShiftLabel = pKeyInfo.HasShiftLabel;
            labels.ShiftLabel    = pKeyInfo.ShiftLabel;

            if (pKeyInfo.RelativeSizeX != 1)
            {
                HoverLayoutRectRelativeSizer sizer =
                    itemGo.AddComponent <HoverLayoutRectRelativeSizer>();
                sizer.RelativeSizeX = pKeyInfo.RelativeSizeX;
            }

            HoverCanvas can = itemGo.GetComponentInChildren <HoverCanvas>();

            can.Alignment = HoverCanvas.CanvasAlignmentType.Center;
            can.PaddingX  = 0.001f;

            ////

            HoverkeyInterface     inter        = gameObject.GetComponent <HoverkeyInterface>();
            HoverItemDataSelector selData      = (data as HoverItemDataSelector);
            HoverItemDataSticky   stickyData   = (data as HoverItemDataSticky);
            HoverItemDataCheckbox checkboxData = (data as HoverItemDataCheckbox);

            if (selData != null)
            {
#if UNITY_EDITOR
                UnityEditor.Events.UnityEventTools.AddPersistentListener(
                    selData.OnSelectedEvent, inter.HandleItemSelected);
#else
                selData.OnSelectedEvent.AddListener(inter.HandleItemSelected);
#endif
            }
            else if (stickyData != null)
            {
#if UNITY_EDITOR
                UnityEditor.Events.UnityEventTools.AddPersistentListener(
                    stickyData.OnSelectedEvent, inter.HandleItemSelected);
                UnityEditor.Events.UnityEventTools.AddPersistentListener(
                    stickyData.OnDeselectedEvent, inter.HandleItemDeselected);
#else
                stickyData.OnSelectedEvent.AddListener(inter.HandleItemSelected);
                stickyData.OnDeselectedEvent.AddListener(inter.HandleItemDeselected);
#endif
            }
            else if (checkboxData != null)
            {
#if UNITY_EDITOR
                UnityEditor.Events.UnityEventTools.AddPersistentListener(
                    checkboxData.OnSelectedEvent, inter.HandleItemSelected);
                UnityEditor.Events.UnityEventTools.AddPersistentListener(
                    checkboxData.OnValueChangedEvent, inter.HandleItemValueChanged);
#else
                checkboxData.OnSelectedEvent.AddListener(inter.HandleItemSelected);
                checkboxData.OnValueChangedEvent.AddListener(inter.HandleItemValueChanged);
#endif
            }

            return(itemGo);
        }