private GameObject CreateAnimObj(string animName, bool createForInit = false) { UiAnimMgr.AnimData animData; this.m_animData.TryGetValue(animName, out animData); if (animData == null) { return(null); } GameObject gameObject = null; if (!createForInit && animData.m_availableObjects.Count > 0) { gameObject = animData.m_availableObjects.Pop(); } if (gameObject != null) { if (animData.m_activeObjects.Contains(gameObject)) { Debug.Log("Error! new anim object already in active object list."); } else { animData.m_activeObjects.Add(gameObject); } gameObject.SetActive(true); UiAnimation component = gameObject.GetComponent <UiAnimation>(); component.Reset(); component.m_ID = this.GetNextID(); return(gameObject); } gameObject = new GameObject(); if (createForInit) { animData.m_availableObjects.Push(gameObject); } else if (animData.m_activeObjects.Contains(gameObject)) { Debug.Log("Error! new anim object already in active object list."); } else { animData.m_activeObjects.Add(gameObject); } CanvasGroup canvasGroup = gameObject.AddComponent <CanvasGroup>(); canvasGroup.blocksRaycasts = false; canvasGroup.interactable = false; gameObject.name = animName; UiAnimation uiAnimation = gameObject.AddComponent <UiAnimation>(); uiAnimation.m_ID = this.GetNextID(); uiAnimation.Deserialize(animName); RectTransform rectTransform = gameObject.AddComponent <RectTransform>(); rectTransform.SetSizeWithCurrentAnchors(0, uiAnimation.GetFrameWidth()); rectTransform.SetSizeWithCurrentAnchors(1, uiAnimation.GetFrameHeight()); foreach (UiAnimation.UiTexture uiTexture in uiAnimation.m_textures.Values) { GameObject gameObject2 = new GameObject(); gameObject2.name = uiTexture.m_parentKey + "_Texture"; gameObject2.transform.SetParent(gameObject.transform, false); uiTexture.m_image = gameObject2.AddComponent <Image>(); uiTexture.m_image.sprite = uiTexture.m_sprite; uiTexture.m_image.canvasRenderer.SetAlpha(uiTexture.m_alpha); if (uiTexture.m_alphaMode == "ADD") { uiTexture.m_image.material = new Material(UiAnimMgr.instance.m_additiveMaterial); } else { uiTexture.m_image.material = new Material(UiAnimMgr.instance.m_blendMaterial); } uiTexture.m_image.material.mainTexture = uiTexture.m_sprite.texture; RectTransform component2 = gameObject2.GetComponent <RectTransform>(); if (uiTexture.m_anchor != null && uiTexture.m_anchor.relativePoint != null) { string relativePoint = uiTexture.m_anchor.relativePoint; switch (relativePoint) { case "TOP": component2.anchorMin = new Vector2(0.5f, 1f); component2.anchorMax = component2.anchorMin; break; case "BOTTOM": component2.anchorMin = new Vector2(0.5f, 0f); component2.anchorMax = component2.anchorMin; break; case "LEFT": component2.anchorMin = new Vector2(0f, 0.5f); component2.anchorMax = component2.anchorMin; break; case "RIGHT": component2.anchorMin = new Vector2(1f, 0.5f); component2.anchorMax = component2.anchorMin; break; case "CENTER": component2.anchorMin = new Vector2(0.5f, 0.5f); component2.anchorMax = component2.anchorMin; break; case "TOPLEFT": component2.anchorMin = new Vector2(0f, 1f); component2.anchorMax = component2.anchorMin; break; case "TOPRIGHT": component2.anchorMin = new Vector2(1f, 1f); component2.anchorMax = component2.anchorMin; break; case "BOTTOMLEFT": component2.anchorMin = new Vector2(0f, 0f); component2.anchorMax = component2.anchorMin; break; case "BOTTOMRIGHT": component2.anchorMin = new Vector2(1f, 0f); component2.anchorMax = component2.anchorMin; break; } } Vector2 vector = default(Vector2); if (uiTexture.m_anchor != null && uiTexture.m_anchor.point != null) { string point = uiTexture.m_anchor.point; switch (point) { case "TOP": vector.Set(0f, -0.5f * uiTexture.m_image.sprite.rect.height); break; case "BOTTOM": vector.Set(0f, 0.5f * uiTexture.m_image.sprite.rect.height); break; case "LEFT": vector.Set(0.5f * uiTexture.m_image.sprite.rect.width, 0f); break; case "RIGHT": vector.Set(-0.5f * uiTexture.m_image.sprite.rect.width, 0f); break; case "TOPLEFT": vector.Set(0.5f * uiTexture.m_image.sprite.rect.width, -0.5f * uiTexture.m_image.sprite.rect.height); break; case "TOPRIGHT": vector.Set(-0.5f * uiTexture.m_image.sprite.rect.width, -0.5f * uiTexture.m_image.sprite.rect.height); break; case "BOTTOMLEFT": vector.Set(0.5f * uiTexture.m_image.sprite.rect.width, 0.5f * uiTexture.m_image.sprite.rect.height); break; case "BOTTOMRIGHT": vector.Set(-0.5f * uiTexture.m_image.sprite.rect.width, 0.5f * uiTexture.m_image.sprite.rect.height); break; } } component2.anchoredPosition = new Vector2(vector.x + uiTexture.m_anchor.x, vector.y + uiTexture.m_anchor.y); int num2 = 0; int num3 = 0; int.TryParse(uiTexture.m_width, out num2); int.TryParse(uiTexture.m_height, out num3); component2.SetSizeWithCurrentAnchors(0, (num2 <= 0) ? uiTexture.m_image.sprite.rect.width : ((float)num2)); component2.SetSizeWithCurrentAnchors(1, (num3 <= 0) ? uiTexture.m_image.sprite.rect.height : ((float)num3)); } foreach (UiAnimation.UiTexture uiTexture2 in uiAnimation.m_textures.Values) { RectTransform rectTransform2 = uiTexture2.m_image.rectTransform; uiTexture2.m_localPosition = rectTransform2.localPosition; } return(gameObject); }
private GameObject CreateAnimObj(string animName, bool createForInit = false) { UiAnimMgr.AnimData animDatum; Dictionary <string, int> strs; int num; this.m_animData.TryGetValue(animName, out animDatum); if (animDatum == null) { return(null); } GameObject gameObject = null; if (!createForInit && animDatum.m_availableObjects.Count > 0) { gameObject = animDatum.m_availableObjects.Pop(); } if (gameObject != null) { if (!animDatum.m_activeObjects.Contains(gameObject)) { animDatum.m_activeObjects.Add(gameObject); } else { Debug.Log("Error! new anim object already in active object list."); } gameObject.SetActive(true); UiAnimation component = gameObject.GetComponent <UiAnimation>(); component.Reset(); component.m_ID = this.GetNextID(); return(gameObject); } gameObject = new GameObject(); if (createForInit) { animDatum.m_availableObjects.Push(gameObject); } else if (!animDatum.m_activeObjects.Contains(gameObject)) { animDatum.m_activeObjects.Add(gameObject); } else { Debug.Log("Error! new anim object already in active object list."); } CanvasGroup canvasGroup = gameObject.AddComponent <CanvasGroup>(); canvasGroup.blocksRaycasts = false; canvasGroup.interactable = false; gameObject.name = animName; UiAnimation nextID = gameObject.AddComponent <UiAnimation>(); nextID.m_ID = this.GetNextID(); nextID.Deserialize(animName); RectTransform rectTransform = gameObject.AddComponent <RectTransform>(); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, nextID.GetFrameWidth()); rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, nextID.GetFrameHeight()); foreach (UiAnimation.UiTexture value in nextID.m_textures.Values) { GameObject gameObject1 = new GameObject() { name = string.Concat(value.m_parentKey, "_Texture") }; gameObject1.transform.SetParent(gameObject.transform, false); value.m_image = gameObject1.AddComponent <Image>(); value.m_image.sprite = value.m_sprite; value.m_image.canvasRenderer.SetAlpha(value.m_alpha); if (value.m_alphaMode != "ADD") { value.m_image.material = new Material(UiAnimMgr.instance.m_blendMaterial); } else { value.m_image.material = new Material(UiAnimMgr.instance.m_additiveMaterial); } value.m_image.material.mainTexture = value.m_sprite.texture; RectTransform vector2 = gameObject1.GetComponent <RectTransform>(); if (value.m_anchor != null && value.m_anchor.relativePoint != null) { string mAnchor = value.m_anchor.relativePoint; if (mAnchor != null) { if (UiAnimMgr.< > f__switch$map9 == null) { strs = new Dictionary <string, int>(9) { { "TOP", 0 }, { "BOTTOM", 1 }, { "LEFT", 2 }, { "RIGHT", 3 }, { "CENTER", 4 }, { "TOPLEFT", 5 }, { "TOPRIGHT", 6 }, { "BOTTOMLEFT", 7 }, { "BOTTOMRIGHT", 8 } }; UiAnimMgr.< > f__switch$map9 = strs; } if (UiAnimMgr.< > f__switch$map9.TryGetValue(mAnchor, out num)) { switch (num) { case 0: { vector2.anchorMin = new Vector2(0.5f, 1f); vector2.anchorMax = vector2.anchorMin; goto Label0; } case 1: { vector2.anchorMin = new Vector2(0.5f, 0f); vector2.anchorMax = vector2.anchorMin; goto Label0; } case 2: { vector2.anchorMin = new Vector2(0f, 0.5f); vector2.anchorMax = vector2.anchorMin; goto Label0; } case 3: { vector2.anchorMin = new Vector2(1f, 0.5f); vector2.anchorMax = vector2.anchorMin; goto Label0; } case 4: { vector2.anchorMin = new Vector2(0.5f, 0.5f); vector2.anchorMax = vector2.anchorMin; goto Label0; } case 5: { vector2.anchorMin = new Vector2(0f, 1f); vector2.anchorMax = vector2.anchorMin; goto Label0; } case 6: { vector2.anchorMin = new Vector2(1f, 1f); vector2.anchorMax = vector2.anchorMin; goto Label0; } case 7: { vector2.anchorMin = new Vector2(0f, 0f); vector2.anchorMax = vector2.anchorMin; goto Label0; } case 8: { vector2.anchorMin = new Vector2(1f, 0f); vector2.anchorMax = vector2.anchorMin; goto Label0; } } } } } Label0: Vector2 vector21 = new Vector2(); if (value.m_anchor != null && value.m_anchor.point != null) { string str = value.m_anchor.point; if (str != null) { if (UiAnimMgr.< > f__switch$mapA == null) { strs = new Dictionary <string, int>(9) { { "TOP", 0 }, { "BOTTOM", 1 }, { "LEFT", 2 }, { "RIGHT", 3 }, { "CENTER", 4 }, { "TOPLEFT", 5 }, { "TOPRIGHT", 6 }, { "BOTTOMLEFT", 7 }, { "BOTTOMRIGHT", 8 } }; UiAnimMgr.< > f__switch$mapA = strs; } if (UiAnimMgr.< > f__switch$mapA.TryGetValue(str, out num)) { switch (num) { case 0: { Rect mImage = value.m_image.sprite.rect; vector21.Set(0f, -0.5f * mImage.height); goto Label1; } case 1: { Rect rect = value.m_image.sprite.rect; vector21.Set(0f, 0.5f * rect.height); goto Label1; } case 2: { Rect mImage1 = value.m_image.sprite.rect; vector21.Set(0.5f * mImage1.width, 0f); goto Label1; } case 3: { Rect rect1 = value.m_image.sprite.rect; vector21.Set(-0.5f * rect1.width, 0f); goto Label1; } case 4: { goto Label1; } case 5: { float single = 0.5f * value.m_image.sprite.rect.width; Rect mImage2 = value.m_image.sprite.rect; vector21.Set(single, -0.5f * mImage2.height); goto Label1; } case 6: { float single1 = -0.5f * value.m_image.sprite.rect.width; Rect rect2 = value.m_image.sprite.rect; vector21.Set(single1, -0.5f * rect2.height); goto Label1; } case 7: { float single2 = 0.5f * value.m_image.sprite.rect.width; Rect mImage3 = value.m_image.sprite.rect; vector21.Set(single2, 0.5f * mImage3.height); goto Label1; } case 8: { float single3 = -0.5f * value.m_image.sprite.rect.width; Rect rect3 = value.m_image.sprite.rect; vector21.Set(single3, 0.5f * rect3.height); goto Label1; } } } } } Label1: vector2.anchoredPosition = new Vector2(vector21.x + value.m_anchor.x, vector21.y + value.m_anchor.y); int num1 = 0; int num2 = 0; int.TryParse(value.m_width, out num1); int.TryParse(value.m_height, out num2); vector2.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, (num1 <= 0 ? value.m_image.sprite.rect.width : (float)num1)); vector2.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (num2 <= 0 ? value.m_image.sprite.rect.height : (float)num2)); } foreach (UiAnimation.UiTexture uiTexture in nextID.m_textures.Values) { uiTexture.m_localPosition = uiTexture.m_image.rectTransform.localPosition; } return(gameObject); }