Exemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        EditorGUILayout.Space();
        if (targets.Length == 1)
        {
            ElectricLight obj = target as ElectricLight;
            EditorGUILayout.HelpBox($"Voltage:\t{obj.Voltage} V{Environment.NewLine}Current:\t{obj.Current.Magnitude} A{Environment.NewLine}Phase:\t{obj.Current.Phase * (Math.PI / 180.0)}", MessageType.Info);
        }
        if (GUILayout.Button("Turn On"))
        {
            foreach (var obj in targets)
            {
                (obj as ElectricLight).TurnOn();
            }
        }

        else if (GUILayout.Button("Turn Off"))
        {
            foreach (var obj in targets)
            {
                (obj as ElectricLight).TurnOff();
            }
        }
    }
Exemplo n.º 2
0
    public void CheckForInit()
    {
        if (_isInit)
        {
            return;
        }

        for (int i = 0; i < _plants.Count; i++)
        {
            ElectricLight light = ElectricLightManager.instance.FindElectricLight(_plants[i].transform.position);

            if (light == null)
            {
                Debug.Log("Error for plant " + _plants[i] + " index " + i);
            }
            else
            {
                _plants[i].SetLight(light);
            }
        }

        _isInit = true;
    }
Exemplo n.º 3
0
    public ElectricLight FindElectricLight(Vector2 wpos)
    {
        float         bestDist = float.MaxValue;
        ElectricLight best     = null;

        for (int i = 0; i < _lights.Count; i++)
        {
            Rect rect = _lights[i].GetCollider();

            if (rect.Contains(wpos))
            {
                float dist = Vector2.Distance(rect.center, wpos);

                if (dist < bestDist)
                {
                    best     = _lights[i];
                    bestDist = dist;
                }
            }
        }

        return(best);
    }
Exemplo n.º 4
0
 public void Register(ElectricLight light)
 {
     _lights.Add(light);
 }
Exemplo n.º 5
0
 public void Unregister(ElectricLight light)
 {
     _lights.Remove(light);
 }
Exemplo n.º 6
0
 public void SetLight(ElectricLight light)
 {
     _light = light;
 }