Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        Player p = new Player();

        p.timerManager = tmanager;
        Data           = new BridgeData(p);
        bmanager       = new BuffManager(Data);

        var b = new Protection(bmanager, 10);

        b.AddEffect();
        b = new Protection(bmanager, 5);
        b.AddEffect();

        It1 t1 = p as It1;

        p.Reset();
        It2 t2 = p as It2;

        p.Reset();

        AtlasManager.Cache(new string[] { "test", "dd" });

        InvokeRepeating("t", 0, 1);
        // Invoke("tt",5);
    }
Beispiel #2
0
    void t()
    {
        var s = AtlasManager.GetSprite("test", "G4");

        Resources.UnloadUnusedAssets();
        Debug.Log(s == null);
    }
Beispiel #3
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
 }
Beispiel #4
0
    private void UpdateSprite(Action <UIAtlasTarget> onComplete = null)
    {
        if (!m_image)
        {
            m_image = this.GetComponentDefault <Image>();
        }

        var an = m_atlas; var sn = m_sprite;

        AtlasManager.GetSprite(m_atlas, m_sprite, s =>
        {
            if (!this || an != m_atlas || sn != m_sprite)
            {
                return;
            }

            m_current       = s;
            m_image.enabled = m_current;
            m_image.sprite  = m_current;

            if (m_useNativeSize)
            {
                m_image.SetNativeSize();
            }

            onComplete?.Invoke(this);
        });
    }
Beispiel #5
0
 void LoadSprite(string spriteName)
 {
     if (target && !string.IsNullOrEmpty(spriteName))
     {
         target.enabled = false;
         ResLoader.LoadAssetAsync <Sprite>(AtlasManager.GetAtlasKey(spriteName), OnSpriteCompleted, null);
     }
 }
Beispiel #6
0
 protected void ClearImage(Image img)
 {
     if (m_ImageIds.ContainsKey(img))
     {
         long id = m_ImageIds[img];
         AtlasManager.WindowImageIdReturn(this, id);
         m_ImageIds.Remove(img);
     }
 }
Beispiel #7
0
        protected override void Init(IServiceCollection services)
        {
            _spriteFilter = CreateFilter(new EntityFilterConfiguration().With <RectTransform>().With <SpriteComponent>());

            _transform = GetReadOnly <RectTransform>();
            _sprite    = GetReadOnly <SpriteComponent>();

            _renderQueue  = services.Get <SpriteRenderQueue>();
            _atlasManager = services.Get <AtlasManager>();
        }
Beispiel #8
0
 private static Texture2D GetTexture(GameObject prefab, string spriteName)
 {
     if (prefab != null && spriteName != null)
     {
         UISprite component = prefab.GetComponent <UISprite>();
         UIAtlas  atlas     = component.atlas;
         return(AtlasManager.ExtractSprite(atlas, spriteName));
     }
     return(null);
 }
Beispiel #9
0
        public virtual void Draw(SpriteBatch spriteBatch)
        {
            if (AtlasManager != null)
            {
                AtlasManager.Draw(spriteBatch);
            }
            else
            {
                throw new Exception("this ni goe");
            }

            //HealthHandler.Draw(spriteBatch);
        }
