コード例 #1
0
        void EmitFX()
        {
            if (moduleObject.enableInteraction)
            {
                if (Application.isPlaying && moduleObject != null && moduleObject.gameObject.activeInHierarchy)
                {
                    if (actionPass)
                    {
                        //######################################
                        //##    CALCULATE TIMING and DELAYS   ##
                        //######################################
                        delayPass = false;

                        emitTimer += _deltaTime;
                        if (emitTimer >= emitSpeed)
                        {
                            emitTimer = 0f;
                            delayPass = true;
                        }



                        //####################################
                        //##    CALCULATE WATER RELATION   ##
                        //####################################
                        heightValues    = moduleObject.SuimonoGetHeightAll(this.transform.position);
                        currentWaterPos = heightValues[3];
                        isOverWater     = heightValues[4];


                        //##########################
                        //##    CALCULATE RULES   ##
                        //##########################
                        rulepass = false;
                        if (ruleCheck == null)
                        {
                            ruleCheck = new bool[effectRule.Length];
                        }
                        ruleCKNum = 0;
                        if (resetCheck == null)
                        {
                            resetCheck = new bool[resetRule.Length];
                        }


                        if (Application.isPlaying)
                        {
                            var rp = false;
                            for (rCK = 0; rCK < effectRule.Length; rCK++)
                            {
                                //CHECK ALL RULES

                                rp       = false;
                                ruleData = speedThreshold;

                                //get depth
                                depth = currentWaterPos;

                                if (rCK < effectData.Length)
                                {
                                    ruleData = effectData[rCK];
                                }

                                //rules.none
                                if (ruleIndex[rCK] == 0)
                                {
                                    rp = true;
                                }

                                //rules.ObjectIsUnderwater
                                if (ruleIndex[rCK] == 1 && isOverWater == 1f)
                                {
                                    if (depth > 0f)
                                    {
                                        rp = true;
                                    }
                                }

                                //rules.ObjectIsAbovewater
                                if (ruleIndex[rCK] == 2 && isOverWater == 1f)
                                {
                                    if (depth <= 0f)
                                    {
                                        rp = true;
                                    }
                                }

                                //rules.ObjectIsAtSurface
                                if (ruleIndex[rCK] == 3 && isOverWater == 1f)
                                {
                                    if (depth < 0.15f && depth > -0.15f)
                                    {
                                        rp = true;
                                    }
                                }

                                //rules.speedIsGreater
                                if (ruleIndex[rCK] == 4 && isOverWater == 1f)
                                {
                                    if (currentSpeed > ruleData)
                                    {
                                        rp = true;
                                    }
                                }

                                //rules.speedIsLess
                                if (ruleIndex[rCK] == 5 && isOverWater == 1f)
                                {
                                    if (currentSpeed < ruleData)
                                    {
                                        rp = true;
                                    }
                                }

                                //rules.WaterDepthGreater
                                if (ruleIndex[rCK] == 6 && isOverWater == 1f)
                                {
                                    if (depth > ruleData)
                                    {
                                        rp = true;
                                    }
                                }

                                //rules.WaterDepthIsLess
                                if (ruleIndex[rCK] == 7 && isOverWater == 1f)
                                {
                                    if (depth < ruleData)
                                    {
                                        rp = true;
                                    }
                                }

                                ruleCheck[rCK] = rp;
                            }
                        }

                        //determine if all rules are passed
                        for (rCK = 0; rCK < effectRule.Length; rCK++)
                        {
                            if (ruleCheck[rCK])
                            {
                                ruleCKNum += 1;
                            }
                        }
                        if (ruleCKNum == effectRule.Length)
                        {
                            rulepass = true;
                        }

                        //no rules
                        if (effectRule.Length == 0)
                        {
                            rulepass = true;
                        }


                        //######################
                        //##    INITIATE FX   ##
                        //######################
                        if (delayPass && rulepass)
                        {
                            emitN   = Mathf.FloorToInt(fxRand.Next(emitNum.x, emitNum.y));
                            emitS   = fxRand.Next(effectSize.x, effectSize.y);
                            emitV   = new Vector3(0f, 0f, 0f);
                            emitPos = transform.position;
                            emitR   = transform.eulerAngles.y - 180f;

                            if (!clampRot)
                            {
                                emitR = fxRand.Next(-30f, 10f);
                            }
                            emitAR = fxRand.Next(-360f, 360f);

                            //get water level
                            if (emitAtWaterLevel)
                            {
                                emitPos = new Vector3(emitPos.x, (transform.position.y + currentWaterPos) - 0.35f, emitPos.z);
                            }

                            if (directionMultiplier > 0f)
                            {
                                emitV = transform.up * (directionMultiplier * Mathf.Clamp01((currentSpeed / speedThreshold)));
                            }

                            //EMIT PARTICLE SYSTEM
                            if (timerParticle > emitSpeed)
                            {
                                timerParticle = 0f;

                                if (systemIndex - 1 >= 0)
                                {
                                    emitPos.y += (emitS * 0.4f);
                                    emitPos.x += fxRand.Next(-0.2f, 0.2f);
                                    emitPos.z += fxRand.Next(-0.2f, 0.2f);
                                    moduleObject.AddFX(systemIndex - 1, emitPos, emitN, fxRand.Next(0.5f, 0.75f) * emitS, emitR, emitAR, emitV, tintCol);
                                }

                                actionCount++;
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        void SetUpdate()
        {
            if (moduleObject != null)
            {
                //set Random
                if (buyRand == null)
                {
                    buyRand = new Suimono.Core.Random(randSeed);
                }

                //check activations
                performHeight = true;
                if (physTarget != null && moduleObject.setCamera != null)
                {
                    //check for range activation
                    if (activationRange > 0f)
                    {
                        currRange = Vector3.Distance(moduleObject.setCamera.transform.position, physTarget.transform.position);
                        if (currRange >= activationRange)
                        {
                            performHeight = false;
                        }
                    }

                    if (activationRange <= 0f)
                    {
                        performHeight = true;
                    }

                    /*
                     * //check for frustrum activation
                     * camRange = 0.2f;
                     * if (moduleObject != null && performHeight){
                     * if (moduleObject.setCameraComponent != null){
                     *      currCamPos = moduleObject.setCameraComponent.WorldToViewportPoint(physTarget.transform.position);
                     *      if (currCamPos.x > (1f+camRange) || currCamPos.y > (1f+camRange)){
                     *              performHeight = false;
                     *      }
                     *      if (currCamPos.x < (0f-camRange) || currCamPos.y < (0f-camRange)){
                     *              performHeight = false;
                     *      }
                     * }
                     * }
                     */

                    //check for enable activation
                    if (!isEnabled)
                    {
                        performHeight = false;
                    }
                }


                //perform height check
                if (performHeight)
                {
                    // Get all height variables from Suimono Module object
                    heightValues = moduleObject.SuimonoGetHeightAll(this.transform.position);
                    isOver       = heightValues[4];
                    waveHt       = heightValues[8];
                    surfaceLevel = heightValues[0];
                    forceAngles  = moduleObject.SuimonoConvertAngleToVector(heightValues[6]);
                    forceSpeed   = heightValues[7] * 0.1f;
                }

                //clamp variables
                forceHeightFactor = Mathf.Clamp01(forceHeightFactor);

                //Reset values
                isUnderwater    = false;
                underwaterLevel = 0f;

                //calculate scaling
                testObjectHeight = (transform.position.y + buoyancyOffset - 0.5f);

                waveHeight = surfaceLevel;
                if (testObjectHeight < waveHeight)
                {
                    isUnderwater = true;
                }
                underwaterLevel = waveHeight - testObjectHeight;


                //set buoyancy
                if (!keepAtSurface && rigidbodyComponent)
                {
                    rigidbodyComponent.isKinematic = saveRigidbodyState;
                }

                if (!keepAtSurface && engageBuoyancy && isOver == 1f)
                {
                    if (rigidbodyComponent && !rigidbodyComponent.isKinematic)
                    {
                        //reset rigidbody if turned off
                        if (rigidbodyComponent.isKinematic)
                        {
                            rigidbodyComponent.isKinematic = saveRigidbodyState;
                        }

                        buoyancyFactor = 10.0f;

                        if (isUnderwater)
                        {
                            if (this.transform.position.y + buoyancyOffset - 0.5f < waveHeight - surfaceRange)
                            {
                                // add vertical force to buoyancy while underwater
                                forceMod = (buoyancyFactor * (buoyancy * rigidbodyComponent.mass) * (underwaterLevel) * splitFac * (isUnderwater ? 1f : 0f));
                                if (rigidbodyComponent.velocity.y < maxVerticalSpeed)
                                {
                                    rigidbodyComponent.AddForceAtPosition(new Vector3(0f, 1f, 0f) * forceMod, transform.position);
                                }

                                modTime = 0f;
                            }
                            else
                            {
                                // slow down vertical velocity as it reaches water surface or wave zenith
                                modTime = (this.transform.position.y + buoyancyOffset - 0.5f) / (waveHeight + buyRand.Next(0f, 0.25f) * (isUnderwater ? 1f : 0f));
                                if (rigidbodyComponent.velocity.y > 0f)
                                {
                                    rigidbodyComponent.velocity = new Vector3(
                                        rigidbodyComponent.velocity.x,
                                        Mathf.SmoothStep(rigidbodyComponent.velocity.y, 0f, modTime),
                                        rigidbodyComponent.velocity.z);
                                }
                            }


                            //Add Water Force / Direction to Buoyancy Object
                            if (inheritForce)
                            {
                                if (this.transform.position.y + buoyancyOffset - 0.5f <= waveHeight)
                                {
                                    waveFac = Mathf.Lerp(0f, forceHeightFactor, waveHt);
                                    if (forceHeightFactor == 0f)
                                    {
                                        waveFac = 1f;
                                    }
                                    rigidbodyComponent.AddForceAtPosition(new Vector3(forceAngles.x, 0f, forceAngles.y) * (buoyancyFactor * 2f) * forceSpeed * waveFac * splitFac * forceAmount, transform.position);
                                }
                            }
                        }
                    }
                }



                //Keep At Surface Option
                if (keepAtSurface && isOver == 1f)
                {
                    saveKeepAtSurface = keepAtSurface;
                    float testPos = (surfaceLevel - physTarget.position.y - buoyancyOffset);
                    if (testPos >= -0.25f)
                    {
                        //remove rigidbody
                        if (rigidbodyComponent != null)
                        {
                            //rigidbodyComponent.velocity = Vector3.zero;
                            if (!rigidbodyComponent.isKinematic)
                            {
                                saveRigidbodyState             = false;
                                rigidbodyComponent.isKinematic = true;
                            }
                        }

                        //set Y position
                        physPosition        = physTarget.position;
                        physPosition.y      = Mathf.Lerp(startYPosition, targetYPosition, lerpSurfacePosTime);
                        physTarget.position = physPosition;
                    }
                    else
                    {
                        rigidbodyComponent.isKinematic = saveRigidbodyState;
                    }


                    //set timer for smooth blend
                    lerpSurfacePosTime += Time.deltaTime * 4f;
                    if (lerpSurfacePosTime > 1f || keepAtSurface != saveKeepAtSurface)
                    {
                        lerpSurfacePosTime = 0f;
                        startYPosition     = physTarget.position.y;
                        targetYPosition    = surfaceLevel - buoyancyOffset;             //physTarget.position.y;
                    }
                }
            }
        }