コード例 #1
0
ファイル: SoundManager.cs プロジェクト: EliGould/HordeMode
    public SoundHandle Play(
        Sound sound,
        SoundFlag flags,
        Transform parent  = null,
        Vector3?worldPos  = null,
        Unit attachToUnit = null
        )
    {
        if (sound == null)
        {
            return(new SoundHandle());
        }
        if (sound.clips.Length == 0)
        {
            return(new SoundHandle());
        }

        if (!sound.loop && 0 == (flags & SoundFlag.OneShot))
        {
            Dbg.LogWarnOnce(sound, "Tried to play {0} as one shot", sound);
            return(new SoundHandle());
        }

        if (sound.loop && 0 == (flags & SoundFlag.Looping))
        {
            Dbg.LogWarnOnce(sound, "Tried to play {0} as looping", sound);
            return(new SoundHandle());
        }

        string       channelName = sound.channel.name;
        SoundChannel channel     = channels.GetValue(channelName);

        if (channel == null)
        {
            channel = settings.defaultChannelSettings;
        }

        var sfx = GetSfxInst();

        sfx.sound = sound;
#if UNITY_EDITOR
        string name = GarbageCache.GetName(sound);
        if (!sfx.name.EndsWith(name))
        {
            sfx.name = "SFX_" + name;
        }
#endif // UNITY_EDITOR
        if (parent != null)
        {
            sfx.gameObject.transform.parent = parent;
        }

        sfx.attachedToUnit     = attachToUnit;
        sfx.transform.position = worldPos ?? (parent == null ? Vector3.zero : parent.position);

        sfx.Reset(sound, channel, timeScale: App.timeScale);
        sfx.source.Play();

        return(new SoundHandle(sfx));
    }
コード例 #2
0
ファイル: Coroutines.cs プロジェクト: EliGould/HordeMode
    CoroutineHandle StartInternal(IEnumerator enumerator, Component attachTo, RoutineFlags flags = RoutineFlags.None)
    {
        if (enumerator == null)
        {
            throw new ArgumentNullException("routine");
        }

        if (attachTo != null && !attachTo.gameObject.activeInHierarchy)
        {
            Dbg.LogError(
                attachTo,
                "Coroutine couldn't be started because the the game object '{0}' is inactive!",
                GarbageCache.GetName(attachTo.gameObject)
                );

            return(new CoroutineHandle());
        }

        var routine = new Routine(
            id: ++idCounter,
            flags: flags,
            enumerator: enumerator,
            attachedTo: attachTo
            );

        bool started = Resolve(ref routine, cameFromPostRender: false);

        return(new CoroutineHandle(
                   id: started?routine.id: 0
                   ));
    }
コード例 #3
0
    public void DamageUnit(
        Collider hitCollider,
        int damage,
        float knockbackForce,
        float impactForce,
        Vector3 direction,
        Vector3 point
        )
    {
        Unit unit = collToUnit.FindOrNull(hitCollider);

        if (unit == null)
        {
            return;
        }

        BodyParts bodyParts = unit.parts.bodyParts;

        BodyParts.PartData partData = bodyParts.GetPartDataForCollider(hitCollider);

        if (!partData.isAttached)
        {
            return;
        }

        BodyParts.PartDef partDef = bodyParts.GetPartDefForKind(partData.kind);

        int newHp = Mathf.Max(0, partData.hitPoints - damage);

        partData.hitPoints = newHp;

        Dbg.Log("{0} in {1} for {2} damage!", GarbageCache.GetName(unit), partData.kind, damage);

        if (unit.parts.navMeshAgent != null)
        {
            unit.parts.navMeshAgent.Move(direction * knockbackForce);
        }

        if (newHp == 0)
        {
            if (partDef.lifeCritical)
            {
                Vector3 killPoint = point;
                float?  killForce = impactForce;
                KillUnit(unit, killPoint, killForce);
            }
            else
            {
                Vector3?worldForce = null;

                if (direction != Vector3.zero)
                {
                    worldForce = direction * impactForce;
                }

                bodyParts.Detach(partData, worldForce);
            }
        }
    }
