void Dosimulating()
    {
        if (ShootSolutionEditor.instance != null && ShootSolutionEditor.instance.mCurSelectedSolution != null)
        {
            m_editingShootSolution = ShootSolutionEditor.instance.mCurSelectedSolution;
        }
        else
        {
            m_editingShootSolution = m_simulatingShootSolution;
        }


        if (mirrorClicked)
        {
            m_ball.transform.position = new Vector3(-m_ball.transform.position.x, m_ball.transform.position.y, m_ball.transform.position.z);
            m_vAngleAdjustment.x     *= -1;
            m_editingShootSolution    = m_editingShootSolution.Clone();
            ShootSolutionEditor.instance.mCurSelectedSolution = m_editingShootSolution;
        }
        m_iCurSector = GameSystem.Instance.shootSolutionManager.CalcSectorIdx(m_basket.m_rim.center, m_ball.position);
        ShootSimulation.Instance.Build(m_basket, m_ball);

        m_editingShootSolution.m_vBounceRimAdjustment = IM.Editor.Tools.Convert(m_vBounceRimAdjustment);
        m_editingShootSolution.m_fBounceBackboard     = IM.Editor.Tools.Convert(m_fBounceBackboard);

        m_editingShootSolution.m_animationType  = type;
        m_editingShootSolution.m_playTime       = IM.Editor.Tools.Convert(m_playTime);
        m_editingShootSolution.m_playSpeed      = IM.Editor.Tools.Convert(m_playSpeed);
        m_editingShootSolution.m_reductionIndex = IM.Editor.Tools.Convert(m_reductionIndex);

        if (!ShootSimulation.Instance.DoSimulate(m_iCurSector, IM.Editor.Tools.Convert(m_vAngleAdjustment), IM.Editor.Tools.Convert(m_fSpeed), type, IM.Editor.Tools.Convert(m_reductionIndex), ref m_editingShootSolution))
        {
            return;
        }

        m_shootSolutionKeys.Clear();
        if (m_editingShootSolution == null)
        {
            return;
        }

        float fTime = 0.0f;
        float fStep = 0.01f;

        IM.Vector3 curPos;

        while (m_editingShootSolution.GetPosition(IM.Editor.Tools.Convert(fTime), out curPos))
        {
            m_shootSolutionKeys.Add((Vector3)curPos);
            fTime += fStep;
        }

        m_ball.m_shootSolution = m_editingShootSolution;
        SceneView.RepaintAll();
        ShootSolutionEditor.instance._DrawCurves();
    }
    public override ShootSolution GetShootSolution(UBasket basket, Area area, Player shooter, IM.PrecNumber rate, ShootSolution.Type type)
    {
        ShootSolution solution = practise_behaviour.GetShootSolution(basket, area, shooter, rate);

        if (solution == null)
        {
            solution = base.GetShootSolution(basket, area, shooter, rate, type);
        }
        Debug.Log("Practise shoot solution: " + solution.m_id);
        return(solution);
    }
    public ShootSolution GetShootSolution(int id)
    {
        int iSecId = id / 1000;
        ShootSolutionSector sector = m_ShootSolutionSectors[iSecId];
        ShootSolution       result = sector.success.Find((ShootSolution solution) => { return(solution.m_id == id); });

        if (result == null)
        {
            result = sector.fail.Find((ShootSolution solution) => { return(solution.m_id == id); });
        }
        return(result);
    }
        public void AddSolution(ShootSolution inSolution)
        {
            List <ShootSolution> solutions = inSolution.m_bSuccess ? success : fail;

            //TODO: check whether the same
            foreach (ShootSolution solution in solutions)
            {
                if (solution == inSolution)
                {
                    return;
                }
            }
            solutions.Add(inSolution);
        }
    ShootSolutionSector _LoadShootSolutionSector(int idx, string strFileName, bool bForEditor)
    {
        ShootSolutionSector sector = new ShootSolutionSector(idx);

        //读取以及处理XML文本的类
        XmlDocument xmlDoc;

        if (bForEditor)
        {
            xmlDoc = new XmlDocument();
            xmlDoc.Load("Assets/Resources/" + GlobalConst.DIR_XML_SHOOT_SOLUTION + strFileName + ".xml");
        }
        else
        {
            xmlDoc = CommonFunction.LoadXmlConfig(GlobalConst.DIR_XML_SHOOT_SOLUTION + strFileName);
        }
        //解析xml的过程

        int         iSolutionIdx = 0;
        XmlNodeList nodelist     = xmlDoc.SelectNodes("root/success");

        foreach (XmlElement elem in nodelist)
        {
            ShootSolution sucSolution = new ShootSolution(idx * 1000 + iSolutionIdx);
            if (!sucSolution.Create(elem, true, bForEditor))
            {
                continue;
            }
            sector.success.Add(sucSolution);
            iSolutionIdx++;
        }

        nodelist = xmlDoc.SelectNodes("root/fail");
        foreach (XmlElement elem in nodelist)
        {
            ShootSolution failSolution = new ShootSolution(idx * 1000 + iSolutionIdx);
            if (!failSolution.Create(elem, false, bForEditor))
            {
                continue;
            }
            sector.fail.Add(failSolution);
            iSolutionIdx++;
        }
        return(sector);
    }
 void CorrectSolutionSector(int index, ref List <ShootSolution> solutions)
 {
     for (int i = 0; i < solutions.Count;)
     {
         ShootSolution solution    = solutions[i];
         int           actualIndex = CalcSectorIdx(new IM.Vector3(IM.Number.zero, IM.Number.zero, new IM.Number(12, 800)), solution.m_vInitPos);
         if (index != actualIndex)
         {
             Debug.Log("Sector mismatching, saved index : " + index + " actual index: " + actualIndex + ". Corrected. Please save again.");
             ShootSolutionSector actualSector = m_ShootSolutionSectors.Find((ShootSolutionSector sector) => { return(sector.index == actualIndex); });
             actualSector.AddSolution(solution);
             solutions.RemoveAt(i);
         }
         else
         {
             ++i;
         }
     }
 }
    public ShootSolution Clone()
    {
        ShootSolution solution = new ShootSolution(m_id);

        solution.m_fTime    = m_fTime;
        solution.m_bSuccess = m_bSuccess;

        solution.m_vInitPos  = m_vInitPos;
        solution.m_vInitVel  = m_vInitVel;
        solution.m_vFinPos   = m_vFinPos;
        solution.m_vFinVel   = m_vFinVel;
        solution.m_vStartPos = m_vStartPos;

        solution.m_vBounceRimAdjustment = m_vBounceRimAdjustment;
        solution.m_fBounceBackboard     = m_fBounceBackboard;

        solution.m_ShootCurveList = new List <SShootCurve>(m_ShootCurveList.ToArray());
        return(solution);
    }
    void ReadShootSolutionSector(int index, string filePath)
    {
        ShootSolutionSector sector = new ShootSolutionSector(index);

        //读取以及处理XML文本的类
        string text = ResourceLoadManager.Instance.GetConfigText(GlobalConst.DIR_XML_SHOOT_SOLUTION + filePath);

        if (text == null)
        {
            Debug.LogError("LoadConfig failed: " + name + filePath);
            return;
        }
        XmlDocument xmlDoc = CommonFunction.LoadXmlConfig(GlobalConst.DIR_XML_SHOOT_SOLUTION + filePath, text);
        //解析xml的过程

        int         iSolutionIdx = 0;
        XmlNodeList nodelist     = xmlDoc.SelectNodes("root/success");

        foreach (XmlElement elem in nodelist)
        {
            ShootSolution sucSolution = new ShootSolution(index * 1000 + iSolutionIdx);
            if (!sucSolution.Create(elem, true))
            {
                continue;
            }
            sector.success.Add(sucSolution);
            iSolutionIdx++;
        }

        nodelist = xmlDoc.SelectNodes("root/fail");
        foreach (XmlElement elem in nodelist)
        {
            ShootSolution failSolution = new ShootSolution(index * 1000 + iSolutionIdx);
            if (!failSolution.Create(elem, false))
            {
                continue;
            }
            sector.fail.Add(failSolution);
            iSolutionIdx++;
        }

        shootSolutionData.shootSolutionSectors.Add(index, sector);
    }
    void OnEnable()
    {
        m_ball = (UBasketball)target;
        GameObject goBasket = GameObject.FindGameObjectWithTag("basketStand");

        if (goBasket == null)
        {
            return;
        }
        m_basket = goBasket.GetComponent <UBasket>();
        if (m_basket == null)
        {
            m_basket = goBasket.AddComponent <UBasket>();
        }
        m_basket.Build(new IM.Vector3(IM.Number.zero, IM.Number.zero, new IM.Number(12, 8)));

        m_ball.m_ballRadius = new IM.Number(0, 125);

        m_simulatingShootSolution = new ShootSolution(0);
        GameSystem.Instance.shootSolutionManager = new ShootSolutionManager();


        instance = this;
    }
