Exemplo n.º 1
0
        public BlitableArray <byte> heights;          // x * z chunk slice

        public void Initialize(int width_, int height_)
        {
            width     = width_;
            height    = height_;
            topVoxels = new BlitableArray <byte>(width * height, Allocator.Persistent);
            heights   = new BlitableArray <byte>(width * height, Allocator.Persistent);
        }
Exemplo n.º 2
0
 public void Initialize(List <QuestDatam> meta = null)
 {
     quests = new BlitableArray <Quest>(meta.Count, Allocator.Persistent);
     for (int j = 0; j < quests.Length; j++)
     {
         if (meta != null && j < meta.Count)
         {
             Quest newQuest = new Quest {
                 metaID = meta[j].Value.id
             };
             List <QuestBlock> blocks = meta[j].Value.questBlocks;
             newQuest.blocks = new BlitableArray <QuestBlock>(blocks.Count, Allocator.Persistent);
             for (int k = 0; k < blocks.Count; k++)
             {
                 newQuest.blocks[k] = blocks[k];
             }
             quests[j] = newQuest;
         }
         else
         {
             quests[j] = new Quest {
             };
         }
     }
 }
Exemplo n.º 3
0
        public static BlitableArray <byte> StringToBytes(string text, BlitableArray <byte> fontIndexes, out byte updated)
        {
            List <byte> fontIndexesList = new List <byte>();
            int         numbersCount    = 10;
            int         aInt            = (int)'a';
            int         zInt            = (int)'z';

            for (int i = 0; i < text.Length; i++)
            {
                int  singleDigit = (int)text[i];
                byte fontIndex   = 0;
                if (text[i] == ' ')
                {
                    // byte is 255 for spaces!
                    fontIndex = (byte)255;
                }
                else if (singleDigit >= aInt && singleDigit <= zInt)
                {
                    fontIndex = (byte)((singleDigit - aInt) + numbersCount);
                }
                else
                {
                    if (int.TryParse(text[i].ToString(), out singleDigit))
                    {
                        fontIndex = (byte)singleDigit;
                    }
                    else
                    {
                        UnityEngine.Debug.Log("Unsupported character [" + text[i] + "]");
                        continue;
                    }
                }
                fontIndexesList.Add(fontIndex);
                //UnityEngine.Debug.LogError("Adding character: " + fontIndex + " at: " + fontIndexesList.Count);
            }
            if (fontIndexes.Length == fontIndexesList.Count)
            {
                bool isSame = true;
                for (int i = 0; i < fontIndexes.Length; i++)
                {
                    if (fontIndexes[i] != fontIndexesList[i])
                    {
                        isSame = false;
                        break;
                    }
                }
                if (isSame)
                {
                    updated = 0;
                    return(fontIndexes);
                }
            }
            fontIndexes = new BlitableArray <byte>(fontIndexesList.Count, Unity.Collections.Allocator.Persistent);
            for (int i = 0; i < fontIndexes.Length; i++)
            {
                fontIndexes[i] = fontIndexesList[i];
            }
            updated = 1;
            return(fontIndexes);
        }
