Example #1
0
    void Update()
    {
        bool b0Down = Input.GetMouseButtonDown(0);
        bool b0Up   = Input.GetMouseButtonUp(0);

        bool inActiveArea = (float)Input.mousePosition.x / Screen.width < activeScreenWidth;

        if (mPhase == MPhase.idle)
        {
            if (b0Down && inActiveArea)
            {
                mouseInfos.Clear();
                AddMouseInfo();

                if (mouseInfos[0].hit)
                {
                    MouseDown();
                    mPhase = MPhase.down;
                }
            }
        }
        if (mPhase == MPhase.down)
        {
            AddMouseInfo();
            if (b0Up)
            {
                MouseTap();
                mPhase = MPhase.idle;
            }
            else if (Time.time - mouseInfos[0].time > mTapTime)
            {
                float dragDist = (lastMouseInfo.screenLoc -
                                  mouseInfos[0].screenLoc).magnitude;
                if (dragDist >= mDragDist)
                {
                    mPhase = MPhase.drag;
                }

                if (selectedElements.Count == 0)
                {
                    mPhase = MPhase.drag;
                }
            }
        }
        if (mPhase == MPhase.drag)
        {
            AddMouseInfo();
            if (b0Up)
            {
                MouseDragUp();
                mPhase = MPhase.idle;
            }
            else
            {
                MouseDrag();
            }
        }
        OrbitSelectedElements();
    }
Example #2
0
	void Awake(){
		S = this;
		mPhase = MPhase.idle;
		characterTrans = transform.Find("CharacterTrans");
		viewCharacterTrans = characterTrans.Find("View_Character");
		liner = GetComponent<LineRenderer>();
		liner.enabled = false; 

		GameObject saGO = new GameObject("Spell Anchor"); 
		spellAnchor = saGO.transform; 
	}//end of Awake()
Example #3
0
    private void Awake()
    {
        S      = this;
        mPhase = MPhase.idle;

        //find the characterTrans to rotate with Fade()
        characterTrans     = transform.Find("CharacterTrans");
        viewCharacterTrans = characterTrans.Find("View_Character");

        liner         = GetComponent <LineRenderer>();
        liner.enabled = false;

        GameObject saGO = new GameObject("Spell Anchor");

        spellAnchor = saGO.transform;
    }
Example #4
0
    void Awake()
    {
        S      = this;    // Set the Mage Singleton
        mPhase = MPhase.idle;
        // Find the characterTrans to rotate with Face()
        characterTrans     = transform.Find("CharacterTrans");
        viewCharacterTrans = characterTrans.Find("View_Character");
        // Get the LineRenderer component and disable it //**
        liner         = GetComponent <LineRenderer>(); //**
        liner.enabled = false;

        GameObject saGO = new GameObject("Spell Anchor");

        // ^ Create an empty GameObject named "Spell Anchor". When you create a
        // new GameObject this way, it's at P:[0,0,0] R:[0,0,0] S:[1,1,1]
        spellAnchor = saGO.transform;         // Get its transform
    }
Example #5
0
    private void Awake()
    {
        S      = this; // Задаём синглтон как грица
        mPhase = MPhase.idle;

        // Находим characterTrans, чтобы поворачивать с помощью Face()
        characterTrans     = transform.Find("CharacterTrans");
        viewCharacterTrans = characterTrans.Find("View_Character");

        // Получаем компонент LineRenderer
        liner         = GetComponent <LineRenderer>();
        liner.enabled = false;

        GameObject saGO = new GameObject("SpellAnchor");

        // ^ когда создаём новый ио, он становится в позицию 000 000 111
        spellAnchor = saGO.transform;
    }
Example #6
0
        /// <summary>
        /// Calculate the approximate mean time of various phases of the moon.
        /// This will give the approximate time that the specified phase
        /// will occur near the given date.   This is only accurate to within
        /// some number of hours.
        /// </summary>
        /// <param name="k"></param>
        /// <returns></returns>
        public static DateTime MeanPhase(DateTime startDate, MPhase phase)
        {
            double ph = 0.0;

            if (phase == MPhase.FirstQuater)
            {
                ph = 0.25;
            }
            else if (phase == MPhase.Full)
            {
                ph = 0.50;
            }
            else if (phase == MPhase.LastQuater)
            {
                ph = 0.75;
            }

            TimeSpan tp = startDate - NEW_MOON_TIME;

            double k = tp.TotalDays / MOON_PERIOD;

            double kint = Math.Floor(k);
            double kfra = k - kint;

            if (kfra > ph)
            {
                k = kint + 1 + ph; //we already pass that phase, look for the next one
            }
            else
            {
                k = kint + ph;
            }

            double T  = k / 1236.85;
            double T2 = T * T;
            double T3 = T2 * T;
            double T4 = T3 * T;

            double dayPass = MOON_PERIOD * k + 0.00015437 * T2 - 0.000000150 * T3 + 0.00000000073 * T4;

            //return DateTimeUtil.JulianToDateTime(dayPass);

            return(NEW_MOON_TIME.AddDays(dayPass));
        }
