Example #1
0
    /// <summary>
    /// Do all operations related to deploing drill (or hiding it) - animation
    /// </summary>
    private void HandleDeployment(float dt, bool down = true)
    {
        if (DrillDeploymentState != DeployState.Idle)
        {
            float Rotation = dt * 3.75f;
            Cyl1Transform.RotateAroundLocal(new Vector3(0, 1, 0), Rotation);
            Cyl2Transform.RotateAroundLocal(new Vector3(0, 1, 0), Rotation);
            Cyl3Transform.RotateAroundLocal(new Vector3(0, 1, 0), Rotation);
        }

        switch (DrillDeploymentState)
        {
        case DeployState.Idle:
        {
            if (down)
            {
                DrillDeploymentState = DeployState.DeployBase;
            }
        } break;

        case DeployState.DeployBase:
        {
            Vector3 Translation = new Vector3(-dt * 0.35f, 0, 0);
            BaseTransform.localPosition += (down ? Translation : -Translation);
            //BaseTransform.collider.transform.localPosition += Translation;
            if (down)
            {
                if (BaseTransform.localPosition.x <= -0.35)
                {
                    BaseTransform.localPosition = new Vector3(-0.35f, BaseTransform.localPosition.y, BaseTransform.localPosition.z);
                    //BaseTransform.collider.transform.localPosition.Set(-0.25f, 0, 0);
                    DrillDeploymentState = DeployState.DeployArm1;
                }
            }
            else
            {
                if (BaseTransform.localPosition.x >= -0.0521)
                {
                    BaseTransform.localPosition = new Vector3(-0.0521f, BaseTransform.localPosition.y, BaseTransform.localPosition.z);
                    //BaseTransform.collider.transform.localPosition.Set(-0.25f, 0, 0);
                    DrillDeploymentState = DeployState.Idle;
                }
            }
        } break;

        case DeployState.DeployArm1:
        {
            float   Speed       = (!IsDrillUndergorund ? 0.5f : 0.2f);
            Vector3 Translation = new Vector3(0, -dt * Speed, 0);
            Cyl1Transform.localPosition += (down ? Translation : -Translation);
            //Cyl1Transform.collider.transform.localPosition += Translation;
            if (down)
            {
                if (Cyl1Transform.localPosition.y <= -0.399f)
                {
                    Cyl1Transform.localPosition = new Vector3(Cyl1Transform.localPosition.x, -0.399f, Cyl1Transform.localPosition.z);
                    //Cyl1Transform.collider.transform.localPosition.Set(-5, 0, 0);
                    DrillDeploymentState = DeployState.DeployArm2;
                }
            }
            else
            {
                if (Cyl1Transform.localPosition.y >= 0.417346f)
                {
                    Cyl1Transform.localPosition = new Vector3(Cyl1Transform.localPosition.x, 0.417346f, Cyl1Transform.localPosition.z);
                    //Cyl1Transform.collider.transform.localPosition.Set(-5, 0, 0);
                    DrillDeploymentState = DeployState.DeployBase;
                }
            }
        } break;

        case DeployState.DeployArm2:
        {
            float   Speed       = (!IsDrillUndergorund ? 0.5f : 0.2f);
            Vector3 Translation = new Vector3(0, -dt * Speed, 0);
            Cyl2Transform.localPosition += (down ? Translation : -Translation);
            //Cyl2Transform.collider.transform.localPosition += Translation;
            if (down)
            {
                if (Cyl2Transform.localPosition.y <= -0.899f)
                {
                    Cyl2Transform.localPosition = new Vector3(Cyl2Transform.localPosition.x, -0.899f, Cyl2Transform.localPosition.z);
                    //Cyl1Transform.collider.transform.localPosition.Set(-5, 0, 0);
                    DrillDeploymentState = DeployState.DeployArm3;
                }
            }
            else
            {
                if (Cyl2Transform.localPosition.y >= -0.01016799f)
                {
                    Cyl2Transform.localPosition = new Vector3(Cyl2Transform.localPosition.x, -0.01016799f, Cyl2Transform.localPosition.z);
                    //Cyl1Transform.collider.transform.localPosition.Set(-5, 0, 0);
                    DrillDeploymentState = DeployState.DeployArm1;
                }
            }
        } break;

        case DeployState.DeployArm3:
        {
            float   Speed       = (!IsDrillUndergorund ? 0.5f : 0.2f);
            Vector3 Translation = new Vector3(0, -dt * Speed, 0);
            Cyl3Transform.localPosition += (down ? Translation : -Translation);
            //Cyl2Transform.collider.transform.localPosition += Translation;
            if (down)
            {
                if (Cyl3Transform.localPosition.y <= -0.899f)
                {
                    Cyl3Transform.localPosition = new Vector3(Cyl3Transform.localPosition.x, -0.899f, Cyl3Transform.localPosition.z);
                    //Cyl1Transform.collider.transform.localPosition.Set(-5, 0, 0);
                    DrillDeploymentState = DeployState.Deployed;
                }
            }
            else
            {
                if (Cyl3Transform.localPosition.y >= 0.037)
                {
                    Cyl3Transform.localPosition = new Vector3(Cyl3Transform.localPosition.x, 0.037f, Cyl3Transform.localPosition.z);
                    //Cyl1Transform.collider.transform.localPosition.Set(-5, 0, 0);
                    DrillDeploymentState = DeployState.DeployArm2;
                }
            }
        } break;

        case DeployState.Deployed:
        {
            if (down == false)
            {
                DrillDeploymentState = DeployState.DeployArm3;
            }
        } break;
        }
        DeployLength = Math.Abs(Cyl1Transform.localPosition.y - 0.417346f) + Math.Abs(Cyl2Transform.localPosition.y + 0.01016799f) + Math.Abs(Cyl3Transform.localPosition.y - 0.037f);
    }
