예제 #1
0
    private void changeComponent()
    {
        //updates rotation, flipped, and compoent type of the visuals

        this.currentState = EditorState.AddCompoent;

        this.destroyMouseChildren();

        this.component = this.duplicateAt(this.component.GetType(), this.previousGridPosition, this.rotation, this.flipped);

        GraphComponentController gcc = this.logicGraphController.ComponentManager.createComponent(this.component);

        gcc.transform.SetParent(this.mouseObject.transform);
        Rect dmn = this.component.getDimentions();

        gcc.transform.localPosition = new Vector3(dmn.width / 2f, dmn.height / 2f, 0);

        //deactivates the sender controllers
        if (this.component.GetType().IsSubclassOf(typeof(InteractiveComponent)))
        {
            foreach (Transform child in gcc.transform)
            {
                SpriteRenderer rend = child.GetComponent <SpriteRenderer>();

                if (rend != null)
                {
                    rend.sortingLayerName = "Mouse";
                }

                SenderController sendCon = child.GetComponent <SenderController>();

                if (sendCon != null)
                {
                    GameObject.Destroy(sendCon);
                }
            }
        }

        if (this.component.GetType().IsSubclassOf(typeof(InteractiveComponent)))
        {
            gcc.transform.Find("MiddleBody").Find("LogicComponentSprite").GetComponent <SpriteRenderer>().sortingLayerName = "Mouse";
        }

        //adds the X to the sprite
        SpriteRenderer xGO = this.makeX();

        xGO.transform.SetParent(this.mouseObject.transform);
        xGO.color = Color.red;
        xGO.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);

        xGO.transform.position = gcc.transform.position;

        bool placeable = this.logicGraphController.Graph.LightGraph.canPlace(this.component);

        if (placeable)
        {
            xGO.gameObject.SetActive(false);
        }
    }
예제 #2
0
    /// <summary>
    /// Add a Light Component to the Logic Graph
    /// </summary>
    private void addComponentToGraph(LightComponent comp)
    {
        this.logicGraphController.Graph.LightGraph.addComponent(comp);
        GraphComponentController gcc = this.logicGraphController.ComponentManager.createComponent(comp);

        this.logicGraphController.ComponentManager.addComponent(gcc);
        this.logicGraphController.ComponentManager.reconnectRays();
    }
    public void loadComponents(LogicChip logicGraph, Vector3 bottomLeft)
    {
        //loads all of the components on to the graph
        this.bottomLeftofGraph = bottomLeft;

        List <LightComponent> graphComponents = logicGraph.LightGraph.getAllGraphComponents();

        //makes all the components
        foreach (GraphComponent gc in graphComponents)
        {
            //creates the gameobject
            GraphComponentController gcc = createComponent(gc);
            this.addComponent(gcc);
        }

        this.reconnectRays();
    }
    public bool removeComponent(GraphComponent component)
    {
        bool result  = false;
        int  counter = 0;

        while (counter < this.componentControllers.Count && !result)
        {
            if (this.componentControllers[counter].GetGraphComponent.Equals(component))
            {
                GraphComponentController controller = this.componentControllers[counter];
                this.componentControllers.RemoveAt(counter);
                GameObject.Destroy(controller.gameObject);
                result = true;
            }

            counter++;
        }

        return(result);
    }
    public GraphComponentController createComponent(GraphComponent comp)
    {
        //creates the component

        //find the x and y of the component
        Vector2Int pos          = comp.Position;
        Vector2Int size         = comp.Size;
        Vector3    basePosition = new Vector3(pos.x, pos.y, 0);
        Vector3    offset       = new Vector3(size.x / 2f, size.y / 2f, 0);

        if (comp.Rotation % 2 == 1)
        {
            float newX = offset.y;
            offset.y = offset.x;
            offset.x = newX;
        }

        //rotates the component
        Vector2 position = this.bottomLeftofGraph + basePosition + offset;

        Vector3 componentRotation = new Vector3(0, 0, -90 * comp.Rotation);

        if (comp.Flipped)
        {
            componentRotation = new Vector3(0, 180, 90 * comp.Rotation);
        }

        Type       resultType = null;
        GameObject prefab     = null;

        //logic compoents
        if (comp.GetType().BaseType == typeof(LogicComponent))
        {
            prefab     = (GameObject)SceneResouces.SceneObjects["Default"][typeof(GameObject)]["BasicLogicComponent"];
            resultType = typeof(LogicComponentController);

            //passive components
        }
        else if (comp.GetType().BaseType == typeof(PassiveComponent))
        {
            prefab     = (GameObject)SceneResouces.SceneObjects["Default"][typeof(GameObject)]["PassingMirror"];
            resultType = typeof(PassiveComponentController);
        }
        else if (comp.GetType().BaseType == typeof(LinkComponent))
        {
            prefab     = (GameObject)SceneResouces.SceneObjects["Default"][typeof(GameObject)]["BasicLogicComponent"];
            resultType = typeof(BridgeComponentController);
        }
        else
        {
            throw new System.Exception("This Component is not supported while making the GameObject");
        }

        GameObject go = Instantiate(prefab);
        GraphComponentController gcc = (GraphComponentController)go.AddComponent(Type.GetType(resultType.ToString()));

        go.transform.SetParent(this.transform, true);
        go.transform.position    = position;
        go.transform.eulerAngles = componentRotation;
        gcc.setUp(comp);

        return(gcc);
    }
 public void addComponent(GraphComponentController comp)
 {
     this.componentControllers.Add(comp);
 }