Beispiel #10
0
 static int GetAtlasManager(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 0);
         AtlasManager o = LuaFramework.LuaHelper.GetAtlasManager();
         ToLua.PushSealed(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #11
0
    public static Sprite GetPicByID(int pictureID)
    {
        string      pid_str = string.Format("{0:000}", pictureID);
        SpriteAtlas atlas   = AtlasManager.LoadAtlas("CardPics_" + (pictureID / 100));
        Sprite      sprite  = atlas.GetSprite(pid_str);

        if (sprite == null)
        {
            Debug.LogError("所选卡片没有图片资源:" + pid_str);
            return(GetPicByID((int)AllCards.SpecialPicIDs.Empty));
        }

        return(sprite);
    }
        public void LoadAllAnimationsIntoCache()
        {
            /*
             *  Builds all animations from sprites and adds them to the cache.
             *  This should be called when a scene is FIRST loaded, before initializing characters.
             */

            List <string> modelList = AtlasManager.GetModelList();

            for (int i = 0; i < modelList.Count; i++)
            {
                LoadAnimationIntoCache(modelList[i]);
                AtlasManager.IncrementModelLoaded();
            }
        }
Beispiel #13
0
    public override void OnInspectorGUI()
    {
        _am = target as AtlasManager;
        serializedObject.Update();

        _dirty = false;

        if (_am?.SpriteList == null)
        {
            _am            = _am ?? new AtlasManager();
            _am.SpriteList = new List <Sprite>();
            _dirty         = true;
        }

        if (GUILayout.Button("Load"))
        {
            UnloadSprites();

            var characterSprites = Directory.GetFiles(Application.dataPath + PathToCharacterTextures, "*", SearchOption.AllDirectories);
            var equipmentSprites = Directory.GetFiles(Application.dataPath + PathToEquipmentTextures, "*", SearchOption.AllDirectories);

            LoadFiles(characterSprites);
            LoadFiles(equipmentSprites);

            // update the model-list text file
            using (var outputFile = new StreamWriter("model-list.txt"))
            {
                foreach (var model in _am.ModelList)
                {
                    outputFile.WriteLine(model);
                }
            }
        }

        if (GUILayout.Button("Unload"))
        {
            UnloadSprites();
        }

        if (_dirty)
        {
            EditorUtility.SetDirty(_am.gameObject);
        }

        DrawDefaultInspector();
        serializedObject.ApplyModifiedProperties();
    }
Beispiel #14
0
    public static Texture2D ExtractSprite(UIAtlas atlas, string spriteName)
    {
        if (atlas.texture == null)
        {
            return(null);
        }
        UISpriteData sprite = atlas.GetSprite(spriteName);

        if (sprite == null)
        {
            return(null);
        }
        Texture2D tex = atlas.texture as Texture2D;

        AtlasManager.SpriteEntry spriteEntry = AtlasManager.ExtractSprite(sprite, tex);
        return(spriteEntry.tex);
    }
Beispiel #15
0
 static int LoadSprite(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 4);
         AtlasManager obj  = (AtlasManager)ToLua.CheckObject(L, 1, typeof(AtlasManager));
         string       arg0 = ToLua.CheckString(L, 2);
         string       arg1 = ToLua.CheckString(L, 3);
         System.Action <UnityEngine.Sprite> arg2 = (System.Action <UnityEngine.Sprite>)ToLua.CheckDelegate <System.Action <UnityEngine.Sprite> >(L, 4);
         obj.LoadSprite(arg0, arg1, arg2);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #16
0
    public static void LoadSpriteAtlas_Editor()
    {
        AtlasManager.Reset();
        SpriteAtlas[] sas = Resources.LoadAll <SpriteAtlas>("SpriteAtlas");
        foreach (SpriteAtlas sa in sas)
        {
            if (!AtlasManager.SpriteAtlasDict.ContainsKey(sa.name))
            {
                AtlasManager.SpriteAtlasDict.Add(sa.name.Split('.')[0], sa);
            }
        }

        BackGroundManager.BGs = new Sprite[AtlasManager.LoadAtlas("BGs").spriteCount];
        AtlasManager.LoadAtlas("BGs").GetSprites(BackGroundManager.BGs);

        Debug.Log("LoadSpriteAtlas_Editor Success");
    }
Beispiel #17
0
        public virtual void Update(GameTime gameTime, MapManager mapManager)
        {
            Mover.Move(gameTime, mapManager);

            AtlasManager.SetAnimation();
            AtlasManager.Update(gameTime);

            //Collision check should happen here
            //CollisionHandler.CheckCollision(mapManager);
            //CollisionHandler.CheckCollisionSprite(mapManager);

            Mover.UpdatePosition();
            Mover.ResetVelocity();

            //HealthReduction test at AtlasManager Attack and mapManager UpdateMap
            //HealthHandler.Update();
        }
Beispiel #18
0
    private static void oneCopyImgToTmpPath(Children child, string fileName = "")
    {
        if (child.classname == "IMAGE")
        {
            string[] link_split = child.options.link.Split('#');
            string   rootPath   = (link_split.Length > 0) ? (link_split[0]) : "";
            string   imgPath    = (link_split.Length > 0) ? link_split[link_split.Length - 1] : "";

            string atlasName = "rootPath" + "_" + Path.GetFileNameWithoutExtension(imgPath);

            Sprite sprite = null;
            // 先到公共图集中查询是否有该图片
            if (File.Exists(PSDConst.ATLAS_PATH_COMMON))
            {
                sprite = AtlasManager.getSpriteForTextureP(PSDConst.ATLAS_PATH_COMMON, atlasName);
            }

            if (sprite == null)
            {
                //复制到临时文件夹,给打包图集用
                string tmpDir       = PSD2UI.texturePackerTempPath + fileName + "/";
                string singleImg    = PSD2UI.curBaseAssetsDir + rootPath + "/" + imgPath;
                string tarSingleImg = tmpDir + imgPath;
                string saveTempDir  = Directory.GetParent(tarSingleImg).FullName;
                Debug.Log("###tarImg:" + tarSingleImg);
                Debug.Log("###saveDir:" + saveTempDir);
                if (!Directory.Exists(saveTempDir))
                {
                    Directory.CreateDirectory(saveTempDir);
                }
                if ((!File.Exists(tarSingleImg)) && (!Directory.Exists(tarSingleImg)))
                {
                    File.Copy(singleImg, tarSingleImg);
                }
            }
        }
        if (child.children.Length > 0)
        {
            for (int i = child.children.Length - 1; i >= 0; i--)
            {
                oneCopyImgToTmpPath(child.children[i], fileName);
            }
        }
    }
 private void Start()
 {
     if (_listenersData == null)
     {
         _listenersData = new ListenersData();
     }
     if (_commentData == null)
     {
         _commentData = new CommentData();
     }
     if (_atlasManager == null)
     {
         _atlasManager = new AtlasManager();
     }
     if (_liveStatus == null)
     {
         _liveStatus = this.gameObject.GetComponent <LiveStatus> ();
     }
 }
    void Awake()
    {
        /// If this is the first GameManager instance, store self in a static forever.
        /// If not, self-destruct because that static position has been filled.

        // Check if instance exists
        if (Instance == null)
        {
            //if not, set instance to this
            Instance = this;
        }
        //If instance already exists and it's not this:
        else if (Instance != this)
        {
            //Then wipe self. Zero mercy for late arrivals.
            Destroy(gameObject);
        }

        //Sets this one to not be destroyed when reloading scene
        DontDestroyOnLoad(gameObject);
    }
        public AnimationDNABlock BuildAnimation(SingleAnimationImporter animationDefinition, string spritesheetKey, string direction)
        {
            string animationKey = spritesheetKey + "_" + animationDefinition.TagName;

            // fetch all frames for an model/action/direction into a list
            List <Sprite> spriteList = new List <Sprite>();

            for (int i = 0; i < animationDefinition.NumberOfFrames; i++)
            {
                string spriteKey = animationKey + "_" + i;
                Sprite sprite    = AtlasManager.GetSprite(spriteKey);
                spriteList.Add(sprite);
            }

            // get the model key from the animation key
            string modelKey     = animationKey.Split('_')[0].ToUpper();
            int    sortingOrder = DNABlockType.GetSortingOrder(modelKey, direction);

            // create a new animation block
            return(new AnimationDNABlock(animationKey, spriteList, direction, sortingOrder));
        }
Beispiel #22
0
    public static bool IsCardPictureValid(int pictureID)
    {
        string pid_str = string.Format("{0:000}", pictureID);

        if (string.IsNullOrEmpty(pid_str))
        {
            return(false);
        }

        SpriteAtlas atlas = AtlasManager.LoadAtlas("CardPics_" + (pictureID / 100));

        if (atlas)
        {
            Sprite sprite = atlas.GetSprite(pid_str);
            return(sprite != null);
        }
        else
        {
            return(false);
        }
    }
Beispiel #23
0
    private void LoadSpriteAtlas_AB()
    {
        AtlasManager.Reset();
        List <AssetBundle> list = ABManager.LoadAllAssetBundleNamedLike("atlas_");

        foreach (AssetBundle assetBundle in list)
        {
            SpriteAtlas[] sas = assetBundle.LoadAllAssets <SpriteAtlas>();
            foreach (SpriteAtlas sp in sas)
            {
                if (!AtlasManager.SpriteAtlasDict.ContainsKey(sp.name))
                {
                    AtlasManager.SpriteAtlasDict.Add(sp.name, sp);
                }
            }
        }

        BackGroundManager.BGs = new Sprite[AtlasManager.LoadAtlas("BGs").spriteCount];
        AtlasManager.LoadAtlas("BGs").GetSprites(BackGroundManager.BGs);

        Debug.Log("LoadSpriteAtlas_AB");
    }
Beispiel #24
0
        internal static UIAtlas GetRequiredAtlas(UISprite sprite, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(sprite.atlas);
            }

            UIAtlas atlas = AtlasManager.GetSpriteAtlas(value);

            if (atlas != null)
            {
                return(atlas);
            }

            SaveAtlas restoreAtlas = sprite.gameObject.GetComponent <SaveAtlas>();

            if (restoreAtlas != null)
            {
                return(restoreAtlas.original);
            }

            return(sprite.atlas);
        }