Example #2
0
        public override void OnUpdate()
        {
            var dt   = Time.deltaTime;
            var down = ArmWantToGoDown;

            if (DrillDeploymentState != DeployState.Idle)
            {
                float Rotation = dt * 3.75f;
                Cyl1Transform.RotateAroundLocal(new Vector3(0, 1, 0), Rotation);
                Cyl2Transform.RotateAroundLocal(new Vector3(0, 1, 0), Rotation);
                Cyl3Transform.RotateAroundLocal(new Vector3(0, 1, 0), Rotation);
            }

            switch (DrillDeploymentState)
            {
            case DeployState.Idle:
            {
                if (down)
                {
                    DrillDeploymentState = DeployState.DeployBase;
                }
            } break;

            case DeployState.DeployBase:
            {
                Vector3 Translation = new Vector3(-dt * 0.35f, 0, 0);
                BaseTransform.localPosition += (down ? Translation : -Translation);
                if (down)
                {
                    if (BaseTransform.localPosition.x <= -0.35)
                    {
                        BaseTransform.localPosition = new Vector3(-0.35f, BaseTransform.localPosition.y, BaseTransform.localPosition.z);
                        DrillDeploymentState        = DeployState.DeployArm1;
                    }
                }
                else
                {
                    if (BaseTransform.localPosition.x >= -0.0521)
                    {
                        BaseTransform.localPosition = new Vector3(-0.0521f, BaseTransform.localPosition.y, BaseTransform.localPosition.z);
                        DrillDeploymentState        = DeployState.Idle;
                    }
                }
            } break;

            case DeployState.DeployArm1:
            {
                float   Speed       = 0.5f;
                Vector3 Translation = new Vector3(0, -dt * Speed, 0);
                Cyl1Transform.localPosition += (down ? Translation : -Translation);
                if (down)
                {
                    if (Cyl1Transform.localPosition.y <= -0.399f)
                    {
                        Cyl1Transform.localPosition = new Vector3(Cyl1Transform.localPosition.x, -0.399f, Cyl1Transform.localPosition.z);
                        DrillDeploymentState        = DeployState.DeployArm2;
                    }
                }
                else
                {
                    if (Cyl1Transform.localPosition.y >= 0.417346f)
                    {
                        Cyl1Transform.localPosition = new Vector3(Cyl1Transform.localPosition.x, 0.417346f, Cyl1Transform.localPosition.z);
                        DrillDeploymentState        = DeployState.DeployBase;
                    }
                }
            } break;

            case DeployState.DeployArm2:
            {
                float   Speed       = 0.5f;
                Vector3 Translation = new Vector3(0, -dt * Speed, 0);
                Cyl2Transform.localPosition += (down ? Translation : -Translation);
                if (down)
                {
                    if (Cyl2Transform.localPosition.y <= -0.899f)
                    {
                        Cyl2Transform.localPosition = new Vector3(Cyl2Transform.localPosition.x, -0.899f, Cyl2Transform.localPosition.z);
                        DrillDeploymentState        = DeployState.DeployArm3;
                    }
                }
                else
                {
                    if (Cyl2Transform.localPosition.y >= -0.01016799f)
                    {
                        Cyl2Transform.localPosition = new Vector3(Cyl2Transform.localPosition.x, -0.01016799f, Cyl2Transform.localPosition.z);
                        DrillDeploymentState        = DeployState.DeployArm1;
                    }
                }
            } break;

            case DeployState.DeployArm3:
            {
                float   Speed       = 0.5f;
                Vector3 Translation = new Vector3(0, -dt * Speed, 0);
                Cyl3Transform.localPosition += (down ? Translation : -Translation);
                if (down)
                {
                    if (Cyl3Transform.localPosition.y <= -0.899f)
                    {
                        Cyl3Transform.localPosition = new Vector3(Cyl3Transform.localPosition.x, -0.899f, Cyl3Transform.localPosition.z);
                        DrillDeploymentState        = DeployState.Deployed;
                    }
                }
                else
                {
                    if (Cyl3Transform.localPosition.y >= 0.037)
                    {
                        Cyl3Transform.localPosition = new Vector3(Cyl3Transform.localPosition.x, 0.037f, Cyl3Transform.localPosition.z);
                        DrillDeploymentState        = DeployState.DeployArm2;
                    }
                }
            } break;

            case DeployState.Deployed:
            {
                if (down == false)
                {
                    DrillDeploymentState = DeployState.DeployArm3;
                }
            } break;
            }
        }