コード例 #1
0
ファイル: CameraTargeting.cs プロジェクト: hzbaba/Assets
    public void TargetingRaycast()
    {
        // Current mouse position on screen
        Vector3 mp = Input.mousePosition;

        // Current target object transform component
        Transform targetTransform = null;

        // If camera component is available
        if (cam != null)
        {
            RaycastHit hitInfo;

            // Create a ray from mouse coords
            Ray ray = cam.ScreenPointToRay(new Vector3(mp.x, mp.y, 0f));

            // Targeting raycast
            if (Physics.Raycast(ray.origin, ray.direction, out hitInfo, targetingRayLength, targetingLayerMask.value))
            {
                // Cache what we've hit
                targetTransform = hitInfo.collider.transform;
            }
        }

        // If we've hit an object during raycast
        if (targetTransform != null)
        {
            // And this object has HighlightableObject component
            HighlightableObject ho = targetTransform.root.GetComponentInChildren <HighlightableObject>();
            if (ho != null)
            {
                // If left mouse button down
                if (Input.GetButtonDown("Fire1"))
                {
                    // Start flashing with frequency = 2
                    ho.FlashingOn(2f);
                }

                // If right mouse button is up
                if (Input.GetButtonUp("Fire2"))
                {
                    // Stop flashing
                    ho.FlashingOff();
                }

                // If middle mouse button is up
                if (Input.GetButtonUp("Fire3"))
                {
                    // Switch flashing
                    ho.FlashingSwitch();
                }

                // One-frame highlighting (to highlight an object which is currently under mouse cursor)
                ho.On(Color.red);
            }
        }
    }
コード例 #2
0
 void Awake()
 {
     //初始化组件
     m_ho = GetComponent <HighlightableObject>();
     m_ho.FlashingOn(Color.green, Color.gray, 1f);
     //m_ho.FlashingOn(Color.gray,Color.green);
     //m_ho.FlashingParams(Color.green,Color.gray, 1f);
     //m_ho.FlashingSwitch();
 }
コード例 #3
0
ファイル: HighLightCtrl.cs プロジェクト: xzp-cn/PcesProject
    /// <summary>
    /// 关闭闪烁
    /// </summary>
    /// <param name="go"></param>
    public void FlashOff(GameObject go)
    {
        HighlightableObject ho = go.GetComponent <HighlightableObject>();

        if (ho != null)
        {
            //Debug.Log("flash off  " + ho.name);
            ho.FlashingOff();
        }
    }
コード例 #4
0
        void SwitchHighlightedObject(HighlightableObject obj)
        {
            if (m_Highlighted != null)
            {
                m_Highlighted.Dehighlight();
            }

            m_Highlighted = obj;
            if (m_Highlighted != null)
            {
                m_Highlighted.Highlight();
            }
        }
コード例 #5
0
    /// <summary>
    /// 设置物体是否高亮
    /// </summary>
    /// <param name="isShow"></param>
    private void SetObjectHighing(GameObject obj, bool isShow)
    {
        HighlightableObject hitHighing = obj.GetComponent <HighlightableObject>();

        if (null != hitHighing && isShow)
        {
            hitHighing.ConstantOn();
        }

        if (null != hitHighing && !isShow)
        {
            hitHighing.ConstantOff();
        }
    }
コード例 #6
0
    void RaycastForHighlightable()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            HighlightOff();
            return;
        }

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        Collider[] colliders = Physics.OverlapCapsule(ray.origin, ray.origin + ray.direction * distance, radius, highlaytableLayers, QueryTriggerInteraction.Collide);

        float distanceFromRay = float.MaxValue;
        bool  highlighted     = false;

        foreach (Collider col in colliders)
        {
            HighlightableObject highlightScript = col.gameObject.GetComponentInParent <HighlightableObject>();
            if (highlightScript != null && highlightScript.canBeHighlighted)
            {
                LemmingStateController lemming = highlightScript.GetComponent <LemmingStateController>();
                if (lemming != null)
                {
                    if (lemming.Team != playerTeam)
                    {
                        continue;
                    }
                }

                float angle = Vector3.Angle(ray.direction, (col.bounds.center - Camera.main.transform.position));
                float dist  = Mathf.Sin(Mathf.Deg2Rad * angle) * Vector3.Distance(col.bounds.center, Camera.main.transform.position);
                if (dist < distanceFromRay)
                {
                    distanceFromRay   = distance;
                    highlightedObject = highlightScript;
                    highlighted       = true;
                }
            }
        }

        if (highlighted && !isHighlighting)
        {
            HighlightOn();
        }
        else if (!highlighted && isHighlighting)
        {
            HighlightOff();
        }
    }
コード例 #7
0
ファイル: HighLightCtrl.cs プロジェクト: xzp-cn/PcesProject
    /// <summary>
    /// 初始高亮物体
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    HighlightableObject InitHighlightObj(GameObject obj)
    {
        HighlightableObject ho = obj.GetComponent <HighlightableObject>();

        if (ho == null)
        {
            ho = obj.AddComponent <HighlightableObject>();
        }
        Init();
        if (!hoList.Contains(ho))
        {
            hoList.Add(ho);
        }
        return(ho);
    }
コード例 #8
0
    public EleItem(Transform tran)
    {
        Go            = tran.gameObject;
        Name          = tran.name;
        LookPos       = tran.Find("LookPos").position;
        LookQua       = tran.Find("LookPos").rotation;
        DefaultPos    = tran.localPosition;
        DefaultQua    = tran.localRotation;
        TargetMovePos = Vector3.zero;

        _hlObj = tran.gameObject.AddComponent <HighlightableObject>();
        if (_hlObj == null)
        {
            Debug.LogError("HighlightableObject not find!");
        }
    }
