Beispiel #1
0
        // Start is called before the first frame update
        void Start()
        {
            cc = Camera_Controller.Instance;                   // camera instance
            playerController = Player_Controller_RPG.Instance; // player instance

            if (cc == null)
            {
                Debug.LogError("There is no camera controller in the scene!!");
            }
            else
            {
                playerCam = cc.Cam_Obj.GetComponent <Camera>();
            }
            if (playerCam == null)
            {
                Debug.LogError("There is no camera controller in camera controller!!");
            }

            if (playerController == null)
            {
                Debug.LogError("There is no player controller in scene");
                return;
            }
            // read player controller script attached object
            playerOBJ = playerController.gameObject;
            // looking for ai script
            pathRichAI = playerOBJ.GetComponent <Pathfinding.RichAI>();
            pathAIPath = playerOBJ.GetComponent <Pathfinding.AIPath>();
            pathAILerp = playerOBJ.GetComponent <Pathfinding.AILerp>();
            // disable ai because in rpg mode it will conflict with the control
            aiOn = false;
            if (pathRichAI != null)
            {
                pathRichAI.enabled = false;
            }
            else if (pathAIPath != null)
            {
                pathAIPath.enabled = false;
            }
            else if (pathAILerp != null)
            {
                pathAILerp.enabled = false;
            }

            rightClickInfoType = RC_InfoType.None;
        }
Beispiel #2
0
        protected virtual void Detect_New_pos()
        {
            //	double click judgement
            if (timer > 0)
            {
                timer -= Time.deltaTime;
            }
            else if (timer <= 0 && timerTriger) // insure this function only execute once
            {
                if (rightClickInfoType != RC_InfoType.None)
                {// if there are some ords
                    if (mousRBTiggerTwiceFlag)
                    {
                        isRunning = true;
                    }
                    else
                    {
                        isRunning = false;
                    }
                    if (newOrder != null)
                    {// if there are subscribers
                        var _info = new RightClickInfoToUnits
                        {
                            isRun = isRunning
                            ,
                            type = rightClickInfoType
                            ,
                            newPos = newFloorPos
                            ,
                            newTar = targetOBJ
                        };
                        newOrder(_info);   // sent a event to tell subscriber is a new order
                    }
                }
                timerTriger        = mousRBTiggerOnceFlag = mousRBTiggerTwiceFlag = false; // reset flags
                rightClickInfoType = RC_InfoType.None;
            }
            bool _mRb = Input.GetMouseButton(1);

            //	set a bool vaule and judge left mouse button
            //	only triger one cycle for each time left mouse button has been pusshed down
            //	do this is because sometimes Input.GetMouseButtonUp (0) miss value from mouse button
            if (_mRb & !mousRBTiggerOnceFlag)   // if mouse button been hit
            {
                mousRBTiggerOnce     = true;
                mousRBTiggerOnceFlag = true;
                if (!timerTriger)   // if timer is not ticking
                {
                    timerTriger = true;
                    timer       = 0.3f; // start timer
                }
                else
                {
                    mousRBTiggerTwiceFlag = true;   // double click before timer finish
                }
            }
            else if (!_mRb) // if mouse button has been release
            {
                mousRBTiggerOnceFlag = false;
            }

            //	if right mouse button has been click then give mouse clcik postion to calculate path
            if (mousRBTiggerOnce)
            {
                //Debug.Log("mouseHIt");
                mousRBTiggerOnce = false;
                Vector3    mousHitPos;
                Quaternion roteTo;

                if (RTS_Right_Mouse_Point_Select(_mRb))
                {// if not hit floor
                    rightClickInfoType = RC_InfoType.enemyTar;
                    //Debug.Log("---objHit");
                }
                else if (Public_Functions.Mous_Click_Get_Pos_Dir(Camera.main, transform, LayerMask.GetMask(RightClickOrderLayerName), out mousHitPos, out roteTo))
                {// if hit floor
                    newFloorPos        = mousHitPos;
                    rightClickInfoType = RC_InfoType.pos;
                    //Debug.Log("--------------------floorHit");
                }
                else
                {
                    //Debug.Log("------------------------------------hitnothing");
                }
            }
        }