Пример #1
0
    public float getSpanAngleByLocationMode(SE_SkillObject skillObj)
    {
        var   spawnModule = GetComponent <EM_Spawn>();
        float fullSpan    = Mathf.PI * 2f;

        switch (locationMode)
        {
        case SpawnLocationMode.Random:
            return(Random.value * fullSpan);

        case SpawnLocationMode.LoopByTimeRatio:
            return(emitter.timeRatio * fullSpan);

        case SpawnLocationMode.LoopByCount:
            float totalSpawnOverDuration = bUseSpawnTotalCount ? spawnModule.GetSpawnCountOverEmitterDuration() : unitPerLoop;
            //Invalid spawn count
            if (totalSpawnOverDuration == 0)
            {
                return(0);
            }
            return(((emitter.spawnCount / totalSpawnOverDuration) % 1) * fullSpan);

        case SpawnLocationMode.LoopByBrust:
            return(skillObj.brustCount == 0 ? 0 : ((skillObj.brustIndex * 1.0f / skillObj.brustCount) % 1) * fullSpan);
        }
        return(0);
    }
Пример #2
0
    public override Vector3 UpdateVelocity(SE_SkillObject skillObj, float deltaTime)
    {
        float homingSpeed = fl_homingSpeed.GetValueByTimeRatio(1 - skillObj.lifetimeRemainRatio);

        if (!enabled)
        {
            return(skillObj.velocity);
        }
        if (skillObj.target == null)
        {
            return(skillObj.velocity);
        }

        float   velocityMagnitude = skillObj.velocity.magnitude;
        Vector3 faceDir           = (skillObj.target.position - skillObj.transform.position);
        Vector3 homingStrength    = fl_homingStrengthXYZ.GetValueByTimeRatio(1 - skillObj.lifetimeRemainRatio);

        faceDir.x *= Mathf.Clamp01(homingStrength.x);
        faceDir.y *= Mathf.Clamp01(homingStrength.y);
        faceDir.z *= Mathf.Clamp01(homingStrength.z);
        Vector3 faceToTargetVelocity = faceDir.normalized * velocityMagnitude;
        Vector3 lerpVelocity         = Vector3.Lerp(skillObj.velocity, faceToTargetVelocity, deltaTime * homingSpeed).normalized *velocityMagnitude;

        Transform objSimulationSpace = skillObj.transform.parent;

        if (objSimulationSpace == null)//World Space
        {
            return(lerpVelocity);
        }
        else
        {
            return(Vector3.Lerp(skillObj.velocity, objSimulationSpace.TransformDirection(faceToTargetVelocity), deltaTime * homingSpeed).normalized *velocityMagnitude);
        }
    }
Пример #3
0
    public override EM_SpawnLocationData GetSpawnLocation(SE_SkillObject skillObj)
    {
        updateParamsChanged();

        var data = new EM_SpawnLocationData();

        baseLocation = transform.position - transform.right * (length / 2);

        baseLocation += transform.right * (getPositionRatioByLocationMode(skillObj) * length);

        float spanAngle = -Mathf.PI * 2f * angle / 360;

        Vector3 dir = TransformUtility.Get3DCirclePoint(spanAngle, 1, Vector3.zero, -transform.right, transform.up);

        data.Location = baseLocation;
        data.Foward   = dir;


        debugLine.Enqueue(data);
        if (debugLine.Count > 10)
        {
            debugLine.Dequeue();
        }
        return(data);
    }