Exemplo n.º 4
0
 public void InitializeLinks(int newCount)
 {
     links = new BlitableArray <int>(newCount, Allocator.Persistent);
     for (int i = 0; i < links.Length; i++)
     {
         links[i] = 0;
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Only supports lowercase atm
 /// </summary>
 /// <param name="text"></param>
 public void SetText(string text)
 {
     if (fontIndexes.Length > 0)
     {
         fontIndexes.Dispose();
     }
     fontIndexes = StringToBytes(text.ToLower(), fontIndexes, out updated);
 }
Exemplo n.º 6
0
 public void Initialize(List <SkillDatam> startingSkills)
 {
     Dispose();
     skills = new BlitableArray <SkillData>(startingSkills.Count, Unity.Collections.Allocator.Persistent);
     for (int i = 0; i < startingSkills.Count; i++)
     {
         skills[i] = startingSkills[i].Value;
     }
 }
Exemplo n.º 7
0
Arquivo: Stats.cs Projeto: Deus0/zoxel
 public void InitializeLevels(int count)
 {
     levels = new BlitableArray <Level>(count, Allocator.Persistent);
     for (int j = 0; j < levels.Length; j++)
     {
         levels[j] = new Level {
         };
     }
 }
Exemplo n.º 8
0
Arquivo: Stats.cs Projeto: Deus0/zoxel
 public void InitializeRegens(int count)
 {
     regens = new BlitableArray <RegenStaz>(count, Allocator.Persistent);
     for (int j = 0; j < regens.Length; j++)
     {
         regens[j] = new RegenStaz {
         };
     }
 }
Exemplo n.º 9
0
Arquivo: Stats.cs Projeto: Deus0/zoxel
 public void InitializeAttributes(int count)
 {
     attributes = new BlitableArray <AttributeStaz>(count, Allocator.Persistent);
     for (int j = 0; j < attributes.Length; j++)
     {
         attributes[j] = new AttributeStaz {
         };
     }
 }
Exemplo n.º 10
0
Arquivo: Stats.cs Projeto: Deus0/zoxel
 public void InitializeStates(int count)
 {
     states = new BlitableArray <StateStaz>(count, Allocator.Persistent);
     for (int j = 0; j < states.Length; j++)
     {
         states[j] = new StateStaz {
         };
     }
 }
Exemplo n.º 11
0
        public void SetText(string text, ref RenderText newText)
        {
            byte updatedText;

            fontIndexes = RenderText.StringToBytes(text, fontIndexes, out updatedText);
            endIndex    = 0;
            maxIndex    = (byte)text.Length;
            newText.SetText(new BlitableArray <byte>(0, Unity.Collections.Allocator.Persistent));
        }
Exemplo n.º 12
0
 public void Initialize(int count)
 {
     skills = new BlitableArray <SkillData>(count, Allocator.Persistent);
     for (int j = 0; j < skills.Length; j++)
     {
         skills[j] = new SkillData {
         };
     }
 }
Exemplo n.º 13
0
        public void AddBranchLink()
        {
            var oldLinks = links.ToArray();

            links = new BlitableArray <int>(links.Length + 1, Allocator.Persistent);
            for (int i = 0; i < links.Length - 1; i++)
            {
                links[i] = oldLinks[i];
            }
            links[links.Length - 1] = 0;
        }
Exemplo n.º 14
0
        public void BakeWeights(EntityManager EntityManager, NativeArray <ZoxelVertex> verticesN, int vertsCount)
        {
            var vertices = verticesN.ToArray();

            boneIndexes = new BlitableArray <byte>(vertsCount, Allocator.Persistent);
            for (int j = 0; j < boneIndexes.Length; j++)
            {
                boneIndexes[j] = 0;
            }
            for (int i = 0; i < bones.Length; i++)
            {
                var    bone            = EntityManager.GetComponentData <Bone>(bones[i]);
                var    bonePosition    = bone.position;
                float3 influenceSize   = bone.GetInfluenceSize();
                float3 influenceOffset = bone.GetInfluenceOffset();

                /*float3 influenceSize = 1.0f * ((bone.influenceMax - bone.influenceMin).ToFloat3() / 32f);
                 * float3 midPoint = (influenceSize / 2f);
                 * float3 influenceOffset = (bone.influenceMax.ToFloat3() / 32f - midPoint);*/

                var influenceMin = bonePosition + influenceOffset - influenceSize / 2f;
                var influenceMax = bonePosition + influenceOffset + influenceSize / 2f;
                //Debug.LogError("Baking Weights " + i + " influenceOffset: " + influenceOffset + " influenceSize: " + influenceSize);
                for (int j = 0; j < vertsCount; j++)
                {
                    if (boneIndexes[j] == 0)
                    {
                        var vertPosition = vertices[j].position;
                        if (vertPosition.x >= influenceMin.x && vertPosition.x <= influenceMax.x &&
                            vertPosition.y >= influenceMin.y && vertPosition.y <= influenceMax.y &&
                            vertPosition.z >= influenceMin.z && vertPosition.z <= influenceMax.z)
                        {
                            //DebugLines.DrawCubeLines(vertPosition, skeletonRotation.Value, 0.5f * influenceSize, Color.red);
                            boneIndexes[j] = (byte)(i + 1);
                        }
                    }
                }
                // influence should have a minimum and max, a bounding box around the bone position
                // this can be set in bones when generating and debugged with more box lines
                //DrawDebugSphere(chunk.bones[i], influence);
                // for each bone, fight weights within radius using vertexes
            }
            //influence += influenceAdd;
            //}

            for (int j = 0; j < boneIndexes.Length; j++)
            {
                if (boneIndexes[j] != 0)
                {
                    boneIndexes[j] = (byte)((int)boneIndexes[j] - 1);
                }
            }
        }
Exemplo n.º 15
0
 public void EquipGear(List <ItemDatam> body_)
 {
     if (body_.Count > 0)
     {
         dirty = 1;
         gear  = new BlitableArray <EquipmentItem>(0, Allocator.Persistent);
         foreach (var item in body_)
         {
             AddNewBodyPart(item.data);
         }
     }
 }
Exemplo n.º 16
0
Arquivo: Stats.cs Projeto: Deus0/zoxel
 public void RemoveStat(StatDatam statDatam, int indexOf)
 {
     if (statDatam.type == StatType.Base)
     {
         List <Staz> priorStates = new List <Staz>(stats.ToArray());
         stats = new BlitableArray <Staz>(stats.Length - 1, Allocator.Persistent);
         priorStates.RemoveAt(indexOf);
         for (int i = 0; i < priorStates.Count; i++)
         {
             stats[i] = priorStates[i];
         }
     }
     else if (statDatam.type == StatType.State)
     {
         List <StateStaz> priorStates = new List <StateStaz>(states.ToArray());
         states = new BlitableArray <StateStaz>(states.Length - 1, Allocator.Persistent);
         priorStates.RemoveAt(indexOf);
         for (int i = 0; i < priorStates.Count; i++)
         {
             states[i] = priorStates[i];
         }
     }
     else if (statDatam.type == StatType.Regen)
     {
         List <RegenStaz> priorStates = new List <RegenStaz>(regens.ToArray());
         regens = new BlitableArray <RegenStaz>(regens.Length - 1, Allocator.Persistent);
         priorStates.RemoveAt(indexOf);
         for (int i = 0; i < priorStates.Count; i++)
         {
             regens[i] = priorStates[i];
         }
     }
     else if (statDatam.type == StatType.Attribute)
     {
         List <AttributeStaz> priorStats = new List <AttributeStaz>(attributes.ToArray());
         attributes = new BlitableArray <AttributeStaz>(attributes.Length - 1, Allocator.Persistent);
         priorStats.RemoveAt(indexOf);
         for (int i = 0; i < priorStats.Count; i++)
         {
             attributes[i] = priorStats[i];
         }
     }
     else if (statDatam.type == StatType.Level)
     {
         List <Level> priorStats = new List <Level>(levels.ToArray());
         levels = new BlitableArray <Level>(levels.Length - 1, Allocator.Persistent);
         priorStats.RemoveAt(indexOf);
         for (int i = 0; i < priorStats.Count; i++)
         {
             levels[i] = priorStats[i];
         }
     }
 }
Exemplo n.º 17
0
        public BlitableArray <AnimationData> GetBlittableArray()
        {
            BlitableArray <AnimationData> data = new BlitableArray <AnimationData>(datas.Length, Allocator.Persistent);
            int i = 0;

            foreach (AnimationData dat in datas)
            {
                data[i] = dat;
                i++;
            }
            return(data);
        }
Exemplo n.º 18
0
        public BlitableArray <BoneData> GetBlittableArray()
        {
            BlitableArray <BoneData> data = new BlitableArray <BoneData>(datas.Count, Allocator.Persistent);
            int i = 0;

            foreach (BoneData dat in datas)
            {
                data[i] = dat;
                i++;
            }
            return(data);
        }
Exemplo n.º 19
0
 public void SetIDs(List <int> worldsChunkIDs, List <int> oldChunkIDs)
 {
     newIDs = new BlitableArray <int>(worldsChunkIDs.Count, Unity.Collections.Allocator.Persistent);
     for (int i = 0; i < newIDs.Length; i++)
     {
         newIDs[i] = worldsChunkIDs[i];
     }
     oldIDs = new BlitableArray <int>(oldChunkIDs.Count, Unity.Collections.Allocator.Persistent);
     for (int i = 0; i < oldIDs.Length; i++)
     {
         oldIDs[i] = oldChunkIDs[i];
     }
 }
Exemplo n.º 20
0
 public void AddPlayerCharacter(int characterID)
 {
     int[] previousPlayers = spawnedPlayerIDs.ToArray();
     if (spawnedPlayerIDs.Length > 0)
     {
         spawnedPlayerIDs.Dispose();
     }
     spawnedPlayerIDs = new BlitableArray <int>(previousPlayers.Length + 1, Unity.Collections.Allocator.Persistent);
     for (int i = 0; i < previousPlayers.Length; i++)
     {
         spawnedPlayerIDs[i] = previousPlayers[i];
     }
     spawnedPlayerIDs[spawnedPlayerIDs.Length - 1] = characterID;
 }
Exemplo n.º 21
0
 public void Initialize(ClassDatam classer)
 {
     if (classer != null)
     {
         //if (skills.Length == 0)
         {
             skills = new BlitableArray <SkillData>(classer.startingSkills.Count, Unity.Collections.Allocator.Persistent);
             for (int i = 0; i < classer.startingSkills.Count; i++)
             {
                 skills[i] = classer.startingSkills[i].Value;
             }
         }
     }
 }
Exemplo n.º 22
0
 public void SetRenders(Dictionary <int, bool> allRenders)
 {
     newRenders = new BlitableArray <byte>(newIDs.Length, Unity.Collections.Allocator.Persistent);
     for (int i = 0; i < newRenders.Length; i++)
     {
         if (allRenders.ContainsKey(newIDs[i]))
         {
             if (allRenders[newIDs[i]])
             {
                 newRenders[i] = 1;
             }
         }
     }
 }
Exemplo n.º 23
0
        public void Initialize(List <Entity> entities, List <float3> positions, List <Entity> newParents)
        {
            // should find closest in certain directions
            // if nothing in that direction dont add that direction
            // create navigation based no positions
            // top left is start of navigation
            List <NavigateUIElement> newNavigationElements = new List <NavigateUIElement>();

            if (positions.Count == 1)
            {
                NavigateUIElement element = new NavigateUIElement();
                //element.previousPosition = positions[0];
                element.targetPosition = positions[0];
                element.direction      = 0;
                element.ui             = newParents[0];
                //element.arrayIndex = 0;
                element.entity = entities[0];
                newNavigationElements.Add(element);
            }
            else
            {
                for (int i = 0; i < positions.Count; i++)
                {
                    // up
                    newNavigationElements = AddNavigationUI(entities, newParents, newNavigationElements, positions,
                                                            positions[i], i, 2, 10000);
                    // down
                    newNavigationElements = AddNavigationUI(entities, newParents, newNavigationElements, positions,
                                                            positions[i], i, 3, -10000);
                    // left
                    newNavigationElements = AddNavigationUI(entities, newParents, newNavigationElements, positions,
                                                            positions[i], i, 1, -10000);
                    // right
                    newNavigationElements = AddNavigationUI(entities, newParents, newNavigationElements, positions,
                                                            positions[i], i, 0, 10000);
                }
            }
            NavigateUIElement[] originalNavigationElements = navigationElements.ToArray();
            navigationElements = new BlitableArray <NavigateUIElement>(originalNavigationElements.Length + newNavigationElements.Count, Unity.Collections.Allocator.Persistent);
            for (int i = 0; i < originalNavigationElements.Length; i++)
            {
                navigationElements[i] = originalNavigationElements[i];
            }
            for (int i = 0; i < newNavigationElements.Count; i++)
            {
                navigationElements[i + originalNavigationElements.Length] = newNavigationElements[i];
            }
            //UnityEngine.Debug.LogError("Initialized " + navigationElements.Length + " with navigateUIElement.");
        }
Exemplo n.º 24
0
 public void SetData(List <Entity> newCharacters, List <int> newClans, List <float> newDistances, List <float3> newPositions)
 {
     Dispose();
     characters = new BlitableArray <NearbyCharacter>(newCharacters.Count, Unity.Collections.Allocator.Persistent);
     for (int i = 0; i < characters.Length; i++)
     {
         characters[i] = new NearbyCharacter
         {
             character = newCharacters[i],
             clan      = newClans[i],
             distance  = newDistances[i],
             position  = newPositions[i]
         };
     }
     //UnityEngine.Debug.LogError("Characters found: " + characters.Length);
 }
Exemplo n.º 25
0
        public void AddNewBodyPart(int bodyPartIndex, int slotIndex, Item item)
        {
            var oldBodyParts = body.ToArray();

            body = new BlitableArray <EquipmentItem>(oldBodyParts.Length + 1, Allocator.Persistent);
            for (int i = 0; i < oldBodyParts.Length; i++)
            {
                body[i] = oldBodyParts[i];
            }
            var bodyPart = new EquipmentItem();

            bodyPart.data             = item;
            bodyPart.bodyIndex        = bodyPartIndex;
            bodyPart.slotIndex        = slotIndex;
            body[oldBodyParts.Length] = bodyPart;
            dirty = 1;
        }
Exemplo n.º 26
0
        public void DestroyEntity(EntityManager EntityManager, int index)
        {
            DestroChildAtIndex(EntityManager, index);
            var children_ = children.ToArray();

            children = new BlitableArray <Entity>(children.Length - 1, Allocator.Persistent);
            for (int i = 0; i < children.Length; i++)
            {
                if (i < index)
                {
                    children[i] = children_[i];
                }
                else
                {
                    children[i] = children_[i + 1];
                }
            }
        }
Exemplo n.º 27
0
 public void InitializeItems(int count, List <ItemDatam> meta = null)
 {
     items = new BlitableArray <InventoryItem>(count, Allocator.Persistent);
     for (int j = 0; j < items.Length; j++)
     {
         if (meta != null && j < meta.Count)
         {
             items[j] = new InventoryItem {
                 data = meta[j].data, quantity = 1
             };
         }
         else
         {
             items[j] = new InventoryItem {
             };
         }
     }
 }
Exemplo n.º 28
0
 public void SetBody(int3 size_, List <int3> positions_, List <VoxData> voxes)
 {
     size  = size_;
     sizes = new BlitableArray <int3>(voxes.Count, Unity.Collections.Allocator.Persistent);
     for (int i = 0; i < voxes.Count; i++)
     {
         sizes[i] = voxes[i].size;
     }
     positions = new BlitableArray <int3>(positions_.Count, Unity.Collections.Allocator.Persistent);
     for (int i = 0; i < positions_.Count; i++)
     {
         //Debug.LogError(i + " - Adding position: " + positions_[i] +", and size: " + sizes[i]);
         //Quaternion backwards = Quaternion.Euler(new Vector3(0, 180, 0));
         //quaternion backwards2 = backwards;
         //positions[i] = new int3(-positions_[i].x, positions_[i].y, positions_[i].z); //math.rotate(backwards2, positions_[i]);
         positions[i] = positions_[i];
     }
 }
Exemplo n.º 29
0
        public void AddBranch(DialogueBranch branch)
        {
            // first store branches
            var branches_ = branches.ToArray();

            // now create new array
            if (branches.Length > 0)
            {
                branches.Dispose();
            }
            branches = new BlitableArray <DialogueBranch>(branches.Length + 1, Allocator.Persistent);
            // set old one
            for (int i = 0; i < branches.Length - 1; i++)
            {
                branches[i] = branches_[i];
            }
            // set new one
            branches[branches.Length - 1] = branch;
        }
Exemplo n.º 30
0
        public void RemoveBranch(DialogueBranch branch)
        {
            if (branches.Length == 0)
            {
                return;
            }
            int index = -1;

            for (int i = 0; i < branches.Length; i++)
            {
                if (branches[i].id == branch.id)
                {
                    index = i;
                    break;
                }
            }
            if (index == -1)
            {
                return;
            }
            // first store branches
            var originalBranches = branches.ToArray();

            // now create new array
            if (branches.Length > 0)
            {
                branches.Dispose();
            }
            branches = new BlitableArray <DialogueBranch>(originalBranches.Length - 1, Allocator.Persistent);
            // set old one
            for (int i = 0; i < originalBranches.Length; i++)
            {
                if (i < index)
                {
                    branches[i] = originalBranches[i];
                }
                else if (i > index)
                {
                    branches[i - 1] = originalBranches[i];
                }
            }
        }