Exemple #10
0
    public bool DoSimulate(int sector, IM.Vector2 angleAdjustment, IM.Number speed, ShootSolution.AnimationType type, IM.Number reductionIndex, ref ShootSolution solution)
    {
        if (sector == -1)
        {
            return(false);
        }

        IM.Vector3 vecInitPos, vecInitVel;
        IM.Vector3 vecFinPos, vecFinVel;

        /*
         * if(sector == 0)
         * {
         *      vecInitPos = m_basket.m_rim.center;
         *      vecInitVel = new IM.Vector3(0.0f, 0.0f, 1.0f);
         *
         *      vecInitVel = Quaternion.AngleAxis(m_fBeta, IM.Vector3.up) * vecInitVel;
         *      vecInitVel = Quaternion.AngleAxis(m_fAlpha, IM.Vector3.Cross(vecInitVel.normalized, IM.Vector3.up)) * vecInitVel;
         *
         *      vecInitVel.Normalize();
         *      vecInitVel *= m_fVel_ini;
         * }
         * else
         */
        {
            vecInitPos   = m_ball.position;
            vecInitVel   = m_basket.m_rim.center - vecInitPos;
            vecInitVel.y = IM.Number.zero;

            vecInitVel = IM.Quaternion.AngleAxis(angleAdjustment.x, IM.Vector3.up) * vecInitVel;
            vecInitVel = IM.Quaternion.AngleAxis(angleAdjustment.y, IM.Vector3.Cross(vecInitVel.normalized, IM.Vector3.up)) * vecInitVel;

            vecInitVel.Normalize();
            vecInitVel *= speed;
        }
        solution.m_vInitPos  = vecInitPos;
        solution.m_vInitVel  = vecInitVel;
        solution.m_vFinPos   = vecInitPos;
        solution.m_vFinVel   = vecInitVel;
        solution.m_vStartPos = vecInitPos;

        _Simulating(vecInitPos, vecInitVel, type, reductionIndex, ref solution);

        vecInitPos = solution.m_vInitPos;
        vecFinPos  = solution.m_vFinPos;
        vecFinVel  = solution.m_vFinVel;

        return(true);
    }
    override public void OnEnter(PlayerState lastState)
    {
        base.OnEnter(lastState);

        m_failReason = FailReason.None;

        Player attacker = m_ball.m_actor;

        if (attacker == null)
        {
            attacker = m_ball.m_owner;
        }

        //main player
        bool bBlockable = false, bBlockInRange = false;

        IM.Number  fBlockRate = IM.Number.zero, fBlockValue = IM.Number.zero;
        IM.Vector3 attackerPos = IM.Vector3.zero;
        bool       bValid      = false;

        m_success = false;
        IM.Vector3 vBallVel = IM.Vector3.zero;
        IM.Vector3 vBallPos = IM.Vector3.zero;

        if (attacker != null)
        {
            m_player.FaceTo(attacker.position);

            //shooter is blocked.. set a ball solution to him
            m_failedShootSolution = GameSystem.Instance.shootSolutionManager.GetShootSolution(m_basket.m_vShootTarget, attacker.position, false);
            if (m_failedShootSolution == null)
            {
                Debug.LogError("No shoot solution can be set to block.");
            }

            m_bMoveForward = false;
            m_speed        = IM.Vector3.zero;
            m_bFailDown    = false;

            if (!m_ball.m_bBlockSuccess && m_ball.m_picker == null)
            {
                m_heightScale = IM.Number.one;

                if (m_ball != null && !m_ball.m_bReachMaxHeight &&
                    (m_ball.m_ballState == BallState.eUseBall_Shoot || m_ball.m_ballState == BallState.eUseBall))
                {
                    if (attacker.m_StateMachine.m_curState.m_eState == State.eShoot)
                    {
                        m_success = _CalcBlockShoot(attacker, out bBlockable, out bBlockInRange, out fBlockRate, out fBlockValue, out attackerPos, out vBallVel, out bValid);
                        if (m_success)
                        {
                            _BeginBlockShoot(m_failedShootSolution, attacker, out vBallPos);
                        }
                    }
                    else if (attacker.m_StateMachine.m_curState.m_eState == State.eLayup)
                    {
                        m_success = _CalcBlockLayup(attacker, out bBlockable, out bBlockInRange, out fBlockRate, out fBlockValue, out attackerPos, out vBallVel, out bValid);
                        if (m_success)
                        {
                            _BeginBlockLayup(m_failedShootSolution, attacker, out vBallPos);
                        }
                    }
                    else if (attacker.m_StateMachine.m_curState.m_eState == State.eDunk)
                    {
                        m_success = _CalcBlockDunk(attacker, out bBlockable, out bBlockInRange, out fBlockRate, out fBlockValue, out attackerPos, out vBallVel, out bValid);
                        if (m_success)
                        {
                            _BeginBlockDunk(attacker, out vBallPos);
                        }
                    }
                    else
                    {
                        Debug.Log("Block failed, cur attacker state: " + attacker.m_StateMachine.m_curState.m_eState);
                        m_success = false;
                    }
                    string rateLog = "Block rate: " + fBlockRate + " value: " + fBlockValue;
                    Debugger.Instance.m_steamer.message = rateLog;
                    Debug.Log(rateLog);
                    Debug.Log("block success: " + m_success);
                    Debug.Log("block ball pos: " + vBallPos + ", vel: " + vBallVel);
                    if (!m_success)
                    {
                        Debug.Log("Block fail reason: " + m_failReason);
                    }

                    m_player.mStatistics.SkillUsageSuccess(m_curExecSkill.skill.id, m_success);
                }
                else
                {
                    m_success = false;
                    Debug.Log("496 failed.");
                    m_failReason = FailReason.TooLate;
                }
            }//if( !m_ball.m_bBlockSuccess )
        }

        if (m_curExecSkill.skill.id == idBlockPassBall || m_curExecSkill.skill.id == idBlockGrabBall)
        {
            if (m_ball.m_picker != null || m_ball.m_bGoal)
            {
                m_success = false;
            }
            else
            {
                m_ball.m_picker = m_player;
            }
        }

        if (!m_success)
        {
            m_speed        = m_player.forward;
            m_bMoveForward = false;

            if (attacker != null && attacker.m_StateMachine.m_curState.m_eState == State.eDunk &&
                GameUtils.HorizonalDistance(m_player.position, attacker.position) < IM.Number.one)
            {
                m_bFailDown = IM.Random.value > IM.Number.half;
            }
        }

        if (!m_success)
        {
            List <SkillInstance> basicBlockSkills = m_player.m_skillSystem.GetBasicSkillsByCommand(Command.Block);
            m_curExecSkill = basicBlockSkills[0];
        }
        else
        {
            //m_curExecSkill = _DecideBlockSkill();
            bool bBlockPass = false;
            if (m_curExecSkill.skill.id == idBlockPassBall)
            {
                int value = IM.Random.Range(0, 2);
                bBlockPass = true;
                if (value == 0)
                {
                    Player catcher = PassHelper.ChoosePassTarget(m_player);
                    if (catcher != null)
                    {
                        m_player.m_passTarget = catcher;
                    }
                }
            }
            m_loseBallContext.vInitPos = vBallPos;
            m_loseBallContext.vInitVel = vBallVel;
        }

        m_player.animMgr.Play(m_curAction, false);

        ++m_player.mStatistics.data.block_times;
        if (bValid)
        {
            ++m_player.mStatistics.data.valid_block_times;
        }
    }