Пример #4
0
    public float getPositionRatioByLocationMode(SE_SkillObject skillObj)
    {
        var spawnModule = GetComponent <EM_Spawn>();

        switch (locationMode)
        {
        case SpawnLocationMode.Random:
            return(Random.value);

        case SpawnLocationMode.LoopByTimeRatio:
            return(emitter.timeRatio);

        case SpawnLocationMode.LoopByCount:
            float totalSpawnOverDuration = bUseSpawnTotalCount ? spawnModule.GetSpawnCountOverEmitterDuration() : unitPerLoop;
            //Invalid spawn count
            if (totalSpawnOverDuration == 0)
            {
                return(0);
            }
            return(((emitter.spawnCount / totalSpawnOverDuration) % 1) * (1f + 1f / (totalSpawnOverDuration - 1)));

        case SpawnLocationMode.LoopByBrust:
            Debug.Log(skillObj.brustCount);
            return(skillObj.brustCount == 0 ? 0 : ((skillObj.brustIndex * 1.0f / skillObj.brustCount) % 1) * (1f + 1f / (skillObj.brustCount - 1)));
        }
        return(0);
    }
    public override Vector3 UpdateAnchorOffset(SE_SkillObject skillObj, float deltaTime)
    {
        anchorOffsetOverLife = fl_anchorOffsetOverLife.GetValueByTimeRatio(1 - skillObj.lifetimeRemainRatio);
        switch (modifierType)
        {
        case ModifierType.Override:
            return(anchorOffsetOverLife);

        case ModifierType.Multiplier:
        {
            calAnchorOffset.x = skillObj.initAnchorOffset.x * anchorOffsetOverLife.x;
            calAnchorOffset.y = skillObj.initAnchorOffset.y * anchorOffsetOverLife.y;
            calAnchorOffset.z = skillObj.initAnchorOffset.z * anchorOffsetOverLife.z;
            return(calAnchorOffset);
        }

        case ModifierType.Add:
            return(skillObj.initAnchorOffset + anchorOffsetOverLife);

        case ModifierType.AddMultiplier:
        {
            calAnchorOffset.x = skillObj.initAnchorOffset.x * anchorOffsetOverLife.x;
            calAnchorOffset.y = skillObj.initAnchorOffset.y * anchorOffsetOverLife.y;
            calAnchorOffset.z = skillObj.initAnchorOffset.z * anchorOffsetOverLife.z;
            return(skillObj.initAnchorOffset + calAnchorOffset);
        }

        default:
            break;
        }
        return(anchorOffsetOverLife);
    }
Пример #6
0
    public override EM_SpawnLocationData GetSpawnLocation(SE_SkillObject skillObj)
    {
        updateParamsChanged();

        var   data      = new EM_SpawnLocationData();
        float spanAngle = -(arcOffset / 360) * (Mathf.PI * 2f);

        spanAngle -= getSpanAngleByLocationMode(skillObj);

        Vector3 a            = transform.up;
        float   radiusByType = radius - (radiusThickness) * radius * Random.value;

        //zero radius cannot generate correct rotation
        if (radiusByType == 0)
        {
            radiusByType = 0.001f;
        }
        spanAngle   *= bReverseDirection ? -1 : 1;
        baseLocation = TransformUtility.Get3DCirclePoint(spanAngle, radiusByType, transform.position, a, transform.right);

        data.Location = baseLocation;
        data.Foward   = (baseLocation - transform.position).normalized;


        debugLine.Enqueue(data);
        if (debugLine.Count > 10)
        {
            debugLine.Dequeue();
        }
        return(data);
    }
    public override Vector3 UpdateVelocity(SE_SkillObject skillObj, float deltaTime)
    {
        if (!enabled)
        {
            return(skillObj.velocity);
        }

        float scale = fl_velocityScale.GetValueByTimeRatio(1 - skillObj.lifetimeRemainRatio);
        float initVelocityMagnitude = skillObj.initVelocity.magnitude;

        Vector3 velocityDir = skillObj.velocity.normalized;

        switch (modifierType)
        {
        case ModifierType.Override:
            return(scale * velocityDir);

        case ModifierType.Multiplier:
            return((initVelocityMagnitude * scale) * velocityDir);

        case ModifierType.Add:
            return((initVelocityMagnitude + scale) * velocityDir);

        case ModifierType.AddMultiplier:
            return((initVelocityMagnitude + initVelocityMagnitude * scale) * velocityDir);

        default:
            break;
        }
        return(skillObj.velocity);
    }
