Beispiel #1
0
    public static PlatformGroup Combine(PlatformGroup lhs, PlatformGroup rhs, Int2 playerIdx)
    {
        GameObject    output      = new GameObject("PlatformGroup");
        PlatformGroup outputGroup = output.AddComponent <PlatformGroup>();

        outputGroup.container = new HashSet <Platform>();
        //outputGroup.OnGroupMoved += robot.replanPath;

        //transfer ownership
        outputGroup.container.UnionWith(lhs.container);
        outputGroup.container.UnionWith(rhs.container);

        //transfer childObjs
        List <Transform> children = new List <Transform>();

        for (int i = 0; i < lhs.gameObject.transform.childCount; i++)
        {
            children.Add(lhs.gameObject.transform.GetChild(i));
        }
        foreach (Transform child in children)
        {
            child.transform.parent = output.transform;
        }

        children.Clear();
        for (int i = 0; i < rhs.gameObject.transform.childCount; i++)
        {
            children.Add(rhs.gameObject.transform.GetChild(i));
        }
        foreach (Transform child in children)
        {
            child.transform.parent = output.transform;
        }

        //Vector2 robotPos2d = new Vector2(robot.transform.position.x, robot.transform.position.z);
        if (ReferenceEquals(lhs, gridSystem.ComputeGroup(playerIdx)) ||
            ReferenceEquals(rhs, gridSystem.ComputeGroup(playerIdx)) ||
            ReferenceEquals(lhs, gridSystem.ComputeGroup(gridSystem.goal)) ||
            ReferenceEquals(rhs, gridSystem.ComputeGroup(gridSystem.goal)))
        {
            foreach (Transform child in output.transform)
            {
                child.gameObject.layer = Utility.ToLayerNumber(gridSystem.lockedPfLayer);//?
            }
        }

        foreach (Platform pf in outputGroup.container)
        {
            pf.group = outputGroup;
        }

        lhs.container.Clear();
        rhs.container.Clear();
        Destroy(lhs.gameObject);
        Destroy(rhs.gameObject);


        return(outputGroup);
    }