コード例 #9
0
    void SetTarget(GameObject go)
    {
        // remove old highlight
        if (_target != null)
        {
            HighlightableObject highlight = _target.GetComponent <HighlightableObject> ();
            if (highlight != null)
            {
                highlight.ConstantOffImmediate();
            }
        }

        if (go == null)
        {
            goX.SetActive(false);
            goY.SetActive(false);
            goZ.SetActive(false);

            _target = null;
        }
        else
        {
            _target = go;
            goX.SetActive(true);
            goY.SetActive(true);
            goZ.SetActive(true);

            transform.position = go.transform.position;

            //goX.transform.SetParent (go.transform);
            goX.transform.up = go.transform.right;

            //goY.transform.SetParent (go.transform);
            goY.transform.up = go.transform.up;

            //goZ.transform.SetParent (go.transform);
            goZ.transform.up = go.transform.forward;

            // add new highlight
            HighlightableObject highlight = go.transform.GetComponent <HighlightableObject>();
            if (highlight == null)
            {
                highlight = go.AddComponent <HighlightableObject> ();
            }
            highlight.ConstantOn(new Color32(255, 100, 0, 255));
        }
    }
コード例 #10
0
    // Update is called once per frame
    void Update()
    {
        Ray        ray;
        RaycastHit hit;

        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out hit))
        {
            if (hit.collider.gameObject != null)
            {
                HighlightableObject ho = hit.collider.transform.GetComponentInChildren <HighlightableObject>();
                if (ho != null)
                {
                    ho.On(Color.red);
                    //ho.OccluderOn();
                }
            }
        }
    }
コード例 #11
0
 public void Seclet(bool seclet)
 {
     mSelected = seclet;
     if (mSelected)
     {
         // 1.选中
         msCurrentWujiang = this;
         if (mHighlightableObjecto == null)
         {
             mHighlightableObjecto = gameObject.AddComponent <HighlightableObject>();
         }
         mHighlightableObjecto.ConstantOnImmediate(Color.red);
     }
     else
     {
         // 2.不选中
         msCurrentWujiang = null;
         mHighlightableObjecto.Off();
     }
 }
コード例 #12
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (lasttargetTransform != null)
            {
                HighlightableObject targetho = lasttargetTransform.GetComponent <HighlightableObject>();
                targetho.Off();

                if (game_ui_autopos.target_bar != null)
                {
                    game_ui_autopos.hideTargetBar();
                    TargetManger.cancelAutoAttack();
                }
            }
            return;
        }

        TargetingRaycast();
    }
コード例 #13
0
        protected override void Init()
        {
            base.Init();
            if (null != GetComponent <TrollDrawLine>())
            {
                trollDrawLine = GetComponent <TrollDrawLine>();
            }
            GameMapManager.UnitData UnitData = GameMapManager.Instance.GetUnitData(gameObject.tag);
            if (UnitData.object_UnitName != "")
            {
                Object_UnitName = EnumChange <GameUnitName> .StringToEnum(UnitData.object_UnitName);

                Object_Camp = EnumChange <CampEnum> .StringToEnum(UnitData.object_Camp);

                Object_UnitType = EnumChange <UnitTypeEnum> .StringToEnum(UnitData.object_UnitType);

                Object_HP     = UnitData.object_HP;
                Max_HP        = UnitData.object_HP;
                Object_Radius = UnitData.unit_Radius;
                if (Object_Camp == GameMapManager.Instance.PlayerCamp)
                {
                    IsPlayerCamp = true;
                }
                else
                {
                    IsPlayerCamp = false;
                }
            }
            if (IsPlayerCamp)
            {
                gameObject.AddComponent <HighlightableObject>();
                highlightable = GetComponent <HighlightableObject>();
            }
            else
            {
                StartCoroutine(StartAI());
            }
            Is_AI = !IsPlayerCamp;
        }
コード例 #14
0
    public void TargetingRaycast()
    {
        // Current mouse position on screen
        Vector3 mp = Input.mousePosition;

        // Current target object transform component
        targetTransform = null;

        // If camera component is available
        if (cam != null)
        {
            RaycastHit hitInfo;

            // Create a ray from mouse coords
            Ray ray = cam.ScreenPointToRay(new Vector3(mp.x, mp.y, 0f));

            // Targeting raycast
            if (Physics.Raycast(ray.origin, ray.direction, out hitInfo, targetingRayLength, targetingLayerMask.value))
            {
                // Cache what we've hit
                targetTransform = hitInfo.collider.transform;
            }
        }

        // If we've hit an object during raycast
        if (targetTransform != null)
        {
            // And this object has HighlightableObject component
            //    HighlightableObject ho = targetTransform.root.GetComponentInChildren<HighlightableObject>();
            HighlightableObject ho = targetTransform.GetComponent <HighlightableObject>();
            if (ho != null && !IsMousePointUI)
            {
                ho.On(Color.cyan);//如果鼠标经过 就会执行
            }
        }
    }
コード例 #15
0
    void dealWithDrawers(bool isSlider)
    {
        foreach (Drawer drawer in drawers)
        {
            if (hSliderValue < drawer.WfirstPosition.time.totalTime)
            {
                drawer.obj.SetActive(false);
            }
            else if (hSliderValue < drawer.WlastPosition.time.totalTime)
            {
                if (isSlider)
                {
                    drawer.tweener.Goto(Drawer.getDuration(drawer.WfirstPosition.time.totalTime, hSliderValue), false);
                }
                else
                {
                    drawer.tweener.PlayForward();
                }
                drawer.obj.SetActive(true);
                if (drawer.isFocus)
                {
                    drawer.obj.transform.position = drawer.myPosition + Drawer.objFocus;
                    HighlightableObject ho = drawer.obj.GetComponent <HighlightableObject>();
                    if (ho != null)
                    {
                        ho.ConstantOn(Color.red);
                    }
                    else
                    {
                        Debug.Log("ho is null");
                    }
                }
                else
                {
                    drawer.obj.transform.position = drawer.myPosition;
                }
                //?
                if (drawer.isCompanion)
                {
                    foreach (Transform child in drawer.obj.transform)
                    {
                        if (child.name.Contains("line"))
                        {
                            child.GetComponent <LineRenderer>().SetVertexCount(0);
                        }
                    }
                }
                drawer.drawLine(isPlaying);
            }
            else
            {
                drawer.obj.SetActive(false);
            }

            //for companion
            if (drawer.isCompanion)
            {
                if (drawer.moveTimes.ContainsKey(((int)hSliderValue / 60)))
                {
                    drawer.obj.GetComponent <Renderer>().material.mainTexture = companionTexture;
                    drawer.obj.transform.FindChild("board").GetComponent <Renderer>().material.mainTexture = boardCompanionTexture;
                }
                else
                {
                    drawer.obj.GetComponent <Renderer>().material.mainTexture = normalTexture;
                    drawer.obj.transform.FindChild("board").GetComponent <Renderer>().material.mainTexture = boardNormalTexture;
                }
            }
        }
    }
