Esempio n. 1
0
        private void CopyCreateMenu(UIToggle aCopyToggle)
        {
            if(m_ToggleParams != null && aCopyToggle != null)
            {
                DebugUtils.Log(aCopyToggle.uiType);
                switch(aCopyToggle.uiType)
                {

                    case UIType.IMAGE:
                        {
                            UIImageParams imageParams = new UIImageParams();
                            m_ToggleParams = imageParams;
                            m_ToggleParams.isSelectable = aCopyToggle.selectable;
                            m_ToggleParams.recieveActions = aCopyToggle.receivesActionEvents;
                            m_ToggleParams.uiSpace = aCopyToggle.uiSpace;
                            m_ToggleParams.uiType = aCopyToggle.uiType;

                            UIImage image = aCopyToggle.GetComponentInChildren<UIImage>();
                            if(image != null)
                            {
                                imageParams.color = image.color;
                                imageParams.height = image.height;
                                imageParams.width = image.width;
                                imageParams.meshBoarder = image.meshBoarder;
                                imageParams.innerUVBoarder = image.innerUVBoarder;
                                imageParams.outerUVBoarder = image.innerUVBoarder;
                                imageParams.shader = image.shader;
                                imageParams.texture = image.texture;
                            }
                            else
                            {
                                DebugUtils.LogError(MISSING_IMAGE);
                            }
                        }
                        break;
                    case UIType.LABEL:
                        {
                            UILabelParams labelParams = new UILabelParams();
                            m_ToggleParams = labelParams;
                            m_ToggleParams.isSelectable = aCopyToggle.selectable;
                            m_ToggleParams.recieveActions = aCopyToggle.receivesActionEvents;
                            m_ToggleParams.uiSpace = aCopyToggle.uiSpace;
                            m_ToggleParams.uiType = aCopyToggle.uiType;

                            UILabel label = aCopyToggle.GetComponentInChildren<UILabel>();
                            if (label != null)
                            {
                                labelParams.color = label.color;
                                labelParams.font = label.font;
                                labelParams.fontSize = label.fontSize;
                                labelParams.fontTexture = label.fontTexture;
                                labelParams.text = label.text;
                            }
                            else
                            {
                                DebugUtils.LogError(MISSING_LABEL);
                            }
                        }
                        break;
                    case UIType.BUTTON:
                        {
                            DebugUtils.Log("Create Button");
                            UIButtonParams buttonParams = new UIButtonParams();
                            m_ToggleParams = buttonParams;
                            m_ToggleParams.isSelectable = aCopyToggle.selectable;
                            m_ToggleParams.recieveActions = aCopyToggle.receivesActionEvents;
                            m_ToggleParams.uiSpace = aCopyToggle.uiSpace;
                            m_ToggleParams.uiType = aCopyToggle.uiType;

                            UIButton button = aCopyToggle.GetComponentInChildren<UIButton>();
                            if (button == null)
                            {
                                DebugUtils.LogError(MISSING_BUTTON);
                                break;
                            }
                            buttonParams.disabled = button.buttonState == UIButtonState.DISABLED;
                            buttonParams.disabledTexture = button.disabledTexture;
                            buttonParams.normalTexture = button.normalTexture;
                            buttonParams.hoverTexture = button.hoverTexture;
                            buttonParams.downTexture = button.downTexture;
                            buttonParams.enabledTextColor = button.enabledTextColor;
                            buttonParams.disabledTextColor = button.disabledTextColor;
                            buttonParams.eventListener = button.eventListener;

                            UILabel label = button.GetComponentInChildren<UILabel>();
                            if (label == null)
                            {
                                DebugUtils.LogError(MISSING_LABEL);
                            }
                            else
                            {
                                buttonParams.labelColor = label.color;
                                buttonParams.labelFont = label.font;
                                buttonParams.labelFontSize = label.fontSize;
                                buttonParams.labelFontTexture = label.fontTexture;
                                buttonParams.labelText = label.text;
                            }
                            UIImage image = button.GetComponentInChildren<UIImage>();
                            if (image == null)
                            {
                                DebugUtils.LogError(MISSING_IMAGE);
                            }
                            else
                            {
                                buttonParams.imageColor = image.color;
                                buttonParams.imageHeight = image.height;
                                buttonParams.imageWidth = image.width;
                                buttonParams.imageMeshBoarder = image.meshBoarder;
                                buttonParams.imageInnerUVBoarder = image.innerUVBoarder;
                                buttonParams.imageOuterUVBoarder = image.outerUVBoarder;
                                buttonParams.imageShader = image.shader;
                                buttonParams.imageTexture = image.texture;
                            }
                        }
                        break;
                    case UIType.TEXTFIELD:
                        {
                            UITextfieldParams textfieldParams = new UITextfieldParams();
                            m_ToggleParams = textfieldParams;
                            m_ToggleParams.isSelectable = aCopyToggle.selectable;
                            m_ToggleParams.recieveActions = aCopyToggle.receivesActionEvents;
                            m_ToggleParams.uiSpace = aCopyToggle.uiSpace;
                            m_ToggleParams.uiType = aCopyToggle.uiType;

                            UITextfield textfield = aCopyToggle.GetComponentInChildren<UITextfield>();
                            if (textfield == null)
                            {
                                DebugUtils.LogError(MISSING_TEXTFIELD);
                                break;
                            }
                            textfieldParams.disabled = textfield.buttonState == UIButtonState.DISABLED;
                            textfieldParams.disabledTexture = textfield.disabledTexture;
                            textfieldParams.normalTexture = textfield.normalTexture;
                            textfieldParams.hoverTexture = textfield.hoverTexture;
                            textfieldParams.downTexture = textfield.downTexture;
                            textfieldParams.enabledTextColor = textfield.enabledTextColor;
                            textfieldParams.disabledTextColor = textfield.disabledTextColor;
                            textfieldParams.eventListener = textfield.eventListener;
                            textfieldParams.maxCharacter = textfield.maxCharacter;

                            UILabel label = textfield.GetComponentInChildren<UILabel>();
                            if (label == null)
                            {
                                DebugUtils.LogError(MISSING_LABEL);
                            }
                            else
                            {
                                textfieldParams.labelColor = label.color;
                                textfieldParams.labelFont = label.font;
                                textfieldParams.labelFontSize = label.fontSize;
                                textfieldParams.labelFontTexture = label.fontTexture;
                                textfieldParams.labelText = label.text;
                            }
                            UIImage image = textfield.GetComponentInChildren<UIImage>();
                            if (image == null)
                            {
                                DebugUtils.LogError(MISSING_IMAGE);
                            }
                            else
                            {
                                textfieldParams.imageColor = image.color;
                                textfieldParams.imageHeight = image.height;
                                textfieldParams.imageWidth = image.width;
                                textfieldParams.imageMeshBoarder = image.meshBoarder;
                                textfieldParams.imageInnerUVBoarder = image.innerUVBoarder;
                                textfieldParams.imageOuterUVBoarder = image.outerUVBoarder;
                                textfieldParams.imageShader = image.shader;
                                textfieldParams.imageTexture = image.texture;
                            }
                        }
                        break;
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Creates the UI Label prefab using the toggle as the root.
 /// </summary>
 /// <param name="aParams">The parameters for creating</param>
 /// <param name="aToggle">The toggle to create</param>
 /// <returns></returns>
 public static UILabel CreateUILabel(UILabelParams aParams, UIToggle aToggle)
 {
     if(aParams == null || aToggle == null)
     {
         return null;
     }
     GameObject rootGameObject = aToggle.gameObject;
     GameObject labelGameObject = new GameObject(aParams.name + LABEL_POST_FIX);
     labelGameObject.transform.position = Vector3.zero;
     labelGameObject.transform.rotation = Quaternion.identity;
     labelGameObject.transform.parent = rootGameObject.transform;
     labelGameObject.layer = rootGameObject.layer;
     labelGameObject.AddComponent<MeshRenderer>();
     labelGameObject.AddComponent<TextMesh>();
     UILabel uiLabel = labelGameObject.AddComponent<UILabel>();
     uiLabel.text = aParams.text;
     uiLabel.fontSize = aParams.fontSize;
     uiLabel.font = aParams.font;
     uiLabel.color = aParams.color;
     uiLabel.fontTexture = aParams.fontTexture;
     uiLabel.UpdateComponents();
     #if UNITY_EDITOR
     UnityEditor.EditorUtility.SetDirty(uiLabel);
     #endif
     return uiLabel;
 }