Exemple #12
0
    void _ListSolutions(ref List <ShootSolution> solutions, bool success)
    {
        ShootSolution toDelSolution = null;

        foreach (ShootSolution solution in solutions)
        {
            GUILayout.Space(-1f);
            GUI.backgroundColor = solution == mCurSelectedSolution ? Color.white : new Color(0.8f, 0.8f, 0.8f);
            GUILayout.BeginHorizontal("AS TextArea", GUILayout.MaxHeight(20f));
            GUI.backgroundColor = Color.white;

            int idx = solutions.IndexOf(solution);
            GUILayout.Label(idx.ToString(), GUILayout.Width(24f));

            if (GUILayout.Button("solution_" + idx.ToString(), "OL TextField", GUILayout.MaxHeight(20f)))
            {
                mCurSelectedSolution = solution;
                //_DrawCurves();
            }


            if (success)
            {
                solution.m_bCleanShot = GUILayout.Toggle(solution.m_bCleanShot, "Clean shot");
            }

            if (solution.m_ShootCurveList.Count == 2)
            {
                EditorGUILayout.PrefixLabel("count: ");
                EditorGUILayout.FloatField(solution.m_ShootCurveList.Count);

                EditorGUILayout.PrefixLabel("Animation Type: ");
                solution.m_animationType = (ShootSolution.AnimationType)EditorGUILayout.EnumPopup(solution.m_animationType);

                EditorGUILayout.PrefixLabel("Animation Time: ");
                solution.m_playTime = IM.Editor.Tools.Convert(EditorGUILayout.FloatField((float)solution.m_playTime));

                EditorGUILayout.PrefixLabel("Animation Speed: ");
                solution.m_playSpeed = IM.Editor.Tools.Convert(EditorGUILayout.FloatField((float)solution.m_playSpeed));

                EditorGUILayout.PrefixLabel("Animation ReductionIndex: ");
                solution.m_reductionIndex = IM.Editor.Tools.Convert(EditorGUILayout.FloatField((float)solution.m_reductionIndex));

                solution.m_isLock = GUILayout.Toggle(solution.m_isLock, "isLock");
            }

            solution.m_type = (ShootSolution.Type)EditorGUILayout.EnumPopup(solution.m_type);

            List <int> delNames = success ? mDelNamesSuccess : mDelNamesFail;

            if (delNames.Contains(idx))
            {
                GUI.backgroundColor = Color.red;
                if (GUILayout.Button("Delete", GUILayout.Width(60f)))
                {
                    toDelSolution = solution;
                }
                GUI.backgroundColor = Color.green;
                if (GUILayout.Button("X", GUILayout.Width(22f)))
                {
                    delNames.Remove(idx);
                }
                GUI.backgroundColor = Color.white;
            }
            else
            {
                if (GUILayout.Button("X", GUILayout.Width(22f)))
                {
                    delNames.Add(idx);
                }
            }
            GUILayout.EndHorizontal();
        }

        if (toDelSolution != null)
        {
            if (toDelSolution == mCurSelectedSolution)
            {
                mCurSelectedSolution = null;
            }
            solutions.Remove(toDelSolution);
        }

        if (ShootSimulator.instance == null)
        {
            return;
        }

        if (mCurSelectedSolution != null && mBall.m_shootSolution != mCurSelectedSolution)
        {
            mBall.m_shootSolution = mCurSelectedSolution;
            mBall.position        = mCurSelectedSolution.m_vInitPos;
            Vector3 dirBall2BasketH = ((Vector3)mBasket.m_rim.center - mBall.transform.position).normalized;
            dirBall2BasketH.y = 0.0f;

            Vector3 dirInitVel  = (Vector3)mCurSelectedSolution.m_vInitVel.normalized;
            Vector3 dirInitVelH = dirInitVel;
            dirInitVelH.y = 0.0f;
            ShootSimulator.instance.m_vAngleAdjustment.y   = Vector3.Angle(dirInitVelH, dirInitVel);
            ShootSimulator.instance.m_vAngleAdjustment.x   = Vector3.Cross(dirInitVelH, dirBall2BasketH).y > 0.0f ? -Vector3.Angle(dirInitVelH, dirBall2BasketH) : Vector3.Angle(dirInitVelH, dirBall2BasketH);
            ShootSimulator.instance.m_fSpeed               = (float)mCurSelectedSolution.m_vInitVel.magnitude;
            ShootSimulator.instance.m_fBounceBackboard     = (float)mCurSelectedSolution.m_fBounceBackboard;
            ShootSimulator.instance.m_vBounceRimAdjustment = (Vector3)mCurSelectedSolution.m_vBounceRimAdjustment;

            ShootSimulator.instance.Repaint();
            SceneView.RepaintAll();
        }
    }
    bool _BeginBlockLayup(ShootSolution failedShootSolution, Player shooter, out IM.Vector3 ballPos)
    {
        m_ball.m_shootSolution = failedShootSolution;
        ballPos = IM.Vector3.zero;

        Dictionary <string, PlayerAnimAttribute.AnimAttr> blocks = m_player.m_animAttributes.m_block;
        int blockKey = blocks[m_player.animMgr.GetOriginName(m_curAction)].GetKeyFrame("OnBlock").frame;

        IM.Number fEventBlockTime = blockKey / m_player.animMgr.GetFrameRate(m_curAction);

        SkillInstance shooterSkill = shooter.m_StateMachine.m_curState.m_curExecSkill;
        string        shoot_id     = shooter.m_skillSystem.ParseAction(shooterSkill.curAction.action_id, shooterSkill.matchedKeyIdx, Command.Layup);

        PlayerAnimAttribute.AnimAttr shootAnims = shooter.m_animAttributes.GetAnimAttrById(Command.Layup, shoot_id);
        int shootOutKey = shootAnims.GetKeyFrame("OnLayupShot").frame;

        IM.Number fEventShootOutTime = shootOutKey / shooter.animMgr.GetFrameRate(shoot_id);
        IM.Number fShootEclipseTime  = shooter.animMgr.curPlayInfo.time;
        IM.Number fPlayerMovingTime  = fEventShootOutTime - fShootEclipseTime;
        IM.Number fBallFlyTime       = fEventBlockTime - fPlayerMovingTime;

        IM.Vector3 vRootBegin, vRootBlock, vRootShoot;
        m_player.GetNodePosition(SampleNode.Root, shoot_id, fShootEclipseTime, out vRootBegin);
        m_player.GetNodePosition(SampleNode.Root, shoot_id, fShootEclipseTime + fEventBlockTime, out vRootBlock);
        m_player.GetNodePosition(SampleNode.Root, shoot_id, fEventShootOutTime, out vRootShoot);

        IM.Vector3 playerPosWhenLayup = shooter.position + vRootShoot - vRootBegin;
        IM.Vector3 playerPosWhenBlock = shooter.position + vRootBlock - vRootBegin;
        //ball still in player hand
        if (fBallFlyTime < IM.Number.zero)
        {
            IM.Vector3 dirJump = (playerPosWhenBlock - m_player.position) / fEventBlockTime;
            dirJump.y = IM.Number.zero;
            m_speed   = dirJump;

            IM.Vector3 vBallPosWhenLayup;
            m_player.GetNodePosition(SampleNode.Ball, shoot_id, fShootEclipseTime + fEventBlockTime, out vBallPosWhenLayup);
            ballPos = vBallPosWhenLayup;
        }
        else
        {
            IM.Vector3 vBallPosWhenLayup;
            m_player.GetNodePosition(SampleNode.Ball, shoot_id, fEventShootOutTime, out vBallPosWhenLayup);
            IM.Vector3 delta = vBallPosWhenLayup - vRootShoot;
            vBallPosWhenLayup = playerPosWhenLayup + delta;
            //Debugger.Instance.DrawSphere("vBallPosWhenLayup", vBallPosWhenLayup, Color.red);

            m_ball.m_shootSolution             = GameSystem.Instance.shootSolutionManager.GetShootSolution(m_basket.m_rim.center, playerPosWhenLayup, false);
            m_ball.m_shootSolution.m_vStartPos = vBallPosWhenLayup;

            IM.Vector3 vBallPosBlock;
            if (!m_ball.GetPositionInAir(fBallFlyTime, out vBallPosBlock))
            {
                Debugger.Instance.m_steamer.message = "can not block, not shoot curve info.";
                return(false);
            }
            ballPos = vBallPosBlock;

            IM.Vector3 blockAnimBall;
            m_player.GetNodePosition(SampleNode.Ball, m_curAction, fEventBlockTime, out blockAnimBall);
            IM.Vector3 root;
            m_player.GetNodePosition(SampleNode.Root, m_curAction, fEventBlockTime, out root);

            m_heightScale = vBallPosBlock.y / (blockAnimBall.y * m_player.scale.y);
            IM.Vector3 deltaPos2Root = blockAnimBall - root;
            deltaPos2Root.y = IM.Number.zero;
            IM.Vector3 rootPosWhenBlock = vBallPosBlock - deltaPos2Root;
            rootPosWhenBlock.y = IM.Number.zero;

            IM.Vector3 dirJump = (rootPosWhenBlock - m_player.position) / fEventBlockTime;
            m_speed = dirJump;
        }

        m_ball.m_bBlockSuccess = true;

        return(true);
    }
    void _BeginBlockShoot(ShootSolution failedShootSolution, Player shooter, out IM.Vector3 ballPos)
    {
        ballPos = IM.Vector3.zero;

        m_ball.m_shootSolution = failedShootSolution;

        /*
         * if( m_ball.m_shootSolution.m_bSuccess )
         * {
         *      Debug.LogError("block shoot success, but ball goals in.");
         *      return;
         * }
         */

        Dictionary <string, PlayerAnimAttribute.AnimAttr> blocks = m_player.m_animAttributes.m_block;
        int blockKey = blocks[m_player.animMgr.GetOriginName(m_curAction)].GetKeyFrame("OnBlock").frame;

        IM.Number fEventBlockTime = blockKey / m_player.animMgr.GetFrameRate(m_curAction);

        SkillInstance shooterSkill = shooter.m_StateMachine.m_curState.m_curExecSkill;
        Dictionary <string, PlayerAnimAttribute.AnimAttr> shootAnims = shooter.m_animAttributes.m_shoot;
        string shoot_id = shooter.m_skillSystem.ParseAction(shooterSkill.curAction.action_id, shooterSkill.matchedKeyIdx, Command.Shoot);

        int shootOutKey = shootAnims[shooter.animMgr.GetOriginName(shoot_id)].GetKeyFrame("OnShoot").frame;

        IM.Number fEventShootOutTime = shootOutKey / shooter.animMgr.GetFrameRate(shoot_id);
        IM.Number fShootEclipseTime  = shooter.animMgr.curPlayInfo.time;
        if (fShootEclipseTime > fEventShootOutTime)
        {
            fShootEclipseTime = fEventShootOutTime;
        }

        IM.Number fBallFlyTime = fEventBlockTime - (fEventShootOutTime - fShootEclipseTime);
        if (fBallFlyTime < IM.Number.zero)
        {
            fBallFlyTime = IM.Number.zero;
        }

        IM.Vector3 ballPos1;
        m_player.GetNodePosition(SampleNode.Ball, shoot_id, fEventShootOutTime, out ballPos1);
        m_ball.m_shootSolution.m_vStartPos = ballPos1;

        IM.Vector3 vBallPosBlock;
        if (m_ball.GetPositionInAir(fBallFlyTime, out vBallPosBlock))
        {
            IM.Vector3 tempblockAnimBall;
            m_player.GetNodePosition(SampleNode.Ball, m_curAction, fEventBlockTime, out tempblockAnimBall);
            IM.Vector3 temproot;
            m_player.GetNodePosition(SampleNode.Root, m_curAction, fEventBlockTime, out temproot);

            IM.Vector3 blockAnimBall = tempblockAnimBall;
            IM.Vector3 root          = temproot;

            IM.Vector3 deltaPos2Root = blockAnimBall - root;
            deltaPos2Root.y = IM.Number.zero;

            m_heightScale = vBallPosBlock.y / (blockAnimBall.y * m_player.scale.y);
            IM.Vector3 rootPosWhenBlock = vBallPosBlock - deltaPos2Root;
            IM.Vector3 dirJump          = (rootPosWhenBlock - m_player.position) / fEventBlockTime;
            dirJump.y = IM.Number.zero;

            //if( !bTurnBack )
            m_speed = dirJump;
            //else
            //	m_speed = Vector3.zero;

            m_ball.m_bBlockSuccess = true;

            ballPos = vBallPosBlock;
        }
        else
        {
            Debug.LogError("reboundTime out of the curve, too slow");
            return;
        }
    }
