示例#1
0
    private GameObject CreateMovingBridge(PCGHistory.SearchPatternResult curr, GameObject parent, Vector3 startPoint, Vector3 endPoint)
    {
        GameObject movingBridge = Instantiate(movingBrigdePrefab, parent.transform.parent);

        movingBridge.transform.rotation = history.GetElement(curr.indexOfBridge).obj.transform.rotation;
        movingBridge.transform.position = (startPoint + endPoint) / 2 + startPoint;
        movingBridge.GetComponent <BridgeMoving>().SetEndPoints(startPoint, endPoint);
        return(movingBridge);
    }
示例#2
0
    private void CreateMovingBridges()
    {
        PCGHistory.SearchPatternResult[] bridges = history.SearchBrigde("01*2+1*0");

        for (int i = 0; i < bridges.Length; i++)
        {
            PCGHistory.SearchPatternResult curr = bridges[i];

            GameObject platform1 = history.GetElement(curr.index).obj;
            GameObject platform2 = history.GetElement(curr.index + curr.match.Length - 1).obj;

            bool isHoled1 = platform1.GetComponent <PlatformHoled>() != null;
            bool isHoled2 = platform2.GetComponent <PlatformHoled>() != null;

            if (isHoled1 || isHoled2)
            {
                continue;
            }

            float scale1 = platform1.transform.localScale.x;
            float scale2 = platform2.transform.localScale.x;

            float distance = (platform2.transform.position - platform1.transform.position).magnitude - (scale1 + scale2) / 2;

            if (distance > 5)
            {
                Vector3 startPoint = history.GetElement(curr.index).obj.transform.position;
                Vector3 endPoint   = history.GetElement(curr.index + curr.match.Length - 1).obj.transform.position;

                if (Math.Abs(startPoint.y - endPoint.y) > Mathf.Epsilon)
                {
                    return;
                }

                GameObject bridgeDestroyer = Instantiate(bridgeDestroyerPrefab, platform1.transform.parent);
                bridgeDestroyer.transform.rotation = history.GetElement(curr.indexOfBridge).obj.transform.rotation;
                bridgeDestroyer.GetComponent <BridgeDestroyer>().SetEndPoints(startPoint, endPoint);

                CreateMovingBridge(curr, platform1, startPoint, endPoint);

                if (distance > 20)
                {
                    CreateMovingBridge(curr, platform1, endPoint, startPoint);
                }
            }
        }
    }