public virtual void OnPointerExit(PointerEventData eventData)
 {
     if (!UnityTools.IsPointerOverUI())
     {
         ExecuteEvent <ITriggerPointerExit>(Execute, eventData);
     }
 }
 public void OnPointerClick(PointerEventData eventData)
 {
     //Check if  TriggerInputType.OnClick is included.
     if (triggerType.HasFlag <TriggerInputType>(TriggerInputType.OnClick) && !UnityTools.IsPointerOverUI())
     {
         Use();
     }
 }
        //Can the trigger be used?
        public virtual bool CanUse()
        {
            //Return false if the trigger is already used
            if (InUse || (BaseTrigger.currentUsedTrigger != null && BaseTrigger.currentUsedTrigger.InUse))
            {
                DisplayInUse();
                return(false);
            }

            if (this.useDistance == -1)
            {
                return(true);
            }

            //Return false if the player is not in range
            if (!InRange)
            {
                DisplayOutOfRange();
                return(false);
            }

            if (this.m_CheckBlocking)
            {
                Vector3 targetPosition = UnityTools.GetBounds(gameObject).center;
                Vector3 playerPosition = PlayerInfo.transform.position;
                Bounds  bounds         = PlayerInfo.bounds;
                playerPosition.y += bounds.center.y + bounds.extents.y;
                Vector3  direction = targetPosition - playerPosition;
                Collider collider  = PlayerInfo.collider;
                collider.enabled = false;
                RaycastHit hit;

                LayerMask layerMask = Physics.DefaultRaycastLayers;
                bool      raycast   = Physics.Raycast(playerPosition, direction, out hit, float.PositiveInfinity, layerMask, QueryTriggerInteraction.Collide);
                collider.enabled = true;
                if (raycast && !UnityEngine.Object.ReferenceEquals(hit.transform, transform))
                {
                    return(false);
                }
            }

            Animator animator = PlayerInfo.animator;

            if (PlayerInfo != null && animator != null)
            {
                for (int j = 0; j < animator.layerCount; j++)
                {
                    if (animator.IsInTransition(j))
                    {
                        return(false);
                    }
                }
            }
            //Trigger can be used
            return(true);
        }
 private void OnPointerTriggerClick(int button)
 {
     if (!UnityTools.IsPointerOverUI() &&
         triggerType.HasFlag <TriggerInputType>(TriggerInputType.LeftClick) && button == 0 ||
         triggerType.HasFlag <TriggerInputType>(TriggerInputType.RightClick) && button == 1 ||
         triggerType.HasFlag <TriggerInputType>(TriggerInputType.MiddleClick) && button == 2)
     {
         Use();
     }
 }
        public override ActionStatus OnUpdate()
        {
            if (m_Original == null)
            {
                Debug.LogWarning("The game object you want to instantiate is null.");
                return(ActionStatus.Failure);
            }

            GameObject go = GameObject.Instantiate(m_Original, this.m_Bone.position + this.m_Offset, this.m_Bone.rotation, this.m_Bone);

            if (m_IgnorePlayerCollision)
            {
                UnityTools.IgnoreCollision(playerInfo.gameObject, go);
            }
            return(ActionStatus.Success);
        }
        //Can the trigger be used?
        public virtual bool CanUse()
        {
            //Return false if the trigger is already used
            if (InUse || (BaseTrigger.currentUsedTrigger != null && BaseTrigger.currentUsedTrigger.InUse))
            {
                DisplayInUse();
                return(false);
            }

            if (this.useDistance == -1)
            {
                return(true);
            }

            //Return false if the player is not in range
            if (!InRange)
            {
                DisplayOutOfRange();
                return(false);
            }

            Vector3 targetPosition = UnityTools.GetBounds(gameObject).center;
            Vector3 playerPosition = PlayerInfo.transform.position;
            Bounds  bounds         = PlayerInfo.bounds;

            playerPosition.y += bounds.center.y + bounds.extents.y;
            Vector3  direction = targetPosition - playerPosition;
            Collider collider  = PlayerInfo.collider;

            collider.enabled = false;
            RaycastHit hit;
            bool       raycast = Physics.Raycast(playerPosition, direction, out hit);

            collider.enabled = true;
            if (raycast && hit.transform != transform && gameObject != PlayerInfo.gameObject)
            {
                return(false);
            }

            //Trigger can be used
            return(true);
        }
        // Update is called once per frame
        private void Update()
        {
            if (this.m_Focus)
            {
                Transform target          = this.m_ThirdPersonCamera.Target;
                Vector3   targetPosition  = target.position + this.m_OffsetPosition.x * target.right + this.m_OffsetPosition.y * target.up;
                Vector3   direction       = -m_Distance * transform.forward;
                Vector3   desiredPosition = targetPosition + direction;

                transform.position = Vector3.Lerp(transform.position, desiredPosition, this.m_Speed * Time.deltaTime);
                transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(this.m_Pitch, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z), this.m_Speed * Time.deltaTime);

                if (!this.m_TargetRotationFinished)
                {
                    Vector3 cameraDirection = transform.position - this.m_ThirdPersonCamera.Target.position;
                    cameraDirection.y = 0f;
                    Quaternion targetRotation = Quaternion.LookRotation(cameraDirection, Vector3.up);
                    this.m_ThirdPersonCamera.Target.rotation = Quaternion.Lerp(target.rotation, targetRotation, Time.deltaTime * this.m_Speed);
                    if (Quaternion.Angle(target.rotation, targetRotation) < 0.1f)
                    {
                        this.m_TargetRotationFinished = true;
                    }
                }
                else if (this.m_SpinTarget)
                {
                    if (Input.GetMouseButtonDown(0) && UnityTools.IsPointerOverUI())
                    {
                        this.m_GUIClick = true;
                    }
                    if (Input.GetMouseButtonUp(0))
                    {
                        this.m_GUIClick = false;
                    }

                    if (Input.GetMouseButton(0) && !this.m_GUIClick)
                    {
                        float input = Input.GetAxis("Mouse X") * -this.m_Speed;
                        target.Rotate(0, input, 0, Space.World);
                    }
                }
            }
        }
        private void Update()
        {
            if (!UnityTools.IsPointerOverUI())
            {
                RaycastHit hit;
                if (Physics.Raycast(this.m_Transform.position, this.m_Transform.forward, out hit, float.PositiveInfinity, this.m_LayerMask, QueryTriggerInteraction.Ignore))
                {
                    if (m_LastCameraHit != null && m_LastCameraHit != hit.collider.gameObject)
                    {
                        EventHandler.Execute <bool>(this.m_LastCameraHit, "OnCameraRaycast", false);
                    }
                    m_LastCameraHit = hit.collider.gameObject;
                    EventHandler.Execute <bool>(m_LastCameraHit, "OnCameraRaycast", true);
                }
                else
                {
                    if (m_LastCameraHit != null)
                    {
                        EventHandler.Execute <bool>(m_LastCameraHit, "OnCameraRaycast", false);
                        m_LastCameraHit = null;
                    }
                }

                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, float.PositiveInfinity, this.m_LayerMask, QueryTriggerInteraction.Ignore))
                {
                    if (m_LastMouseHit != null && m_LastMouseHit != hit.collider.gameObject)
                    {
                        EventHandler.Execute <bool>(this.m_LastMouseHit, "OnMouseRaycast", false);
                    }
                    m_LastMouseHit = hit.collider.gameObject;
                    EventHandler.Execute <bool>(m_LastMouseHit, "OnMouseRaycast", true);
                }
                else
                {
                    if (m_LastMouseHit != null)
                    {
                        EventHandler.Execute <bool>(m_LastMouseHit, "OnMouseRaycast", false);
                        m_LastMouseHit = null;
                    }
                }
            }
        }
        public override ActionStatus OnUpdate()
        {
            if (m_Original == null)
            {
                Debug.LogWarning("The game object you want to instantiate is null.");
                return(ActionStatus.Failure);
            }

            RaycastHit hit;

            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100))
            {
                GameObject go = GameObject.Instantiate(m_Original, hit.point, Quaternion.identity);
                if (m_IgnorePlayerCollision)
                {
                    UnityTools.IgnoreCollision(playerInfo.gameObject, go);
                }
                return(ActionStatus.Success);
            }

            return(ActionStatus.Failure);
        }
        private void Update()
        {
            bool selected = false;

            //Selection
            if (Input.GetMouseButtonDown(0) && selectionType.HasFlag <SelectionInputType>(SelectionInputType.LeftClick) ||
                Input.GetMouseButtonDown(1) && selectionType.HasFlag <SelectionInputType>(SelectionInputType.RightClick) ||
                Input.GetMouseButtonDown(2) && selectionType.HasFlag <SelectionInputType>(SelectionInputType.MiddleClick))
            {
                selected = TrySelect(this.m_Camera.ScreenPointToRay(Input.mousePosition));
            }
            else if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) && selectionType.HasFlag <SelectionInputType>(SelectionInputType.Raycast))
            {
                selected = TrySelect(new Ray(this.m_CameraTransform.position, this.m_CameraTransform.forward + this.m_RaycastOffset));
            }
            else if (Input.GetKeyDown(this.m_SelectionKey) && selectionType.HasFlag <SelectionInputType>(SelectionInputType.Key))
            {
                RaycastHit[] hits       = Physics.SphereCastAll(this.m_Transform.position, this.m_SelectionDistance, this.m_Transform.forward);
                ISelectable  selectable = GetBestSelectable(hits.Select(x => x.collider.GetComponent <ISelectable>()).OfType <ISelectable>().Where(x => x.enabled));
                if (selectable != null)
                {
                    Select(selectable);
                    selected = true;
                }
            }

            //Deselection
            if (!UnityTools.IsPointerOverUI())
            {
                if (!selected && (Input.GetMouseButtonDown(0) && deselectionType.HasFlag <DeselectionInputType>(DeselectionInputType.LeftClick) ||
                                  Input.GetMouseButtonDown(1) && deselectionType.HasFlag <DeselectionInputType>(DeselectionInputType.RightClick) ||
                                  Input.GetMouseButtonDown(2) && deselectionType.HasFlag <DeselectionInputType>(DeselectionInputType.MiddleClick) ||
                                  Input.GetKeyDown(this.m_DeselectionKey) && deselectionType.HasFlag <DeselectionInputType>(DeselectionInputType.Key)))
                {
                    Deselect();
                }
            }
        }
 /// <summary>
 /// Colors the string.
 /// </summary>
 /// <returns>The colored string.</returns>
 /// <param name="value">Value.</param>
 /// <param name="color">Color.</param>
 public static string ColorString(string value, Color color)
 {
     return("<color=#" + UnityTools.ColorToHex(color) + ">" + value + "</color>");
 }
