Ejemplo n.º 1
0
 // Remove a gear from the "Connected Outputs" list (with the gearDriver script as reference)
 //
 // Call from other scripts:
 //	  anotherGameObject.GetComponent<GearDriver>().DisconnectGear(gearDriver);
 //
 public void DisconnectGear(GearDriver gearDriver)
 {
     if (gearDriver != null)
     {
         settings.outputTo.Remove(gearDriver);
     }
 }
Ejemplo n.º 2
0
    // Breadth first search to update distances
    private void UpdateDistances()
    {
        Debug.Log("Updating Distances!");
        dist = 0;
        gear_manager.dist_calculated.Clear();
        gear_manager.dist_calculated.Add(name, 0);
        Queue <GearDriver> q = new Queue <GearDriver>();

        q.Enqueue(this);

        while (q.Count > 0)
        {
            GearDriver gd = q.Dequeue();

            CircleCollider2D collider = gd.GetComponent <CircleCollider2D>();
            Collider2D[]     results  = new Collider2D[MAX_CONTACTS];
            int collisions            = Physics2D.OverlapCollider(collider, new ContactFilter2D(), results);

            // Update each node that hasn't been touched
            for (int i = 0; i < collisions; ++i)
            {
                if (!gear_manager.dist_calculated.ContainsKey(results[i].GetComponent <GearDriver>().name))
                {
                    results[i].GetComponent <GearDriver>().dist = gd.dist + 1;
                    Debug.Log(results[i].GetComponent <GearDriver>().name + ": " + results[i].GetComponent <GearDriver>().dist);
                    gear_manager.dist_calculated.Add(results[i].GetComponent <GearDriver>().name, gd.dist + 1);
                    q.Enqueue(results[i].GetComponent <GearDriver>());
                }
            }
        }
    }
Ejemplo n.º 3
0
    // public methods to call from events, Buttons, Animation Events or other scripts:
    //
    // to work "live update" on the motor gear has to be set true !!!


    // Connect a gear by its gearDriver script as reference
    //
    // Call from other scripts:
    //	  anotherGameObject.GetComponent<GearDriver>().ConnectGear(gearDriver);
    //
    public void ConnectGear(GearDriver gearDriver)
    {
        if (gearDriver != null)
        {
            settings.outputTo.Add(gearDriver);
        }
    }
Ejemplo n.º 4
0
 private void ShowUpdatePowerchainOnceButton()
 {
     if (GUILayout.Button(onceUpdCont))
     {
         GearDriver gd = (GearDriver)target;
         gd.UpdatePowerchain();
     }
     EditorGUILayout.Separator();
 }
Ejemplo n.º 5
0
    // Disconnects a gear from another by their names
    //
    // Call from other scripts:
    //   GameObject.Find("gearThatDrives").GetComponent<GearDriver>().DisconnectGearByName("GearToDisconnect");
    //
    public void DisconnectGearByName(string name)
    {
        GameObject go = GameObject.Find(name);

        if (go == null)
        {
            return;
        }
        GearDriver gd = go.GetComponent <GearDriver> ();

        if (gd == null)
        {
            return;
        }
        settings.outputTo.Remove(gd);
    }
Ejemplo n.º 6
0
    private void ShowInfoField()
    {
        GearDriver gearDriver = (GearDriver)target;

        if (gearDriver.settings.outputTo == null)
        {
            return;
        }
        Color  gCol = GUI.color;
        string str  = (gearDriver.settings.isShaft && gearDriver.settings.isMotor)? "\n Motor (Shaft)" :
                      (!gearDriver.settings.isShaft && !gearDriver.settings.isMotor)? "\n Gear" : gearDriver.settings.isShaft? "\n Shaft": "\n Motor (Gear)";

        str = gearDriver.settings.isWorm? (gearDriver.settings.isMotor)? "\n Motor (Worm Gear)" : "\n Worm Gear"  : str;
        InfoField(" Outputs connected: " + gearDriver.settings.outputTo.Count.ToString() + str +
                  "\n Actual Speed: " + (-gearDriver.actualSpeed / 6.0f).ToString() + " rpm", new Color(0.85f, 0.85f, 0.85f), 220f);
        GUI.color = gCol;
    }
Ejemplo n.º 7
0
    private void Update()
    {
        rotationDisplay.text = "Rotations / s: " + System.Math.Abs(System.Math.Round(global_speed / 6.0, 2));

        // Update each gear's speed
        foreach (DictionaryEntry pair in dist_calculated)
        {
            GearDriver gd = GameObject.Find(pair.Key.ToString()).GetComponent <GearDriver>();
            gd.Rotate(global_speed * System.Math.Pow(-1, gd.dist));
            money_manager.AddGold(System.Math.Abs(global_speed));
        }

        if (!clicked)
        {
            UpdateSpeed();
        }
    }
Ejemplo n.º 8
0
    void OnSceneGUI()
    {
        GearDriver gearDriver = (GearDriver)target;

        if (gearDriver.settings.outputTo == null)
        {
            return;
        }

        for (int i = 0; i < gearDriver.settings.outputTo.Count; i++)
        {
            if (gearDriver.settings.outputTo[i] != null)
            {
                DrawHandleCircles(gearDriver.settings.outputTo[i].gameObject);
            }
            else
            {
                gearDriver.settings.outputTo.RemoveAt(i);
            }
        }
    }
Ejemplo n.º 9
0
    // Disconnects a gear from the connected output lists of all other gears by its name
    //
    // Call from other scripts:
    //	  GameObject.FindObjectOfType<GearDriver>().DisconnectFromAllByName("NameOfGearToDisconnect");
    //
    public void DisconnectFromAllByName(string name)
    {
        GameObject go = GameObject.Find(name);

        if (go == null)
        {
            return;
        }
        GearDriver gd = go.GetComponent <GearDriver> ();

        if (gd == null)
        {
            return;
        }
        foreach (GearDriver g in GameObject.FindObjectsOfType <GearDriver>())
        {
            if (g.settings.outputTo.Contains(gd))
            {
                g.settings.outputTo.Remove(gd);
            }
        }
    }