Example #7
0
    private void Awake()
    {
        S      = this;
        mPhase = MPhase.idle;

        //查询characterTrans以轮转Face()
        characterTrans = transform.Find("CharacterTrans");

        //获取LineRenderer组件并禁用
        liner         = GetComponent <LineRenderer>();
        liner.enabled = false;

        //创建空游戏对象命名为 Spell Anchor
        GameObject saGo = new GameObject("Spell Anchor");

        spellAnchor = saGo.GetComponent <Transform>();

        viewCharacterTrans = characterTrans.Find("View_Character");
    }
Example #8
0
 // Stop any active drag or other mouse input
 public void ClearInput()
 {
     mPhase = MPhase.idle;
 }
Example #9
0
    void Update()
    {
        //Find whether the mouse button - was pressed or released this frame
        bool b0Down = Input.GetMouseButtonDown(0);
        bool b0Up   = Input.GetMouseButtonUp(0);

        //Handle all input here except for inventory buttons

        /*
         * There are only a few possible actions
         * 1. tap on ground to move to that point
         * 2. Drag on ground with no spell selected to move the Mage
         * 3. Drag on ground with spell to cast along ground
         * 4. Tap on an enemy to atk (or force-push away without an element)
         */

        //An example of using <to return a bool value
        bool inActiveArea = (float)Input.mousePosition.x / Screen.width < activeScreenWidth;

        //This is handled as an if statement instead of siwtch beacsue a tap
        //can sometimes happen within a single frame
        if (mPhase == MPhase.idle)           //if the mouse is idle
        {
            if (b0Down && inActiveArea)
            {
                mouseInfos.Clear();             //clear the mouseinfos
                AddMouseInfo();                 //And add a first MouseInfo

                //IF the mouse was clicked on stomething, its a valid mousedown
                if (mouseInfos[0].hit)               //Something was hit!
                {
                    MouseDown();                     //Call MouseDown()
                    mPhase = MPhase.down;            //and set the phase
                }
            }
        }

        if (mPhase == MPhase.down)  //if the mouse is down
        {
            AddMouseInfo();         //Add a mouseinfo for this frame
            if (b0Up)               //The mouse button was released
            {
                MouseTap();         //this was a tap
                mPhase = MPhase.idle;
            }
            else if (Time.time - mouseInfos[0].time > mTapTime)
            {
                //If its been down longer than a tap, this may be a drag but
                //to be a drag, it must also have moved a certain number of pixels on screen
                float dragDist = (lastMouseInfo.screenLoc - mouseInfos[0].screenLoc).magnitude;
                if (dragDist >= mDragDist)
                {
                    mPhase = MPhase.drag;
                }

                //However, drag will immediately start after mTapTime if there are no elements selected
                if (selectedElements.Count == 0)
                {
                    mPhase = MPhase.drag;
                }
            }
        }
        if (mPhase == MPhase.drag)          //if the mouse is being dragged
        {
            AddMouseInfo();
            if (b0Up)
            {
                //The mouse button was released
                MouseDragUp();
                mPhase = MPhase.idle;
            }
            else
            {
                MouseDrag();                 //stil dragging
            }
        }

        OrbitSelectedElements();
    }