コード例 #16
0
 void OutlineFlicker(HighlightableObject outline, bool isTrue)
 {
     outline.flicker = isTrue;
 }
コード例 #17
0
    public void TargetingRaycast()
    {
        // Current mouse position on screen
        Vector3 mp = Input.mousePosition;

        Transform targetTransform = null;

        // If camera component is available
        if (cam != null)
        {
            RaycastHit hitInfo;

            // Create a ray from mouse coords
            Ray ray = cam.ScreenPointToRay(new Vector3(mp.x, mp.y, 0f));

            // Targeting raycast
            if (Physics.Raycast(ray.origin, ray.direction, out hitInfo, targetingRayLength, targetingLayerMask.value))
            {
                if (RPG_Animation.instance != null && hitInfo.collider.transform.gameObject != RPG_Animation.instance.transform.gameObject)
                {
                    // Cache what we've hit
                    targetTransform = hitInfo.collider.transform;
                }
            }
        }

        // If we've hit an object during raycast
        if (targetTransform != null)
        {
            // And this object has HighlightableObject component
            HighlightableObject ho = targetTransform.GetComponent <HighlightableObject>();

            if (ho != null)
            {
                // If left mouse button down
                if (Input.GetButtonDown("Fire1"))
                {
                    if (lasttargetTransform == targetTransform)
                    {
                        if ((Time.time - doubleClickStart) < 0.3f)
                        {
                            Common.DEBUG_MSG("Double Clicked!");
                            setTarget(targetTransform);
                        }

                        doubleClickStart = Time.time;
                        return;
                    }

                    doubleClickStart = Time.time;

                    setTarget(targetTransform);
                }

                /*
                 * // If right mouse button is up
                 * if (Input.GetButtonUp("Fire2"))
                 *      // Stop flashing
                 *      ho.FlashingOff();
                 *
                 * // If middle mouse button is up
                 * if (Input.GetButtonUp("Fire3"))
                 *      // Switch flashing
                 *      ho.FlashingSwitch();
                 */

                // One-frame highlighting (to highlight an object which is currently under mouse cursor)
                ho.On(Color.red);
            }
        }
    }
コード例 #18
0
ファイル: DianGui.cs プロジェクト: xxmm2018/shanghaiDate
 // Use this for initialization
 void Start()
 {
     color = Color.red;
     ho    = gameObject.AddComponent <HighlightableObject>();
 }
コード例 #19
0
 private void OnMouseExit()
 {
     m_ho = GetComponent <HighlightableObject>();
     m_ho.ConstantOff();
 }
コード例 #20
0
	void Awake()
	{
		ho = gameObject.AddComponent<HighlightableObject>();
	}
コード例 #21
0
    void Awake()
    {
        HighlightableObject ho = gameObject.AddComponent <HighlightableObject>();

        ho.OccluderOn();
    }
コード例 #22
0
 // 初始化
 void Start()
 {
     ho = GetComponent <HighlightableObject>();
     rooms.setRooms();
     //ho.ConstantOn(Color.yellow);
 }
コード例 #23
0
ファイル: Highlight.cs プロジェクト: fgeraci/CS195-Core
 void Awake()
 {
     this.highlighted = this.selected = false;
     ho = gameObject.AddComponent<HighlightableObject>();
 }
