该功能是在取色器的基础上实现的,我的取色器是百度用的别人的,所以就不放了,
如果有需要的可以找我要,我发给你们。然后我会详细介绍一下我的代码,帮助大
家编写自己的功能。
编写代码前,对各个面板添加CanvasGroup这个组件
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using System;
public class Change : MonoBehaviour {
public Button WordBtn;
public GameObject WordPanel;
public Button ColorBtn;
public GameObject ColourPanel;
public GameObject playLeftPanel;
public GameObject playRightPanel;
public GameObject topPanel;
public GameObject bottomPanel;
public GameObject ColorShow;
public GameObject WordColorShow;
public Button WordSureBtn;
public Button WordDelBtn;
public InputField WordSize;
public Button SureBtn;
public Button DelBtn;
void Start ()
{
WordBtn.onClick.AddListener(onWordBtnClicked);
ColorBtn.onClick.AddListener(onColorBtnClicked);
WordSureBtn.onClick.AddListener(onWordSureBtnClicked);
WordDelBtn.onClick.AddListener(onWordDelBtnClicked);
SureBtn.onClick.AddListener(onSureBtnClicked);
DelBtn.onClick.AddListener(onDelBtnClicked);
}
void onWordBtnClicked()
{
WordPanel.GetComponent<CanvasGroup>().alpha = 1;
}
void onColorBtnClicked()
{
ColourPanel.GetComponent<CanvasGroup>().alpha = 1;
}
void onWordSureBtnClicked()
{
Image wordcolor = GameObject.Find("WordColorShow").GetComponent<Image>();
string a = WordSize.text;
Debug.Log(a);
Transform canvas = GameObject.Find("Canvas").transform;
if (!canvas)
{
Debug.Log("NO Canvas");
return;
}
Transform[] tArray = canvas.GetComponentsInChildren<Transform>();
for (int i = 0; i < tArray.Length; i++)
{
Text t = tArray[i].GetComponent<Text>();
if (t)
{
Undo.RecordObject(t, t.gameObject.name);
t.color = wordcolor.color;
t.fontSize = int.Parse(a.ToString());
EditorUtility.SetDirty(t);
}
}
Debug.Log("Succed");
WordPanel.GetComponent<CanvasGroup>().alpha = 0;
}
void onWordDelBtnClicked()
{
WordPanel.GetComponent<CanvasGroup>().alpha = 0;
}
void onSureBtnClicked()
{
Image color = GameObject.Find("ColorShow").GetComponent<Image>();
Image right = GameObject.Find("playRightPanel").GetComponent<Image>();
right.color = color.color;
Image left = GameObject.Find("playLeftPanel").GetComponent<Image>();
left.color = color.color;
Image bottom = GameObject.Find("bottomPanel").GetComponent<Image>();
bottom.color = color.color;
Image top = GameObject.Find("topPanel").GetComponent<Image>();
top.color = color.color;
ColourPanel.GetComponent<CanvasGroup>().alpha = 0;
}
void onDelBtnClicked()
{
ColourPanel.GetComponent<CanvasGroup>().alpha = 0;
}
}
其他问题还有询问。
|