Unity复制GameObject路径到剪切板 作者: rontian 时间: 2017-12-22 分类: Unity3D 评论 ```csharp /// /// 添加Hierarychy中的右键菜单 /// 说明:"GameObject/"下[priority小于等于49]的按钮会出现在Hierarychy的右键菜单中 /// public class HierarchyEditor { private static readonly TextEditor CopyTool = new TextEditor(); /// /// 将一个GameObject在Hierarchy中的完整路径拷贝的剪切板 /// [MenuItem("GameObject/Copy Path", priority = 20)] static void CopyTransPath() { Transform trans = Selection.activeTransform; if(null == trans) return; CopyTool.text = GetTransPath(trans); CopyTool.SelectAll(); CopyTool.Copy(); } /// /// 获得GameObject在Hierarchy中的完整路径 /// public static string GetTransPath(Transform trans) { if (null == trans) return string.Empty; if (null == trans.parent) return trans.name; return GetTransPath(trans.parent) + "/" + trans.name; } } ``` ---- > 转载来源:[http://www.jianshu.com/p/19dac8d94f29](http://www.jianshu.com/p/19dac8d94f29)
UGUI 新手引导镂空代码 作者: rontian 时间: 2017-12-22 分类: Unity3D 评论 ```csharp /// /// 实现镂空效果的Mask组件 /// public class HollowOutMask : MaskableGraphic, ICanvasRaycastFilter { [SerializeField] private RectTransform _target; private Vector3 _targetMin = Vector3.zero; private Vector3 _targetMax = Vector3.zero; private bool _canRefresh = true; private Transform _cacheTrans = null; /// /// 设置镂空的目标 /// public void SetTarget(RectTransform target) { _canRefresh = true; _target = target; _RefreshView(); } private void _SetTarget(Vector3 tarMin, Vector3 tarMax) { if (tarMin == _targetMin && tarMax == _targetMax) return; _targetMin = tarMin; _targetMax = tarMax; SetAllDirty(); } private void _RefreshView() { if(!_canRefresh) return; _canRefresh = false; if (null == _target) { _SetTarget(Vector3.zero, Vector3.zero); SetAllDirty(); } else { Bounds bounds = RectTransformUtility.CalculateRelativeRectTransformBounds(_cacheTrans, _target); _SetTarget(bounds.min, bounds.max); } } protected override void OnPopulateMesh(VertexHelper vh) { if (_targetMin == Vector3.zero && _targetMax == Vector3.zero) { base.OnPopulateMesh(vh); return; } vh.Clear(); // 填充顶点 UIVertex vert = UIVertex.simpleVert; vert.color = color; Vector2 selfPiovt = rectTransform.pivot; Rect selfRect = rectTransform.rect; float outerLx = -selfPiovt.x*selfRect.width; float outerBy = -selfPiovt.y*selfRect.height; float outerRx = (1 - selfPiovt.x)*selfRect.width; float outerTy = (1 - selfPiovt.y)*selfRect.height; // 0 - Outer:LT vert.position = new Vector3(outerLx, outerTy); vh.AddVert(vert); // 1 - Outer:RT vert.position = new Vector3(outerRx, outerTy); vh.AddVert(vert); // 2 - Outer:RB vert.position = new Vector3(outerRx, outerBy); vh.AddVert(vert); // 3 - Outer:LB vert.position = new Vector3(outerLx, outerBy); vh.AddVert(vert); // 4 - Inner:LT vert.position = new Vector3(_targetMin.x, _targetMax.y); vh.AddVert(vert); // 5 - Inner:RT vert.position = new Vector3(_targetMax.x, _targetMax.y); vh.AddVert(vert); // 6 - Inner:RB vert.position = new Vector3(_targetMax.x, _targetMin.y); vh.AddVert(vert); // 7 - Inner:LB vert.position = new Vector3(_targetMin.x, _targetMin.y); vh.AddVert(vert); // 设定三角形 vh.AddTriangle(4, 0, 1); vh.AddTriangle(4, 1, 5); vh.AddTriangle(5, 1, 2); vh.AddTriangle(5, 2, 6); vh.AddTriangle(6, 2, 3); vh.AddTriangle(6, 3, 7); vh.AddTriangle(7, 3, 0); vh.AddTriangle(7, 0, 4); } bool ICanvasRaycastFilter.IsRaycastLocationValid(Vector2 screenPos, Camera eventCamera) { if (null == _target) return true; // 将目标对象范围内的事件镂空(使其穿过) return !RectTransformUtility.RectangleContainsScreenPoint(_target, screenPos, eventCamera); } protected override void Awake() { base.Awake(); _cacheTrans = GetComponent(); } #if UNITY_EDITOR void Update() { _canRefresh = true; _RefreshView(); } #endif } ``` --- >转载来源:[http://www.jianshu.com/p/ea2b68f0a345](http://www.jianshu.com/p/ea2b68f0a345)
python之字符串格式化(format) 作者: rontian 时间: 2017-12-20 分类: Python 评论 #### 基本用法 它通过{}和:来代替传统%方式 #### 使用位置参数 要点:从以下例子可以看出位置参数不受顺序约束,且可以为{},只要format里有相对应的参数值即可,参数索引从0开,传入位置参数列表可用*列表 ```python >>> li = ['hoho',18] >>> 'my name is {} ,age {}'.format('hoho',18) 'my name is hoho ,age 18' >>> 'my name is {1} ,age {0}'.format(10,'hoho') 'my name is hoho ,age 10' >>> 'my name is {1} ,age {0} {1}'.format(10,'hoho') 'my name is hoho ,age 10 hoho' >>> 'my name is {} ,age {}'.format(*li) 'my name is hoho ,age 18' ``` #### 使用关键字参数 要点:关键字参数值要对得上,可用字典当关键字参数传入值,字典前加**即可 ```python >>> hash = {'name':'hoho','age':18} >>> 'my name is {name},age is {age}'.format(name='hoho',age=19) 'my name is hoho,age is 19' >>> 'my name is {name},age is {age}'.format(**hash) 'my name is hoho,age is 18' ``` #### 填充与格式化 :[填充字符][对齐方式 <^>][宽度] ```python >>> '{0:*>10}'.format(10) ##右对齐 '********10' >>> '{0:*<10}'.format(10) ##左对齐 '10********' >>> '{0:*^10}'.format(10) ##居中对齐 '****10****' ``` #### 精度与进制 ```python >>> '{0:.2f}'.format(1/3) '0.33' >>> '{0:b}'.format(10) #二进制 '1010' >>> '{0:o}'.format(10) #八进制 '12' >>> '{0:x}'.format(10) #16进制 'a' >>> '{:,}'.format(12369132698) #千分位格式化 '12,369,132,698' ``` #### 使用索引 ```python >>> li ['hoho', 18] >>> 'name is {0[0]} age is {0[1]}'.format(li) 'name is hoho age is 18 ``` > 转载来源:http://www.cnblogs.com/benric/p/4965224.html