예제 #1
0
    private void OnPlatformClick(ConnectableObject clickedObject)
    {
        Debug.Log("fsv OnPlatformClick ID == " + clickedObject.Id);
        selectedObject = clickedObject;

        screenZPos     = Camera.main.WorldToScreenPoint(selectedObject.Root.transform.position).z;
        worldPosOffset = selectedObject.Root.transform.position - GetMouseWorldPosition();

        SetState(ApplicationState.Drag);
    }
예제 #2
0
    private void CreateConnectableObjects(int maxCount)
    {
        GameObject connectableGO;

        for (int i = 0; i < maxCount; i++)
        {
            connectableGO = GameObject.Instantiate(connectableObj) as GameObject;
            connectableGO.transform.SetParent(ConnectableRoot);
            connectableGO.transform.localPosition = GetRandomXZPosition(Radius);

            ConnectableObject obj = new ConnectableObject(i, connectableGO);
            obj.OnConnectorClick += OnConnectorClick;
            obj.OnPlatformClick  += OnPlatformClick;

            connectableList.Add(obj);
            connectableList[i].State = ConnectableObjectState.Idle;
        }
    }
예제 #3
0
    private void SetState(ApplicationState appState)
    {
        state = appState;

        switch (state)
        {
        case ApplicationState.Idle:
            selectedObject = null;
            SetObjectsState(ConnectableObjectState.Idle);
            break;

        case ApplicationState.WaitForConnection:
            SetObjectsState(ConnectableObjectState.WaitForConnection);
            break;

        case ApplicationState.Drag:
            SetObjectsState(ConnectableObjectState.Idle);
            break;
        }
    }
예제 #4
0
    public IEnumerator ConnectToParent()
    {
        if (Parent)
        {
            Vector3    newPos = parentConnectPoint.position + (transform.position - ConnectPointParent.position);
            Quaternion newRot = Parent.rotation;
            transform.position = newPos;
            transform.rotation = newRot;
        }

        foreach (Transform t in Children)
        {
            childCO = t.gameObject.GetComponent <ConnectableObject>();
            if (childCO)
            {
                childCO.ConnectToParent();
            }
        }

        yield return(null);
    }
예제 #5
0
    private void SetConnection(ConnectableObject startObject, ConnectableObject endObject)
    {
        if (startObject.Id == endObject.Id)
        {
            return;
        }

        string hash = startObject.Id.ToString() + endObject.Id.ToString();

        // если связь между этими двумя объектами уже установлена, то ничего не делаем
        if (connectionListInUse.ContainsKey(hash))
        {
            return;
        }

        ConnectionBehaviour connection = GetConnectionObjectFromPool();

        connection.SetStartRoot(startObject.Root.transform);
        connection.SetEndRoot(endObject.Root.transform);

        connectionListInUse.Add(hash, connection);
    }
예제 #6
0
    private void OnConnectorClick(ConnectableObject clickedObject)
    {
        Debug.Log("fsv OnConnectorClick ID == " + clickedObject.Id);
        // Кликнули в коннектор
        switch (state)
        {
        case ApplicationState.Idle:
            clickedObject.State = ConnectableObjectState.Selected;
            selectedObject      = clickedObject;

            screenZPos     = Camera.main.WorldToScreenPoint(selectedObject.Root.transform.position).z;
            worldPosOffset = selectedObject.Root.transform.position - GetMouseWorldPosition();

            SetState(ApplicationState.WaitForConnection);
            break;

        case ApplicationState.WaitForConnection:
            // Устанавливаем связь между объектами и сбрасываем состояние приложения на Idle
            SetConnection(selectedObject, clickedObject);
            SetState(ApplicationState.Idle);
            break;
        }
    }