Example #12
0
        private void Update()
        {
            if (!this.m_ControllerActive)
            {
                return;
            }

            if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) && EventSystem.current != null && UnityTools.IsPointerOverUI())
            {
                this.m_GUIClick = true;
            }

            if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1))
            {
                this.m_GUIClick = false;
            }

            this.m_RawInput = new Vector3(Input.GetAxis(this.m_HorizontalInput), 0, Input.GetAxis(this.m_ForwardInput));

            switch (this.m_AimType)
            {
            case AimType.Button:
                IsAiming = Input.GetButton(this.m_AimInput) && !this.m_GUIClick;
                break;

            case AimType.Axis:
                float aim = Input.GetAxis(this.m_AimInput);
                if (Mathf.Abs(aim) > 0.01f)
                {
                    IsAiming          = true;
                    this.m_RawInput.x = aim;
                }
                else
                {
                    IsAiming = false;
                }
                break;

            case AimType.Toggle:
                if (Input.GetButtonDown(this.m_AimInput))
                {
                    IsAiming = !IsAiming;
                }
                break;
            }


            for (int j = 0; j < this.m_Motions.Count; j++)
            {
                MotionState motion = this.m_Motions [j];
                if (!motion.isActiveAndEnabled || motion.ConsumeInputOverUI && this.m_GUIClick)
                {
                    continue;
                }
                if (motion.StartType != StartType.Down && motion.StopType != StopType.Toggle || !Input.GetButtonDown(motion.InputName))
                {
                    if (motion.StopType == StopType.Up && Input.GetButtonUp(motion.InputName))
                    {
                        this.TryStopMotion(motion);
                        this.m_ToggleState [motion] = motion.StopType == StopType.Up && motion.IsActive;
                    }
                }
                else if (!motion.IsActive && motion.StartType == StartType.Down)
                {
                    this.TryStartMotion(motion);
                    this.m_ToggleState [motion] = (motion.StopType == StopType.Toggle || motion.StopType == StopType.Up) && motion.IsActive;
                }
                else if (motion.StopType == StopType.Toggle)
                {
                    this.TryStopMotion(motion);
                    this.m_ToggleState [motion] = motion.StopType == StopType.Toggle && motion.IsActive;
                    break;
                }
                if (motion.StartType == StartType.Press && Input.GetButton(motion.InputName))
                {
                    this.TryStartMotion(motion);
                }
            }
        }
