protected void initGameObject(GameObject obj) { gameObject = obj; transform = obj.transform; Normalize(); rectTransform = obj.GetComponent <RectTransform>(); UIOutlet uiInfo = obj.GetComponent <UIOutlet>(); UISkin uiskin = obj.GetComponent <UISkin>(); for (int i = 0; i < uiInfo.OutletInfos.Count; i++) { objectList.Add(uiInfo.OutletInfos[i].Name, uiInfo.OutletInfos[i].Object as GameObject); } gameObject.SetActive(m_isActive); gameObject.SetVisible(m_isVisible); isInstance = true; InitializeComponent(); Initialize(); InitializeSkin(); Awake(); }
/// <summary> /// 实例化Item /// </summary> /// <param name="prefab">预制体,会重新实例一个</param> /// <param name="parent">父对象</param> public void Instantiate(UIOutlet uiOut, Transform parent) { Instantiate(uiOut.gameObject, parent); }
/// <summary>初始化UI控件</summary> protected override void InitializeComponent() { gridContent = Get <ContentSizeFitter>("gridContent"); prefabSelServerItem = Get <UIOutlet>("prefabSelServerItem"); btnClose = Get <Button>("btnClose"); }
public override void OnInspectorGUI() { _cachedPropertyNames.Clear(); EditorGUI.BeginChangeCheck(); UIOutlet outlet = target as UIOutlet; if (outlet.OutletInfos == null || outlet.OutletInfos.Count == 0) { if (GUILayout.Button("Add New Outlet")) { if (outlet.OutletInfos == null) { outlet.OutletInfos = new List <UIOutlet.OutletInfo>(); } else { outlet.OutletInfos.Clear(); _outletObjects.Clear(); } Undo.RecordObject(target, "Add OutletInfo"); outlet.OutletInfos.Add(new UIOutlet.OutletInfo()); } } else { // outlet ui edit for (var j = outlet.OutletInfos.Count - 1; j >= 0; j--) { var currentTypeIndex = -1; UIOutlet.OutletInfo outletInfo = outlet.OutletInfos[j]; string[] typesOptions = new string[0]; var isValid = outletInfo.Object != null && !_cachedPropertyNames.Contains(outletInfo.Name); _cachedPropertyNames.Add(outletInfo.Name); if (outletInfo.Object != null) { if (outletInfo.Object is GameObject) { var gameObj = outletInfo.Object as GameObject; var components = gameObj.GetComponents <Component>(); if (components.Length == 1) { currentTypeIndex = 0; } else { currentTypeIndex = components.Length;// 设置默认类型,默认选中最后一个 } string objTypeName = ""; typesOptions = new string[components.Length + 1]; typesOptions[0] = gameObj.GetType().FullName; if (typesOptions[0] == outletInfo.ComponentType) { currentTypeIndex = 0; objTypeName = gameObj.GetType().Name; } for (var i = 1; i <= components.Length; i++) { var com = components[i - 1]; var typeName = typesOptions[i] = com.GetType().FullName; if (typeName == outletInfo.ComponentType) { currentTypeIndex = i; objTypeName = com.GetType().Name; } } _outletObjects[gameObj] = new string[] { outletInfo.Name, objTypeName }; if (string.IsNullOrEmpty(outletInfo.Name)) { outletInfo.Name = gameObj.name; } } } EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(string.Format("Property: {0}", outletInfo.Name), isValid ? GreenFont : RedFont); EditorGUILayout.Space(); if (GUILayout.Button("+")) { Undo.RecordObject(target, "Insert OutletInfo"); outlet.OutletInfos.Insert(j, new UIOutlet.OutletInfo()); } if (GUILayout.Button("-")) { Undo.RecordObject(target, "Remove OutletInfo"); if (outlet.OutletInfos[j].Object != null) { _outletObjects.Remove(outlet.OutletInfos[j].Object as GameObject); } outlet.OutletInfos.RemoveAt(j); } if (GUILayout.Button("↑", GUILayout.MaxWidth(20)) && j < outlet.OutletInfos.Count - 1) { UIOutlet.OutletInfo curr = outlet.OutletInfos[j]; outlet.OutletInfos[j] = outlet.OutletInfos[j + 1]; outlet.OutletInfos[j + 1] = curr; } if (GUILayout.Button("↓", GUILayout.MaxWidth(20)) && j > 0) { UIOutlet.OutletInfo curr = outlet.OutletInfos[j]; outlet.OutletInfos[j] = outlet.OutletInfos[j - 1]; outlet.OutletInfos[j - 1] = curr; } GUILayout.Space(20); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); ///outletInfo.Name = EditorGUILayout.TextField("Name:", outletInfo.Name); if (outletInfo.Object != null) { outletInfo.Name = outletInfo.Object.name; outletInfo.Object = EditorGUILayout.ObjectField("", outletInfo.Object, typeof(UnityEngine.Object), true); } else { outletInfo.Name = "Select Object"; outletInfo.Object = EditorGUILayout.ObjectField("", outletInfo.Object, typeof(UnityEngine.Object), true); } if (currentTypeIndex >= 0) { var typeIndex = EditorGUILayout.Popup("", currentTypeIndex, typesOptions); outletInfo.ComponentType = typesOptions[typeIndex].ToString(); } EditorGUILayout.EndHorizontal(); } } //base.OnInspectorGUI (); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "GUI Change Check"); } }