Example #10
0
    private void Update()
    {
        bool b0Down = Input.GetMouseButtonDown(0);
        bool b0Up   = Input.GetMouseButtonUp(0);

        /* 动作类型:
         * 1.单击地面的指定点
         * 2.没用法术时从地面拖动到法师处
         * 3.用法术时沿着地面拖动
         * 4.在敌人面前单击做攻击操作
         */

        bool inActiveArea = (float)Input.mousePosition.x / Screen.width < activeScreenWidth;

        //因为单击有时会发生在单结构中,故用if语句
        //如果鼠标轮为空
        if (mPhase == MPhase.idle)
        {
            if (b0Down && inActiveArea)
            {
                mouseInfos.Clear();     //清空mouseInfo
                AddmouseInfo();         //添加第一个MouseInfo

                //如果有东西被点中
                if (mouseInfos[0].hit)
                {
                    //Debug.Log("有物体被鼠标点中");
                    MouseDown();
                    mPhase = MPhase.down;
                }
            }
        }

        //如果鼠标左键按下
        if (mPhase == MPhase.down)
        {
            //Debug.Log("执行mPhase=" + mPhase + "分支");
            AddmouseInfo();             //添加该结构的MouseInfo

            //如果左键释放
            if (b0Up)
            {
                MouseTap();             //单击动作
                mPhase = MPhase.idle;
            }
            else if (Time.time - mouseInfos[0].time > mTapTime)
            {
                //如果按下长度超过单击的长度,则为拖动
                float dragDist = (lastMouseInfo.screenLoc - mouseInfos[0].screenLoc).magnitude;

                if (dragDist >= mDragDist)
                {
                    mPhase = MPhase.drag;
                }

                //^^^易错处:若代码放在if(mPhase == MPhase.down)下则会将鼠标点击状态改变为拖动状态,造成无法单击移动只可拖动的问题
                //如果道具没有被选中,则mTapTime一旦结束拖动就开始
                if (selectedElements.Count == 0)
                {
                    mPhase = MPhase.drag;
                }
            }
        }

        //如果鼠标被拖动
        if (mPhase == MPhase.drag)
        {
            //Debug.Log("执行mPhase=" + mPhase + "分支");
            AddmouseInfo();

            //鼠标左键释放
            if (b0Up)
            {
                MouseDragUp();
                mPhase = MPhase.idle;
            }
            else
            {
                MouseDrag();    //仍然处于拖动状态
            }
        }
        OrbitSelectedElements();

        //实时更新UI
        healthUI.fillAmount = (float)health / (float)healthMax;
    }
