Exemplo n.º 1
0
        private void SpawnFullCharacters(int NumberOfLines)
        {
            // Obtain the spawing positions of the characters
            List <Vector3> PositionsBuffer = new List <Vector3>();

            for (int SpawnGroups = 0; SpawnGroups < SpawnNodeData.Count; SpawnGroups++)
            {
                for (int i = PreviousSpawningLine; i < PreviousSpawningLine + SpawnNodeData[SpawnGroups].CharacterSpawningData.NumberOfLines; i++)
                {
                    for (int j = 0; j < SpawnNodeData[SpawnGroups].CharacterSpawningData.CharactersPerLine; j++)
                    {
                        // Add these positions into the spawn buffer
                        Vector3 position = SpawnNodeData[SpawnGroups].transform.position - Vector3.forward * i * SpawnNodeData[SpawnGroups].CharacterSpawningData.CharacterSpacing + Vector3.right * j * SpawnNodeData[SpawnGroups].CharacterSpawningData.CharacterSpacing;
                        PositionsBuffer.Add(position);
                    }
                }
            }

            // Instanctate the character that will be skinned into the scene
            GameObject prefab             = CharacterPrefab;
            GameObject instantiatedPrefab = Instantiate(prefab);
            Entity     prefabEntity       = instantiatedPrefab.GetComponent <CG_CharacterSkinner>().entity;

            for (int t = 0; t < PositionsBuffer.Count; t++)
            {
                // Get the current position to spawn
                Vector3 position        = PositionsBuffer[t];
                Entity  CharacterEntity = EntityManager.Instantiate(prefabEntity);

                // Set the character positional data
                CharacterTransformData CharacterTransformationData = EntityManager.GetComponentData <CharacterTransformData>(CharacterEntity);
                CharacterTransformationData.Position = position;
                CharacterTransformationData.Forward  = transform.forward;

                // Set the transform component of this new entitiy
                EntityManager.SetComponentData(CharacterEntity, CharacterTransformationData);

                CharacterCount++;
            }
            // Destroy the instanciated prefab, change the spawning line and update the character count
            Destroy(instantiatedPrefab);
            PreviousSpawningLine += NumberOfLines;
        }
Exemplo n.º 2
0
            public void Execute()
            {
                // Loop through the number of character transform positions
                for (int i = 0; i < charTransforms.Length; i++)
                {
                    // Get the current animation and transform based on the character selected
                    AnimationData          animation          = animData[i];
                    CharacterTransformData characterTransform = charTransforms[i];

                    // Get the animation clip from the current animation
                    AnimationClipDataBaked animClip = animClips[animation.animationID];

                    // The position of the animation position
                    float animTexturePos = animData[i].normalizedAnimationTime * animClip.textureRange + animClip.textureOfset;

                    // The position of centre pixel locations
                    float  lowerCentreTexPos = ((int)math.floor(animTexturePos * animClip.textureWidth) * 1.0f) / animClip.textureWidth;
                    float  upperCentreTexPos = lowerCentreTexPos + animClip.texturePixelOffset;
                    float3 texturePos        = new float3(lowerCentreTexPos, upperCentreTexPos, (animTexturePos - lowerCentreTexPos) / animClip.texturePixelOffset);

                    // Animation transition progress
                    float transitionPercent = animation.transitionPercent;

                    // Pre animation texture (transition)
                    AnimationClipDataBaked preClip = animClips[animation.animationToSwitchID];
                    float preTexturePosition       = animData[i].animationToSwitchNormTime * preClip.textureRange + preClip.textureOfset;
                    int   preLowerPixelInt         = (int)math.floor(preTexturePosition * preClip.textureWidth);

                    // Do this before the new animation
                    float  preLowerCentreTexPos = (preLowerPixelInt * 1.0f) / preClip.textureWidth;
                    float  preUpperCentreTexPos = preLowerCentreTexPos + preClip.texturePixelOffset;
                    float3 preTexturePos        = new float3(preLowerCentreTexPos, preUpperCentreTexPos, (preTexturePosition - preLowerCentreTexPos) / preClip.texturePixelOffset);

                    // Add the positional and rotation character data to their respective native lists
                    characterPositions.Add(new float4(characterTransform.Position, 1));
                    characterRotations.Add(quaternion.LookRotation(characterTransform.Forward, new Vector3(0.0f, 1.0f, 0.0f)));

                    // Add the texture animation data to their respecitve native lists
                    texturePositions.Add(texturePos);
                    preAnimationTexturePositions.Add(preTexturePos);
                    animationTransitionProgress.Add(transitionPercent);
                }
            }
Exemplo n.º 3
0
        private void Awake()
        {
            // Pass the 2 main components into the entity manager
            CharacterTransformData characterTransformData = new CharacterTransformData();
            AnimationData          animationData          = new AnimationData();

            // Get the gameobject and get the active entity manager that is created by the gamemanager
            entity        = GetComponent <GameObjectEntity>().Entity;
            entityManager = World.Active.GetOrCreateManager <EntityManager>();

            if (!characterMat)
            {
                if (characterToSkin)
                {
                    characterMat = characterToSkin.GetComponent <Renderer>().material;
                }
            }

            // Add these componenets to the entity manager
            entityManager.AddComponentData(entity, characterTransformData);
            entityManager.AddComponentData(entity, animationData);
        }