private void AccumulatePowerSources(PowerRelay power)
        {
            List <IPowerInterface> inboundPowerSources = GetInboundPowerSources(power);

            foreach (IPowerInterface iSource in inboundPowerSources)
            {
                if (iSource == null)
                {
                    continue;
                }

                PowerSource   source  = TryGetPowerSource(iSource);
                PowerRelay    relay   = TryGetPowerRelay(iSource);
                BatterySource battery = TryGetBatterySource(iSource);
                if (source != null)
                {
                    AddPowerSourceEntry(source);
                    continue;
                }
                else if (relay != null)
                {
                    AccumulatePowerSources(relay);
                    continue;
                }
                else if (battery != null)
                {
                    AddGenericPowerEntry(battery);
                    continue;
                }
            }
        }
        private BatterySource TryGetBatterySource(IPowerInterface power)
        {
            BatterySource source = power as BatterySource;

            if (source == null && (power as Component) != null)
            {
                source = (power as Component).gameObject.GetComponent <BatterySource>();
            }
            return(source);
        }
Esempio n. 3
0
    void SpawnChicken()
    {
        GameObject clone = Instantiate(chickenPrefab, Spawn, Quaternion.identity);

        clone.transform.parent = chickenFolder.transform;

        clone.transform.position         = Spawn;
        clone.transform.localScale       = new Vector3(45f, 45f, 45f);
        clone.transform.localEulerAngles = new Vector3(0, 0, 0);
        clone.name  = "Chicken";
        clone.layer = LayerMask.NameToLayer("Chickens");

        SphereCollider sphereCollider = clone.AddComponent <SphereCollider>() as SphereCollider;
        Rigidbody      rigidBody      = clone.AddComponent <Rigidbody>() as Rigidbody;

        rigidBody.useGravity = false;
        GravityBody gravityBody = clone.AddComponent <GravityBody>() as GravityBody;

        gravityBody.fixRotation = true;
        WanderAround wanderAround = clone.AddComponent <WanderAround>() as WanderAround;

        wanderAround.speed       = 2f;
        wanderAround.rotation    = 3f;
        wanderAround.maxRotation = 10f;

        GameObject batterySpawner = Instantiate(new GameObject(), new Vector3(0f, 0f, 0f), Quaternion.identity);

        batterySpawner.transform.parent = clone.transform;
        batterySpawner.name             = "BatterySpawner";

        batterySpawner.transform.localPosition    = new Vector3(0f, 0f, 0f);
        batterySpawner.transform.localScale       = new Vector3(1f, 1f, 1f);
        batterySpawner.transform.localEulerAngles = new Vector3(0, 0, 0);

        BatterySource batterySource = batterySpawner.AddComponent <BatterySource>() as BatterySource;

        batterySource.countText            = countText;
        batterySource.batteryPrefab        = batteryPrefab;
        batterySource.batteryScaleX        = 2f;
        batterySource.batteryScaleY        = 4.5f;
        batterySource.batteryScaleZ        = 2f;
        batterySource.batteryTriggerScaleX = 0.4f;
        batterySource.batteryTriggerScaleY = 0.2f;
        batterySource.batteryTriggerScaleZ = 0.4f;
        batterySource.speed            = 2f;
        batterySource.velocity         = 0.5f;
        batterySource.layingPercentage = 0.4f;

        AudioSource audioSource = clone.AddComponent <AudioSource>() as AudioSource;

        audioSource.spatialBlend = 1f;
        audioSource.clip         = chickenAudioCLip;
        audioSource.loop         = true;
        audioSource.Play();
    }
Esempio n. 4
0
 /// <summary>
 /// Sets the power relay that the battery source is connected to.
 /// </summary>
 /// <param name="battery"></param>
 /// <param name="newPowerRelay"></param>
 /// <returns></returns>
 public static void SetPowerRelay(this BatterySource battery, PowerRelay newPowerRelay) => battery.connectedRelay = newPowerRelay;
Esempio n. 5
0
 /// <summary>
 /// returns the power relay that the battery source is connected to.
 /// </summary>
 /// <param name="battery"></param>
 /// <returns></returns>
 public static PowerRelay GetPowerRelay(this BatterySource battery) => battery.connectedRelay;