Example #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="startDate">Start Date</param>
        /// <param name="phase">0, 1/3, 1/2 or 3/4</param>
        /// <returns></returns>
        public static DateTime TruePhase(DateTime startDate, MPhase phase)
        {
            //What will be the return value
            double JD = DateTimeUtil.DateTimeToJulian(MeanPhase(startDate, phase));

            double ph = 0.0;

            if (phase == MPhase.FirstQuater)
            {
                ph = 0.25;
            }
            else if (phase == MPhase.Full)
            {
                ph = 0.50;
            }
            else if (phase == MPhase.LastQuater)
            {
                ph = 0.75;
            }
            TimeSpan tp = startDate - NEW_MOON_TIME;
            double   k  = tp.TotalDays / MOON_PERIOD;

            double kint = Math.Floor(k);
            double kfra = k - kint;

            if (kfra > ph)
            {
                k = kint + 1 + ph; //we already pass that phase, look for the next one
            }
            else
            {
                k = kint + ph;
            }

            //convert from K to T
            double T  = k / 1236.85;
            double T2 = T * T;
            double T3 = T2 * T;
            double T4 = T3 * T;

            double E  = 1 - 0.002516 * T - 0.0000074 * T2;
            double E2 = E * E;

            double M = CoordinateTransformation.MapTo0To360Range(2.5534 + 29.10535670 * k - 0.0000014 * T2 - 0.00000011 * T3);

            M = CoordinateTransformation.DegreesToRadians(M);
            double Mdash = CoordinateTransformation.MapTo0To360Range(201.5643 + 385.81693528 * k + 0.0107582 * T2 + 0.00001238 * T3 - 0.000000058 * T4);

            Mdash = CoordinateTransformation.DegreesToRadians(Mdash);
            double F = CoordinateTransformation.MapTo0To360Range(160.7108 + 390.67050284 * k - 0.0016118 * T2 - 0.00000227 * T3 + 0.00000001 * T4);

            F = CoordinateTransformation.DegreesToRadians(F);
            double omega = CoordinateTransformation.MapTo0To360Range(124.7746 - 1.56375588 * k + 0.0020672 * T2 + 0.00000215 * T3);

            omega = CoordinateTransformation.DegreesToRadians(omega);
            double A1 = CoordinateTransformation.MapTo0To360Range(299.77 + 0.107408 * k - 0.009173 * T2);

            A1 = CoordinateTransformation.DegreesToRadians(A1);
            double A2 = CoordinateTransformation.MapTo0To360Range(251.88 + 0.016321 * k);

            A2 = CoordinateTransformation.DegreesToRadians(A2);
            double A3 = CoordinateTransformation.MapTo0To360Range(251.83 + 26.651886 * k);

            A3 = CoordinateTransformation.DegreesToRadians(A3);
            double A4 = CoordinateTransformation.MapTo0To360Range(349.42 + 36.412478 * k);

            A4 = CoordinateTransformation.DegreesToRadians(A4);
            double A5 = CoordinateTransformation.MapTo0To360Range(84.66 + 18.206239 * k);

            A5 = CoordinateTransformation.DegreesToRadians(A5);
            double A6 = CoordinateTransformation.MapTo0To360Range(141.74 + 53.303771 * k);

            A6 = CoordinateTransformation.DegreesToRadians(A6);
            double A7 = CoordinateTransformation.MapTo0To360Range(207.14 + 2.453732 * k);

            A7 = CoordinateTransformation.DegreesToRadians(A7);
            double A8 = CoordinateTransformation.MapTo0To360Range(154.84 + 7.306860 * k);

            A8 = CoordinateTransformation.DegreesToRadians(A8);
            double A9 = CoordinateTransformation.MapTo0To360Range(34.52 + 27.261239 * k);

            A9 = CoordinateTransformation.DegreesToRadians(A9);
            double A10 = CoordinateTransformation.MapTo0To360Range(207.19 + 0.121824 * k);

            A10 = CoordinateTransformation.DegreesToRadians(A10);
            double A11 = CoordinateTransformation.MapTo0To360Range(291.34 + 1.844379 * k);

            A11 = CoordinateTransformation.DegreesToRadians(A11);
            double A12 = CoordinateTransformation.MapTo0To360Range(161.72 + 24.198154 * k);

            A12 = CoordinateTransformation.DegreesToRadians(A12);
            double A13 = CoordinateTransformation.MapTo0To360Range(239.56 + 25.513099 * k);

            A13 = CoordinateTransformation.DegreesToRadians(A13);
            double A14 = CoordinateTransformation.MapTo0To360Range(331.55 + 3.592518 * k);

            A14 = CoordinateTransformation.DegreesToRadians(A14);

            //convert to radians
            if (phase == MPhase.New) //New Moon
            {
                double DeltaJD = -0.40720 * Math.Sin(Mdash) +
                                 0.17241 * E * Math.Sin(M) +
                                 0.01608 * Math.Sin(2 * Mdash) +
                                 0.01039 * Math.Sin(2 * F) +
                                 0.00739 * E * Math.Sin(Mdash - M) +
                                 -0.00514 * E * Math.Sin(Mdash + M) +
                                 0.00208 * E2 * Math.Sin(2 * M) +
                                 -0.00111 * Math.Sin(Mdash - 2 * F) +
                                 -0.00057 * Math.Sin(Mdash + 2 * F) +
                                 0.00056 * E * Math.Sin(2 * Mdash + M) +
                                 -0.00042 * Math.Sin(3 * Mdash) +
                                 0.00042 * E * Math.Sin(M + 2 * F) +
                                 0.00038 * E * Math.Sin(M - 2 * F) +
                                 -0.00024 * E * Math.Sin(2 * Mdash - M) +
                                 -0.00017 * Math.Sin(omega) +
                                 -0.00007 * Math.Sin(Mdash + 2 * M) +
                                 0.00004 * Math.Sin(2 * Mdash - 2 * F) +
                                 0.00004 * Math.Sin(3 * M) +
                                 0.00003 * Math.Sin(Mdash + M - 2 * F) +
                                 0.00003 * Math.Sin(2 * Mdash + 2 * F) +
                                 -0.00003 * Math.Sin(Mdash + M + 2 * F) +
                                 0.00003 * Math.Sin(Mdash - M + 2 * F) +
                                 -0.00002 * Math.Sin(Mdash - M - 2 * F) +
                                 -0.00002 * Math.Sin(3 * Mdash + M) +
                                 0.00002 * Math.Sin(4 * Mdash);
                JD += DeltaJD;
            }
            else if ((phase == MPhase.FirstQuater) || (phase == MPhase.LastQuater)) //First Quarter or Last Quarter
            {
                double DeltaJD = -0.62801 * Math.Sin(Mdash) +
                                 0.17172 * E * Math.Sin(M) +
                                 -0.01183 * E * Math.Sin(Mdash + M) +
                                 0.00862 * Math.Sin(2 * Mdash) +
                                 0.00804 * Math.Sin(2 * F) +
                                 0.00454 * E * Math.Sin(Mdash - M) +
                                 0.00204 * E2 * Math.Sin(2 * M) +
                                 -0.00180 * Math.Sin(Mdash - 2 * F) +
                                 -0.00070 * Math.Sin(Mdash + 2 * F) +
                                 -0.00040 * Math.Sin(3 * Mdash) +
                                 -0.00034 * E * Math.Sin(2 * Mdash - M) +
                                 0.00032 * E * Math.Sin(M + 2 * F) +
                                 0.00032 * E * Math.Sin(M - 2 * F) +
                                 -0.00028 * E2 * Math.Sin(Mdash + 2 * M) +
                                 0.00027 * E * Math.Sin(2 * Mdash + M) +
                                 -0.00017 * Math.Sin(omega) +
                                 -0.00005 * Math.Sin(Mdash - M - 2 * F) +
                                 0.00004 * Math.Sin(2 * Mdash + 2 * F) +
                                 -0.00004 * Math.Sin(Mdash + M + 2 * F) +
                                 0.00004 * Math.Sin(Mdash - 2 * M) +
                                 0.00003 * Math.Sin(Mdash + M - 2 * F) +
                                 0.00003 * Math.Sin(3 * M) +
                                 0.00002 * Math.Sin(2 * Mdash - 2 * F) +
                                 0.00002 * Math.Sin(Mdash - M + 2 * F) +
                                 -0.00002 * Math.Sin(3 * Mdash + M);
                JD += DeltaJD;

                double W = 0.00306 - 0.00038 * E * Math.Cos(M) + 0.00026 * Math.Cos(Mdash) - 0.00002 * Math.Cos(Mdash - M) + 0.00002 * Math.Cos(Mdash + M) + 0.00002 * Math.Cos(2 * F);
                if (phase == MPhase.FirstQuater) //First quarter
                {
                    JD += W;
                }
                else
                {
                    JD -= W;
                }
            }
            else if (phase == MPhase.Full) //Full Moon
            {
                double DeltaJD = -0.40614 * Math.Sin(Mdash) +
                                 0.17302 * E * Math.Sin(M) +
                                 0.01614 * Math.Sin(2 * Mdash) +
                                 0.01043 * Math.Sin(2 * F) +
                                 0.00734 * E * Math.Sin(Mdash - M) +
                                 -0.00514 * E * Math.Sin(Mdash + M) +
                                 0.00209 * E2 * Math.Sin(2 * M) +
                                 -0.00111 * Math.Sin(Mdash - 2 * F) +
                                 -0.00057 * Math.Sin(Mdash + 2 * F) +
                                 0.00056 * E * Math.Sin(2 * Mdash + M) +
                                 -0.00042 * Math.Sin(3 * Mdash) +
                                 0.00042 * E * Math.Sin(M + 2 * F) +
                                 0.00038 * E * Math.Sin(M - 2 * F) +
                                 -0.00024 * E * Math.Sin(2 * Mdash - M) +
                                 -0.00017 * Math.Sin(omega) +
                                 -0.00007 * Math.Sin(Mdash + 2 * M) +
                                 0.00004 * Math.Sin(2 * Mdash - 2 * F) +
                                 0.00004 * Math.Sin(3 * M) +
                                 0.00003 * Math.Sin(Mdash + M - 2 * F) +
                                 0.00003 * Math.Sin(2 * Mdash + 2 * F) +
                                 -0.00003 * Math.Sin(Mdash + M + 2 * F) +
                                 0.00003 * Math.Sin(Mdash - M + 2 * F) +
                                 -0.00002 * Math.Sin(Mdash - M - 2 * F) +
                                 -0.00002 * Math.Sin(3 * Mdash + M) +
                                 0.00002 * Math.Sin(4 * Mdash);
                JD += DeltaJD;
            }


            //Additional corrections for all phases
            double DeltaJD2 = 0.000325 * Math.Sin(A1) +
                              0.000165 * Math.Sin(A2) +
                              0.000164 * Math.Sin(A3) +
                              0.000126 * Math.Sin(A4) +
                              0.000110 * Math.Sin(A5) +
                              0.000062 * Math.Sin(A6) +
                              0.000060 * Math.Sin(A7) +
                              0.000056 * Math.Sin(A8) +
                              0.000047 * Math.Sin(A9) +
                              0.000042 * Math.Sin(A10) +
                              0.000040 * Math.Sin(A11) +
                              0.000037 * Math.Sin(A12) +
                              0.000035 * Math.Sin(A13) +
                              0.000023 * Math.Sin(A14);

            JD += DeltaJD2;

            return(DateTimeUtil.JulianToDateTime(JD));
        }
