private void AutoConnectEvents(ConnectDirections connectDirection, IShapeBase shapeBase, IEBCBase ebcBase, EventInfo[] events, MethodInfo[] methods)
        {
            Dictionary<string, MethodInfo> methodInfoToName = new Dictionary<string, MethodInfo>();

            object eventSource = null;
            object firstDelegateArgument = null;

            // Shape to EBC
            if (connectDirection == ConnectDirections.ShapeToEBC)
            {
                eventSource = shapeBase;
                firstDelegateArgument = ebcBase;
            }
            // EBC to Shape
            else if (connectDirection == ConnectDirections.EBCToShape)
            {
                eventSource = ebcBase;
                firstDelegateArgument = shapeBase;
            }

            // Save all methods in a dictionary with it's name as key.
            foreach (var currentMethod in methods)
            {
                if (currentMethod.Name.StartsWith("In_"))
                    methodInfoToName.Add(currentMethod.Name.Replace("In_", ""), currentMethod);
            }

            // Iterate over all found EBC-events and check if there is a matching EBC-handler.
            foreach (var currentEvent in events)
            {
                if (currentEvent.Name.StartsWith("Out_"))
                {
                    string name = currentEvent.Name.Replace("Out_", "");

                    if (methodInfoToName.ContainsKey(name))
                    {
                        // Connect them.
                        currentEvent.AddEventHandler(eventSource,
                                Delegate.CreateDelegate(currentEvent.EventHandlerType, firstDelegateArgument, methodInfoToName[name]));
                    }
                }
            }
        }
Exemple #2
0
    public GameObject CreateMassObject; //デフォルトの massGameObject
    public void CreateMass(ConnectDirections direction, float distance)
    {
        if (distance == 0)
        {
            distance += 0.4f;
        }
        var inst = Instantiate(this.CreateMassObject, this.transform.parent).GetComponent <Mass>();

        inst.transform.position = this.transform.position;
        inst.CreateMassObject   = this.CreateMassObject;
        switch (direction)
        {
        case ConnectDirections.up:
            inst.transform.position += new Vector3(0, distance, 0);
            this.next.up             = inst;
            inst.next.down           = this;
            break;

        case ConnectDirections.left:
            inst.transform.position += new Vector3(-distance, 0, 0);
            this.next.left           = inst;
            inst.next.right          = this;
            break;

        case ConnectDirections.down:
            inst.transform.position += new Vector3(0, -distance, 0);
            this.next.down           = inst;
            inst.next.up             = this;
            break;


        case ConnectDirections.right:
            inst.transform.position += new Vector3(distance, 0, 0);
            this.next.right          = inst;
            inst.next.left           = this;
            break;
        }
        this.UpdateLinesConnection();
    }
Exemple #3
0
 public void CreateMass(ConnectDirections direction, float distance, GameObject massGameObject)
 {
     this.CreateMassObject = massGameObject;
     this.CreateMass(direction, distance);
 }