コード例 #1
0
    /**
     *<summary>
     * Mouse Picks from screen point to world space.
     * Returns true if the ray crosses a collider with an <see cref="IObjectControl"/> componenet.
     * Otherwise returns false
     *</summary>
     */
    bool mousePick()
    {
        //Initialize the variables
        //Reset picked this frame to null, will be assigned if raycast is successful
        pickedThisFrame = null;
        RaycastHit hitObject;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        //Cast the ray (No masks)
        Physics.Raycast(ray, out hitObject, 15);

        //Return false if ray didn't hit anything with a collider
        if (hitObject.transform == null)
        {
            return(false);
        }

        //Get the IObjectControl component on the hit object
        //Method will return false if pickedThisFrame == null
        pickedThisFrame = hitObject.transform.gameObject.GetComponent <IObjectControl>();

        if (pickedThisFrame == null)
        {
            Debug.LogError("MousePicker did not pick an object with an IObjectControl Component");
        }

        //Returns true if the object hit has an IObjectControl, else returns false
        return(pickedThisFrame != null);
    }
コード例 #2
0
    /**
     *<summary>
     * Runs a mouse pick and stores the picked gameObject in <see cref="pickedThisFrame"/>
     * if the stored object is null, returns false
     * if the stored object doesn't have a componenet with an IObjectControl, returns false
     * If the gameObject is not null, and has an IObjectControl component, return true
     *</summary>
     */
    public bool mousePick()
    {
        //Initialize the variables
        pickedThisFrame = null;
        RaycastHit hitObject;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        //Cast the ray with max distance and layermask
        //Physics.Raycast(ray.origin, ray.direction, out hitObject, 1000f, layerMask);

        //Cast the ray (with less parameters)
        Physics.Raycast(ray, out hitObject);

        //If nothing is hit, return false
        if (hitObject.transform == null)
        {
            pickedThisFrame = null;
            return(false);
        }

        //Get the objectControl componenet on the hit object
        pickedThisFrame = hitObject.transform.gameObject.GetComponent <IObjectControl>();
        if (pickedThisFrame == null)
        {
            //Debug.LogError("MousePicker did not pick an object with an IObjectControl Component");
        }

        //Return true if object has an objectControl, else return false
        return(pickedThisFrame != null);
    }
コード例 #3
0
 /**
  *<summary>
  * Calls <see cref="IObjectControl.PriamryMouseUp"/> if this is the first frame the mouse button
  * was released and if ignoreMouseUp is false
  *</summary>
  */
 void callMouseUp()
 {
     if (Input.GetMouseButtonUp(0))
     {
         //IgnoreMouseUp is true when
         //--while the mouse is held down--
         //clickedObject != pickedObject
         if (ignoreMouseUp)
         {
             ignoreMouseUp = false;
         }
         else
         {
             if (clickedObject != null)
             {
                 clickedObject.PriamryMouseUp();
             }
             else
             {
                 Debug.LogError("ClickedObject is null");
             }
             clickedObject = null;
         }
     }
 }
コード例 #4
0
 /**
  *<summary>
  * Calls <see cref="IObjectControl.PrimaryMouseDownRevert"/> pickedThisFrame and clicked object are different
  * Sets IgnoreMouseUp to true, and clickedObject to false
  *</summary>
  */
 void callMouseDownRevert()
 {
     if (pickedThisFrame != clickedObject && clickedObject != null)
     {
         clickedObject.PrimaryMouseDownRevert();
         ignoreMouseUp = true;
         clickedObject = null;
     }
 }
コード例 #5
0
 /**
  *<summary>>
  * Calls the appropriate behaviour on <see cref="IObjectControl"/>'s based on the stored data from mouse picks.
  *</summary>
  */
 public void mousePickObjectControl()
 {
     if (mousePick())
     {
         if (callHoverOff())
         {
             Debug.Log(this + " is calling HoverOff for " + pickedLastFrame);
         }
         //callMouseDownRevert();
         callMouseUp();
         callMouseDown();
         callHoverOn();
     }
     pickedLastFrame = pickedThisFrame;
 }
コード例 #6
0
 /**
  *<summary>
  * Calls <see cref="IObjectControl.PrimaryMouseDown"/>. Called on the first frame
  * where the mouse button is down. Assigns pickedThisFrame to clickedObject.
  *</summary>
  */
 void callMouseDown()
 {
     if (Input.GetMouseButtonDown(0))
     {
         clickedObject = pickedThisFrame;
         if (clickedObject != null)
         {
             clickedObject.PrimaryMouseDown();
         }
         else
         {
             Debug.LogError("ClickedObject is null");
         }
     }
 }
