Beispiel #1
0
        private static void CreateSpriter(string path)
        {
            string  data       = File.ReadAllText(path);
            Spriter spriter    = SpriterReader.Default.Read(data);
            string  rootFolder = Path.GetDirectoryName(path);

            string      name        = Path.GetFileNameWithoutExtension(path);
            SpriterData spriterData = CreateSpriterData(spriter, rootFolder, name);

            foreach (SpriterEntity entity in spriter.Entities)
            {
                GameObject go       = new GameObject(entity.Name);
                GameObject sprites  = new GameObject(ObjectNameSprites);
                GameObject metadata = new GameObject(ObjectNameMetadata);

                SpriterDotNetBehaviour behaviour = go.AddComponent <SpriterDotNetBehaviour>();
                behaviour.UseNativeTags = UseNativeTags;
                if (SpriterImporterUtil.HasSound(entity))
                {
                    go.AddComponent <AudioSource>();
                }

                sprites.SetParent(go);
                metadata.SetParent(go);

                ChildData cd = new ChildData();
                SpriterImporterUtil.CreateSprites(entity, cd, sprites);
                SpriterImporterUtil.CreateCollisionRectangles(entity, cd, metadata);
                SpriterImporterUtil.CreatePoints(entity, cd, metadata);

                behaviour.EntityIndex = entity.Id;
                behaviour.enabled     = true;
                behaviour.SpriterData = spriterData;
                behaviour.ChildData   = cd;

                GameObject prefab = CreatePrefab(go, rootFolder);

                EntityImported(entity, prefab);
            }

            if (UseNativeTags)
            {
                CreateTags(spriter);
            }
        }
Beispiel #2
0
        public static SpriterDotNetBehaviour CreateSpriter(string path, string entityName, Transform parent = null)
        {
            GameObject             go        = new GameObject(entityName);
            SpriterDotNetBehaviour behaviour = go.AddComponent <SpriterDotNetBehaviour>();
            SpriterEntity          entity    = FetchOrCacheSpriterEntityDataFromFile(path, entityName, behaviour);

            if (entity == null)
            {
                UnityEngine.Object.Destroy(go);
                return(null);
            }

            GameObject sprites  = new GameObject(ObjectNameSprites);
            GameObject metadata = new GameObject(ObjectNameMetadata);

            behaviour.UseNativeTags = false;
            if (SpriterImporterUtil.HasSound(entity))
            {
                go.AddComponent <AudioSource>();
            }

            sprites.SetParent(go);
            metadata.SetParent(go);

            ChildData cd = new ChildData();

            SpriterImporterUtil.CreateSprites(entity, cd, sprites);
            SpriterImporterUtil.CreateCollisionRectangles(entity, cd, metadata);
            SpriterImporterUtil.CreatePoints(entity, cd, metadata);
            cd.Verify();

            behaviour.EntityIndex = entity.Id;
            behaviour.enabled     = true;
            behaviour.ChildData   = cd;

            go.transform.parent = parent;
            return(behaviour);
        }