Пример #8
0
    public void OnCollision(SE_SkillObject skillObj, Collider other)
    {
        if (collisionMask != (collisionMask | (1 << other.gameObject.layer)))
        {
            return;
        }
        Debug.Log(gameObject.name + " hit " + other.gameObject);

        if (skillObj.collisionCooldown > 0)
        {
            return;
        }
        skillObj.collisionCooldown = collisionGap;

        if (killOnCollision)
        {
            skillObj.Kill();
        }

        for (int i = 0; i < spawnGameObjectList.Count; i++)
        {
            var spawnInfo = spawnGameObjectList[i];
            if (spawnInfo.template != null)
            {
                for (int j = 0; j < spawnInfo.count; j++)
                {
                    var instance = GameObject.Instantiate <GameObject>(spawnInfo.template);
                    if (spawnInfo.useLocation)
                    {
                        instance.transform.position = skillObj.skillInstance.transform.position;
                    }
                    if (spawnInfo.useRotation)
                    {
                        instance.transform.rotation = skillObj.skillInstance.transform.rotation;
                    }
                    switch (spawnInfo.parentTo)
                    {
                    case ParentTo.None:
                        break;

                    case ParentTo.TriggerObject:
                        instance.transform.parent = skillObj.skillInstance.transform;
                        break;

                    case ParentTo.TriggerObjectParent:
                        instance.transform.parent = skillObj.transform.parent;
                        break;

                    default:
                        break;
                    }
                }
            }
        }
    }
 protected void OnSkillObjectLifetimeEnd(SE_SkillObject obj)
 {
     emittedObjList.Remove(obj);
     obj.DestroyTrigger();
     if (Application.isPlaying)
     {
         Destroy(obj.gameObject);
     }
     else
     {
         DestroyImmediate(obj.gameObject);
     }
 }
    public override void UpdateRotation(SE_SkillObject skillObj, float deltaTime)
    {
        Transform objSimulationSpace = skillObj.transform.parent;
        Vector3   targetDir;

        if (objSimulationSpace == null)//World Space
        {
            targetDir = skillObj.transform.position + skillObj.velocity;
        }
        else
        {
            targetDir = skillObj.transform.position + objSimulationSpace.TransformDirection(skillObj.velocity);
        }
        skillObj.transform.LookAt(targetDir);
    }
Пример #11
0
    public void OnObjectDestroy(SE_SkillObject skillObj)
    {
        for (int i = 0; i < spawnGameObjectList.Count; i++)
        {
            var spawnInfo = spawnGameObjectList[i];
            if (spawnInfo.template != null)
            {
                for (int j = 0; j < spawnInfo.count; j++)
                {
                    var instance = GameObject.Instantiate <GameObject>(spawnInfo.template);
                    if (spawnInfo.useLocation)
                    {
                        instance.transform.position = skillObj.skillInstance.transform.position;
                    }
                    if (spawnInfo.useRotation)
                    {
                        instance.transform.rotation = skillObj.skillInstance.transform.rotation;
                    }
                    switch (spawnInfo.parentTo)
                    {
                    case ParentTo.None:
                        break;

                    case ParentTo.TriggerObject:
                        instance.transform.parent = skillObj.skillInstance.transform;
                        break;

                    case ParentTo.TriggerObjectParent:
                        instance.transform.parent = skillObj.transform.parent;
                        break;

                    default:
                        break;
                    }
                }
            }
        }
    }
Пример #12
0
    public override Vector3 UpdateVelocity(SE_SkillObject skillObj, float deltaTime)
    {
        if (!enabled)
        {
            return(skillObj.velocity);
        }
        Vector3 faceToTargetVelocity, noiseSpeed, noiseStrength, noiseVal, lerpVelocity = Vector3.zero;

        if (!bSeperateXYZ)
        {
            noiseSpeed    = Vector3.one * fl_noiseSpeed.GetValueByTimeRatio(1 - skillObj.lifetimeRemainRatio);
            noiseStrength = Vector3.one * fl_noiseStrength.GetValueByTimeRatio(1 - skillObj.lifetimeRemainRatio);
        }
        else
        {
            noiseSpeed    = fl_noiseSpeedXYZ.GetValueByTimeRatio(1 - skillObj.lifetimeRemainRatio);
            noiseStrength = fl_noiseStrengthXYZ.GetValueByTimeRatio(1 - skillObj.lifetimeRemainRatio);
        }
        noiseVal.x           = Mathf.PerlinNoise(Time.time * noiseSpeed.x + (skillObj.transform.position.x * worldPositionInfluence.x), 0.0f);
        noiseVal.y           = Mathf.PerlinNoise(Time.time * noiseSpeed.y + (skillObj.transform.position.y * worldPositionInfluence.y), 0.3f);
        noiseVal.z           = Mathf.PerlinNoise(Time.time * noiseSpeed.z + (skillObj.transform.position.z * worldPositionInfluence.z), 0.6f);
        faceToTargetVelocity = new Vector3(noiseVal.x - 0.5f, noiseVal.y - 0.5f, noiseVal.z - 0.5f).normalized;

        lerpVelocity.x = Mathf.Lerp(skillObj.velocity.normalized.x, faceToTargetVelocity.x, Mathf.Clamp01(deltaTime * noiseStrength.x));
        lerpVelocity.y = Mathf.Lerp(skillObj.velocity.normalized.y, faceToTargetVelocity.y, Mathf.Clamp01(deltaTime * noiseStrength.y));
        lerpVelocity.z = Mathf.Lerp(skillObj.velocity.normalized.z, faceToTargetVelocity.z, Mathf.Clamp01(deltaTime * noiseStrength.z));

        float velocityMagnitude = skillObj.velocity.magnitude;

        lerpVelocity = lerpVelocity.normalized * velocityMagnitude;
        Transform objSimulationSpace = skillObj.transform.parent;

        //if (objSimulationSpace == null)//World Space
        return(lerpVelocity);
        //else
        //    return Vector3.Lerp(skillObj.velocity, objSimulationSpace.TransformDirection(faceToTargetVelocity), deltaTime * noiseSpeed).normalized * velocityMagnitude;
    }