Beispiel #25
0
    internal void InitializePicSelectGrid(string labelStrKey)
    {
        LanguageManager.Instance.RegisterTextKey(Label, labelStrKey);

        PicSelectGridPanel.SetActive(false);
        PicSelectGridCloseButton.gameObject.SetActive(false);
        foreach (PicPreviewButton ppb in PicPreviewButtons)
        {
            ppb.PoolRecycle();
        }

        PicPreviewButtons.Clear();

        SortedDictionary <int, Sprite> SpriteDict = new SortedDictionary <int, Sprite>();

        for (int i = 0; i <= 10; i++)
        {
            SpriteAtlas sa      = AtlasManager.LoadAtlas("CardPics_" + i);
            Sprite[]    Sprites = new Sprite[sa.spriteCount];
            sa.GetSprites(Sprites);
            foreach (Sprite sprite in Sprites)
            {
                SpriteDict.Add(int.Parse(sprite.name.Replace("(Clone)", "")), sprite);
            }
        }

        foreach (KeyValuePair <int, Sprite> kv in SpriteDict)
        {
            PicPreviewButton ppb = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.PicPreviewButton].AllocateGameObject <PicPreviewButton>(PicSelectGridContainer.transform);
            ppb.Initialize(kv.Value, delegate
            {
                OnClickPicAction?.Invoke(kv.Key.ToString(), false);
                OnPicSelectGridCloseButtonClick();
            });
            PicPreviewButtons.Add(ppb);
        }
    }
    void Start()
    {
        // Initialize atlas dictionaries for all block types
        foreach (string bodyKey in DNABlockType.GetTypeList())
        {
            AtlasLookup[bodyKey] = new Dictionary <string, Sprite>();
        }

        int i = 0;

        // Sort each sprite in the spritelist into respective dictionary
        foreach (Sprite sprite in spriteList)
        {
            i++;
            string atlasKey = sprite.name.Split('_')[0].ToUpper();
            try {
                AtlasLookup[atlasKey][sprite.name] = sprite;
            } catch (Exception ex) {
                Debug.Log(string.Format("Failed to load sprite for atlas key; {0} sprite name {1}", atlasKey, sprite.name));
            }
        }

        instance = GetComponent <AtlasManager>();
    }