Exemple #15
0
    public void _DrawCurves()
    {
        //draw shoot solution
        ShootSolution solution = mBall.m_shootSolution;

        if (solution == null)
        {
            return;
        }
        if (solution.m_fTime > new IM.Number(1000))
        {
            return;
        }
        _BuildShootCurves();
        int iKeyCount = m_shootCurveKeys.Count;

        for (int idx = 0; idx != iKeyCount; idx++)
        {
            if (idx + 1 >= iKeyCount)
            {
                break;
            }
            if (solution.m_bSuccess)
            {
                Handles.color = Color.red;
            }
            else
            {
                if (ShootSimulator.instance != null && solution == ShootSimulator.instance.m_simulatingShootSolution)
                {
                    Handles.color = Color.red;
                }
                else
                {
                    Handles.color = Color.red;
                }
            }
            Handles.DrawLine(m_shootCurveKeys[idx], m_shootCurveKeys[idx + 1]);
        }

        if (!solution.m_bSuccess)
        {
            int iCurveCnt = solution.m_ShootCurveList.Count;
            if (iCurveCnt == 0)
            {
                return;
            }
            ShootSolution.SShootCurve curve = solution.m_ShootCurveList[iCurveCnt - 1];
            Vector3 vPosHighest             = (Vector3)curve.GetHighestPosition();

            GUIStyle style = new GUIStyle();
            style.normal.textColor = Color.red;
            Handles.Label(vPosHighest, vPosHighest.y.ToString(), style);

            const float    dotLineLength = 0.2f;
            List <Vector3> poly          = new List <Vector3>();
            while (vPosHighest.y > 0.0f)
            {
                poly.Add(vPosHighest);
                vPosHighest.y -= dotLineLength;
                poly.Add(vPosHighest);
                vPosHighest.y -= dotLineLength;
            }

            Handles.color = Color.red;
            Handles.DrawPolyLine(poly.ToArray());
        }
    }