コード例 #24
0
    // Update is called once per frame
    void Update()
    {
        switch (mouseFlow)
        {
        case 0:
            if (Input.GetMouseButtonDown(1))
            {
                position       = Input.mousePosition;
                cameraPosition = Camera.main.transform.position;
            }
            //right hold to drag
            if (Input.GetMouseButton(1))
            {
                Vector3 change = new Vector3(Input.mousePosition.x - position.x, 0, Input.mousePosition.y - position.y);
                if (Camera.main.transform.position.y < 4)
                {
                    speed = 0.01f;
                }
                else
                {
                    speed = 0.05f;
                }
                Camera.main.transform.position = change * speed + cameraPosition;
            }
            //zoom in
            if (Input.GetAxis("Mouse ScrollWheel") > 0)
            {
                if (distance > 3.5f)
                {
                    if (distance > 4)
                    {
                        distance -= Input.GetAxis("Mouse ScrollWheel") * 5;
                    }
                    else
                    {
                        distance -= Input.GetAxis("Mouse ScrollWheel") * 2;
                    }

                    if (distance < 3.5f)
                    {
                        distance = 3.5f;
                    }
                }
                else
                {
                    distance = 3.5f;
                }
                theCamera.transform.position = new Vector3(theCamera.transform.position.x, distance, theCamera.transform.position.z);
            }
            //zoom out
            if (Input.GetAxis("Mouse ScrollWheel") < 0)
            {
                if (distance < 20)
                {
                    if (distance > 4)
                    {
                        distance -= Input.GetAxis("Mouse ScrollWheel") * 5;
                    }
                    else
                    {
                        distance -= Input.GetAxis("Mouse ScrollWheel") * 2;
                    }

                    if (distance < 3.5f)
                    {
                        distance = 3.5f;
                    }
                }
                else
                {
                    distance = 20;
                }
                theCamera.transform.position = new Vector3(theCamera.transform.position.x, distance, theCamera.transform.position.z);
            }

            if (mouseLock)
            {
                //ray test
                ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit))
                {
                    //for monitor
                    if (hit.collider.gameObject.name.Contains("mon"))
                    {
                        if (hited != null && hited != hit.collider.gameObject)
                        {
                            HighlightableObject ho1 = hited.GetComponent <HighlightableObject>();
                            if (ho1 != null)
                            {
                                ho1.Off();
                            }
                            else
                            {
                                Debug.Log("ho1 is null");
                            }
                        }
                        hited = hit.collider.gameObject;

                        if (mainTest.levelNow != 2)
                        {
                            HighlightableObject ho = hit.collider.gameObject.GetComponent <HighlightableObject>();
                            if (ho != null)
                            {
                                ho.ConstantOn(Color.red);
                            }
                            else
                            {
                                Debug.Log("ho is null");
                            }
                        }

                        if (Input.GetMouseButtonUp(0))
                        {
                            if (mainTest.levelNow < 2)
                            {
                                HighlightableObject ho1 = hited.GetComponent <HighlightableObject>();
                                if (ho1 != null)
                                {
                                    ho1.Off();
                                }
                                else
                                {
                                    Debug.Log("ho1 is null");
                                }
                                GameObject tempMonitor = hit.collider.gameObject;
                                string[]   tempString  = tempMonitor.name.Split('r');
                                mainTest.center = Track.world2position(new VecTime(tempMonitor.transform.position, new PTime(0)), mainTest.center, mainTest.map.fullLat, mainTest.map.fullLon);
                                switch (mainTest.levelNow)
                                {
                                case 0:
                                    mainTest.lastLevel_0 = int.Parse(tempString[1]);
                                    break;

                                case 1:
                                    mainTest.lastLevel_1 = int.Parse(tempString[1]);
                                    break;

                                default:
                                    break;
                                }
                                theCamera.transform.position = new Vector3(0, 7, 0);
                                distance  = (theCamera.transform.position - new Vector3(0, 0, 0)).magnitude;
                                mouseLock = false;

                                mainTest.map.zoom += 3;
                                mainTest.levelNow++;
                                for (int i = 0; i < mainTest.monitors.Length; i++)
                                {
                                    mainTest.monitors[i].transform.FindChild("Area").GetComponent <TextMesh>().text = "";
                                }

                                mainTest.flow = 2;
                            }
                        }
                        if (Input.GetKeyDown(KeyCode.Space))
                        {
                            if (mainTest.levelNow > 0)
                            {
                                HighlightableObject ho1 = hited.GetComponent <HighlightableObject>();
                                if (ho1 != null)
                                {
                                    ho1.Off();
                                }
                                else
                                {
                                    Debug.Log("ho1 is null");
                                }
                                mainTest.lastLevel_0         = -1;
                                mainTest.lastLevel_1         = -1;
                                theCamera.transform.position = new Vector3(0, 7, 0);
                                distance = (theCamera.transform.position - new Vector3(0, 0, 0)).magnitude;

                                mouseLock         = false;
                                mainTest.map.zoom = mainTest.basicZoom;
                                mainTest.levelNow = 0;
                                mainTest.center   = new Position(mainTest.avgLat, mainTest.avgLon, new PTime(0));
                                for (int i = 0; i < mainTest.monitors.Length; i++)
                                {
                                    mainTest.monitors[i].transform.FindChild("Area").GetComponent <TextMesh>().text = "";
                                }

                                mainTest.flow = 2;
                            }
                        }
                    }
                }
            }

            break;

        default:
            break;
        }
    }
コード例 #25
0
	void Awake()
	{
		ho = gameObject.AddComponent<HighlightableObject>();
		m = this.GetComponent<MeshRenderer> ();
	}
コード例 #26
0
    public void ClearUnits()
    {
        //Clear all Selected Units
        Debug.Log("Clearing Units");
        if(selectedUnit != null)
        {
            tempRend = selectedUnit.gameObject.GetComponentInChildren<Renderer>();
            //tempRend.material.shader = Shader.Find("Self-Illumin/Bumped Diffuse");

            tempHL = selectedUnit.gameObject.GetComponent<HighlightableObject>();
            tempHL.Off();

            tempUnitControl = (script_2PBot)selectedUnit.GetComponent("script_2PBot");
            tempUnitControl.selected = false;
            tempUnitControl.selectedBy = null;
            tempUnitControl.currentState = 0;
            tempUnitControl.distanceDrawn = false;
            Destroy (tempUnitControl.localMoveDistanceObj);
            selectedUnit = null;
            unitStats = null;
        }
    }
コード例 #27
0
ファイル: HighlightingController.cs プロジェクト: atomom/MyGF
 void Awake()
 {
     ho = gameObject.GetOrAddComponent <HighlightableObject>();
 }
