某人

此前素未谋面、此后遥遥无期

0%

escape()和unescape()函数

escape()函数

定义和用法: escape() 函数可对字符串进行编码,这样就可以在所有的计算机上读取该字符串。

字符的16进制格式值,当该值小于等于0xFF时,用一个2位转移序列: %xx 表示. 大于的话则使用4位序列:%uxxxx 表示.

返回值: 已编码的 string 的副本。其中某些字符被替换成了十六进制的转义序列。

阅读全文 »

bower

Bower一个好用的Web包管理器,可以搜索、安装和卸载如JavaScript、HTML、CSS等资源

阅读全文 »

最近遇到的试题

1.求字符串的字节长度(英文一个字节,汉字两个字节)

1
2
3
4
5
6
7
8
9
10
11
/*charCodeAt() 方法可返回指定位置的字符的 Unicode 编码。这个返回值是 0 - 65535 之间的整数。*/
function getByte(str) {
var len = str.length,
bytes = 0;
for (var i = 0; i < str.length; i++) {
if (str[i].charCodeAt() > 255) {
bytes++;
}
}
return len + bytes;
}
阅读全文 »

需求

  1. 鼠标滚轮实现缩放
  2. 鼠标拖动物体,移动

实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using UnityEngine;
using System.Collections;

public class MouseMoveCube : MonoBehaviour {

private void Start()
{
StartCoroutine(OnMouseDown());
}

private void Update()
{
ZoomCube();
}

private void ZoomCube()
{
//projection:投射方式

//zoom out
if (Input.GetAxis("Mouse ScrollWheel") < 0)
{
//Perspective:透视
if (Camera.main.fieldOfView <= 80)
{
Camera.main.fieldOfView += 2;
}

//Orthographic:正交
if (Camera.main.orthographicSize <= 18)
{
Camera.main.orthographicSize += 0.5f;
}
}

//zoom in
if (Input.GetAxis("Mouse ScrollWheel") > 0)
{

if (Camera.main.fieldOfView >= 2)
{
Camera.main.fieldOfView -= 2;
}

if (Camera.main.orthographicSize >= 1)
{
Camera.main.orthographicSize -= 0.5f;
}
}
}

IEnumerator OnMouseDown()
{

//将物体由世界坐标系转换为屏幕坐标系
Vector3 screenPostion = Camera.main.WorldToScreenPoint(transform.position);

//将鼠标屏幕坐标转为三维坐标,再算出物体位置与鼠标之间的距离(offset)
Vector3 offset = transform.position-Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y,
screenPostion.z));

while( Input.GetMouseButton(0) )
{
//当前鼠标位置
Vector3 curMousePostion = new Vector3(Input.mousePosition.x, Input.mousePosition.y,
screenPostion.z);

//将鼠标位置转换为世界位置,加上偏移量
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curMousePostion) + offset;

//将当前位置赋给世界物体的位置
transform.position = curPosition;

yield return new WaitForFixedUpdate();//循环
}
}
}

参考链接

  1. OnMouseDown-Unity

委托

委托(Delegate)都派生自 System.Delegate 类

委托(Delegate)特别用于实现事件和回调方法

委托可以叫为函数指针

c#委托-博客园传送

写的很详细,我参考抄的学习一下,希望作者不要嫌弃

阅读全文 »