private void OnEnable()
 {
     m_interactableObj = GetComponent <VRTK_InteractableObject>();
     m_device          = GetComponent <EnergyDevice>();
     m_timer           = 0;
     m_collisions      = 0;
 }
    private void OnEnable()
    {
        if (device == null)
        {
            device = GetComponent <EnergyDevice>();
        }

        clouds.Clear();
        GetComponentsInChildren(true, clouds);

        if (device.targetForEffects != null)
        {
            var pos = device.targetForEffects.transform.position;
            pos.y = height;
            transform.position = pos;
        }

        for (int i = 0; i < clouds.Count; ++i)
        {
            if (clouds[i].enabled)
            {
                clouds[i].enabled = false;
                clouds[i].enabled = true;
            }
        }
    }
Ejemplo n.º 3
0
    private void GetGridSpacePosition(EnergyDevice device, out int x, out int y)
    {
        Vector3 p = WorldToGridSpace(device.transform.position);

        p -= new Vector3((device.grid.width - 1) * 0.5f, 0, (device.grid.height - 1) * 0.5f);
        x  = Mathf.RoundToInt(p.x);
        y  = Mathf.RoundToInt(p.z);
    }
Ejemplo n.º 4
0
    private Vector3 GetRandomPositionInGrid(EnergyDevice device, float yOffset)
    {
        Vector3 pos = device.transform.position;
        Vector3 extents = device.grid.size * 0.5f;
        float   minX = pos.x - extents.x; float maxX = pos.x + extents.x;
        float   minZ = pos.z - extents.z; float maxZ = pos.z + extents.z;

        return(new Vector3(Random.Range(minX, maxX), pos.y + yOffset, Random.Range(minZ, maxZ)));
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Try to attach the device to the holder at the specified slot.
    /// </summary>
    /// <param name="device"></param>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <returns></returns>
    public bool TryAttach(EnergyDevice device, int x, int y)
    {
        if (!slot.TryAddToPosition(device, x, y))
        {
            return(false);
        }

        AttachDevice(device, x, y);
        return(true);
    }
Ejemplo n.º 6
0
    private bool FindNearestSlot(EnergyDevice device, out int x, out int y)
    {
        GetGridSpacePosition(device, out x, out y);

        if (slot.IsValidPosition(device, x, y))
        {
            return(true);
        }

        // TODO: try all indices sorted by distance to gridPos
        return(false);
    }
Ejemplo n.º 7
0
 private void Awake()
 {
     if (device == null)
     {
         device = GetComponent <EnergyDevice>();
     }
     if (fd == null)
     {
         fd = GetComponentInParent <FireData>();
     }
     particleSystemFlames = transform.GetChild(0).GetChild(0).gameObject;
     IncreaseFireTimer    = Time.time + fd.levelDuration;
 }
Ejemplo n.º 8
0
    /// <summary>
    /// Try to attach the device to the holder. A slot is selected automatically. x and y will contain the attached slot position.
    /// </summary>
    /// <param name="data"></param>
    /// <param name="x"></param>
    /// <param name="y"></param>
    /// <returns></returns>
    public bool TryAttach(EnergyDevice device, out int x, out int y)
    {
        // try a reasonable index based on rounded position of device transform
        GetGridSpacePosition(device, out x, out y);

        if (!slot.TryAddToPosition(device, x, y))
        {
            return(false);
        }

        // TODO: try all indexes sorted by distance

        AttachDevice(device, x, y);
        return(true);
    }
Ejemplo n.º 9
0
    private void OnEnable()
    {
        if (device == null)
        {
            device = GetComponent <EnergyDevice>();
        }
        if (ud == null)
        {
            ud = GetComponent <UfoData>();
        }
        if (hazardManager == null)
        {
            hazardManager = FindObjectOfType <DeviceHazardManager>();
        }
        rigid = GetComponent <Rigidbody>();

        device.forceDeactive = true;

        interactable = GetComponent <VRTK_InteractableObject>();
        interactable.InteractableObjectGrabbed   += OnGrabbed;
        interactable.InteractableObjectUngrabbed += OnUnGrabbed;
    }
Ejemplo n.º 10
0
    private IEnumerator LerpDeviceIntoPlace(EnergyDevice device, Vector3 targetPosition, Quaternion targetRotation, Vector3 targetScale)
    {
        var        devTransfrom = device.transform;
        Vector3    currentPos   = devTransfrom.localPosition;
        Quaternion currentRot   = devTransfrom.localRotation;
        Vector3    currentScale = devTransfrom.localScale;

        while (true)
        {
            var posDist  = Vector3.Distance(currentPos, targetPosition);
            var posAlpha = Time.deltaTime * 8;
            currentPos = Vector3.Lerp(currentPos, targetPosition, posAlpha);
            devTransfrom.localPosition = currentPos;

            var rotDist  = Quaternion.Angle(currentRot, targetRotation);
            var rotAlpha = Time.deltaTime * 8;
            currentRot = Quaternion.Lerp(currentRot, targetRotation, rotAlpha);
            devTransfrom.localRotation = currentRot;

            var scaleAlpha = Time.deltaTime * 8;
            currentScale            = Vector3.Lerp(currentScale, targetScale, scaleAlpha);
            devTransfrom.localScale = currentScale;

            if (posDist < 0.01f && rotDist < 0.01f)
            {
                devTransfrom.localPosition = targetPosition;
                devTransfrom.localRotation = targetRotation;
                devTransfrom.localScale    = targetScale;
                break;
            }

            yield return(null);
        }

        slot.SetElementsActive(device, true, 0);
        device.forceDeactive = false;
        onAttached.Invoke();
    }
Ejemplo n.º 11
0
    private void AttachDevice(EnergyDevice device, int x, int y)
    {
        Vector3 localPos = new Vector3(
            (x + (device.grid.width - 1f) * 0.5f) * slot.grid.unitSize.x,
            0,
            (y + (device.grid.height - 1f) * 0.5f) * slot.grid.unitSize.z
            );

        Vector3 gridHalfOffset = new Vector3((slot.grid.width - 1) * slot.grid.unitSize.x * 0.5f, 0, (slot.grid.height - 1) * slot.grid.unitSize.z * 0.5f);

        localPos -= gridHalfOffset;

        //device.gameObject.SetCollidersEnabled(false);
        device.grid.unitSize.y = 0.13f;
        //Vector3 targetScale = Vector3.one;
        Vector3 targetScale = device.transform.localScale;

        device.transform.SetParent(transform, true);

        var rb = device.GetComponent <Rigidbody>();

        if (rb != null)
        {
            rb.isKinematic = true;
        }

        var vrio = device.GetComponent <VRTK_InteractableObject>();

        if (vrio != null)
        {
            vrio.isGrabbable = false;
        }

        StartCoroutine(LerpDeviceIntoPlace(device, localPos, Quaternion.identity, targetScale));

        //device.transform.localRotation = Quaternion.identity;
        //device.transform.localPosition = pos;
    }
Ejemplo n.º 12
0
    private void OnEnable()
    {
        if (device == null)
        {
            device = GetComponent <EnergyDevice>();
        }
        if (pd == null)
        {
            pd = GetComponent <PoopData>();
        }
        rb = GetComponent <Rigidbody>();

        pd.currentCount = 0;
        pd.cleanedCount = 0;
        pd.totalCount   = 0;

        if (device.targetForEffects != null)
        {
            Vector2 xz = Random.insideUnitCircle.normalized * 20;
            float   y  = pd.dropHeight + Random.Range(-0f, 5f);
            transform.position = device.targetForEffects.transform.position + new Vector3(xz.x, y, xz.y);
        }
    }
Ejemplo n.º 13
0
        internal async Task <bool> LoadDataAsync()
        {
            var homesData = await _aPICommands.GetHomesData().ConfigureAwait(false);

            if (homesData == null)
            {
                return(false);
            }
            Mail                = homesData.Body.User.Email;
            Language            = homesData.Body.User.Language;
            CultureInfo         = new CultureInfo(homesData.Body.User.Locale);
            Unit                = homesData.Body.User.UnitSystem.ToUnitSystem();
            WindUnit            = homesData.Body.User.UnitWind.ToWindUnit();
            PressureUnit        = homesData.Body.User.UnitPressure.ToPressureUnit();
            FeelLikeTemperature = homesData.Body.User.FeelLikeAlgorithm.ToFeelLikeAlgo();
            foreach (HomesData.HomeData home in homesData.Body.Homes)
            {
                EnergyDevice energyDevice = new EnergyDevice(_aPICommands);

                // Search for relays.
                foreach (HomesData.HomesModule module in home.Modules)
                {
                    if (module.Type.ToModuleType() == ModuleType.Relay)
                    {
                        energyDevice.Relay.Id        = module.Id;
                        energyDevice.Relay.Name      = module.Name;
                        energyDevice.Relay.SetupDate = module.SetupDate.ToLocalDateTime();
                        break;
                    }
                }
                // Search for thermostats and valves.
                foreach (HomesData.HomesModule module in home.Modules)
                {
                    switch (module.Type.ToModuleType())
                    {
                    case ModuleType.Valve:
                        Valve valve = new Valve
                        {
                            Id        = module.Id,
                            Name      = module.Name,
                            RoomId    = module.RoomId,
                            SetupDate = module.SetupDate.ToLocalDateTime()
                        };
                        energyDevice.Relay.Valves.Add(valve);
                        break;

                    case ModuleType.Thermostat:
                        Thermostat thermostat = new Thermostat()
                        {
                            Id        = module.Id,
                            Name      = module.Name,
                            RoomId    = module.RoomId,
                            SetupDate = module.SetupDate.ToLocalDateTime()
                        };
                        energyDevice.Relay.Thermostats.Add(thermostat);
                        break;
                    }
                }
                Devices.Add(energyDevice);
            }
            return(true);
        }