コード例 #28
0
    // Update is called once per frame
    void Update()
    {
        //If it's my turn
        if (isMyTurn)
        {
            //And we LEFT click
            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                mousePosUp = Input.mousePosition;
                mouseXUp = mousePosUp.x;
                mouseYUp = mousePosUp.y;
                leftUpRay = mainCam.ScreenPointToRay(new Vector3(mouseXUp, mouseYUp, 0));
                Debug.DrawRay (leftUpRay.origin, leftUpRay.direction * 800, Color.yellow);

                //And that click is on a
                if (Physics.Raycast(leftUpRay, out leftUpHit, 800, nonTileMask))
                {
                    mouse3DHitUp = leftUpHit.point;
                    publicLeftHit = leftUpHit.point;
                    Debug.Log(leftUpHit.collider.gameObject.name);

                    GameObject tempHit = leftUpHit.transform.gameObject;
                    script_2PBot tempBot = tempHit.transform.gameObject.GetComponent<script_2PBot>();

                    //Game object on the "Child" layer
                    if (tempHit.gameObject.tag == "Child")
                    {
                        if (selectedUnit != null)
                        {
                            if (tempUnitControl.targetMover.target != null)
                            {
                                //Deselect All Units
                                selectedUnit.transform.position = startPos;

                                //Disable the Unit's Movement
                                tempUnitControl = (script_2PBot)selectedUnit.GetComponent("script_2PBot");
                                tempUnitControl.selected = false;
                                tempUnitControl.selectedBy = null;
                                tempUnitControl.currentState = 0;
                                tempUnitControl.targetMover.target.transform.position = selectedUnit.transform.position;

                                //Reset our variables
                                movingUnit = false;
                            }

                            ClearUnits();
                        }

                        //If this is OUR unit and not the enemy's
                        if (gameManager.player1Turn)
                        {
                            if (tempBot.player1Unit == true)
                            {
                                //Select Unit
                                selectedUnit = tempHit;
                                targetScript.selectedUnit = selectedUnit;
                                unitStats = selectedUnit.GetComponent<UnitStats>();
                                tempUnitControl = (script_2PBot)tempHit.GetComponent("script_2PBot");
                                tempUnitControl.targetMover.target.transform.position = selectedUnit.transform.position;
                                tempUnitControl.selected = true;
                                tempUnitControl.selectedBy = this.gameObject;
                                //tempUnitControl.currentState = 1;

                                //Hi-light the unit
                                tempRend = tempHit.gameObject.GetComponentInChildren<Renderer>();
                                //tempRend.material.shader = hiLightShader;

                                tempHL = selectedUnit.gameObject.GetComponent<HighlightableObject>();
                                tempHL.ConstantOn(highlightColor);

                                //Get the unit's Starting Position
                                startPos = tempHit.gameObject.transform.position;
                                if (tempUnitControl.canMove)
                                {
                                    movingUnit = true;
                                }
                                showAttack = false;
                            }
                            else //This is the enemy's unit
                            {
                                Debug.Log("Enemy Unit hit.");

        //								if (movingUnit)
        //								{
        //									showAttack = true;
        //									tempUnitControl.botAI.target.position = tempHit.transform.position;
        //								}
                                //else
                                //{
                                    selectedUnit = tempHit;
                                    targetScript.selectedUnit = selectedUnit;
                                    unitStats = selectedUnit.GetComponent<UnitStats>();
                                    tempUnitControl = (script_2PBot)tempHit.GetComponent("script_2PBot");
                                    Debug.Log("Selecting unit.");
                                    tempUnitControl.selected = true;
                                    tempUnitControl.currentState = 0;

                                    tempUnitControl.selectedBy = this.gameObject;

                                    tempRend = tempHit.gameObject.GetComponentInChildren<Renderer>();
                                    //tempRend.material.shader = enemyShader;

                                    tempHL = selectedUnit.gameObject.GetComponent<HighlightableObject>();
                                    tempHL.ConstantOn(Color.red);
                                //}
                            }
                        }
                        else if (gameManager.player2Turn)
                        {
                            if (tempBot.player2Unit == true)
                            {
                                //Select Unit
                                selectedUnit = tempHit;
                                targetScript.selectedUnit = selectedUnit;
                                unitStats = selectedUnit.GetComponent<UnitStats>();
                                tempUnitControl = (script_2PBot)tempHit.GetComponent("script_2PBot");
                                tempUnitControl.targetMover.target.transform.position = selectedUnit.transform.position;
                                tempUnitControl.selected = true;
                                tempUnitControl.selectedBy = this.gameObject;
                                //tempUnitControl.currentState = 1;

                                //Hi-light the unit
                                tempRend = tempHit.gameObject.GetComponentInChildren<Renderer>();
                                //tempRend.material.shader = hiLightShader;

                                tempHL = selectedUnit.gameObject.GetComponent<HighlightableObject>();
                                tempHL.ConstantOn(highlightColor);

                                //Get the unit's Starting Position
                                startPos = tempHit.gameObject.transform.position;
                                if (tempUnitControl.canMove)
                                {
                                    movingUnit = true;
                                }
                                showAttack = false;
                            }
                            else //This is the enemy's unit
                            {
                                Debug.Log("Enemy Unit hit.");
        //								if (movingUnit)
        //								{
        //									showAttack = true;
        //									tempUnitControl.botAI.target.position = tempHit.transform.position;
        //								}
        //								else
        //								{
                                    selectedUnit = tempHit;
                                    targetScript.selectedUnit = selectedUnit;
                                    unitStats = selectedUnit.GetComponent<UnitStats>();
                                    tempUnitControl = (script_2PBot)tempHit.GetComponent("script_2PBot");
                                    tempUnitControl.selected = true;
                                    tempUnitControl.selectedBy = this.gameObject;
                                    tempUnitControl.currentState = 0;

                                    tempRend = tempHit.gameObject.GetComponentInChildren<Renderer>();
                                    //tempRend.material.shader = enemyShader;

                                    Debug.Log("Highlighting");
                                    tempHL = selectedUnit.gameObject.GetComponent<HighlightableObject>();
                                    tempHL.ConstantOn(Color.red);
                                //}
                            }
                        }
                    }
                    else // This is not a unit, so clear everything
                    {
                        Debug.Log("Clearing All");
                        if (GUIUtility.hotControl == 0)
                        {
                            //Send the unit back to the starting spot
                            if (selectedUnit != null)
                            {
                                if (tempUnitControl.selectedBy == tempUnitControl.ourPlayer)
                                {
                                    selectedUnit.transform.position = startPos;
                                }

                                //Disable the Unit's Movement
                                tempUnitControl = (script_2PBot)selectedUnit.GetComponent("script_2PBot");
                                tempUnitControl.selected = true;
                                tempUnitControl.currentState = 0;

                                //Reset our variables
                                movingUnit = false;
                                showAttack = false;
                                ClearUnits();
                            }
                        }
                    }
                }
            }

            //If we RIGHT click
            if (Input.GetKeyDown(KeyCode.Mouse1))
            {
                mousePosUp = Input.mousePosition;
                mouseXUp = mousePosUp.x;
                mouseYUp = mousePosUp.y;
                leftUpRay = mainCam.ScreenPointToRay(new Vector3(mouseXUp, mouseYUp, 0));
                Debug.DrawRay (leftUpRay.origin, leftUpRay.direction * 800, Color.yellow);

                //And that click is on a
                if (Physics.Raycast(leftUpRay, out leftUpHit, 800))
                {
                    mouse3DHitUp = leftUpHit.point;
                    publicLeftHit = leftUpHit.point;
                    Debug.Log(leftUpHit.collider.gameObject.name);

                    GameObject tempHit = leftUpHit.transform.gameObject;
                    script_2PBot tempBot = tempHit.transform.gameObject.GetComponent<script_2PBot>();

                    //we hit a unit
                    if (tempHit.gameObject.tag == "Child")
                    {
                        //we have a unit selected
                        if (selectedUnit != null)
                        {
                            //we are a jock
                            if (playerType == PlayerType.Jock)
                            {
                                //we selected a nerd
                                if (tempHit.gameObject.name.Contains("Nerd"))
                                {
                                    //our selected unit is a jock
                                    if (selectedUnit.gameObject.name.Contains("Jock"))
                                    {
                                        Debug.Log("Nerd Hit");
                                        targetEnemy = tempHit.gameObject;

                                        if (Vector3.Distance(selectedUnit.gameObject.transform.position, targetEnemy.transform.position) < tempUnitControl.remainingDistance)
                                        {
                                            if (tempUnitControl.canAttack)
                                            {
                                                tempUnitControl.selected = true;
                                                tempUnitControl.currentState = 1;

                                                //Get the unit's Starting Position
                                                startPos = tempHit.gameObject.transform.position;

                                                tempUnitControl.targetMover.target.transform.position = targetEnemy.transform.position;
                                                attackMode = true;
                                                AkSoundEngine.PostEvent("Play_AttackSelect", this.gameObject);
                                                AkSoundEngine.PostEvent("Set_State_Attack", this.gameObject);
                                                Destroy(tempUnitControl.localMoveDistanceObj);
                                            }
                                        }
                                    }
                                }
                            }
                            else if (playerType == PlayerType.Nerd)
                            {
                                if (tempHit.gameObject.name.Contains("Jock"))
                                {
                                    if (selectedUnit.gameObject.name.Contains("Nerd"))
                                    {
                                        Debug.Log("Jock Hit");
                                        targetEnemy = tempHit.gameObject;

                                        if (Vector3.Distance(selectedUnit.gameObject.transform.position, targetEnemy.transform.position) < tempUnitControl.remainingDistance)
                                        {
                                            if (tempUnitControl.canAttack)
                                            {
                                                tempUnitControl.selected = true;
                                                tempUnitControl.currentState = 1;

                                                //Get the unit's Starting Position
                                                startPos = tempHit.gameObject.transform.position;

                                                tempUnitControl.targetMover.target.transform.position = targetEnemy.transform.position;
                                                attackMode = true;
                                                AkSoundEngine.PostEvent("Play_AttackSelect", this.gameObject);
                                                AkSoundEngine.PostEvent("Set_State_Attack", this.gameObject);
                                                Destroy(tempUnitControl.localMoveDistanceObj);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                    }
                }

            } //End of Right Click

            if (attackMode)
            {
                if (selectedUnit != null)
                {
                    float distance = Vector3.Distance(selectedUnit.gameObject.transform.position, targetEnemy.gameObject.transform.position);

                    if (distance < unitStats.AtkRng)
                    {
                        script_2PBot botScript = selectedUnit.gameObject.GetComponent<script_2PBot>();

                        if (botScript.canAttack)
                        {
                            Vector3 spawnSpot = new Vector3(targetEnemy.transform.position.x, targetEnemy.transform.position.y + 3, targetEnemy.transform.position.z);
                            Instantiate(attackEffect, spawnSpot, Quaternion.identity);
                            tempUnitControl.targetMover.target.transform.position = selectedUnit.transform.position;
                            tempUnitControl.currentState = 0;
                            Debug.Log("Attacking!!!!");
                            UnitStats enemyScript = targetEnemy.gameObject.GetComponent<UnitStats>();
                            enemyScript.CurrentHealth -= unitStats.AtkDmg;
                            attackMode = false;
                            movingUnit = false;
                            botScript.currentState = 0;
                            botScript.canAttack = false;
                            ClearUnits();
                        }

                    }
                }
            }

            if (movingUnit)
            {
                if (movesRemaining > 0)
                {
                    if (Input.GetKeyDown(KeyCode.Space))
                    {
                        if (Vector3.Distance(selectedUnit.transform.position, startPos) > 1)
                        {
                            movesRemaining--;
                        }

                        //Disable the Unit's Movement
                        tempUnitControl = (script_2PBot)selectedUnit.GetComponent("script_2PBot");
                        tempUnitControl.selected = true;
                        tempUnitControl.currentState = 0;

                        if (Vector3.Distance(tempUnitControl.targetSpot, tempUnitControl.spotPos) < tempUnitControl.remainingDistance)
                        {
                            Vector3 newPos = new Vector3(tempUnitControl.targetMover.target.transform.position.x, tempUnitControl.gameObject.transform.position.y, tempUnitControl.targetMover.target.transform.position.z);
                            tempUnitControl.gameObject.transform.position = newPos;
                        }

                        //Reset our variables
                        movingUnit = false;
                        tempUnitControl.canMove = false;
                        ClearUnits();
                        AkSoundEngine.PostEvent("Play_Confirm", this.gameObject);
                    }
                }
            }

            //Constant Update for Highlighting
            mousePosUp = Input.mousePosition;
            mouseXUp = mousePosUp.x;
            mouseYUp = mousePosUp.y;
            leftUpRay = mainCam.ScreenPointToRay(new Vector3(mouseXUp, mouseYUp, 0));
            Debug.DrawRay (leftUpRay.origin, leftUpRay.direction * 800, Color.yellow);

            //And that click is on a
            if (Physics.Raycast(leftUpRay, out leftUpHit, 800))
            {
                mouse3DHitUp = leftUpHit.point;
                publicLeftHit = leftUpHit.point;
                //Debug.Log(leftUpHit.collider.gameObject.name);

                GameObject tempHit = leftUpHit.transform.gameObject;
                script_2PBot tempBot = tempHit.transform.gameObject.GetComponent<script_2PBot>();

                //Game object on the "Child" layer
                if (tempHit.gameObject.tag == "Child")
                {
                    if (playerType == PlayerType.Nerd)
                    {
                        if (tempHit.gameObject.name.Contains("Nerd"))
                        {
                            tempHL = tempHit.gameObject.GetComponent<HighlightableObject>();
                            tempHL.On(highlightColor);
                        }

                        if (tempHit.gameObject.name.Contains("Jock"))
                        {
                            tempHL = tempHit.gameObject.GetComponent<HighlightableObject>();
                            tempHL.On(Color.red);
                        }
                    }

                    if (playerType == PlayerType.Jock)
                    {
                        if (tempHit.gameObject.name.Contains("Jock"))
                        {
                            tempHL = tempHit.gameObject.GetComponent<HighlightableObject>();
                            tempHL.On(highlightColor);
                        }

                        if (tempHit.gameObject.name.Contains("Nerd"))
                        {
                            tempHL = tempHit.gameObject.GetComponent<HighlightableObject>();
                            tempHL.On(Color.red);
                        }
                    }
                }
            }
        }
    }
コード例 #29
0
    // Update is called once per frame
    void Update()
    {
        switch (mouseFlow)
        {
        //for the orthographic
        case 0:
            //right press to log the position now
            if (Input.GetMouseButtonDown(1))
            {
                position       = Input.mousePosition;
                cameraPosition = Camera.main.transform.position;
            }
            //right hold to drag
            if (Input.GetMouseButton(1))
            {
                Vector3 change = new Vector3(Input.mousePosition.x - position.x, 0, Input.mousePosition.y - position.y);
                if (Camera.main.transform.position.y < 4)
                {
                    speed = 0.01f;
                }
                else
                {
                    speed = 0.05f;
                }
                Camera.main.transform.position = change * speed + cameraPosition;
            }
            //zoom in
            if (Input.GetAxis("Mouse ScrollWheel") > 0)
            {
                if (distance > 2.5f)
                {
                    if (distance > 4)
                    {
                        distance -= Input.GetAxis("Mouse ScrollWheel") * 5;
                    }
                    else
                    {
                        distance -= Input.GetAxis("Mouse ScrollWheel") * 2;
                    }

                    if (distance < 2.5f)
                    {
                        distance = 2.5f;
                    }
                }
                else
                {
                    distance = 2.5f;
                }
                theCamera.transform.position = new Vector3(theCamera.transform.position.x, distance, theCamera.transform.position.z);
            }
            //zoom out
            if (Input.GetAxis("Mouse ScrollWheel") < 0)
            {
                if (distance < 50)
                {
                    if (distance > 4)
                    {
                        distance -= Input.GetAxis("Mouse ScrollWheel") * 5;
                    }
                    else
                    {
                        distance -= Input.GetAxis("Mouse ScrollWheel") * 2;
                    }

                    if (distance < 2.5f)
                    {
                        distance = 2.5f;
                    }
                }
                else
                {
                    distance = 50;
                }
                theCamera.transform.position = new Vector3(theCamera.transform.position.x, distance, theCamera.transform.position.z);
            }
            //the ray hit
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit))
            {
                //for plane
                if (hit.collider.gameObject.name.Contains("lane") || hit.collider.gameObject.name.Contains("board"))
                {
                    if (hited != null)
                    {
                        var em = hited.GetComponent <ParticleSystem>().emission;
                        em.enabled = false;
                    }
                    label.GetComponent <Text>().text = "";
                }    //for new hited object, empty the last hited
                else if (hited != hit.collider.gameObject)
                {
                    if (hited != null)
                    {
                        var em = hited.GetComponent <ParticleSystem>().emission;
                        em.enabled = false;
                    }
                    hited = hit.collider.gameObject;
                    label.GetComponent <Text>().text = "";
                }    //for hited object now
                else
                {
                    hited = hit.collider.gameObject;
                    if (hited != focusObj)
                    {
                        var em = hited.GetComponent <ParticleSystem>().emission;
                        em.enabled = true;
                    }
                    label.GetComponent <Text>().text = "The target object is " + hited.name;
                    //left press to focus object
                    if (Input.GetMouseButtonUp(0))
                    {
                        mouseFlow    = 1;
                        focusObj     = hit.collider.gameObject;
                        focusObjName = "The target object is " + focusObj.name;
                        var em = focusObj.GetComponent <ParticleSystem>().emission;
                        em.enabled = false;
                    }
                }
            }
            break;

        //changing to focus object
        case 1:
            switch (cameraButton)
            {
            //look at the target first
            case 0:
                changeTarget = theCamera.transform.DOLookAt(focusObj.transform.position, 0.8f);
                changeTarget.SetAutoKill(false).SetEase(Ease.Linear);
                changeTarget.Play();
                cameraButton = 1;
                break;

            //set path and rotate
            case 1:
                if (changeTarget.IsComplete())
                {
                    //release last one
                    changeTarget.Kill();

                    Vector3[] path = new Vector3[2];
                    path[0] = focusObj.transform.position + new Vector3(0, 2.5f, 5);
                    path[1] = focusObj.transform.position + new Vector3(0, 1.5f, 3);

                    changeTarget = theCamera.transform.DOPath(path, 3, PathType.CatmullRom, PathMode.Full3D, 5, null).SetLookAt(focusObj.transform.position);

                    changeTarget.SetAutoKill(false).SetEase(Ease.Linear);
                    changeTarget.Play();

                    theCamera.transform.DORotate(new Vector3(27, 180, 0), 3).Play();

                    cameraButton = 2;
                    //release
                    Array.Clear(path, 0, path.Length);
                }
                break;

            //when finished change to next situation
            case 2:
                if (changeTarget.IsComplete())
                {
                    //release last one
                    changeTarget.Kill();

                    //prepare
                    Vector2 angles = theCamera.transform.eulerAngles;
                    x = angles.y;
                    y = angles.x;

                    Drawer temp = null;
                    foreach (Drawer drawer in main.drawers)
                    {
                        if (drawer.obj.name == focusObj.name)
                        {
                            temp = drawer;
                        }
                    }
                    temp.isFocus = true;
                    HighlightableObject ho = focusObj.GetComponent <HighlightableObject>();
                    if (ho != null)
                    {
                        ho.ConstantOn(Color.red);
                    }
                    else
                    {
                        Debug.Log("ho is null");
                    }
                    var em = hited.GetComponent <ParticleSystem>().emission;
                    em.enabled = false;
                    em         = focusObj.GetComponent <ParticleSystem>().emission;
                    em.enabled = false;

                    if (GetComponent <Rigidbody>())
                    {
                        GetComponent <Rigidbody>().freezeRotation = true;
                    }
                    distance     = (theCamera.transform.position - focusObj.transform.position).magnitude;
                    mouseFlow    = 2;
                    cameraButton = 0;
                }
                break;

            default:
                break;
            }
            break;

        //focuse rotate
        case 2:
            //right press to drag
            if (Input.GetMouseButton(1))
            {
                if (focusObj)
                {
                    x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
                    y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
                    y  = ClampAngle(y, yMinLimit, yMaxLimit);
                }
            }
            //zoom in
            if (Input.GetAxis("Mouse ScrollWheel") > 0)
            {
                if (distance > 2.5f)
                {
                    if (distance > 4)
                    {
                        distance -= Input.GetAxis("Mouse ScrollWheel") * 5;
                    }
                    else
                    {
                        distance -= Input.GetAxis("Mouse ScrollWheel") * 2;
                    }

                    if (distance < 2.5f)
                    {
                        distance = 2.5f;
                    }
                }
                else
                {
                    distance = 2.5f;
                }
            }
            //zoom out
            if (Input.GetAxis("Mouse ScrollWheel") < 0)
            {
                if (distance < 50)
                {
                    if (distance > 4)
                    {
                        distance -= Input.GetAxis("Mouse ScrollWheel") * 5;
                    }
                    else
                    {
                        distance -= Input.GetAxis("Mouse ScrollWheel") * 2;
                    }

                    if (distance < 2.5f)
                    {
                        distance = 2.5f;
                    }
                }
                else
                {
                    distance = 50;
                }
            }
            //let camera focus on object
            moveCamera();
            //the ray hit
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit))
            {
                //for plane
                if (hit.collider.gameObject.name.Contains("lane"))
                {
                    if (hited != null && hited != focusObj)
                    {
                        var em = hited.GetComponent <ParticleSystem>().emission;
                        em.enabled = false;
                    }
                    else
                    {
                        var em = focusObj.GetComponent <ParticleSystem>().emission;
                        em.enabled = false;
                    }
                    label.GetComponent <Text>().text = focusObjName;
                }    //for new hited object, empty the last hited
                else if (hited != hit.collider.gameObject)
                {
                    if (hited != null && hited != focusObj)
                    {
                        var em = hited.GetComponent <ParticleSystem>().emission;
                        em.enabled = false;
                    }
                    hited = hit.collider.gameObject;
                    label.GetComponent <Text>().text = focusObjName;
                }    //for new hited object
                else
                {
                    hited = hit.collider.gameObject;
                    if (hited != focusObj)
                    {
                        var em = hited.GetComponent <ParticleSystem>().emission;
                        em.enabled = true;
                    }
                    label.GetComponent <Text>().text = "The target object is " + hited.name;
                    if (Input.GetMouseButtonUp(0))
                    {
                        mouseFlow = 1;
                        Drawer temp = null;
                        foreach (Drawer drawer in main.drawers)
                        {
                            if (drawer.obj.name == focusObj.name)
                            {
                                temp = drawer;
                            }
                        }
                        temp.isFocus = false;
                        HighlightableObject ho = focusObj.GetComponent <HighlightableObject>();
                        if (ho != null)
                        {
                            ho.Off();
                        }
                        else
                        {
                            Debug.Log("ho is null");
                        }
                        //focusObj.GetComponent<MeshRenderer>().material.SetFloat("_GlowStrength", 0);
                        //focusObj.GetComponent<LineRenderer>().material.SetColor("_Color", new Color(0, 97.0f/255.0f, 1, 1));
                        focusObj     = hit.collider.gameObject;
                        focusObjName = "The target object is " + focusObj.name;
                        var em = focusObj.GetComponent <ParticleSystem>().emission;
                        em.enabled = false;
                    }
                }
            }
            break;

        default:
            break;
        }
    }
コード例 #30
0
 //关于高亮部分
 private void OnMouseEnter()
 {
     m_ho = GetComponent <HighlightableObject>();
     m_ho.ConstantOn(Color.red);
 }
コード例 #31
0
 void OutlineConstant(HighlightableObject outline, bool isTrue)
 {
     outline.constantly = isTrue;
 }
コード例 #32
0
 void Awake()
 {
     //初始化组件
     m_ho = GetComponent <HighlightableObject>();
 }
コード例 #33
0
 /// <summary>
 /// 初始化
 /// </summary>
 public virtual void Initialize()
 {
     _HighlightableObject = GetComponent <HighlightableObject> ();
     _Renderer            = GetComponent <Renderer> ();
 }
コード例 #34
0
 void Start()
 {
     h    = gameObject.GetComponent <HighlightableObject>();
     CMap = GameObject.FindGameObjectWithTag("Map").GetComponent <Map>();
 }
コード例 #35
0
 void Awake()
 {
     ho = gameObject.AddComponent <HighlightableObject>();
     //ho.ConstantOn(Color.red);
 }