Example #1
0
    /// <summary>
    /// Builds a prefab to connect the current placeable to the given placeable
    /// </summary>
    /// <param name="connectPlaceable"></param>
    /// <param name="angle"></param>
    public override void hardConnectToPlaceable(Placeable connectPlaceable, float angle, int forcedConnectorIndex)
    {
        ConnectablePlaceable downconverted = (ConnectablePlaceable)connectPlaceable;
        int otherObjectsForcedIndex        = WorldManager.instance.mod(forcedConnectorIndex + 2, 4);//it will allways be a fence because of how the system works

        if (downconverted.id != id && forcedConnectors[forcedConnectorIndex] == false)
        {
        }
        else
        {
            downconverted.forcedConnectors[otherObjectsForcedIndex] = false;
            Debug.Log("Hard connecting");
            GameObject connectorPrefab = Instantiate(GameObject.Find("World").GetComponent <FlowerProperties>().getConnectorPrefab(this.id));
            connectorPrefab.transform.localPosition = gameObject.transform.position;
            connectorPrefab.transform.RotateAround(transform.position, Vector3.up, angle);
            if (Vector3.Dot(transform.right, transform.position - connectPlaceable.transform.position) > 0)//to the right
            {
                connectorPrefab.transform.position -= transform.right * 1.5f;
            }
            else
            {
                connectorPrefab.transform.position += transform.right * 1.5f;
            }
            //connectorPrefab.transform.localRotation = Quaternion.Euler(0, angle, 0);
            connectorPrefab.transform.parent = gameObject.transform;
            connectorList.Add(connectorPrefab);
            downconverted.softConnectToPlaceable(connectorPrefab);
        }
    }
    /// <summary>
    /// Builds a prefab to connect the current placeable to the given placeable
    /// </summary>
    /// <param name="connectPlaceable"></param>
    /// <param name="angle"></param>
    public override void hardConnectToPlaceable(Placeable connectPlaceable, float angle, int forcedConnectorIndex)
    {
        ConnectablePlaceable downconverted = (ConnectablePlaceable)connectPlaceable;
        int otherObjectsForcedIndex        = -1;

        if (downconverted is PostDecorationController)
        {
            otherObjectsForcedIndex = WorldManager.instance.mod(forcedConnectorIndex + 2, 4);
        }
        else if (downconverted is ArchControler)
        {
            otherObjectsForcedIndex = ((ArchControler)downconverted).getForcedIndex(flowerGridPos[0], flowerGridPos[1]);
        }
        if (downconverted.id != id && forcedConnectors[forcedConnectorIndex] == false)
        {
        }
        else
        {
            downconverted.forcedConnectors[otherObjectsForcedIndex] = false;
            foreach (GameObject p in connectorList)
            {
                if (downconverted.connectorList.Contains(p))
                {
                    return;
                }
            }
            //Debug.Log("Hard connecting");
            GameObject connectorPrefab = Instantiate(GameObject.Find("World").GetComponent <FlowerProperties>().getConnectorPrefab(this.id), gameObject.transform);
            connectorPrefab.transform.localPosition = Vector3.zero;
            connectorPrefab.transform.localRotation = Quaternion.Euler(0, angle, 0);
            connectorList.Add(connectorPrefab);
            ((ConnectablePlaceable)connectPlaceable).softConnectToPlaceable(connectorPrefab);
        }
    }