Exemple #16
0
    void OnGUI()
    {
        if (SceneView.onSceneGUIDelegate != this.OnSceneGUI)
        {
            SceneView.onSceneGUIDelegate += this.OnSceneGUI;
        }

        if (mBall == null)
        {
            return;
        }

        //NGUIEditorTools.SetLabelWidth(100f);
        GUILayout.Space(3f);

        NGUIEditorTools.DrawHeader("Input");
        NGUIEditorTools.BeginContents();
        GUILayout.BeginHorizontal();
        {
            string resPath = "Assets/Resources/";
            if (GUILayout.Button("Save", GUILayout.ExpandWidth(true)))
            {
                //save solution manager
                string path = resPath + GlobalConst.DIR_XML_SHOOT_SOLUTION + "shootsolutionset";
                GameSystem.Instance.shootSolutionManager.SaveShootSolutionSet(path);
                List <ShootSolutionManager.ShootSolutionSector> sectors = GameSystem.Instance.shootSolutionManager.m_ShootSolutionSectors;
                foreach (ShootSolutionManager.ShootSolutionSector sector in sectors)
                {
                    GameSystem.Instance.shootSolutionManager.SaveShootSolutionSector(sector.index, resPath + GlobalConst.DIR_XML_SHOOT_SOLUTION + "shoot");
                }
                EditorUtility.DisplayDialog("ShootSolutionEditor", "Save complete.", "ok");
            }
            if (GUILayout.Button("Load", GUILayout.ExpandWidth(true)))
            {
                //load solution manager
                string path = GlobalConst.DIR_XML_SHOOT_SOLUTION + "shootsolutionset";
                if (!GameSystem.Instance.shootSolutionManager.LoadShootSolutionSet(path, true))
                {
                    EditorUtility.DisplayDialog("Solution", "load shoot solution set failed.", "ok");
                }
                else
                {
                    mDistanceCount = GameSystem.Instance.shootSolutionManager.m_DistanceList.Count;
                    mAngleCount    = GameSystem.Instance.shootSolutionManager.m_AngleList.Count;
                    if (GameSystem.Instance.shootSolutionManager.m_AngleList.Count > 1)
                    {
                        mDistanceStep = (float)GameSystem.Instance.shootSolutionManager.m_DistanceList[0];
                    }
                }
                ShootSimulator.instance.Repaint();
                SceneView.RepaintAll();
            }
        }
        GUILayout.EndHorizontal();
        NGUIEditorTools.EndContents();

        NGUIEditorTools.DrawHeader("Sectors");
        NGUIEditorTools.BeginContents();
        {
            GUILayout.BeginHorizontal();
            mAngleCount = Mathf.Clamp(EditorGUILayout.IntField("Angle: ", mAngleCount, GUILayout.ExpandWidth(true)), 1, 8);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            mDistanceCount = Mathf.Clamp(EditorGUILayout.IntField("Distance: ", mDistanceCount, GUILayout.ExpandWidth(true)), 1, 8);
            mDistanceStep  = Mathf.Clamp(EditorGUILayout.FloatField("Distance step: ", mDistanceStep, GUILayout.ExpandWidth(true)), 1.0f, 2.0f);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(string.Format("Sector Count: {0}", (mAngleCount + 1) * (mDistanceCount + 1)));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Generate", GUILayout.Height(20f)))
            {
                GameSystem.Instance.shootSolutionManager.Reset();
                for (int idx = 1; idx <= mDistanceCount; idx++)
                {
                    GameSystem.Instance.shootSolutionManager.m_DistanceList.Add(IM.Editor.Tools.Convert(mDistanceStep) * idx);
                }

                float angleStep = 180.0f / (mAngleCount + 1);
                for (int idx = 1; idx <= mAngleCount; idx++)
                {
                    GameSystem.Instance.shootSolutionManager.m_AngleList.Add(IM.Editor.Tools.Convert(angleStep) * idx);
                }

                int iNumSector = (mDistanceCount + 1) * (mAngleCount + 1);
                for (int idx = 0; idx < iNumSector; idx++)
                {
                    ShootSolutionManager.ShootSolutionSector sector = new ShootSolutionManager.ShootSolutionSector(idx);
                    GameSystem.Instance.shootSolutionManager.m_ShootSolutionSectors.Add(sector);
                }

                ShootSimulator.instance.Repaint();
                SceneView.RepaintAll();
            }
            GUILayout.EndHorizontal();
        }
        NGUIEditorTools.EndContents();

        int iSectorCount = GameSystem.Instance.shootSolutionManager.m_ShootSolutionSectors.Count;

        if (iSectorCount == 0)
        {
            return;
        }

        bool delete = false;

        if (Event.current.type == EventType.keyDown && Event.current.keyCode == KeyCode.Escape)
        {
            mCurSelectedSolution = null;
            if (ShootSimulator.instance)
            {
                ShootSimulator.instance.Repaint();
            }
        }

        NGUIEditorTools.DrawHeader("Solutions", true);
        NGUIEditorTools.BeginContents();
        {
            GUILayout.BeginHorizontal();
            string[] strSectors = new string[iSectorCount];
            for (int idx = 0; idx != iSectorCount; idx++)
            {
                strSectors[idx] = idx.ToString();
            }
            mCurSelectSector = EditorGUILayout.Popup("CurrentSector", mCurSelectSector, strSectors);
            GUILayout.EndHorizontal();

            if (mCurSelectSector >= iSectorCount || mCurSelectSector < 0)
            {
                NGUIEditorTools.EndContents();
                return;
            }

            if (ShootSimulator.instance != null && ShootSimulator.instance.m_simulating)
            {
                mCurSelectSector = GameSystem.Instance.shootSolutionManager.CalcSectorIdx(mBasket.m_rim.center, mBall.position);
                Repaint();
            }

            ShootSolutionManager.ShootSolutionSector curSector = GameSystem.Instance.shootSolutionManager.m_ShootSolutionSectors[mCurSelectSector];
            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Add current solution.", GUILayout.Width(240.0f)))
                {
                    if (ShootSimulator.instance != null && ShootSimulator.instance.m_simulating)
                    {
                        ShootSolution solution    = mBall.m_shootSolution.Clone();
                        int           actualIndex = GameSystem.Instance.shootSolutionManager.CalcSectorIdx(mBasket.m_rim.center, mBall.position);
                        ShootSolutionManager.ShootSolutionSector actualSector = GameSystem.Instance.shootSolutionManager.m_ShootSolutionSectors[actualIndex];
                        if (actualSector != curSector)
                        {
                            Debug.LogError("Actual index is not current index. Contact to programmer.");
                        }
                        curSector.AddSolution(solution);
                        mCurSelectedSolution = solution;
                    }
                    else
                    {
                        EditorUtility.DisplayDialog("ShootSolutionEditor", "Make a solution by simulate on UBasketball component at the first.", "ok");
                        GUILayout.EndHorizontal();
                    }
                }
            }
            GUILayout.EndHorizontal();

            NGUIEditorTools.DrawHeader("Success", true);
            GUILayout.BeginHorizontal();
            GUILayout.Space(3f);
            GUILayout.BeginVertical();
            mSuccessScroll = GUILayout.BeginScrollView(mSuccessScroll, GUILayout.Height(250f));

            _ListSolutions(ref curSector.success, true);

            GUILayout.EndScrollView();
            GUILayout.Space(3f);
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            NGUIEditorTools.DrawHeader("Fail", true);
            GUILayout.BeginHorizontal();
            GUILayout.Space(3f);
            GUILayout.BeginVertical();
            mFailScroll = GUILayout.BeginScrollView(mFailScroll, GUILayout.Height(250f));

            _ListSolutions(ref curSector.fail, false);

            GUILayout.EndScrollView();
            GUILayout.Space(3f);
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            if (GUILayout.Button("AutoAddAnimationCurrent", GUILayout.Height(20f)))
            {
                AutoAddAnimation();
            }

            if (GUILayout.Button("AutoAddAnimationTotal", GUILayout.Height(20f)))
            {
                AutoAddAnimationTotal();
            }

            if (GUILayout.Button("ClcAnimationTotal", GUILayout.Height(20f)))
            {
                ClcAnimationTotal();
            }

            Repaint();
        }
        NGUIEditorTools.EndContents();
    }
