Example #1
0
        private void OnDrawGizmos()
        {
            var formationSlots = GroupFormation.GetDefaultFormationSlots();

            if (!formationSlots.IsCreated)
            {
                return;
            }

            Gizmos.color = Color.yellow;
            var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

            if (_groupEntity != Entity.Null)
            {
                var transformData = entityManager.GetComponentData <TransformData>(_groupEntity);
                var position      = new Vector3(transformData.Position.x, 0, transformData.Position.y);
                var forward       = new Vector3(transformData.Forward.x, 0, transformData.Forward.y);
                Gizmos.DrawWireSphere(position, 1);

                Gizmos.DrawLine(position, position + forward);
            }


            var localToWorld = Math.TrsFloat3x3(_curDestination, _curForward);
            int index        = 0;

            foreach (var slot in formationSlots)
            {
                var position = math.mul(localToWorld, new float3(slot, 1));
                Gizmos.color = new Color(1 - index / (float)formationSlots.Length, 0, 0);
                index++;
                Gizmos.DrawSphere(new Vector3(position.x, 0, position.y), 0.1f);
            }

            Gizmos.color = Color.white;
            Gizmos.DrawWireSphere(new Vector3(_curDestination.x, 0, _curDestination.y), 0.5f);
            Gizmos.DrawLine(new Vector3(_curDestination.x, 0, _curDestination.y),
                            new Vector3(_curDestination.x, 0, _curDestination.y) + new Vector3(_curForward.x, 0, _curForward.y));

            //draw move line
            var world   = World.DefaultGameObjectInjectionWorld;
            var members = entityManager.GetBuffer <GroupMemberElement>(_groupEntity);

            foreach (var member in members)
            {
                if (!entityManager.HasComponent <SteerArriveData>(member))
                {
                    continue;
                }
                var position    = entityManager.GetComponentData <TransformData>(member).Position;
                var destination = entityManager.GetComponentData <SteerArriveData>(member).Goal;
                Gizmos.DrawLine(new Vector3(position.x, 0, position.y), new Vector3(destination.x, 0, destination.y));
            }
        }
Example #2
0
        private void Start()
        {
            var flockData = FlockEntityPrefab.GetComponent <FlockEntityAuthor>();

            //create group
            var world         = World.DefaultGameObjectInjectionWorld;
            var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
            var ecb           = new EntityCommandBuffer(Allocator.Temp);

            _groupEntity = entityManager.CreateEntity();
            entityManager.SetName(_groupEntity, "GroupEntity");
            entityManager.AddComponent <KeepDestinationForward>(_groupEntity);
            entityManager.AddComponent <GroupFlag>(_groupEntity);
            entityManager.AddComponent <TransformData>(_groupEntity);
            entityManager.AddComponentData(_groupEntity, new SteerData
            {
                MaxSpeed     = flockData.MaxSpeed,
                MaxForce     = flockData.MaxPower,
                MaxSpeedRate = 1,
            });
            var memberList     = ecb.AddBuffer <GroupMemberElement>(_groupEntity);
            var convertSetting = new GameObjectConversionSettings
            {
                DestinationWorld = world,
            };
            var formationSlots = GroupFormation.GetDefaultFormationSlots();

            for (int i = 0; i < MemberCount; i++)
            {
                //spawn entity
                var flockEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(FlockEntityPrefab, convertSetting);
                entityManager.SetName(flockEntity, $"FlockEntity:{i}");
                var spawnPosition = formationSlots[i];
                //spawnPosition = new float2(Random.Range(-10, 10), Random.Range(-10, 10));
                entityManager.SetComponentData(flockEntity, new TransformData {
                    Position = spawnPosition
                });
                //entityManager.SetComponentData(flockEntity, new SteerArriveData {Goal = spawnPosition, ArriveRadius = 1});
                entityManager.RemoveComponent <Prefab>(flockEntity);
                entityManager.RemoveComponent <LinkedEntityGroup>(flockEntity);
                entityManager.AddComponentData(flockEntity, new GroupOwner {
                    GroupEntity = _groupEntity
                });
                entityManager.AddComponentData(flockEntity, new FormationLocalPosition {
                    Value = formationSlots[i]
                });
                memberList.Add(flockEntity);
            }

            ecb.Playback(entityManager);
            ecb.Dispose();
        }
Example #3
0
    public void Setup(Vector3 targetPos, List <Unit> newUnitList, GroupFormation.Type formationType)
    {
        _targetPos = targetPos;
        _unitList  = new List <Unit>(newUnitList);

        _groupFormation = GetComponent <GroupFormation>();
        _groupFormation.SetUpFormation(formationType, _unitList.Count);

        transform.position = FindCentroid();
        _maxSpeed          = ComputeSpeed();
        GetComponent <Movement>().UpdateGroupSpeed();

        foreach (Unit unit in _unitList)
        {
            unit.GoToGroupFormationPosition(this, transform.position);
        }
    }
Example #4
0
 public void SetFormation(GroupFormation formation)
 {
     Function.Call(Hash.SET_GROUP_FORMATION, handle, (int)formation);
 }
Example #5
0
 public void SetFormation(GroupFormation formation)
 {
     Function.Call(Hash.SET_GROUP_FORMATION, handle, (int)formation);
 }
Example #6
0
 void SetFormation(GroupFormation _newFormation)
 {
     currentFormation = _newFormation;
 }
Example #7
0
 private void OnDestroy()
 {
     GroupFormation.Dispose();
 }
Example #8
0
 //use constant speed
 private void Awake()
 {
     GroupFormation.Initialize();
 }