Example #12
0
	void Awake()
	{
		S = this; // Set the Mage Singleton
		mPhase = MPhase.idle;
		// Find the characterTrans to rotate with Face()
		characterTrans = transform.Find("CharacterTrans");
		viewCharacterTrans = characterTrans.Find("View_Character");
		// Get the LineRenderer component and disable it //**
		liner = GetComponent<LineRenderer>(); //**
		liner.enabled = false; 

		GameObject saGO = new GameObject("Spell Anchor"); 
		// ^ Create an empty GameObject named "Spell Anchor". When you create a
		// new GameObject this way, it's at P:[0,0,0] R:[0,0,0] S:[1,1,1]
		spellAnchor = saGO.transform; // Get its transform 

	}
Example #13
0
	// Stop any active drag or other mouse input
	public void ClearInput()
	{
		mPhase = MPhase.idle;
	}
Example #14
0
	void Update()
	{
		// Find whether the mouse button 0 was pressed or released this frame
		bool b0Down = Input.GetMouseButtonDown(0);
		bool b0Up = Input.GetMouseButtonUp(0);
		// An example of using < to return a bool value
		bool inActiveArea = (float)Input.mousePosition.x / Screen.width < activeScreenWidth;
		// This is handled as an if statement instead of switch because a tap
		// can sometimes happen within a single frame
		if (mPhase == MPhase.idle)
		{ // If the mouse is idle
			if (b0Down && inActiveArea)
			{
				mouseInfos.Clear(); // Clear the mouseInfos
				AddMouseInfo(); // And add a first MouseInfo
								// If the mouse was clicked on something, it's a valid MouseDown
				if (mouseInfos[0].hit)
				{ // Something was hit!
					MouseDown(); // Call MouseDown()
					mPhase = MPhase.down; // and set the mPhase
				}
			}
		}
		if (mPhase == MPhase.down)
		{ // if the mouse is down
			AddMouseInfo(); // Add a MouseInfo for this frame
			if (b0Up)
			{ // The mouse button was released
				MouseTap(); // This was a tap
				mPhase = MPhase.idle;
			}
			else if (Time.time - mouseInfos[0].time > mTapTime)
			{
				// If it's been down longer than a tap, this may be a drag, but
				// to be a drag, it must also have moved a certain number of
				// pixels on screen.
				float dragDist = (lastMouseInfo.screenLoc -
				mouseInfos[0].screenLoc).magnitude;
				if (dragDist >= mDragDist)
				{
					mPhase = MPhase.drag;
				}
				// However, drag will immediately start after mTapTime if there
				// are no elements selected.
				if (selectedElements.Count == 0)
				{ 
					mPhase = MPhase.drag; 
				}
			}
		}
		if (mPhase == MPhase.drag)
		{ // if the mouse is being drug
			AddMouseInfo();
			if (b0Up)
			{
				// The mouse button was released
				MouseDragUp();
				mPhase = MPhase.idle;
			}
			else
			{
				MouseDrag(); // Still dragging
			}
		}
		OrbitSelectedElements();
	}
