Example #1
0
        /// <summary>
        /// Copies the toggles properties to the parameters for editting.
        /// </summary>
        /// <param name="aCopyToggle"></param>
        private void CopyEditMenu(UIToggle aCopyToggle)
        {
            if(m_ToggleParams != null && aCopyToggle != null)
            {
                if(m_ToggleParams.uiType != aCopyToggle.uiType)
                {
                    CreateParamsForType(aCopyToggle.uiType);
                }
                m_ToggleParams.Clear();
                m_ToggleParams.name = aCopyToggle.gameObject.name;
                m_ToggleParams.id = aCopyToggle.id;
                m_ToggleParams.isSelectable = aCopyToggle.selectable;
                m_ToggleParams.recieveActions = aCopyToggle.receivesActionEvents;
                m_ToggleParams.uiSpace = aCopyToggle.uiSpace;
                m_ToggleParams.uiType = aCopyToggle.uiType;
                switch(m_ToggleParams.uiType)
                {
                    case UIType.IMAGE:
                        {
                            UIImageParams imageParams = m_ToggleParams as UIImageParams;
                            UIImage image = aCopyToggle.GetComponentInChildren<UIImage>();
                            if(imageParams == null || image == null)
                            {
                                DebugUtils.LogError(MISSING_IMAGE);
                                break;
                            }
                            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;
                        }
                        break;
                    case UIType.LABEL:
                        {
                            UILabelParams labelParams = m_ToggleParams as UILabelParams;
                            UILabel label = aCopyToggle.GetComponentInChildren<UILabel>();
                            if(labelParams == null || label == null)
                            {
                                DebugUtils.LogError(MISSING_LABEL);
                                break;
                            }
                            labelParams.color = label.color;
                            labelParams.font = label.font;
                            labelParams.fontSize = label.fontSize;
                            labelParams.fontTexture = label.fontTexture;
                            labelParams.text = label.text;
                        }
                        break;
                    case UIType.BUTTON:
                        {
                            UIButtonParams buttonParams = m_ToggleParams as UIButtonParams;
                            UIButton button = aCopyToggle.GetComponentInChildren<UIButton>();
                            if (buttonParams == null || 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
                            {
                                label.color = buttonParams.labelColor;
                                label.font = buttonParams.labelFont;
                                label.fontSize = buttonParams.labelFontSize;
                                label.fontTexture = buttonParams.labelFontTexture;
                                label.text = buttonParams.labelText;
                            }
                            UIImage image = button.GetComponentInChildren<UIImage>();
                            if(image == null)
                            {
                                DebugUtils.LogError(MISSING_IMAGE);
                            }
                            else
                            {
                                image.color = buttonParams.imageColor;
                                image.height = buttonParams.imageHeight;
                                image.width = buttonParams.imageWidth;
                                image.meshBoarder = buttonParams.imageMeshBoarder;
                                image.innerUVBoarder = buttonParams.imageInnerUVBoarder;
                                image.outerUVBoarder = buttonParams.imageInnerUVBoarder;
                                image.shader = buttonParams.imageShader;
                                image.texture = buttonParams.imageTexture;
                            }
                        }
                        break;
                    case UIType.TEXTFIELD:
                        {
                            UITextfieldParams textfieldParams = m_ToggleParams as UITextfieldParams;
                            UITextfield textfield = aCopyToggle.GetComponentInChildren<UITextfield>();
                            if (textfieldParams == null || 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
                            {
                                label.color = textfieldParams.labelColor;
                                label.font = textfieldParams.labelFont;
                                label.fontSize = textfieldParams.labelFontSize;
                                label.fontTexture = textfieldParams.labelFontTexture;
                                label.text = textfieldParams.labelText;
                            }
                            UIImage image = textfield.GetComponentInChildren<UIImage>();
                            if (image == null)
                            {
                                DebugUtils.LogError(MISSING_IMAGE);
                            }
                            else
                            {
                                image.color = textfieldParams.imageColor;
                                image.height = textfieldParams.imageHeight;
                                image.width = textfieldParams.imageWidth;
                                image.meshBoarder = textfieldParams.imageMeshBoarder;
                                image.innerUVBoarder = textfieldParams.imageInnerUVBoarder;
                                image.outerUVBoarder = textfieldParams.imageInnerUVBoarder;
                                image.shader = textfieldParams.imageShader;
                                image.texture = textfieldParams.imageTexture;
                            }
                        }
                        break;

                }
            }
        }
Example #2
0
        private void DrawUIToggleSelection(UIToggle aToggle)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(aToggle.name, m_NameColumnWidth);
            EditorGUILayout.LabelField(aToggle.id.ToString(), m_IDColumnWidth);
            if(GUILayout.Button(EDIT,m_EditButtonWidth))
            {

                if(m_NextState == State.TOGGLE_SELECT)
                {
                    m_NextState = State.TOGGLE_EDIT;
                    m_ToggleToEdit = aToggle;
                    CopyEditMenu(m_ToggleToEdit);
                }
            }
            if(GUILayout.Button(COPY,m_EditButtonWidth))
            {
                if(m_NextState == State.TOGGLE_SELECT)
                {
                    m_NextState = State.TOGGLE_CREATE;
                    CopyCreateMenu(aToggle);
                }
            }
            if(GUILayout.Button(DELETE,m_DeleteButtonWidth))
            {
                m_TogglesToRemove.Add(aToggle);
            }
            EditorGUILayout.EndHorizontal();
        }
        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;
        }
 /// <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;
 }
        /// <summary>
        /// Creates a UI Image prefab at using the toggle as the root
        /// </summary>
        /// <param name="aParams">The parameters for creating the toggle</param>
        /// <param name="aToggle">The root of creation</param>
        /// <returns></returns>
        public static UIImage CreateUIImage(UIImageParams aParams, UIToggle aToggle)
        {
            if (aParams == null || aToggle == null)
            {
                return null;
            }
            GameObject rootGameObject = aToggle.gameObject;

            GameObject imageGameObject = new GameObject(aParams.name + IMAGE_POST_FIX);
            imageGameObject.transform.position = Vector3.zero;
            imageGameObject.transform.rotation = Quaternion.identity;
            imageGameObject.transform.parent = rootGameObject.transform;
            imageGameObject.layer = rootGameObject.layer;
            imageGameObject.AddComponent<MeshRenderer>();
            imageGameObject.AddComponent<MeshFilter>();
            UIImage uiImage = imageGameObject.AddComponent<UIImage>();
            uiImage.meshName = MESH_NAME;
            uiImage.width = aParams.width;
            uiImage.height = aParams.height;
            uiImage.meshBoarder = aParams.meshBoarder;
            uiImage.outerUVBoarder = aParams.outerUVBoarder;
            uiImage.innerUVBoarder = aParams.innerUVBoarder;
            uiImage.texture = aParams.texture;
            uiImage.shader = aParams.shader;
            uiImage.color = aParams.color;

            uiImage.GenerateMaterial();
            uiImage.GenerateMesh();
            uiImage.SetTexture();
            uiImage.SetColor();
            #if UNITY_EDITOR
            UnityEditor.EditorUtility.SetDirty(uiImage);
            #endif
            return uiImage;
        }
 //protected MeshRenderer m_MeshRenderer = null;
 // Use this for initialization
 protected virtual void Start()
 {
     m_Toggle = GetComponent<UIToggle>();
     if(m_Toggle == null)
     {
         m_Toggle = GetComponentInParent<UIToggle>();
     }
     //m_MeshRenderer = GetComponent<MeshRenderer>();
 }
Example #7
0
 /// <summary>
 /// Gets called when a level has loaded.
 /// </summary>
 /// <returns></returns>
 private IEnumerator OnLevelLoaded()
 {
     yield return new WaitForEndOfFrame();
     m_InteractToggle = UIManager.Find("Interact");
 }