Esempio n. 1
0
        public static bool HandleSingleSpriteDragIntoHierarchy(IHierarchyProperty property, Sprite sprite, bool perform)
        {
            GameObject gameObject = null;

            if (property != null && property.pptrValue != null)
            {
                UnityEngine.Object pptrValue = property.pptrValue;
                gameObject = (pptrValue as GameObject);
            }
            if (perform)
            {
                Vector3    defaultInstantiatePosition = SpriteUtility.GetDefaultInstantiatePosition();
                GameObject gameObject2 = SpriteUtility.DropSpriteToSceneToCreateGO(sprite, defaultInstantiatePosition);
                if (gameObject != null)
                {
                    Analytics.Event("Sprite Drag and Drop", "Drop single sprite to existing gameobject", "null", 1);
                    gameObject2.transform.parent        = gameObject.transform;
                    gameObject2.transform.localPosition = Vector3.zero;
                }
                else
                {
                    Analytics.Event("Sprite Drag and Drop", "Drop single sprite to empty hierarchy", "null", 1);
                }
                Selection.activeGameObject = gameObject2;
            }
            return(true);
        }
Esempio n. 2
0
        public static bool HandleMultipleSpritesDragIntoHierarchy(IHierarchyProperty property, Sprite[] sprites, bool perform)
        {
            GameObject gameObject = null;

            if (property == null || property.pptrValue == null)
            {
                if (perform)
                {
                    Analytics.Event("Sprite Drag and Drop", "Drop multiple sprites to empty hierarchy", "null", 1);
                    gameObject      = new GameObject();
                    gameObject.name = ((!string.IsNullOrEmpty(sprites[0].name)) ? sprites[0].name : "Sprite");
                    gameObject.transform.position = SpriteUtility.GetDefaultInstantiatePosition();
                }
            }
            else
            {
                UnityEngine.Object pptrValue = property.pptrValue;
                gameObject = (pptrValue as GameObject);
                if (perform)
                {
                    Analytics.Event("Sprite Drag and Drop", "Drop multiple sprites to gameobject", "null", 1);
                }
            }
            if (perform)
            {
                SpriteRenderer spriteRenderer = gameObject.GetComponent <SpriteRenderer>();
                if (spriteRenderer == null)
                {
                    spriteRenderer = gameObject.AddComponent <SpriteRenderer>();
                }
                if (spriteRenderer == null)
                {
                    return(true);
                }
                if (spriteRenderer.sprite == null)
                {
                    spriteRenderer.sprite = sprites[0];
                }
                SpriteUtility.CreateAnimation(gameObject, sprites);
                Selection.activeGameObject = gameObject;
            }
            return(true);
        }