Exemplo 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;
                }
            }
        }
Exemplo n.º 2
0
        public static UIButton CreateUIButton(UIButtonParams aParams, UIToggle aToggle)
        {
            if(aParams == null || aToggle == null)
            {
                return null;
            }
            GameObject rootGameObject = aToggle.gameObject;
            GameObject buttonGameObject = new GameObject(aParams.name + BUTTON_POST_FIX);
            buttonGameObject.transform.position = Vector3.zero;
            buttonGameObject.transform.rotation = Quaternion.identity;
            buttonGameObject.transform.parent = rootGameObject.transform;
            buttonGameObject.layer = rootGameObject.layer;
            UIButton uiButton = buttonGameObject.AddComponent<UIButton>();
            if (aParams.disabled == true)
            {
                uiButton.Disable();
            }
            else
            {
                uiButton.Enable();
            }
            uiButton.disabledTexture = aParams.disabledTexture;
            uiButton.normalTexture = aParams.normalTexture;
            uiButton.hoverTexture = aParams.hoverTexture;
            uiButton.downTexture = aParams.downTexture;
            uiButton.enabledTextColor = aParams.enabledTextColor;
            uiButton.disabledTextColor = aParams.disabledTextColor;
            uiButton.eventListener = aParams.eventListener;

            ///create label
            GameObject labelGameObject = new GameObject(aParams.name + LABEL_POST_FIX);
            labelGameObject.transform.position = new Vector3(0.0f, 0.0f,-0.04f);
            labelGameObject.transform.rotation = Quaternion.identity;
            labelGameObject.transform.parent = buttonGameObject.transform;
            labelGameObject.layer = buttonGameObject.layer;
            labelGameObject.AddComponent<MeshRenderer>();
            labelGameObject.AddComponent<TextMesh>();
            UILabel uiLabel = labelGameObject.AddComponent<UILabel>();
            uiLabel.text = aParams.labelText;
            uiLabel.fontSize = aParams.labelFontSize;
            uiLabel.font = aParams.labelFont;
            uiLabel.color = aParams.labelColor;
            uiLabel.fontTexture = aParams.labelFontTexture;

            ///create image
            GameObject imageGameObject = new GameObject(aParams.name + IMAGE_POST_FIX);
            imageGameObject.transform.position = Vector3.zero;
            imageGameObject.transform.rotation = Quaternion.identity;
            imageGameObject.transform.parent = buttonGameObject.transform;
            imageGameObject.layer = buttonGameObject.layer;
            imageGameObject.AddComponent<MeshFilter>();
            imageGameObject.AddComponent<MeshRenderer>();
            UIImage uiImage = imageGameObject.AddComponent<UIImage>();
            uiImage.meshName = MESH_NAME;
            uiImage.width = aParams.imageWidth;
            uiImage.height = aParams.imageHeight;
            uiImage.meshBoarder = aParams.imageMeshBoarder;
            uiImage.outerUVBoarder = aParams.imageOuterUVBoarder;
            uiImage.innerUVBoarder = aParams.imageInnerUVBoarder;
            uiImage.texture = aParams.imageTexture;
            uiImage.shader = aParams.imageShader;
            uiImage.color = aParams.imageColor;

            uiButton.UpdateComponents();
            uiLabel.UpdateComponents();
            uiImage.GenerateMaterial();
            uiImage.GenerateMesh();
            uiImage.SetTexture();
            uiImage.SetColor();
            aToggle.eventListener = uiButton;
            #if UNITY_EDITOR
            UnityEditor.EditorUtility.SetDirty(uiButton);
            UnityEditor.EditorUtility.SetDirty(uiLabel);
            UnityEditor.EditorUtility.SetDirty(uiImage);
            #endif

            return uiButton;
        }