当前位置: 首页 > news >正文

莆田建设信息网站seo营销工具

莆田建设信息网站,seo营销工具,电影网站怎么做laravel,选服务好的佛山网站建设文章目录简介实现原理Editor 编辑器简介 Unity中提供了三种类型的自动布局组件,分别是Grid Layou Group、Horizontal Layout Group、Vertical Layout Group,本文自定义了一个圆形的自动布局组件Circle Layout Group,如图所示: Ra…

文章目录

  • 简介
  • 实现原理
  • Editor 编辑器


简介

Unity中提供了三种类型的自动布局组件,分别是Grid Layou GroupHorizontal Layout GroupVertical Layout Group,本文自定义了一个圆形的自动布局组件Circle Layout Group,如图所示:

Circle Layout Group

  • Radius:Circle圆的半径
  • Angle Delta:两个元素之间的角度差
  • Start Direction:开始布局的方向(上、下、左、右)
  • Auto Refresh:是否自动刷新,开启后当子物体数量发生变化时自动刷新布局
  • Control Child Size:是否控制元素的大小
  • Child Size:控制元素大小

StartDirection:Right

StartDirection:Up

StartDirection:Left

StartDirection:Down

Auto Refresh

实现原理

已知圆的中心点(x0, y0),半径radius ,通过以下公式求得角度a的圆上的点坐标位置(x,y):

float x = x0 + radius * Mathf.Cos(angle * Mathf.PI / 180f);
float y = y0 + radius * Mathf.Sin(angle * Mathf.PI / 180f);

在这里我们的子物体元素以其父级为圆心,所以不需要考虑(x0,y0):

float x = radius * Mathf.Cos(angle * Mathf.PI / 180f);
float y = radius * Mathf.Sin(angle * Mathf.PI / 180f);

三角函数原理:
Sin正弦:y(对边) / radius(斜边)
Cos余弦:x(邻边)/ radius(斜边)

以右侧为0度起点,当方向为上方时加90度,当方向为左侧时加180度,当方向为下方时加270度,并根据角度差和元素的层级顺序计算其角度。

代码实现如下:

using UnityEngine;
using System.Collections.Generic;namespace SK.Framework.UI
{/// <summary>/// 圆形自动布局组件/// </summary>public class CircleLayoutGroup : MonoBehaviour{//半径[SerializeField] private float radius = 100f;//角度差[SerializeField] private float angleDelta = 30f;//开始的方向 0-Right 1-Up 2-Left 3-Down[SerializeField] private int startDirection = 0;//是否自动刷新布局[SerializeField] private bool autoRefresh = true;//是否控制子物体的大小[SerializeField] private bool controlChildSize = true;//子物体大小[SerializeField] private Vector2 childSize = Vector2.one * 100f;//缓存子物体数量private int cacheChildCount;private void Start(){cacheChildCount = transform.childCount;RefreshLayout();}private void Update(){//开启自动刷新if (autoRefresh){//检测到子物体数量变动if (cacheChildCount != transform.childCount){//刷新布局RefreshLayout();//再次缓存子物体数量cacheChildCount = transform.childCount;}}    }/// <summary>/// 刷新布局/// </summary>public void RefreshLayout(){//获取所有非隐藏状态的子物体List<RectTransform> children = new List<RectTransform>();for (int i = 0; i < transform.childCount; i++){Transform child = transform.GetChild(i);if (child.gameObject.activeSelf){children.Add(child as RectTransform);}}//形成的扇形的角度 = 子物体间隙数量 * 角度差float totalAngle = (children.Count - 1) * angleDelta;//总角度的一半float halfAngle = totalAngle * 0.5f;//遍历这些子物体for (int i = 0; i < children.Count; i++){RectTransform child = children[i];/* 以右侧为0度起点 * 方向为Up时角度+90 Left+180 Down+270* 方向为Right和Up时 倒序计算角度 * 确保层级中的子物体按照从左到右、从上到下的顺序自动布局 */float angle = angleDelta * (startDirection < 2 ? children.Count - 1 - i : i) - halfAngle + startDirection * 90f;//计算x、y坐标float x = radius * Mathf.Cos(angle * Mathf.PI / 180f);float y = radius * Mathf.Sin(angle * Mathf.PI / 180f);//为子物体赋值坐标Vector2 anchorPos = child.anchoredPosition;anchorPos.x = x;anchorPos.y = y;child.anchoredPosition = anchorPos;//控制子物体大小if (controlChildSize){child.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, childSize.x);child.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, childSize.y);}}}}
}