Пример #13
0
    public override EM_SpawnLocationData GetSpawnLocation(SE_SkillObject skillObj)
    {
        updateParamsChanged();

        var data = new EM_SpawnLocationData();

        float spanAngle = -Mathf.PI * 2f;

        spanAngle -= getSpanAngleByLocationMode(skillObj);

        Vector3 a                 = transform.forward;
        float   radiusByType      = getRadiusByEmitType();
        float   lengthRatioByType = getLengthRatioByEmitType();

        coneBaseLocation = TransformUtility.Get3DCirclePoint(spanAngle, radiusByType, transform.position, a, transform.right);
        coneTopLocation  = TransformUtility.Get3DCirclePoint(spanAngle, coneTopRadius * radiusByType / radius, transform.position + a * length, a, transform.right);
        coneTopLocation += topOffset;

        if (!bReverseEmitBase)
        {
            data.Location = coneBaseLocation + (coneTopLocation - coneBaseLocation) * lengthRatioByType;
            data.Foward   = (coneTopLocation - coneBaseLocation).normalized;
        }
        else
        {
            data.Location = coneBaseLocation + (coneTopLocation - coneBaseLocation) * (1 - lengthRatioByType);
            data.Foward   = (coneBaseLocation - coneTopLocation).normalized;
        }

        debugLine.Enqueue(data);
        if (debugLine.Count > 10)
        {
            debugLine.Dequeue();
        }
        return(data);
    }
Пример #14
0
 public abstract EM_SpawnLocationData GetSpawnLocation(SE_SkillObject skillObj);
 public int Priority = 0; //smallest run first
 public abstract Vector3 UpdateVelocity(SE_SkillObject skillObj, float deltaTime);
Пример #16
0
 public int Priority = 0; //smallest run first
 public abstract void UpdateRotation(SE_SkillObject skillObj, float deltaTime);
 public int Priority = 0; //smallest run first
 public abstract Vector3 UpdateAnchorOffset(SE_SkillObject skillObj, float deltaTime);
Пример #18
0
 protected void OnSkillObjectInitDone(SE_SkillObject obj)
 {
     spawnCount++;
 }
