CreateAnimation() private static method

private static CreateAnimation ( GameObject gameObject, Object frames ) : bool
gameObject UnityEngine.GameObject
frames Object
return bool
Exemplo n.º 1
0
 public static GameObject DropFramesToSceneToCreateGO(Sprite[] frames, Vector3 position)
 {
     if (frames.Length > 0)
     {
         Sprite sprite = frames[0];
         string name   = (!string.IsNullOrEmpty(sprite.name)) ? sprite.name : "Sprite";
         name = GameObjectUtility.GetUniqueNameForSibling(null, name);
         GameObject     gameObject     = new GameObject(name);
         SpriteRenderer spriteRenderer = gameObject.AddComponent <SpriteRenderer>();
         spriteRenderer.sprite         = sprite;
         gameObject.transform.position = position;
         Selection.activeObject        = gameObject;
         if (frames.Length > 1)
         {
             Analytics.Event("Sprite Drag and Drop", "Drop multiple sprites to scene", "null", 1);
             if (!SpriteUtility.CreateAnimation(gameObject, frames))
             {
                 UnityEngine.Object.DestroyImmediate(gameObject);
                 return(null);
             }
         }
         else
         {
             Analytics.Event("Sprite Drag and Drop", "Drop single sprite to scene", "null", 1);
         }
         return(gameObject);
     }
     return(null);
 }
Exemplo n.º 2
0
 public static void AddAnimationToGO(GameObject go, Sprite[] frames)
 {
     if (frames != null && frames.Length > 0)
     {
         SpriteRenderer spriteRenderer = go.GetComponent <SpriteRenderer>();
         if (spriteRenderer == null)
         {
             Debug.LogWarning("There should be a SpriteRenderer in dragged object");
             spriteRenderer = go.AddComponent <SpriteRenderer>();
         }
         spriteRenderer.sprite = frames[0];
         if (frames.Length > 1)
         {
             Analytics.Event("Sprite Drag and Drop", "Drop multiple sprites to scene", "null", 1);
             if (!SpriteUtility.CreateAnimation(go, frames))
             {
                 Debug.LogError("Failed to create animation for dragged object");
             }
         }
         else
         {
             Analytics.Event("Sprite Drag and Drop", "Drop single sprite to scene", "null", 1);
         }
     }
 }
Exemplo n.º 3
0
        public static void AddAnimationToGO(GameObject go, Sprite[] frames)
        {
            if (frames == null || frames.Length <= 0)
            {
                return;
            }
            SpriteRenderer spriteRenderer = go.GetComponent <SpriteRenderer>();

            if ((UnityEngine.Object)spriteRenderer == (UnityEngine.Object)null)
            {
                Debug.LogWarning((object)"There should be a SpriteRenderer in dragged object");
                spriteRenderer = go.AddComponent <SpriteRenderer>();
            }
            spriteRenderer.sprite = frames[0];
            if (frames.Length > 1)
            {
                Analytics.Event("Sprite Drag and Drop", "Drop multiple sprites to scene", "null", 1);
                if (SpriteUtility.CreateAnimation(go, (UnityEngine.Object[])frames))
                {
                    return;
                }
                Debug.LogError((object)"Failed to create animation for dragged object");
            }
            else
            {
                Analytics.Event("Sprite Drag and Drop", "Drop single sprite to scene", "null", 1);
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public static bool AddAnimationToGO(GameObject go, Sprite[] frames, SpriteUtility.ShowFileDialogDelegate saveFileDialog)
        {
            SpriteRenderer spriteRenderer = go.GetComponent <SpriteRenderer>();
            bool           result;

            if (spriteRenderer == null)
            {
                Debug.LogWarning(SpriteUtility.SpriteUtilityStrings.unableToFindSpriteRendererWarning.text);
                spriteRenderer = go.AddComponent <SpriteRenderer>();
                if (spriteRenderer == null)
                {
                    Debug.LogWarning(SpriteUtility.SpriteUtilityStrings.unableToAddSpriteRendererWarning.text);
                    result = false;
                    return(result);
                }
            }
            spriteRenderer.sprite = frames[0];
            result = SpriteUtility.CreateAnimation(go, frames, saveFileDialog);
            return(result);
        }
Exemplo n.º 6
0
        public static bool AddAnimationToGO(GameObject go, Sprite[] frames, SpriteUtility.ShowFileDialogDelegate saveFileDialog)
        {
            SpriteRenderer spriteRenderer = go.GetComponent <SpriteRenderer>();
            bool           result;

            if (spriteRenderer == null)
            {
                Debug.LogWarning("There should be a SpriteRenderer in dragged object");
                spriteRenderer = go.AddComponent <SpriteRenderer>();
                if (spriteRenderer == null)
                {
                    Debug.LogWarning("Unable to add SpriteRenderer into Gameobject.");
                    result = false;
                    return(result);
                }
            }
            spriteRenderer.sprite = frames[0];
            result = SpriteUtility.CreateAnimation(go, frames, saveFileDialog);
            return(result);
        }