Example #15
0
    void Update()
    {
        // Find whether the mouse button 0 was pressed or released this frame
        bool b0Down = Input.GetMouseButtonDown(0);
        bool b0Up   = Input.GetMouseButtonUp(0);
        // An example of using < to return a bool value
        bool inActiveArea = (float)Input.mousePosition.x / Screen.width < activeScreenWidth;

        // This is handled as an if statement instead of switch because a tap
        // can sometimes happen within a single frame
        if (mPhase == MPhase.idle)
        {         // If the mouse is idle
            if (b0Down && inActiveArea)
            {
                mouseInfos.Clear();             // Clear the mouseInfos
                AddMouseInfo();                 // And add a first MouseInfo
                // If the mouse was clicked on something, it's a valid MouseDown
                if (mouseInfos[0].hit)
                {                         // Something was hit!
                    MouseDown();          // Call MouseDown()
                    mPhase = MPhase.down; // and set the mPhase
                }
            }
        }
        if (mPhase == MPhase.down)
        {                   // if the mouse is down
            AddMouseInfo(); // Add a MouseInfo for this frame
            if (b0Up)
            {               // The mouse button was released
                MouseTap(); // This was a tap
                mPhase = MPhase.idle;
            }
            else if (Time.time - mouseInfos[0].time > mTapTime)
            {
                // If it's been down longer than a tap, this may be a drag, but
                // to be a drag, it must also have moved a certain number of
                // pixels on screen.
                float dragDist = (lastMouseInfo.screenLoc -
                                  mouseInfos[0].screenLoc).magnitude;
                if (dragDist >= mDragDist)
                {
                    mPhase = MPhase.drag;
                }
                // However, drag will immediately start after mTapTime if there
                // are no elements selected.
                if (selectedElements.Count == 0)
                {
                    mPhase = MPhase.drag;
                }
            }
        }
        if (mPhase == MPhase.drag)
        {         // if the mouse is being drug
            AddMouseInfo();
            if (b0Up)
            {
                // The mouse button was released
                MouseDragUp();
                mPhase = MPhase.idle;
            }
            else
            {
                MouseDrag();                 // Still dragging
            }
        }
        OrbitSelectedElements();
    }
