// Public
        public override void OnCommandGroupCreated(CommandGroup group)
        {
            var commonData = new CommonGroupData();

            group.AddCustomData(commonData);

            var rememberedPathStates = new RememberedPathStates(group.Units.Count);

            group.AddCustomData(rememberedPathStates);

            if (group is PatrolGroup)
            {
                var data = new PatrolData(group.Units);
                group.AddCustomData(data);
                group.OnUnitsWillBeRemoved += (evnt) =>
                {
                    data.RemoveRange(evnt.UnitsIndices);
                };
            }

            group.OnUnitsWillBeRemoved += (evnt) =>
            {
                rememberedPathStates.RemoveRange(evnt.UnitsIndices);
                commonData.Reset();
            };
        }
        void SetCommanderPath(CommonGroupData data, Vector3 targetPos)
        {
            var     commander   = data.Commander;
            Vector3 offset      = data.OffsetCommanderToCenter;
            var     destination = targetPos - offset;
            var     nodes       = new Vector3[] { destination };

            commander.Paths.ClearPaths();
            commander.Paths.CurrentPath = new Path(nodes);
        }
        // Private
        void SetUnitPaths(CommonGroupData data, IReadOnlyList <CommandUnit> units)
        {
            var commanderNodes = data.Commander.Paths.CurrentPath.Nodes;

            for (int i = 0; i < units.Count; i++)
            {
                if (i == data.CommanderIndex)
                {
                    continue;
                }

                var mag       = data.OffsetsUnitToCenter[i].magnitude;
                var dir       = (units[i].Unit.Position - data.Center).normalized;
                var posOffset = data.OffsetCommanderToCenter + dir * mag;
                var nodes     = new Vector3[commanderNodes.Length];
                Array.Copy(commanderNodes, nodes, commanderNodes.Length);
                for (int j = 0; j < nodes.Length; j++)
                {
                    nodes[j] += posOffset;
                }
                units[i].Paths.ClearPaths();
                units[i].Paths.CurrentPath = new Path(nodes);
            }
        }