Example #13
0
        private void UpdateInput()
        {
            this.m_ConsumeTurn = false;
            this.m_ConsumeZoom = false;
            if ((Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) && EventSystem.current != null && UnityTools.IsPointerOverUI())
            {
                this.m_GUIClick = true;
            }

            if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1))
            {
                this.m_GUIClick = false;
            }

            if (!this.m_GUIClick)
            {
                for (int i = 0; i < this.m_Presets.Length; i++)
                {
                    CameraSettings preset = this.m_Presets[i];
                    switch (preset.Activation)
                    {
                    case CameraSettings.ActivationType.Button:
                        if (Input.GetButtonDown(preset.InputName))
                        {
                            preset.IsActive = true;
                        }
                        if (Input.GetButtonUp(preset.InputName))
                        {
                            preset.IsActive = false;
                        }
                        break;

                    case CameraSettings.ActivationType.Toggle:
                        if (Input.GetButtonDown(preset.InputName))
                        {
                            preset.IsActive = !preset.IsActive;
                        }
                        break;
                    }
                }
            }
            for (int i = 0; i < this.m_Presets.Length; i++)
            {
                CameraSettings preset = this.m_Presets[i];
                if (preset.IsActive)
                {
                    if (this.m_ActivePreset != preset)
                    {
                        this.m_ActivePreset = preset;
                        ApplyCrosshair(this.m_ActivePreset.Crosshair);
                    }
                    break;
                }
            }

            if (this.m_ActivePreset.ConsumeInputOverUI && this.m_GUIClick)
            {
                this.m_ConsumeTurn = true;
                this.m_ConsumeZoom = true;
            }

            if (!this.m_ConsumeTurn && (string.IsNullOrEmpty(this.m_ActivePreset.TurnButton) || Input.GetButton(this.m_ActivePreset.TurnButton)))
            {
                float x = Input.GetAxis("Mouse X") * this.m_ActivePreset.TurnSpeed;
                float y = Input.GetAxis("Mouse Y") * this.m_ActivePreset.TurnSpeed;

                if (this.m_ActivePreset.VisibilityDelta == 0f || Mathf.Abs(x) > this.m_ActivePreset.VisibilityDelta || Mathf.Abs(y) > this.m_ActivePreset.VisibilityDelta)
                {
                    Cursor.lockState        = CursorLockMode.Locked;
                    Cursor.visible          = false;
                    this.m_RotatedLastFrame = true;
                }
                this.m_MouseX += x;
                this.m_MouseY -= y;


                if (Mathf.Abs(this.m_ActivePreset.YawLimit.x) + Mathf.Abs(this.m_ActivePreset.YawLimit.y) < 360)
                {
                    this.m_MouseX = ClampAngle(this.m_MouseX, this.m_ActivePreset.YawLimit.x, this.m_ActivePreset.YawLimit.y);
                }
                this.m_MouseY = ClampAngle(this.m_MouseY, this.m_ActivePreset.PitchLimit.x, this.m_ActivePreset.PitchLimit.y);
            }
            else if (this.m_RotatedLastFrame)
            {
                Cursor.lockState        = this.m_ActivePreset.CursorMode;
                Cursor.visible          = this.m_ActivePreset.CursorMode == CursorLockMode.Locked ? false : true;
                this.m_RotatedLastFrame = false;
            }

            if (!this.m_ConsumeZoom)
            {
                this.m_ActivePreset.Zoom -= Input.GetAxis("Mouse ScrollWheel") * this.m_ActivePreset.ZoomSpeed;
                this.m_ActivePreset.Zoom  = Mathf.Clamp(this.m_ActivePreset.Zoom, this.m_ActivePreset.ZoomLimit.x - this.m_ActivePreset.Distance, this.m_ActivePreset.ZoomLimit.y - this.m_ActivePreset.Distance);
            }
        }