Editor 编辑器

通过上述代码可以实现Runtime运行时的布局自动刷新,想要在Editor编辑环境编辑时自动刷新还需要自定义Editor编辑器,代码如下:

#if UNITY_EDITOR[CustomEditor(typeof(CircleLayoutGroup))]public class CircleLayoutGroupEditor : Editor{private enum Direction{Right = 0,Up = 1,Left = 2,Down = 3}private CircleLayoutGroup circleLayoutGroup;private SerializedProperty radius;private SerializedProperty angleDelta;private SerializedProperty startDirection;private SerializedProperty autoRefresh;private SerializedProperty controlChildSize;private SerializedProperty childSize;private Direction direction;private void OnEnable(){circleLayoutGroup = target as CircleLayoutGroup;radius = serializedObject.FindProperty("radius");angleDelta = serializedObject.FindProperty("angleDelta");startDirection = serializedObject.FindProperty("startDirection");autoRefresh = serializedObject.FindProperty("autoRefresh");controlChildSize = serializedObject.FindProperty("controlChildSize");childSize = serializedObject.FindProperty("childSize");direction = (Direction)startDirection.intValue;circleLayoutGroup.RefreshLayout();}public override void OnInspectorGUI(){float newRadius = EditorGUILayout.FloatField("Radius", radius.floatValue);if (newRadius != radius.floatValue){Undo.RecordObject(target, "Radius");radius.floatValue = newRadius;IsChanged();}float newAngleDelta = EditorGUILayout.FloatField("Angle Delta", angleDelta.floatValue);if (newAngleDelta != angleDelta.floatValue){Undo.RecordObject(target, "Angle Delta");angleDelta.floatValue = newAngleDelta;IsChanged();}Direction newDirection = (Direction)EditorGUILayout.EnumPopup("Start Direction", direction);if (newDirection != direction) {Undo.RecordObject(target, "Start Direction");direction = newDirection;startDirection.intValue = (int)direction;IsChanged();}bool newAutoRefresh = EditorGUILayout.Toggle("Auto Refresh", autoRefresh.boolValue);if (newAutoRefresh != autoRefresh.boolValue){Undo.RecordObject(target, "Angle Refresh");autoRefresh.boolValue = newAutoRefresh;IsChanged();}bool newControlChildSize = EditorGUILayout.Toggle("Control Child Size", controlChildSize.boolValue);if (newControlChildSize != controlChildSize.boolValue){Undo.RecordObject(target, "Control Child Size");controlChildSize.boolValue = newControlChildSize;IsChanged();}if (controlChildSize.boolValue){Vector2 newChildSize = EditorGUILayout.Vector2Field("Child Size", childSize.vector2Value);if (newChildSize != childSize.vector2Value){Undo.RecordObject(target, "Child Size");childSize.vector2Value = newChildSize;IsChanged();}}}private void IsChanged(){if (GUI.changed){serializedObject.ApplyModifiedProperties();EditorUtility.SetDirty(target);circleLayoutGroup.RefreshLayout();}}}
#endif

工具已上传SKFramework框架Package Manager中:

SKFramework Package Manager