コード例 #7
0
        /// <summary>
        /// Puts an object back to the pool.
        /// </summary>
        /// <remarks>
        /// This method is invoked by WCF runtime.
        /// </remarks>
        public void ReleaseInstance(InstanceContext instanceContext, object instance)
        {
            lock (poolLock)
            {
                // Check whether the object can be pooled.
                // Call the Deactivate method if possible.
                if (instance is IObjectControl)
                {
                    IObjectControl objectControl = (IObjectControl)instance;
                    objectControl.Deactivate();

                    if (objectControl.CanBePooled)
                    {
                        pool.Push(instance);

                        #if (DEBUG)
                        WritePoolMessage(
                            ResourceHelper.GetString("MsgObjectPooled"));
                        #endif
                    }
                    else
                    {
                        #if (DEBUG)
                        WritePoolMessage(
                            ResourceHelper.GetString("MsgObjectWasNotPooled"));
                        #endif
                    }
                }
                else
                {
                    pool.Push(instance);

                    #if (DEBUG)
                    WritePoolMessage(
                        ResourceHelper.GetString("MsgObjectPooled"));
                    #endif
                }

                activeObjectsCount--;

                if (activeObjectsCount == 0)
                {
                    idleTimer.Start();
                }
            }

            availableCount.Release(1);
        }
コード例 #8
0
        void IManagedObjectInfo.GetIObjectControl(out IObjectControl pCtrl)
        {
            ServicedComponentProxy target = (ServicedComponentProxy)this._scp.Target;

            pCtrl = target.GetProxyTearoff() as IObjectControl;
        }
コード例 #9
0
    void Update()
    {
        if (mousePick())
        {
            //If the mouse is over not over the same object it was last frame
            //Calls HoverOff on the IObjectControl
            if (pickedLastFrame != pickedThisFrame && pickedLastFrame != null)
            {
                pickedLastFrame.HoverOff();
            }

            //If the mouse is not over the object stored in clickedObject
            //Call mouseDown revert and set ignoreMouseUp to true
            if (pickedThisFrame != clickedObject && clickedObject != null)
            {
                clickedObject.MouseDownRevert();
                ignoreMouseUp = true;
                clickedObject = null;
            }

            //If mouse click was released, calls mouseup on the IObjectControl
            // then sets clickedObject to null (since mouseButtonUp can't happen without mouseButtonDown first)
            if (Input.GetMouseButtonUp(0))
            {
                //Ignore mouse up is set to true when
                //--while the mouse button is held down--
                //clickedObject != pickedObject
                if (ignoreMouseUp)
                {
                    ignoreMouseUp = false;
                    return;
                }
                else
                {
                    if (clickedObject != null)
                    {
                        Debug.Log("Sending mouseUp to " + clickedObject);
                        clickedObject.MouseUp();
                    }
                    else
                    {
                        Debug.LogError("ClickedObject == null");
                    }
                    clickedObject = null;
                }
            }

            //If mouse is clicked, assign pickedThisFrame to clickedObject
            //Calls mouseDown on the associated IObjectControl
            if (Input.GetMouseButtonDown(0))
            {
                clickedObject = pickedThisFrame;
                if (clickedObject != null)
                {
                    clickedObject.MouseDown();
                }
                else
                {
                    Debug.LogError("ClickedObject == null");
                }
            }

            //If when picked this frame is different than picked last frame, this is the first frame the object has been picked, so I call HoverOn
            if (pickedThisFrame != pickedLastFrame)
            {
                pickedThisFrame.HoverOn();
            }
        }

        //Update pickedLastFrame
        pickedLastFrame = pickedThisFrame;
    }
コード例 #10
0
ファイル: ObjectModel.cs プロジェクト: Seth-W/EcoTile
 /**
  *<summary>
  * Uses UnityEngine.GetComponent to assign this gameObject's View and Controller components
  * to the <see cref="control"/> and <see cref="view"/> fields in an ObjectModel
  *</summary>
  */
 protected void assign_MVC_components()
 {
     control = GetComponent <IObjectControl>();
     view    = GetComponent <IObjectView>();
 }
 void IManagedObjectInfo.GetIObjectControl(out IObjectControl pCtrl)
 {
     ServicedComponentProxy target = (ServicedComponentProxy) this._scp.Target;
     pCtrl = target.GetProxyTearoff() as IObjectControl;
 }
コード例 #12
0
 public Gate_Methods()
 {
     this.moveObject = new Gate_ChangeObjectPosition(new Gate_Moving());
 }