Unity零碎API(一)

  1. meshRenderer渲染顺序
GetComponent<MeshRenderer>().sortingOrder = GetComponent<SpriteRenderer>().sortingOrder + 1;
  1. 如果正在调用
            if (IsInvoking("jiu"))
            {
                CancelInvoke("jiu");
            }
  1. Renderer渲染顺序
piece.GetComponent<Renderer>().material.renderQueue = this.GetDrawPriorityPiece(n);
  1. 左键
eventData.button==PointerEventData.InputButton.Left
  1. 屏幕点在矩形内的世界坐标
 RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find("KnapsackUI").GetComponent<RectTransform>(), Input.mousePosition, null, out position);
  1. NavMeshAgent组件相关
        if (agent.enabled)
        {
            if (agent.remainingDistance < minDistance)
            {
                agent.Stop();
                agent.enabled = false;
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            SetDestination(target.position);
        }
        
        anim.SetFloat("speed", agent.velocity.magnitude);
  1. 层标记计算方法,如果还想碰撞继续加等于
	hitMask += 1 << LayerMask.NameToLayer("Entrance")
  1. 游戏截图
	ScreenCapture.CaptureScreenshot("游戏截图");
  1. 加载图片
    public static IEnumerator LoadImage(string url, Image image)
    {
        WWW www = new WWW(url);

        while (!www.isDone)
            yield return www;

        Texture2D texture = www.texture;
        Sprite sp = Sprite.Create(
            texture,
            new Rect(0, 0, texture.width, texture.height),
            new Vector2(0.5f, 0.5f));
        image.sprite = sp;
    }
  1. 滑动到哪里了
    public void OnEndDrag(PointerEventData eventData)
    {
        scrollRect.normalizedPosition
    }
  1. 2D射线
	Physics2D.Linecast();
  1. 滑轮向下
	Input.GetAxis("Mouse ScrollWheel") < 0
  1. 判断点击是不是UI
	EventSystem.current.IsPointerOverGameObject() == false
  1. 动画信息
    private void ChangedATKSpeed()
    {
        if (m_anmator != null)
        {
            AnimatorStateInfo asi = m_animator.GetCurrentAnimatorStateInfo(0);
            if (asi.IsName("attack"))
            {
                m_animator.speed = 3 / m_attackSpeed;
            }
        }
    }
  1. 加载设置材质

        Texture tex = Resources.Load("dog", typeof(Texture)) as Texture;

        Debug.Log(tex);

        mr.material.SetTexture("_Maintext", tex);
  1. scrollRect相关
	scrollRect.horizontalNormalizedPosition = pageArray[index];
  1. 相对力AddRelativeForce()
  2. 编辑器在运行吗
	UnityEditor.EditorApplication.isPlaying
  1. AddComponentMenu属性允许您将脚本放在“Component”菜单中的任何位置,而不仅仅是“Component-> Scripts”菜单
	[AddComponentMenu("UI/UIButton")]

猜你喜欢

转载自blog.csdn.net/qq_37811712/article/details/85382071
今日推荐