/// <summary>
 /// Copies the contents from one param to another
 /// </summary>
 /// <param name="aParams">The parameters to copy</param>
 public void Copy(UIToggleParams aParams)
 {
     m_Name = aParams.name;
     m_ID = aParams.id;
     m_RecieveActions = aParams.recieveActions;
     m_IsSelectable = aParams.isSelectable;
     m_UISpace = aParams.uiSpace;
     m_UIType = aParams.uiType;
 }
示例#2
0
 private void CreateParamsForType(UIType aType)
 {
     UIToggleParams tempParams = m_ToggleParams;
     DebugUtils.Log("Create params " + aType);
     switch(aType)
     {
         case UIType.IMAGE:
             m_ToggleParams = new UIImageParams();
             m_ToggleParams.uiType = UIType.IMAGE;
             m_ToggleParams.Copy(tempParams);
             break;
         case UIType.LABEL:
             m_ToggleParams = new UILabelParams();
             m_ToggleParams.uiType = UIType.LABEL;
             m_ToggleParams.Copy(tempParams);
             break;
         case UIType.BUTTON:
             m_ToggleParams = new UIButtonParams();
             m_ToggleParams.uiType = UIType.BUTTON;
             m_ToggleParams.Copy(tempParams);
             break;
         case UIType.TEXTFIELD:
             m_ToggleParams = new UITextfieldParams();
             m_ToggleParams.uiType = UIType.TEXTFIELD;
             m_ToggleParams.Copy(tempParams);
             break;
     }
 }
示例#3
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;
                }
            }
        }
        /// <summary>
        /// Creates a UI Toggle using the parent as the root
        /// </summary>
        /// <param name="aParams">The parameters for creating the toggle</param>
        /// <param name="aParent">The root of the object</param>
        /// <returns></returns>
        public static UIToggle CreateUIToggle(UIToggleParams aParams, Transform aParent)
        {
            if (aParams == null || aParent == null)
            {
                return null;
            }

            GameObject rootGameObject = new GameObject(aParams.name);
            rootGameObject.transform.position = Vector3.zero;
            rootGameObject.transform.rotation = Quaternion.identity;
            rootGameObject.transform.parent = aParent;
            UIToggle uiToggle = rootGameObject.AddComponent<UIToggle>();
            uiToggle.id = aParams.id;
            uiToggle.selectable = aParams.isSelectable;
            uiToggle.receivesActionEvents = aParams.recieveActions;
            uiToggle.uiSpace = aParams.uiSpace;
            uiToggle.uiType = aParams.uiType;
            switch (uiToggle.uiSpace)
            {
                case UISpace.TWO_DIMENSIONAL:
                    rootGameObject.layer = UIManager.UI_2D_LAYER;
                    break;
                case UISpace.THREE_DIMENSIONAL:
                    rootGameObject.layer = UIManager.UI_3D_LAYER;
                    break;
                case UISpace.WORLD:
                    rootGameObject.layer = UIManager.UI_WORLD_LAYER;
                    break;
            }
            return uiToggle;
        }