Beispiel #27
0
        protected void SetImage(Image img, string atlas, string icon)
        {
            SetImageSpriteParam param = new SetImageSpriteParam();

            param.abName    = atlas; // "texture_set/common.jpg";
            param.assetName = icon;  // "anniu4H_4zi_C";
            param.img       = img;
            param.call      = OnSetImageCallback;
            long id = -1;

            if (m_ImageIds.ContainsKey(img))
            {
                id = m_ImageIds[img];
                AtlasManager.WindowImageIdReturn(this, id);
                id = AtlasManager.SetImageSprite(param);
                m_ImageIds[img] = id;
            }
            else
            {
                id = AtlasManager.SetImageSprite(param);
                m_ImageIds.Add(img, id);
            }
            //AtlasManager.WindowImageIdCollect(this, id);
        }
Beispiel #28
0
    private void Start()
    {
        // Initialize atlas dictionaries for all block types
        foreach (var bodyKey in DNABlockType.TypeList)
        {
            _atlasLookup[bodyKey] = new Dictionary <string, Sprite>();
        }

        // Sort each sprite in the spritelist into respective dictionary
        foreach (var sprite in SpriteList)
        {
            var atlasKey = sprite.name.Split('_')[0].ToUpper();
            try
            {
                _atlasLookup[atlasKey][sprite.name] = sprite;
            }
            catch (Exception)
            {
                Debug.Log($"Failed to load sprite for atlas key; {atlasKey} sprite name {sprite.name}");
            }
        }

        Instance = GetComponent <AtlasManager>();
    }
        void OnGUI()
        {
            if (!animationsLoaded)
            {
                // Loading message
                GUI.Box(new Rect(0, 0, Screen.width, Screen.height), "Caching all sprites... " +
                        Math.Floor((AtlasManager.GetModelsLoaded() / AtlasManager.GetModelsTotal() * 100)) + "%");
                if (AtlasManager.GetModelsLoaded() == AtlasManager.GetModelsTotal())
                {
                    // The sprites are all cached. Lets initialize the scene.
                    InitializeCharacterUI();
                    InitializeCharacter();
                    InitializeDemoDNA();
                    animationsLoaded         = true;
                    playerController.enabled = true;
                }
            }
            else
            {
                int increaseYAmt = 25;
                int currentY     = 35;
                int currentX     = 10;

                // generate the model text boxes
                GUI.Label(new Rect(100, 10, 60, 20), "Model Key IDs");
                foreach (string blockKey in DNABlockType.GetTypeList())
                {
                    GUI.Label(new Rect(currentX, currentY, 60, 20), String.Format("{0}:", blockKey.ToLower()));
                    modelTextLookup[blockKey] = GUI.TextField(new Rect(currentX + 60, currentY, 175, 20), modelTextLookup[blockKey], 25);
                    currentY += increaseYAmt;
                }

                // "generate" button
                if (GUI.Button(new Rect(10, currentY, 75, 30), "Generate"))
                {
                    foreach (string blockKey in DNABlockType.GetTypeList())
                    {
                        try {
                            Player.characterDNA.UpdateBlock(blockKey, modelTextLookup[blockKey], modelColorLookup[blockKey]);
                        } catch (Exception ex) {
                            Debug.Log(String.Format("ERROR when importing {0} model: {1}", blockKey, ex.Message));
                        }
                    }
                }

                // generate the model color text boxes
                currentY = 35;
                GUI.Label(new Rect(Screen.width - 230, 10, 220, 20), "Model Color RGB Values (0-255)");
                foreach (string blockKey in DNABlockType.GetTypeList())
                {
                    GUI.Label(new Rect(Screen.width - 240, currentY, 60, 20), String.Format("{0}:", blockKey.ToLower()));
                    modelRLookup[blockKey] = GUI.TextField(new Rect(Screen.width - 130, currentY, 35, 20), modelRLookup[blockKey], 25);
                    modelGLookup[blockKey] = GUI.TextField(new Rect(Screen.width - 90, currentY, 35, 20), modelGLookup[blockKey], 25);
                    modelBLookup[blockKey] = GUI.TextField(new Rect(Screen.width - 50, currentY, 35, 20), modelBLookup[blockKey], 25);
                    //modelTLookup[blockKey] = GUI.TextField(new Rect(Screen.width - 50, currentY, 35, 20), modelTLookup[blockKey], 25);
                    try {
                        float modelR, modelG, modelB;//, modelT;
                        bool  rIsFloat = float.TryParse(modelRLookup[blockKey], out modelR);
                        bool  gIsFloat = float.TryParse(modelGLookup[blockKey], out modelG);
                        bool  bIsFloat = float.TryParse(modelBLookup[blockKey], out modelB);
                        //bool tIsFloat = float.TryParse(modelTLookup[blockKey], out modelT);

                        modelColorLookup[blockKey] = new Color(
                            rIsFloat ? modelR / 255f : 0,
                            gIsFloat ? modelG / 255f : 0,
                            bIsFloat ? modelB / 255f : 0,
                            (rIsFloat || gIsFloat || bIsFloat) ? .85f : 0
                            );
                    } catch (Exception ex) {
                        Debug.Log(String.Format("ERROR when importing {0} color: {1}", blockKey, ex.Message));

                        // dont color the armor on parsing issues
                        modelColorLookup[blockKey] = Color.clear;
                    }
                    currentY += increaseYAmt;
                }
                GUI.Label(new Rect(Screen.width - 115, currentY, 30, 20), "R");
                GUI.Label(new Rect(Screen.width - 80, currentY, 30, 20), "G");
                GUI.Label(new Rect(Screen.width - 40, currentY, 30, 20), "B");
            }
        }
Beispiel #30
0
 public AtlasLoader(AtlasManager manager)
 {
     _manager = manager;
 }
Beispiel #31
0
 void Awake() {
   Instance = this;
 }