Example #16
0
    void Update()
    {
        // Узнаём была ли нажата или отпущена левая кнопка в этот кадр
        bool b0Down = Input.GetMouseButton(0);
        bool b0Up   = Input.GetMouseButtonUp(0);

        // Обрабатываем здесь ввод ( кроме инвентаря )

        /*
         * Здесь только несколько возможных действий
         * 1. Нажимать на экран чтобы перемещаться в эту точку
         * 2. Перемещаем землю с невыбранной способностью чтобы перемещать мага
         * 3. Растягиваем по земле с выбранной способностью что скастовать её
         * 4. Жмём на врага чтобы атаковать
         */

        // Пример использования < чтобы вернуть булевое значение
        bool inActiveArea = (float)Input.mousePosition.x / Screen.width < activeScreenWidth;

        // Обрабатывается с if условием вместо switch, потому что нажатие иногда может происходить в 1 кадр
        if (mPhase == MPhase.idle)   // Если мышка покоится
        {
            if (b0Down && inActiveArea)
            {
                mouseInfos.Clear(); // Очищаем список MouseInfo
                AddMouseInfo();     // Добавляем первое MouseInfo

                // Если мышка указывала на что-то, это подходящее нажатие
                if (mouseInfos[0].hit)    // Что то нажалось
                {
                    MouseDown();          // Вызываем MouseDown()
                    mPhase = MPhase.down; // Задаём фазу
                }
            }
        }


        if (mPhase == MPhase.down) // Если мышка опущена
        {
            AddMouseInfo();        // Добавляем MouseInfo за этот кадр
            if (b0Up)              // Если мышка была отпущена
            {
                MouseTap();        // Это было нажатие
                mPhase = MPhase.idle;
            }
            else if (Time.time - mouseInfos[0].time > mTapTime)
            {
                // Длилось дольше чем просто нажатие, так что это должно быть перемещение
                // Но для перемещения также должно быть пройденно определённое кол-во пикселей
                float dragDist = (lastMouseInfo.screenLoc - mouseInfos[0].screenLoc).magnitude;
                if (dragDist >= mDragDist)
                {
                    mPhase = MPhase.drag;
                }

                // Драг будет сразу начинается после прошедшего времени если нет выбранных элементов
                if (selectedElements.Count == 0)
                {
                    mPhase = MPhase.drag;
                }
            }
        }

        if (mPhase == MPhase.drag)   // Мыш (кродётся)
        {
            AddMouseInfo();
            if (b0Up)
            {
                // Мышь была отпущенна
                MouseDragUp();
                mPhase = MPhase.idle;
            }
            else
            {
                MouseDrag();    // Всё ещё перетаскиваем
            }
        }

        OrbitSelectedElements();
    }