コード例 #4
0
    public EffectHandle Play(
        Effect effect,
        EffectFlag flags,
        Transform parent    = null,
        Vector3?worldPos    = null,
        Quaternion?worldRot = null,
        Unit attachToUnit   = null
        )
    {
        if (effect == null)
        {
            return(new EffectHandle());
        }

        if (!effect.loop && 0 == (flags & EffectFlag.OneShot))
        {
            Dbg.LogWarnOnce(effect, "Tried to play {0} as one shot", effect);
            return(new EffectHandle());
        }

        if (effect.loop && 0 == (flags & EffectFlag.Looping))
        {
            Dbg.LogWarnOnce(effect, "Tried to play {0} as looping", effect);
            return(new EffectHandle());
        }

        var efx = GetEfxInst(effect.prefab);

        efx.Reset(effect);

#if UNITY_EDITOR
        string name = GarbageCache.GetName(effect);
        if (!efx.name.EndsWith(name))
        {
            efx.name = "EFX_" + name;
        }
#endif // UNITY_EDITOR
        if (parent != null)
        {
            efx.gameObject.transform.parent = parent;
        }

        efx.attachedToUnit     = attachToUnit;
        efx.transform.position = DetermineWorldPos(parent, worldPos, effect);
        efx.transform.rotation = DetermineWorldRotation(parent, worldRot, effect);

        efx.Play();

        return(new EffectHandle(efx));
    }
コード例 #5
0
ファイル: Extensions.cs プロジェクト: EliGould/HordeMode
    public static Transform FindDeep(this Transform trans, string name, bool includeInactive = false)
    {
        if (includeInactive)
        {
            for (int i = 0; i < trans.childCount; ++i)
            {
                Transform child = trans.GetChild(i);
                if (GarbageCache.GetName(child) == name)
                {
                    return(child);
                }
                else
                {
                    child = FindDeep(child, name);
                    if (child != null)
                    {
                        return(child);
                    }
                }
            }
        }
        else
        {
            for (int i = 0; i < trans.childCount; ++i)
            {
                Transform child = trans.GetChild(i);

                if (!child.gameObject.activeSelf)
                {
                    continue;
                }

                if (GarbageCache.GetName(child) == name)
                {
                    return(child);
                }
                else
                {
                    child = FindDeep(child, name);
                    if (child != null)
                    {
                        return(child);
                    }
                }
            }
        }

        return(null);
    }
コード例 #6
0
    void KillUnit(Unit unit, Vector3?killPoint = null, float?killForce = null)
    {
        Dbg.Log("{0} dies!", GarbageCache.GetName(unit));
        unit.parts.bodyParts.DetachAll(
            killPoint,
            killForce
            );
        Weapon wieldingWeapon = unit.manState.weaponData.wieldingWeapon;

        if (wieldingWeapon != null)
        {
            wieldingWeapon.SetWielder(null);
        }

        NavMeshAgent navAgent = unit.parts.navMeshAgent;

        if (navAgent != null)
        {
            navAgent.enabled = false;
        }
    }
コード例 #7
0
ファイル: DbgValues.cs プロジェクト: EliGould/HordeMode
    public void SystemOnGUI()
    {
        foreach (var kvp in nodes)
        {
            object        owner = kvp.Key;
            DbgObjectData data  = kvp.Value;

            var ueOwner = owner as UE.Object;
            if (ueOwner != null)
            {
                GUILayout.Label(GarbageCache.GetName(ueOwner));
            }
            else
            {
                GUILayout.Label(owner.ToString());
            }

            for (int i = 0; i < data.roots.Count; i++)
            {
                DbgNode node = data.roots[i];
                DrawNode(node, indent: 1);
            }
        }
    }