// checking if the given VisualSpriteObject is same as this class // mapper class and make sure the object is valid public bool ContentsEqual(VisualSpriteObject vso) { return(name == vso.name && prefabimage == vso.prefabimage && Mathf.Approximately(minX, vso.minX) && Mathf.Approximately(maxX, vso.maxX) && Mathf.Approximately(minY, vso.minY) && Mathf.Approximately(maxY, vso.maxY) && color == vso.color && depth == vso.depth && label == vso.label); }
public void UpdateState(VisualSpriteObject vso) { if (!visualSprite.ContentsEqual(vso)) { visualSprite = vso; // Updates color var imgComp = gameObject.GetComponent <Image>(); string label; if (visualSprite.showlabel) { Debug.Log(vso.label); gameObject.GetComponentInChildren <Text> ().text = visualSprite.label; } imgComp.color = visualSprite.color; // Transit to new state animator.UpdateVisualSprite(vso); animator.Animating = true; } }
// Starts rendering, this method is called by the VisualiserController public void Init(VisualSpriteObject vso) { // Binds visual sprite visualSprite = vso; // Sets game object name gameObject.name = visualSprite.name; // Sets up size, position and rotation UpdateRect(); // Renders name text on the sprite if (visualSprite.showname || visualSprite.showlabel) { var emptyUIObject = Resources.Load <GameObject>("EmptyUIObject"); var spriteName = Instantiate(emptyUIObject); var label = spriteName.AddComponent <Text>(); label.font = Resources.Load <Font>("Arial"); label.color = Color.black; if (visualSprite.showname) { label.text = visualSprite.name; } else { label.text = visualSprite.label; } label.alignment = TextAnchor.MiddleCenter; label.resizeTextForBestFit = true; var nameRectTransform = spriteName.GetComponent <RectTransform>(); nameRectTransform.anchorMin = new Vector2(0, 0); nameRectTransform.anchorMax = new Vector2(1, 1); nameRectTransform.offsetMin = new Vector2(0, 0); nameRectTransform.offsetMax = new Vector2(0, 0); spriteName.transform.SetParent(gameObject.transform, false); } // Sets sprite colour var image = gameObject.GetComponent <Image>(); image.color = visualSprite.color; // Sets default opacity of sprite var canvasGroup = gameObject.GetComponent <CanvasGroup>(); canvasGroup.alpha = 0; }