Exemple #17
0
    bool _Simulating(IM.Vector3 vecInitPos, IM.Vector3 vecInitVel, ShootSolution.AnimationType type, IM.Number reductionIndex, ref ShootSolution solution)
    {
        solution.ClearCurve();

        ShootSolution.SShootCurve shootCurve = new ShootSolution.SShootCurve();
        int  iBoundCount = 0;
        bool bSuccess    = false;

        while (true)
        {
            IM.Vector3 vecFinVel;

            IM.Number fTime_Rim       = IM.Number.zero;
            IM.Number fTime_BackBoard = IM.Number.zero;
            IM.Number fTime_Ground    = IM.Number.zero;

            CalculateShootCurve(ref shootCurve, vecInitPos, vecInitVel);
            if (!_CheckCollision_Rim(shootCurve, ref fTime_Rim) || fTime_Rim < new IM.Number(0, 100))
            {
                fTime_Rim = new IM.Number(10000);
            }
            if (!_CheckCollision_BackBoard(shootCurve, ref fTime_BackBoard) || fTime_BackBoard < new IM.Number(0, 100))
            {
                fTime_BackBoard = new IM.Number(10000);
            }
            if (!_CheckCollision_Ground(shootCurve, ref fTime_Ground))
            {
                fTime_Ground = new IM.Number(10000);
            }

            //collide rim
            if (fTime_Rim < fTime_BackBoard && fTime_Rim < fTime_Ground)
            {
                shootCurve.fTime = fTime_Rim;
                //if (solution.m_animationType != ShootSolution.AnimationType.none)
                //    _DoCollision_Rim(solution.m_vBounceRimAdjustment * reductionIndex, shootCurve, fTime_Rim, ref vecInitPos, ref vecInitVel);
                //else
                _DoCollision_Rim(solution.m_vBounceRimAdjustment, shootCurve, fTime_Rim, ref vecInitPos, ref vecInitVel);

                if (_CheckShootSuccess(shootCurve, ref fTime_Rim))
                {
                    bSuccess = true;
                }

                iBoundCount++;
                solution.AddCurve(shootCurve.fTime, shootCurve.fX_a, shootCurve.fX_b, shootCurve.fX_c,
                                  shootCurve.fY_a, shootCurve.fY_b, shootCurve.fY_c, shootCurve.fZ_a, shootCurve.fZ_b, shootCurve.fZ_c);

                solution.m_vFinPos = vecInitPos;
                solution.m_vFinVel = vecInitVel;
            }
            //collide backboard
            else if (fTime_BackBoard < fTime_Rim && fTime_BackBoard < fTime_Ground)
            {
                shootCurve.fTime = fTime_BackBoard;

                iBoundCount++;
                _DoCollision_BackBoard(solution.m_fBounceBackboard, shootCurve, fTime_BackBoard, ref vecInitPos, ref vecInitVel);

                if (_CheckShootSuccess(shootCurve, ref fTime_BackBoard))
                {
                    bSuccess = true;
                }

                solution.AddCurve(shootCurve.fTime, shootCurve.fX_a, shootCurve.fX_b, shootCurve.fX_c,
                                  shootCurve.fY_a, shootCurve.fY_b, shootCurve.fY_c, shootCurve.fZ_a, shootCurve.fZ_b, shootCurve.fZ_c);

                solution.m_vFinPos = vecInitPos;
                solution.m_vFinVel = vecInitVel;
            }
            else
            {
                shootCurve.fTime = fTime_Ground;
                IM.Number fTime_Goal = IM.Number.zero;
                if (_CheckShootSuccess(shootCurve, ref fTime_Goal))
                {
                    Debug.Log("goal success");

                    bSuccess = true;
                    solution.AddCurve(fTime_Goal, shootCurve.fX_a, shootCurve.fX_b, shootCurve.fX_c,
                                      shootCurve.fY_a, shootCurve.fY_b, shootCurve.fY_c, shootCurve.fZ_a, shootCurve.fZ_b, shootCurve.fZ_c);

                    //goal in rim
                    vecFinVel    = solution.m_vFinVel;
                    vecFinVel.x *= new IM.Number(0, 100);
                    vecFinVel.y *= new IM.Number(0, 200);
                    vecFinVel.z *= new IM.Number(0, 100);

                    solution.m_vFinVel = vecFinVel;
                }
                else
                {
                    bSuccess = false;
                    solution.AddCurve(fTime_Ground, shootCurve.fX_a, shootCurve.fX_b, shootCurve.fX_c,
                                      shootCurve.fY_a, shootCurve.fY_b, shootCurve.fY_c, shootCurve.fZ_a, shootCurve.fZ_b, shootCurve.fZ_c);
                }

                /*
                 * else if(iBoundCount > 0)
                 * {
                 *      bSuccess = false;
                 *
                 *      vecFinVel = solution.m_vFinVel;
                 *      vecFinVel.x *= 0.5f;
                 *      vecFinVel.y *= 1.3f;
                 *      vecFinVel.z *= 0.5f;
                 *
                 *      solution.m_vFinVel = vecFinVel;
                 *      solution.AddCurve(fTime_Ground, shootCurve.fX_a, shootCurve.fX_b, shootCurve.fX_c,
                 *                            shootCurve.fY_a, shootCurve.fY_b, shootCurve.fY_c, shootCurve.fZ_a, shootCurve.fZ_b, shootCurve.fZ_c);
                 * }
                 */

                solution.m_bSuccess = bSuccess;
                break;
            }

            if (iBoundCount > 100)
            {
                Debug.Log("Invalid shoot solution: too many bounds.");
                //solution.ClearCurve();
                return(false);
            }

            if (shootCurve.fTime > new IM.Number(1000))
            {
                return(false);
            }
        }
        return(true);
    }