/// <summary> /// Draw the atlas and sprite selection fields. /// </summary> protected virtual bool ShouldDrawProperties() { GUILayout.BeginHorizontal(); if (UGUIEditorTools.DrawPrefixButton("Atlas")) { ComponentSelector.Show <UGUIAtlas>(OnSelectAtlas); } SerializedProperty atlas = UGUIEditorTools.DrawProperty("", serializedObject, "mAtlas", GUILayout.MinWidth(20f)); if (GUILayout.Button("Edit", GUILayout.Width(40f))) { if (atlas != null) { UGUIAtlas atl = atlas.objectReferenceValue as UGUIAtlas; UGUISettings.atlas = atl; UGUIEditorTools.Select(atl.gameObject); } } GUILayout.EndHorizontal(); UGUISprite uguiSprite = target as UGUISprite; string spriteName = uguiSprite.sprite == null ? "" : uguiSprite.sprite.name; UGUIEditorTools.DrawAdvancedSpriteField(atlas.objectReferenceValue as UGUIAtlas, spriteName, SelectSprite, true); return(true); }
void OnSelectAtlas(Object obj) { UGUISprite sprite = serializedObject.targetObject as UGUISprite; sprite.atlas = obj as UIAtlas; NGUITools.SetDirty(serializedObject.targetObject); NGUISettings.atlas = obj as UIAtlas; }
/// <summary> /// Sprite selection callback function. /// </summary> void SelectSprite(string spriteName) { UGUISprite sprite = serializedObject.targetObject as UGUISprite; sprite.spriteName = spriteName; if (sprite.isValid) { NGUITools.SetDirty(serializedObject.targetObject); NGUISettings.selectedSprite = spriteName; } }
/// <summary> /// Sprite selection callback function. /// </summary> void SelectSprite(string spriteName) { serializedObject.Update(); SerializedProperty atlas = serializedObject.FindProperty("mAtlas"); UGUISprite uguiSprite = target as UGUISprite; uguiSprite.sprite = (atlas.objectReferenceValue as UGUIAtlas).GetSprite(spriteName); serializedObject.ApplyModifiedProperties(); UGUITools.SetDirty(serializedObject.targetObject); UGUISettings.selectedSprite = spriteName; }
/// <summary> /// Draw the inspector properties. /// </summary> public override void OnInspectorGUI() { NGUIEditorTools.SetLabelWidth(80f); EditorGUILayout.Space(); serializedObject.Update(); EditorGUI.BeginDisabledGroup(!ShouldDrawProperties()); EditorGUI.EndDisabledGroup(); EditorGUIUtility.labelWidth = 0; EditorGUILayout.Space(); UGUISprite sprite = (UGUISprite)target; sprite.UseNativeSize = EditorGUILayout.Toggle("Use Native Size", sprite.UseNativeSize); sprite.UsePivot = EditorGUILayout.Toggle("Use Pivot", sprite.UsePivot); EditorGUILayout.BeginHorizontal(); sprite.m_Pivot = EditorGUILayout.Vector2Field("Pivot", sprite.m_Pivot); if (GUILayout.Button("Set Pivot")) { if (sprite != null) { sprite.SetPivot(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); sprite.m_AnimationType = (UGUISprite.AnimationType)EditorGUILayout.EnumPopup("Animation", sprite.m_AnimationType); sprite.IsPlayAnimationOnStart = EditorGUILayout.Toggle("PlayAnimationOnStart", sprite.IsPlayAnimationOnStart); sprite.IsPlayAnimationOnEnable = EditorGUILayout.Toggle("PlayAnimationOnEnable", sprite.IsPlayAnimationOnEnable); var sp = serializedObject.FindProperty("Animations"); EditorGUILayout.PropertyField(sp, new GUIContent("Animations"), true); sprite.AnimationLength = EditorGUILayout.FloatField("Animation Length", sprite.AnimationLength); sprite.AnimationDelay = EditorGUILayout.FloatField("Animation Delay", sprite.AnimationDelay); serializedObject.ApplyModifiedProperties(); // UGUISprite sprite = target as UGUISprite; if (sprite == null || !sprite.isValid) { return; } }
/// <summary> /// Draw the sprite preview. /// </summary> public override void OnPreviewGUI(Rect rect, GUIStyle background) { UGUISprite uguiSprite = target as UGUISprite; Texture2D tex = uguiSprite.mainTexture as Texture2D; if (tex == null) { return; } // UISpriteData sd = sprite.atlas.GetSprite(sprite.spriteName); UGUIEditorTools.DrawSprite(tex, rect, uguiSprite.sprite, uguiSprite.color); }
public override void OnInspectorGUI() { UGUISprite _sprite = target as UGUISprite; //选择图集 if (GUILayout.Button("选择图集", "DropDown", GUILayout.Width(76f))) { ComponentSelector.Show <UGUIAtlas>((_obj) => { _sprite.Atlas = _obj as UGUIAtlas; }); } _sprite.Atlas = EditorGUILayout.ObjectField("图集", _sprite.Atlas, typeof(UGUIAtlas), true) as UGUIAtlas; if (_sprite.Atlas != null) //有图集的情况下,根据name获取图片 { ////选择图集中的图片 //if (GUILayout.Button("选择图集", "DropDown", GUILayout.Width(76f))) //{ // SpriteSelector.Show(_sprite.Atlas, (_obj) => // { // _sprite.sprite = _obj; // }); // Debug.Log("选中了一张图片"); //} if (_sprite.sprite != null) { if (_sprite.Name != _sprite.sprite.name) { _sprite.Name = _sprite.sprite.name; } } else { if (_sprite.Name != "") { _sprite.InitSprite(); } } } EditorGUILayout.LabelField("图片名称:" + _sprite.Name); base.OnInspectorGUI(); }
//--------------------公共方法---------------------- #region 公共方法 /// <summary> /// 初始化方法 /// </summary> public virtual void Init() { if (!mIsInit) { mIsInit = true; if (up == null) { up = GetComponent <UGUISprite>(); if (up == null) { Debug.Log("按钮必须有张默认图片!!!"); return; } } mTrans = transform; mListener = EventTriggerListener.Get(gameObject); mListener.onClick = OnBtnClick; mListener.onUp = OnBtnUp; mListener.onDown = OnBtnDown; state = ButtonState.Up; } }
public virtual void DrawCustomProperties() { UGUISprite uguiSprite = target as UGUISprite; EditorGUILayout.ObjectField("Sprite", uguiSprite.sprite, typeof(Sprite), false); uguiSprite.color = EditorGUILayout.ColorField("Color", uguiSprite.color); uguiSprite.material = EditorGUILayout.ObjectField("Material", uguiSprite.material, typeof(Material), false) as Material; uguiSprite.raycastTarget = EditorGUILayout.Toggle("Raycast Target", uguiSprite.raycastTarget); uguiSprite.type = (Image.Type)EditorGUILayout.EnumPopup("Image Type", uguiSprite.type); switch (uguiSprite.type) { case Image.Type.Simple: uguiSprite.preserveAspect = EditorGUILayout.Toggle("preserveAspect", uguiSprite.preserveAspect); if (GUILayout.Button("Set Native Size")) { uguiSprite.SetNativeSize(); } break; case Image.Type.Sliced: uguiSprite.fillCenter = EditorGUILayout.Toggle("Fill Center", uguiSprite.fillCenter); break; case Image.Type.Tiled: uguiSprite.fillCenter = EditorGUILayout.Toggle("Fill Center", uguiSprite.fillCenter); break; case Image.Type.Filled: { uguiSprite.fillMethod = (Image.FillMethod)EditorGUILayout.EnumPopup("FillMethod Type", uguiSprite.fillMethod); switch (uguiSprite.fillMethod) { case Image.FillMethod.Horizontal: uguiSprite.fillOrigin = (int)(Image.OriginHorizontal)EditorGUILayout.EnumPopup("FillMethod Origin", (Image.OriginHorizontal)(uguiSprite.fillOrigin)); break; case Image.FillMethod.Vertical: uguiSprite.fillOrigin = (int)(Image.OriginVertical)EditorGUILayout.EnumPopup("FillMethod Origin", (Image.OriginVertical)(uguiSprite.fillOrigin)); break; case Image.FillMethod.Radial360: uguiSprite.fillOrigin = (int)(Image.Origin360)EditorGUILayout.EnumPopup("FillMethod Origin", (Image.Origin360)(uguiSprite.fillOrigin)); break; case Image.FillMethod.Radial180: uguiSprite.fillOrigin = (int)(Image.Origin180)EditorGUILayout.EnumPopup("FillMethod Origin", (Image.Origin180)(uguiSprite.fillOrigin)); break; case Image.FillMethod.Radial90: uguiSprite.fillOrigin = (int)(Image.Origin90)EditorGUILayout.EnumPopup("FillMethod Origin", (Image.Origin90)(uguiSprite.fillOrigin)); break; } uguiSprite.fillAmount = EditorGUILayout.Slider("fillAmount Value ", uguiSprite.fillAmount, 0, 1); uguiSprite.fillClockwise = EditorGUILayout.Toggle("fill Clockwise", uguiSprite.fillClockwise);; uguiSprite.preserveAspect = EditorGUILayout.Toggle("preserveAspect", uguiSprite.preserveAspect); } break; } }