public static Vector3 GetSceneToUIWorldPos(Vector3 SceneWorldPos) { Vector3 screenPos = CCTool.GetSceneToScreenPos(SceneWorldPos); Vector3 UIPos = GetScreenToUIWorldPos(screenPos); UIPos.z = 0; return(UIPos); }
public bool HasKey(string key) { if (!CCTool.JSContainsKey(JsData, key)) { return(false); } return(true); }
protected virtual void OnCCDragMove(PointerEventData eventData) { if (!m_InDrag) { return; } m_DragTrans.position = CCTool.GetScreenToUIWorldPos(eventData.position); }
public string GetString(string key) { if (!CCTool.JSContainsKey(JsData, key)) { return(""); } string str = JsData[key].ToString(); return(str); }
public float GetFloat(string key) { if (!CCTool.JSContainsKey(JsData, key)) { return(0); } string jsStr = JsData[key].ToJson(); return(float.Parse(jsStr)); }
public bool GetBool(string key) { if (!CCTool.JSContainsKey(JsData, key)) { return(false); } string jsStr = JsData[key].ToJson(); return(bool.Parse(jsStr)); }
protected override void OnCCDragMove(PointerEventData eventData) { if (!m_InDrag) { return; } if (!m_EnableMove && m_ScrollView != null) { m_ScrollView.OnDrag(eventData); return; } if (CurMoveType == DragMoveType.None) { CurMoveType = GetMoveType(DragStartPos, eventData.position); if (CurMoveType == m_ScrollView.DragType) { base.OnButtonPress(false); if (m_ScrollView != null) { m_ScrollView.OnDragStart(eventData); } } else if (CurMoveType == m_DefaultDragType) { m_DragTrans.SetSiblingIndex(1000); m_DragTrans.SetParent(m_ScrollView.DragRootObj.transform); m_DragTrans.position = CCTool.GetScreenToUIWorldPos(eventData.position); OnStartDarg(); } } else { if (CurMoveType == m_DefaultDragType) { if (m_EnableSetPos) { m_DragTrans.position = CCTool.GetScreenToUIWorldPos(eventData.position); } } else { m_DragTrans.SetSiblingIndex(startSiblingIndex); if (m_ScrollView != null) { m_ScrollView.OnDrag(eventData); } } } }
public static Sprite GetSprite(string pPath, bool nonReandable = true) { if (!System.IO.File.Exists(pPath)) { #if UNITY_EDITOR Debug.LogError("找不到路径 : " + pPath); #endif return(null); } var bytes = System.IO.File.ReadAllBytes(pPath); var tex = new Texture2D(1, 1); tex.LoadImage(bytes, nonReandable); Sprite spr = CCTool.TextureToSprite(tex); return(spr); }
public void SetArea(Vector3 pos, Vector2 size) { Vector2 ScreenSize = CCTool.GetWindowSize(); float ScreenWidth = ScreenSize.x; float ScreenHeight = ScreenSize.y; transform.position = pos; Vector2 halfSize = new Vector2(size.x / 2f, size.y / 2f); Vector3 left_up = new Vector3(pos.x - halfSize.x, pos.y + halfSize.y, 0) + new Vector3(ScreenWidth / 2, +ScreenHeight / 2, 0); Vector3 left_down = new Vector3(pos.x - halfSize.x, pos.y - halfSize.y, 0) + new Vector3(ScreenWidth / 2, +ScreenHeight / 2, 0); Vector3 right_up = new Vector3(pos.x + halfSize.x, pos.y + halfSize.y, 0) + new Vector3(ScreenWidth / 2, +ScreenHeight / 2, 0); Vector3 right_down = new Vector3(pos.x + halfSize.x, pos.y - halfSize.y, 0) + new Vector3(ScreenWidth / 2, +ScreenHeight / 2, 0); //up { RectTransform pCollider = Collider_Up; float cHeight = ScreenHeight - left_up.y; pCollider.SetSize(new Vector2(ScreenWidth, cHeight)); pCollider.transform.SetLocal_Y((size.y + cHeight) / 2); } // // //down // { // BoxCollider pCollider = Collider_Down; // float cHeight = left_down.y; // pCollider.size = new Vector3(ScreenWidth, cHeight, 1); // pCollider.center = new Vector3(0, cHeight/2f-ScreenHeight/2, 0); // } // // //left // { // BoxCollider pCollider = Collider_Left; // float cWidth = left_up.x; // pCollider.size = new Vector3(cWidth, ScreenHeight, 1); // pCollider.center = new Vector3(left_up.x-ScreenWidth/2 -cWidth/2, 0, 0); // } // // //right // { // BoxCollider pCollider = Collider_Right; // float cWidth = ScreenWidth - right_up.x; // pCollider.size = new Vector3(cWidth, ScreenHeight, 1); // pCollider.center = new Vector3(right_up.x-ScreenWidth/2 +cWidth/2, 0, 0); // } }
IEnumerator Play() { CCAction.Stop(gameObject); yield return(new WaitForSeconds(m_delaytime)); gameObject.GetComponent <Image>().color = m_StartColor; CCTool.SetColor(gameObject, m_StartColor); while (true) { CCAction.Color(gameObject, m_EndAlpha, m_time); yield return(new WaitForSeconds(m_time)); yield return(new WaitForSeconds(m_time)); gameObject.GetComponent <Image>().color = m_StartColor; } }
/// <summary> /// 传入图片路径,加载图片到Image /// </summary> ///<param name="pImg">需要设置sprite的UIImage</param> /// <param name="pPath">需要加下载的图片路径</param> /// <param name="pSize">UIImage的大小</param> public static bool SetImageSprite(Image pImg, string pPath, Vector2 pSize) { if (pImg == null) { #if UNITY_EDITOR Debug.LogError("找不到图片"); #endif return(false); } if (!System.IO.File.Exists(pPath)) { #if UNITY_EDITOR Debug.LogError("找不到路径 : " + pPath); #endif return(false); } var bytes = System.IO.File.ReadAllBytes(pPath); var tex = new Texture2D(1, 1); tex.LoadImage(bytes, true); //tex.Apply(); pImg.sprite = CCTool.TextureToSprite(tex); float tWidth = pSize.x; float tHeight = pSize.y; if (tex.width / tex.height > tWidth / tHeight) { tHeight = tex.height * tWidth / tex.width; } else { tWidth = tex.width * tHeight / tex.height; } pImg.GetComponent <RectTransform>().sizeDelta = new Vector2(tWidth, tHeight); return(true); }
void Awake() { m_Logo.SetLocal_Y(800); m_Loading.SetActive(false); int playType = Random.Range(0, 5); isOnlyX = CCTool.RandomBool; m_CurPlayIndexs = new List <int[]> (); // if (playType == 0) { // m_CurPlayIndexs.Add (new int[]{ 1, 26 }); // m_CurPlayIndexs.Add (new int[]{ 2, 3, 14, 25 }); // m_CurPlayIndexs.Add (new int[]{ 9, 10, 4, 24, 20, 8 }); // m_CurPlayIndexs.Add (new int[]{ 15, 16, 17, 11, 5, 23, 19, 13, 7, 22 }); // m_CurPlayIndexs.Add (new int[]{ 21, 18, 12, 6 }); // } else { // int[] block1 = new int[]{ 1, 2, 9, 15 }; // int[] block2 = new int[]{ 3, 10, 16, 17, 21 }; // int[] block3 = new int[]{ 4, 11, 18, 22 }; // int[] block4 = new int[]{ 5, 12, 19, 23 }; // int[] block5 = new int[]{ 6, 13, 20, 24 }; // int[] block6 = new int[]{ 7, 8, 14, 25, 26 }; // // if (playType == 1) { // m_CurPlayIndexs.Add (block1); // m_CurPlayIndexs.Add (block2); // m_CurPlayIndexs.Add (block3); // m_CurPlayIndexs.Add (block4); // m_CurPlayIndexs.Add (block5); // m_CurPlayIndexs.Add (block6); // m_DelayTime = 0.15f; // } else if (playType == 2) { // m_CurPlayIndexs.Add (block6); // m_CurPlayIndexs.Add (block5); // m_CurPlayIndexs.Add (block4); // m_CurPlayIndexs.Add (block3); // m_CurPlayIndexs.Add (block2); // m_DelayTime = 0.15f; // m_CurPlayIndexs.Add (block1); // } else { // m_CurPlayIndexs.Add (new int[]{ 1, 2, 9, 15, 7, 8, 14, 25, 26 }); // m_CurPlayIndexs.Add (new int[]{ 3, 10, 16, 17, 21, 6, 13, 20, 24 }); // m_CurPlayIndexs.Add (new int[]{ 4, 11, 18, 22, 5, 12, 19, 23 }); // } // } foreach (RectTransform rtf in m_Images) { Image mask = CocoLoad.InstantiateOrCreate <Image> (string.Empty, rtf.transform); CCTool.SetImageAlpha(mask, 0.3515f); mask.GetComponent <RectTransform> ().sizeDelta = rtf.sizeDelta; if (isOnlyX) { rtf.localScale = new Vector3(0, 1, 1); } else { rtf.localScale = new Vector3(0, 0, 1); } } }