Пример #19
0
    protected void SetupSkillObj(GameObject emittedInstance,
                                 int?brustCount = null,
                                 int?brustIndex = null)
    {
        GameObject     skillObjHolder = new GameObject();
        SE_SkillObject skillObj       = skillObjHolder.AddComponent <SE_SkillObject>();

        emittedObjList.Add(skillObj);

        emittedInstance.transform.parent = skillObjHolder.transform;
        skillObj.skillInstance           = emittedInstance.transform;
        skillObj.emitter    = this;
        skillObj.brustCount = brustCount == null ? 0 : brustCount.Value;
        skillObj.brustIndex = brustIndex == null ? 0 : brustIndex.Value;

        switch (simulationSpace)
        {
        case SpaceType.Local:
            skillObjHolder.transform.parent = this.transform;
            break;

        case SpaceType.World:
            break;
        }

        skillObj.OnInitDone    = OnSkillObjectInitDone;
        skillObj.OnLifetimeEnd = OnSkillObjectLifetimeEnd;

        //select target module delegate
        var m_selectTarget = GetComponent <EM_SelectTarget>();

        if (m_selectTarget != null)
        {
            skillObj.GetSkillTarget = m_selectTarget.GetSkillTarget;
        }

        //skill object transform
        var m_spawnLocation = GetComponent <EM_SpawnLocation>();

        if (m_spawnLocation == null)
        {
            emittedInstance.transform.position = transform.position;
            emittedInstance.transform.rotation = transform.rotation;
        }
        else
        {
            skillObj.GetSpawnLocationData = m_spawnLocation.GetSpawnLocation;
        }
        //Lifetime module delegate
        var m_lifetime = GetComponent <EM_Lifetime>();

        if (m_lifetime != null)
        {
            skillObj.GetInitLifetime = m_lifetime.GetInitLifetime;
        }

        //Anchor Offset module delegate
        var m_initAnchorOffset = GetComponent <EM_InitialAnchorOffset>();

        if (m_initAnchorOffset != null)
        {
            skillObj.GetInitAnchorOffset = m_initAnchorOffset.GetInitAnchorOffset;
        }

        //Initial Size module delegate
        var m_initSize = GetComponent <EM_InitialSize>();

        if (m_initSize != null)
        {
            skillObj.GetInitSize = m_initSize.GetInitSize;
        }

        //Initial Rotation module delegate
        var m_initRotation = GetComponent <EM_InitialRotation>();

        if (m_initRotation != null)
        {
            skillObj.GetInitRotation = m_initRotation.GetInitRotation;
        }

        //Initial Rotation Rate module delegate
        var m_initRotRate = GetComponent <EM_InitialRotRate>();

        if (m_initRotRate != null)
        {
            skillObj.GetInitRotationRate = m_initRotRate.GetInitRotationRate;
        }
        var m_initAnchorRotRate = GetComponent <EM_InitialAnchorRotRate>();

        if (m_initAnchorRotRate != null)
        {
            skillObj.GetInitAnchorRotationRate = m_initAnchorRotRate.GetInitAnchorRotationRate;
        }

        //Initial Velocity module delegate
        var m_initVelocity = GetComponent <EM_InitialVelocity>();

        if (m_initVelocity != null)
        {
            skillObj.GetInitVelocity = m_initVelocity.GetInitVelocity;
        }

        //On Collision module delegate
        var m_onCollision = GetComponent <EM_OnCollision>();

        if (m_onCollision != null)
        {
            skillObj.OnCollisionReceiver = m_onCollision.OnCollision;
        }

        //On Collision module delegate
        var m_onDestroy = GetComponent <EM_OnDestroy>();

        if (m_onDestroy != null)
        {
            skillObj.OnObjectDestroy = m_onDestroy.OnObjectDestroy;
        }

        /**
         * Update Module
         */
        //Anchor Offset Update Delegate
        var m_AnchorOffsetList = new List <EM_AnchorOffsetModifier>(GetComponents <EM_AnchorOffsetModifier>());

        m_AnchorOffsetList.Sort((a, b) => a.Priority.CompareTo(b.Priority));
        for (int i = 0; i < m_AnchorOffsetList.Count; i++)
        {
            skillObj.UpdateAnchorOffsetList.Add(m_AnchorOffsetList[i].UpdateAnchorOffset);
        }
        //Velocity Update Delegate
        var m_VelocityList = new List <EM_VelocityModifier>(GetComponents <EM_VelocityModifier>());

        m_VelocityList.Sort((a, b) => a.Priority.CompareTo(b.Priority));
        for (int i = 0; i < m_VelocityList.Count; i++)
        {
            skillObj.UpdateVelocityList.Add(m_VelocityList[i].UpdateVelocity);
        }

        //Rotation Update Delegate
        var m_RotationList = new List <EM_RotationModifier>(GetComponents <EM_RotationModifier>());

        m_RotationList.Sort((a, b) => a.Priority.CompareTo(b.Priority));
        for (int i = 0; i < m_RotationList.Count; i++)
        {
            skillObj.UpdateRotationList.Add(m_RotationList[i].UpdateRotation);
        }
    }