Example #17
0
	void Update()
	{
		//Find wether the mouse button 0 was pressed or released this frame
		bool b0Down = Input.GetMouseButtonDown (0);
		bool b0Up = Input.GetMouseButtonUp (0);

		//Handle all input here (except for Inventory buttons)
		/*
		There are only a few possiable actions:
		1.  Tap on the ground to move to that point
		2.  Drag on the ground with no spell selected to move to the mage
		3.  Drag on the ground with spell to cast along the ground
		4.  Tap on an enemy to attack (or force-ush away without an element)
		*/

		//An example of using < to return a bool value
		bool inActiveArea = (float)Input.mousePosition.x / Screen.width < activeScreenWidth;

		//This is handled as an if statement instead of switch because a tsap can sometimes happen within a single frame
		if (mPhase == MPhase.idle) //If the mosue is idle
		{
			if (b0Down && inActiveArea)
			{
				mouseInfos.Clear();  //Clear the mouseInfos
				AddMouseInfo();  //And add a first MouseInfo

				//If the mouse was clicked on something, it's a valid MouseDown
				if (mouseInfos[0].hit)  //Something was hit!
				{
					MouseDown();  //Call MouseDown()
					mPhase = MPhase.down;  //and set the mPhase
				}
			}
		}

		if (mPhase == MPhase.down)  //if the mouse is down
		{
			AddMouseInfo();  //Add a MouseInfo for this frame
			if (b0Up)
			{
				MouseTap();  //This was a tap
				mPhase = MPhase.idle;
			} else if (Time.time - mouseInfos[0].time > mTapTime) {
				//If it's been down for longer than a tap, this may be a drag, but
				//to be a drag, it must also have moved a certtian number of
				//pixls on screen.
				float dragDist = (lastMouseInfo.screenLoc - mouseInfos[0].screenLoc).magnitude;
				if (dragDist >= mDragDist)
				{
					mPhase = MPhase.drag;
				}

				// However, drag will immediately start after mTapTime if there
				// are no elements selected.
				if (selectedElements.Count == 0) {
					mPhase = MPhase.drag;
				}
	
			}
		} // end if (mPhase == MPhase.down)

		if (mPhase == MPhase.drag)  //if the mouse is being drug
		{
			AddMouseInfo();
			if (b0Up)
			{
				//The mouse button was released
				MouseDragUp();
				mPhase = MPhase.idle;
			} else {
				MouseDrag();  //Still dragging
			}
		}

		OrbitSelectedElements();
	}
Example #18
0
 void Awake()
 {
     S              = this;
     mPhase         = MPhase.idle;
     characterTrans = transform.Find("CharacterTrans");
 }
Example #19
0
    private void Update()
    {
        //Find whether the mouse button 0 was pressed or released this frame
        bool b0Down = Input.GetMouseButtonDown(0);
        bool b0Up   = Input.GetMouseButtonUp(0);

        // Handle all input here (except for inventory buttons)

        /*There are only a few possible actions;
         * 1. Tap on the ground to move to that point
         * 2. Drag on the ground with no spell selected to move to the Mage
         * 3. Drag on the ground with spell to cast along the ground
         * 4. Tap on an enemy to attack (or force-push away without an element
         * */

        //An example of using < to return a bool value

        bool inActiveArea = (float)Input.mousePosition.x / Screen.width < activeScreenWidth;

        // This is handled as an if statement instead of switch because a tap
        // can sometimes happen within a single frame
        if (mPhase == MPhase.idle)
        {
            if (b0Down && inActiveArea)
            {
                mouseInfos.Clear();
                AddMouseInfo();

                if (mouseInfos[0].hit)
                {
                    MouseDown();
                    mPhase = MPhase.down;
                }
            }
        }
        if (mPhase == MPhase.down)
        {
            AddMouseInfo();
            if (b0Up)
            {
                MouseTap();
                mPhase = MPhase.idle;
            }
            else if (Time.time - mouseInfos[0].time > mTapTime)
            {
                //If its been down longer than a tap, this may be a drag,
                // but to be a drag, It must also have moved a certain number of pixels on the screen
                float dragDist = (lastMouseInfo.screenLoc - mouseInfos[0].screenLoc).magnitude;
                if (dragDist >= mDragDist)
                {
                    mPhase = MPhase.drag;
                }

                //However, drag will immediatelt start after mTapTaime if there are no elements selected
                if (selectedElements.Count == 0)
                {
                    mPhase = MPhase.drag;
                }
            }
        }
        if (mPhase == MPhase.drag)
        {
            AddMouseInfo();
            if (b0Up)
            {
                MouseDragUp();
                mPhase = MPhase.idle;
            }
            else
            {
                MouseDrag();
            }
        }

        OrbitSelectedElements();
    }