Example #14
0
        protected virtual void CreateScript(string scriptName)
        {
            scriptName = scriptName.Replace(" ", "_");
            scriptName = scriptName.Replace("-", "_");
            string path = "Assets/" + scriptName + ".cs";

            if (File.Exists(path) == false)
            {
                using (StreamWriter outfile = new StreamWriter(path))
                {
                    MethodInfo[] methods = elementType.GetAllMethods();
                    methods = methods.Where(x => x.IsAbstract).ToArray();

                    outfile.WriteLine("using UnityEngine;");
                    outfile.WriteLine("using System.Collections;");
                    outfile.WriteLine("using " + elementType.Namespace + ";");
                    outfile.WriteLine("");
                    if (!typeof(Component).IsAssignableFrom(elementType))
                    {
                        outfile.WriteLine("[System.Serializable]");
                    }
                    outfile.WriteLine("public class " + scriptName + " : " + elementType.Name + "{");
                    for (int i = 0; i < methods.Length; i++)
                    {
                        MethodInfo      method          = methods[i];
                        ParameterInfo[] parameters      = method.GetParameters();
                        string          parameterString = string.Empty;
                        for (int j = 0; j < parameters.Length; j++)
                        {
                            string typeName      = parameters[j].ParameterType.Name;
                            string parameterName = string.Empty;
                            if (Char.IsLower(typeName, 0))
                            {
                                parameterName = "_" + typeName;
                            }
                            else
                            {
                                parameterName = char.ToLowerInvariant(typeName[0]) + typeName.Substring(1);
                            }
                            parameterString += ", " + typeName + " " + parameterName;
                        }

                        if (!string.IsNullOrEmpty(parameterString))
                        {
                            parameterString = parameterString.Substring(1);
                        }

                        outfile.WriteLine("\t" + (method.IsPublic?"public":"protected") + " override " + EditorTools.CovertToAliasString(method.ReturnType) + " " + method.Name + "(" + parameterString + ") {");

                        if (method.ReturnType == typeof(string))
                        {
                            outfile.WriteLine("\t\treturn string.Empty;");
                        }
                        else if (method.ReturnType == typeof(bool))
                        {
                            outfile.WriteLine("\t\treturn true;");
                        }
                        else if (method.ReturnType == typeof(Vector2))
                        {
                            outfile.WriteLine("\t\treturn Vector2.zero;");
                        }
                        else if (method.ReturnType == typeof(Vector3))
                        {
                            outfile.WriteLine("\t\treturn Vector3.zero;");
                        }
                        else if (!method.ReturnType.IsValueType || method.ReturnType.IsGenericType && method.ReturnType.GetGenericTypeDefinition() == typeof(Nullable <>))
                        {
                            outfile.WriteLine("\t\treturn null;");
                        }
                        else if (UnityTools.IsInteger(method.ReturnType))
                        {
                            outfile.WriteLine("\t\treturn 0;");
                        }
                        else if (UnityTools.IsFloat(method.ReturnType))
                        {
                            outfile.WriteLine("\t\treturn 0.0f;");
                        }
                        else if (method.ReturnType.IsEnum)
                        {
                            outfile.WriteLine("\t\treturn " + method.ReturnType.Name + "." + Enum.GetNames(method.ReturnType)[0] + ";");
                        }

                        outfile.WriteLine("\t}");
                        outfile.WriteLine("");
                    }
                    outfile.WriteLine("}");
                }
            }
            AssetDatabase.Refresh();
            EditorPrefs.SetString("NewScriptToCreate", scriptName);
            EditorPrefs.SetInt("AssetWindowID", GetInstanceID());
        }
 public override ActionStatus OnUpdate()
 {
     UnityTools.PlaySound(this.m_Clip, this.m_Volume);
     return(ActionStatus.Success);
 }