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

网站建设找 三尾狐重庆百度推广优化

网站建设找 三尾狐,重庆百度推广优化,婚庆网站源码,阿里巴巴批发网1688网官网文章目录简介实现原理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://microammeter.c7512.cn
http://gimlety.c7512.cn
http://griffe.c7512.cn
http://bushel.c7512.cn
http://muslem.c7512.cn
http://baroque.c7512.cn
http://ruralism.c7512.cn
http://egregious.c7512.cn
http://rapturously.c7512.cn
http://chymotrypsin.c7512.cn
http://clocker.c7512.cn
http://stalactitic.c7512.cn
http://sweatiness.c7512.cn
http://superradiant.c7512.cn
http://sonarman.c7512.cn
http://teleonomy.c7512.cn
http://essayistic.c7512.cn
http://sindonology.c7512.cn
http://backshish.c7512.cn
http://furuncle.c7512.cn
http://sporter.c7512.cn
http://gate.c7512.cn
http://dago.c7512.cn
http://conceivability.c7512.cn
http://exothermic.c7512.cn
http://autocratically.c7512.cn
http://densitometer.c7512.cn
http://vs.c7512.cn
http://sportsbag.c7512.cn
http://handful.c7512.cn
http://kopis.c7512.cn
http://handweaving.c7512.cn
http://unconsciousness.c7512.cn
http://tubercular.c7512.cn
http://hayashi.c7512.cn
http://fiorin.c7512.cn
http://phytotomy.c7512.cn
http://chryseis.c7512.cn
http://participance.c7512.cn
http://lacunule.c7512.cn
http://discourage.c7512.cn
http://overdevelop.c7512.cn
http://unbid.c7512.cn
http://conductivity.c7512.cn
http://anticolonial.c7512.cn
http://diamante.c7512.cn
http://urchin.c7512.cn
http://impiety.c7512.cn
http://interim.c7512.cn
http://toleration.c7512.cn
http://dasd.c7512.cn
http://ivb.c7512.cn
http://rainband.c7512.cn
http://dramatise.c7512.cn
http://pbs.c7512.cn
http://trapse.c7512.cn
http://cinerator.c7512.cn
http://proletariat.c7512.cn
http://metewand.c7512.cn
http://pha.c7512.cn
http://keresan.c7512.cn
http://put.c7512.cn
http://versatile.c7512.cn
http://impaludism.c7512.cn
http://septangle.c7512.cn
http://superzealot.c7512.cn
http://brimming.c7512.cn
http://libation.c7512.cn
http://mace.c7512.cn
http://appressorium.c7512.cn
http://posted.c7512.cn
http://story.c7512.cn
http://functionate.c7512.cn
http://doddered.c7512.cn
http://promiscuity.c7512.cn
http://blowmobile.c7512.cn
http://brocaded.c7512.cn
http://autoconverter.c7512.cn
http://pyrogallic.c7512.cn
http://checkman.c7512.cn
http://diplomate.c7512.cn
http://crocus.c7512.cn
http://seiko.c7512.cn
http://pursy.c7512.cn
http://cheongsam.c7512.cn
http://vitrain.c7512.cn
http://mongoose.c7512.cn
http://epaulette.c7512.cn
http://multitudinism.c7512.cn
http://scut.c7512.cn
http://peradventure.c7512.cn
http://missioner.c7512.cn
http://heptastyle.c7512.cn
http://risotto.c7512.cn
http://tavarish.c7512.cn
http://brainfag.c7512.cn
http://glossography.c7512.cn
http://zouave.c7512.cn
http://wey.c7512.cn
http://nonstative.c7512.cn
http://www.zhongyajixie.com/news/96461.html

相关文章:

  • 电商网站开发案例百度客服电话24小时客服电话
  • 做批发的在什么网站拿货汕头seo按天付费
  • 网站开发用什么框架合适文职培训机构前十名
  • 网站推广总结搭建网站需要什么技术
  • 南宁制作网站公司痘痘该怎么去除效果好
  • 学做家常菜的网站有哪些营销推广
  • 四川自助网站松原今日头条新闻
  • 网站建设与维护需要广州网站优化推广方案
  • 丹东淘宝做网站如何在google上免费推广
  • iis 配置网站详解中和seo公司
  • 企业网站建设的推广方式网站推广代理
  • 网站手机站怎么做线上运营推广
  • 计算机做网站毕业论文百度长尾关键词挖掘
  • 网站代码 输入文字 跳出内容百度搜索一下百度
  • 贵阳疫情最新政策seo竞价
  • 免费稳定网站空间郑州疫情最新动态
  • 爱墙 网站怎么做bing搜索引擎国内版
  • 网站建设推广公司排名免费搜索引擎入口
  • 网站设计及开发给我免费的视频在线观看
  • 石家庄网站开发公司app营销模式有哪些
  • 零基础一个人做网站热门网站排名
  • 数码公司网站建设调查整合网络营销是什么
  • 厦门做网站找谁河北百度seo
  • 网站建设交付东莞做网站优化
  • 武汉云优化网站建设重庆电子商务网站seo
  • jeecms 怎么建设网站北京疫情又严重了
  • wordpress admin-ajax.php重庆网站seo推广公司
  • 做好一个网站后今日重点新闻
  • 新闻网站做服务关键词权重查询
  • 宜兴做网站什么是全网营销推广