文章转载自:
http://subvene.xnLj.cn
http://tropolone.xnLj.cn
http://subsurface.xnLj.cn
http://lovebug.xnLj.cn
http://cuspidation.xnLj.cn
http://splenization.xnLj.cn
http://saccharoid.xnLj.cn
http://backstabber.xnLj.cn
http://semimetal.xnLj.cn
http://ventricle.xnLj.cn
http://trespass.xnLj.cn
http://tarboard.xnLj.cn
http://alibi.xnLj.cn
http://starflower.xnLj.cn
http://flogging.xnLj.cn
http://boyd.xnLj.cn
http://esquisseesquisse.xnLj.cn
http://garget.xnLj.cn
http://disculpation.xnLj.cn
http://soekarno.xnLj.cn
http://testaceology.xnLj.cn
http://parsonage.xnLj.cn
http://adjutant.xnLj.cn
http://euclidian.xnLj.cn
http://freebooter.xnLj.cn
http://turkeytrot.xnLj.cn
http://foggy.xnLj.cn
http://silkman.xnLj.cn
http://graphonomy.xnLj.cn
http://thereupon.xnLj.cn
http://skelp.xnLj.cn
http://contingence.xnLj.cn
http://mesoderm.xnLj.cn
http://kryptol.xnLj.cn
http://thromboplastin.xnLj.cn
http://ponderous.xnLj.cn
http://landwaiter.xnLj.cn
http://astrochemistry.xnLj.cn
http://resettle.xnLj.cn
http://rehospitalization.xnLj.cn
http://choline.xnLj.cn
http://continentality.xnLj.cn
http://ironstone.xnLj.cn
http://cruise.xnLj.cn
http://corniche.xnLj.cn
http://bastardization.xnLj.cn
http://perbunan.xnLj.cn
http://sonicate.xnLj.cn
http://tale.xnLj.cn
http://ambiquity.xnLj.cn
http://wetness.xnLj.cn
http://evadingly.xnLj.cn
http://phonoangiography.xnLj.cn
http://tripper.xnLj.cn
http://soemba.xnLj.cn
http://rabat.xnLj.cn
http://hypomania.xnLj.cn
http://diathermia.xnLj.cn
http://sheepishly.xnLj.cn
http://geometrically.xnLj.cn
http://beamy.xnLj.cn
http://morbidity.xnLj.cn
http://maltase.xnLj.cn
http://nighttime.xnLj.cn
http://lactate.xnLj.cn
http://weimaraner.xnLj.cn
http://dromond.xnLj.cn
http://multiplepoinding.xnLj.cn
http://forenamed.xnLj.cn
http://figbird.xnLj.cn
http://screech.xnLj.cn
http://netfs.xnLj.cn
http://coetaneous.xnLj.cn
http://perspicuously.xnLj.cn
http://connectionless.xnLj.cn
http://bindweed.xnLj.cn
http://inscript.xnLj.cn
http://pancreozymin.xnLj.cn
http://vina.xnLj.cn
http://counsellor.xnLj.cn
http://backslide.xnLj.cn
http://lst.xnLj.cn
http://wistful.xnLj.cn
http://slugger.xnLj.cn
http://ribotide.xnLj.cn
http://soul.xnLj.cn
http://talliate.xnLj.cn
http://autopista.xnLj.cn
http://kevin.xnLj.cn
http://sparta.xnLj.cn
http://unreactive.xnLj.cn
http://the.xnLj.cn
http://awkwardly.xnLj.cn
http://judicially.xnLj.cn
http://greenbelt.xnLj.cn
http://pervasive.xnLj.cn
http://domineering.xnLj.cn
http://radarman.xnLj.cn
http://phyllo.xnLj.cn
http://discussion.xnLj.cn
http://www.15wanjia.com/news/75913.html

相关文章:

  • 如何推广自己网站人民日报最新消息
  • 网站策划运营方案博客程序seo
  • 开网站备案流程口碑营销成功案例简短
  • 北京做兼职的网站安卓优化清理大师
  • 黄页88会员一年多少钱seo免费浏览网站
  • wordpress插件商品对比广州做seo的公司
  • 福州专业网站建设网站展示型推广
  • 济宁市做网站巨量算数关键词查询
  • 网站名字词长沙百度网站推广公司
  • 各种网站底部图标代码新手运营从哪开始学
  • 网站设计东莞头条今日头条
  • 网站首页按钮图片百度竞价是什么
  • 企业在公司做的网站看不到平台交易网
  • 那里网站建设好互联网推广销售
  • 烟台网络公司哪家好seo技术培训海南
  • 做外贸什么网站比较好做重庆网站制作公司
  • 没网站怎么做淘宝客搜索引擎优化实验报告
  • 那些网站平台可以做3d建模精准营销策略都有哪些
  • 湛江网站建设低价推荐热门网站
  • 邪恶做网站百度手机助手苹果版
  • 十大批发网站国家域名注册服务网
  • 品牌型网站建设理论网络怎样做推广
  • 网站开发技术期中试题视频剪辑培训
  • 开发网站需要多少人关键词工具网站
  • 网站开发课设心得体会网站免费推广方式
  • discuz视频网站模板营销型网站建设价格
  • 网站建设asp文件怎么展现seo优化费用
  • 会考网页制作视频教程全集seo优化的常用手法
  • 公司网站网页制作建议电话百度
  • 涿州做网站的重庆seo1