public CharacterDNA()
 {
     _dnaBlocks = new Dictionary <string, CharacterDNABlock>();
     foreach (string blockKey in DNABlockType.GetTypeList())
     {
         _dnaBlocks.Add(blockKey, new CharacterDNABlock());
     }
 }
예제 #2
0
 private AnimationCache()
 {
     _cacheLookup = new Dictionary <string, Dictionary <string, AnimationDNABlock> >();
     foreach (string blockKey in DNABlockType.GetTypeList())
     {
         string cacheKey = blockKey.ToLower();
         _cacheLookup[cacheKey] = new Dictionary <string, AnimationDNABlock>();
     }
 }
예제 #3
0
        public AnimationDNA()
        {
            /*
             *  Initialize a block for all DNA Types
             */

            _dnaBlocks = new Dictionary <string, AnimationDNABlock>();
            foreach (string blockKey in DNABlockType.GetTypeList())
            {
                _dnaBlocks.Add(blockKey, new AnimationDNABlock());
            }
        }
    void InitializeCharacterRenderers(AnimationRenderer charAnimator)
    {
        Dictionary <string, SpriteRenderer> spriteRenderers = new Dictionary <string, SpriteRenderer>();

        foreach (string blockKey in DNABlockType.GetTypeList())
        {
            GameObject blockObject = new GameObject(blockKey);
            blockObject.transform.parent = _playerObject.transform;
            spriteRenderers[blockKey]    = blockObject.AddComponent <SpriteRenderer>();
        }

        charAnimator.InitializeSpriteRenderers(spriteRenderers);
    }
        void InitializeCharacterUI()
        {
            modelRLookup = new Dictionary <string, string>();
            modelGLookup = new Dictionary <string, string>();
            modelBLookup = new Dictionary <string, string>();
            //modelTLookup = new Dictionary<string, string>();

            modelTextLookup  = new Dictionary <string, string>();
            modelColorLookup = new Dictionary <string, Color>();
            foreach (string blockKey in DNABlockType.GetTypeList())
            {
                modelTextLookup[blockKey]  = "";
                modelColorLookup[blockKey] = Color.clear;

                modelRLookup[blockKey] = "";
                modelGLookup[blockKey] = "";
                modelBLookup[blockKey] = "";
                //modelTLookup[blockKey] = "";
            }
        }
        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));
        }
    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>();
    }
        public void UpdateDNAForAction(CharacterDNA characterDNA, AnimationDNA animationDNA, BaseAction actionAnimation, string newDirection)
        {
            /*
             *  Uses the characterDNA to fetch the proper animations and update the animationDNA.
             */
            foreach (string blockType in DNABlockType.GetTypeList())
            {
                CharacterDNABlock characterDNABlock = characterDNA.DNABlocks[blockType];

                if (characterDNABlock.Enabled)
                {
                    animationDNA.DNABlocks[blockType] = getAnimation(characterDNABlock.ModelKey, actionAnimation, newDirection);
                    AnimationDNABlock animationDNABlock = animationDNA.DNABlocks[blockType];
                    animationDNABlock.UpdateSpriteColor(characterDNABlock.ItemColor);
                    animationDNABlock.Enabled = true;
                }
                else
                {
                    // Disable the animation slot if the character slot isnt enabled
                    animationDNA.DNABlocks[blockType].Enabled = false;
                }
                characterDNABlock.IsDirty = false;
            }
        }
        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");
            }
        }