Example #1
0
    void Start()
    {
        if (m_TargetView == null)
        {
            m_TargetView = GetComponent <CoherentUIGTView>();

            if (m_TargetView == null)
            {
                Debug.LogWarning("[Coherent GT] ViewEvents : Target view " +
                                 "component is not attached. Events won't be triggered.");
                return;
            }
        }

        m_TargetView.Listener.AudioDataReceived          += AudioDataReceivedInvoke;
        m_TargetView.Listener.AudioStreamClosed          += AudioStreamClosedInvoke;
        m_TargetView.Listener.AudioStreamCreated         += AudioStreamCreatedInvoke;
        m_TargetView.Listener.AudioStreamEnded           += AudioStreamEndedInvoke;
        m_TargetView.Listener.AudioStreamPause           += AudioStreamPauseInvoke;
        m_TargetView.Listener.AudioStreamPlay            += AudioStreamPlayInvoke;
        m_TargetView.Listener.BindingsReleased           += BindingsReleasedInvoke;
        m_TargetView.Listener.Callback                   += CallbackInvoke;
        m_TargetView.Listener.CaretRectChanged           += CaretRectChangedInvoke;
        m_TargetView.Listener.CursorChanged              += CursorChangedInvoke;
        m_TargetView.Listener.FailLoad                   += FailLoadInvoke;
        m_TargetView.Listener.FinishLoad                 += FinishLoadInvoke;
        m_TargetView.Listener.IMEShouldCancelComposition += IMEShouldCancelCompositionInvoke;
        m_TargetView.Listener.NavigateTo                 += NavigateToInvoke;
        m_TargetView.Listener.PerformanceAudit           += PerformanceAuditInvoke;
        m_TargetView.Listener.ReadyForBindings           += ReadyForBindingsInvoke;
        m_TargetView.Listener.StartLoading               += StartLoadingInvoke;
        m_TargetView.Listener.TextInputTypeChanged       += TextInputTypeChangedInvoke;
        m_TargetView.Listener.ViewCreated                += ViewCreatedInvoke;
        m_TargetView.Listener.ViewDestroyed              += ViewDestroyedInvoke;
    }
    static void OnPostprocessAllAssets(
        string[] importedAssets,
        string[] deletedAssets,
        string[] movedAssets,
        string[] movedFromAssetPaths)
    {
        CoherentUIGTSystem system = CoherentUIGTSystem.CurrentUISystem;

        if (system == null)
        {
            return;
        }

        for (int i = 0; i < system.UIViews.Count; i++)
        {
            CoherentUIGTView view = system.UIViews[i];

            if (!view.AutoRefresh)
            {
                continue;
            }

            if (CheckResourcesAndReloadView(view, importedAssets) ||
                CheckResourcesAndReloadView(view, deletedAssets) ||
                CheckResourcesAndReloadView(view, movedFromAssetPaths))
            {
                continue;
            }
        }
    }
Example #3
0
    private void CalculateScaledMouseCoordinates(MouseEventData data,
                                                 CoherentUIGTView view,
                                                 bool invertY)
    {
        float camWidth;
        float camHeight;

        var isOnSurface = (view.RenderingCamera == null);

        if (!isOnSurface)
        {
            Camera cameraComponent = view.RenderingCamera;
            camWidth  = cameraComponent.pixelWidth;
            camHeight = cameraComponent.pixelHeight;
        }
        else
        {
            camWidth  = view.Width;
            camHeight = view.Height;
        }

        float factorX = view.WidthToCamWidthRatio(camWidth);
        float factorY = view.HeightToCamHeightRatio(camHeight);

        float y = (invertY) ? (camHeight - data.Y) : data.Y;

        data.X = (int)(data.X * factorX);
        data.Y = (int)(y * factorY);
    }
Example #4
0
    void SetClickThroughPosition(CoherentUIGTView view)
    {
        if (view.View == null)
        {
            return;
        }

        bool isOnSurface = (view.RenderingCamera == null);

        if (!isOnSurface)
        {
            var normX = (Input.mousePosition.x / view.Width);
            var normY = (1 - Input.mousePosition.y / view.Height);

            normX = normX *
                    view.WidthToCamWidthRatio(view.RenderingCamera.pixelWidth);

            normY = 1 - ((1 - normY) *
                         view.HeightToCamHeightRatio(view.RenderingCamera.pixelHeight));

            if (normX >= 0 && normX <= 1 && normY >= 0 && normY <= 1)
            {
                view.View.SetMouseNormalizedPosition(normX, normY);
            }
        }
        else
        {
            // TODO: Implement raycasting and coordinate transform
            // for click through
        }
    }
        internal UnityGTResourceHandlerDecorator(ResourceHandler handler,
                                                 CoherentUIGTView viewComponent)
        {
            m_Handler       = handler;
            m_ViewComponent = viewComponent;

            m_ViewComponent.Listener.NavigateTo += OnNavigateTo;
        }
 public void OnEnable()
 {
     m_Target = target as CoherentUIGTView;
     m_Fields = CoherentUIGTExposeProperties.GetProperties(m_Target);
     m_ButtonContentEnabled = new GUIContent("Open in Coherent Editor",
                                             "Edit this page in Coherent Editor");
     m_ButtonContentDisabled = new GUIContent("Open in Coherent Editor",
                                              "Only local coui resources can be edited in Coherent Editor");
 }
    static bool CheckResourcesAndReloadView(CoherentUIGTView view, string[] changedFiles)
    {
        if (view.CheckResourcesUsedByView(changedFiles))
        {
            view.Reload();
            return(true);
        }

        return(false);
    }
Example #8
0
    // Use this for initialization
    void Start()
    {
        m_View = GetComponent <CoherentUIGTView>();

        m_GameOptions = new GameOptionsGT {
            Backend = "Unity3D",
            Width   = 1024,
            Height  = 768,
            NetPort = 17777,
        };
    }
Example #9
0
    void Start()
    {
        ViewComponent = GetComponent <CoherentUIGTView>();

        if (ViewComponent)
        {
            ViewComponent.Listener.ReadyForBindings += this.RegisterBindings;
        }

        ViewComponent.ReceivesInput = true;
    }
Example #10
0
    // Use this for initialization
    void Start()
    {
        m_View = GetComponent <CoherentUIGTView>();
        m_View.Listener.ReadyForBindings += HandleReadyForBindings;

        m_GameOptions = new GameOptionsGT {
            Backend = "Unity3D",
            Width   = 1024,
            Height  = 768,
            NetPort = 17777,
        };
    }
Example #11
0
    // Use this for initialization
    void Start()
    {
        CoherentUIGTView view = GetComponent <CoherentUIGTView>();

        if (view == null)
        {
            Debug.LogError("The GameObject must have a CoherentGTView component!");
            return;
        }
        // This is the only view in the sample and we'll always forward the input to it
        view.ReceivesInput = true;
    }
    void Awake()
    {
        m_RectTransform = GetComponent <RectTransform>();
        m_ViewComponent = GetComponent <CoherentUIGTView>();

        m_ViewComponent.ClickToFocus        = false;
        m_ViewComponent.UseCameraDimensions = false;

        Canvas[] canvases   = GetComponentsInParent <Canvas>();
        Canvas   rootCanvas = canvases[canvases.Length - 1];

        if (rootCanvas.renderMode != RenderMode.ScreenSpaceOverlay)
        {
            m_UICamera = rootCanvas.worldCamera;
        }
    }
Example #13
0
    void Start()
    {
        if (m_TargetView == null)
        {
            m_TargetView = GetComponent <CoherentUIGTView>();

            if (m_TargetView == null)
            {
                Debug.LogWarning("[Coherent GT] CustomEvents : Target view " +
                                 "component is not attached. Events won't " +
                                 "be triggered.");
                return;
            }
        }

        m_TargetView.Listener.ReadyForBindings += OnReadyForBindings;
    }
Example #14
0
    void Awake()
    {
        m_ViewComponent     = GetComponent <CoherentUIGTView>();
        m_RawImageComponent = GetComponent <RawImage>();

        //Create a camera component and render texture for the View to draw on
        Camera cameraComponent = GetComponent <Camera>();

        cameraComponent.clearFlags      = CameraClearFlags.SolidColor;
        cameraComponent.backgroundColor = new Color(0, 0, 0, 0);
        cameraComponent.cullingMask     = 0;
        RenderTexture renderTexture = new RenderTexture(m_ViewComponent.Width,
                                                        m_ViewComponent.Height,
                                                        1, RenderTextureFormat.ARGB32,
                                                        RenderTextureReadWrite.Default);

        renderTexture.name            = "CoherentViewRenderTexture";
        cameraComponent.targetTexture = renderTexture;
        m_RawImageComponent.texture   = renderTexture;
    }
Example #15
0
 void Awake()
 {
     viewComponent = GetComponent <CoherentUIGTView>();
 }
Example #16
0
    void Update()
    {
        if (m_UISystem.HasFocusedView)
        {
            return;
        }

        // Reset input processing for all views
        for (int i = 0; i < m_UISystem.UIViews.Count; i++)
        {
            if (!m_UISystem.UIViews[i].ClickToFocus)
            {
                m_UISystem.UIViews[i].ReceivesInput = false;
            }
        }

        // Activate input processing for the view below the mouse cursor
        RaycastHit hitInfo;

        if (isFocused)
        {
            //CoherentUIGTSystem.CurrentUISystem.cursorPosition = GetCursorPosition;

            if (Physics.Raycast(
                    Camera.main.transform.position,
                    GetCursorPosition - Camera.main.transform.position,
                    out hitInfo,
                    20.0f,
                    Physics.DefaultRaycastLayers
                    ))
            {
                CoherentUIGTView viewComponent = null;

                Transform hitTransform = hitInfo.collider.transform;

                //added
                //viewComponent.SetMousePosition(
                //(int)(hitInfo.textureCoord.x * viewComponent.Width),
                //(int)(hitInfo.textureCoord.y * viewComponent.Height));

                for (int i = 0; i < m_UISystem.UIViews.Count; i++)
                {
                    if (m_UISystem.UIViews[i].transform.IsChildOf(hitTransform))
                    {
                        viewComponent = m_UISystem.UIViews[i];
                    }
                }

                if (viewComponent != null && !viewComponent.ClickToFocus)
                {
                    viewComponent.ReceivesInput = true;
                    viewComponent.SetMousePosition(
                        (int)(hitInfo.textureCoord.x * viewComponent.Width),
                        (int)(hitInfo.textureCoord.y * viewComponent.Height), flip);

                    /*viewComponent.SetMousePosition(
                     *  (int)(hitInfo.textureCoord.x * viewComponent.Width*invW),
                     *  (int)(hitInfo.textureCoord.y * viewComponent.Height*invH));
                     */
                    /*
                     * int hitInfox;
                     * int hitInfoy;
                     * if (invertedWidth)
                     * {
                     * hitInfox = (int)(viewComponent.Width - (hitInfo.textureCoord.x * viewComponent.Width));
                     * }
                     * else
                     * {
                     * hitInfox = (int)hitInfo.textureCoord.x * viewComponent.Width;
                     * }
                     *
                     * if (invertedHeight)
                     * {
                     * hitInfoy = (int)(viewComponent.Height - (hitInfo.textureCoord.y * viewComponent.Height));
                     * }
                     * else
                     * {
                     * hitInfoy = (int)hitInfo.textureCoord.y * viewComponent.Height;
                     * }
                     *
                     * viewComponent.SetMousePosition(
                     * hitInfox,
                     * hitInfoy, "y");
                     */

                    viewComponent.ReceivesInput = true;
                }
            }
        }
    }
Example #17
0
    private void TrackInputFocus()
    {
        if (m_MainCamera == null)
        {
            m_MainCamera = Camera.main;
            if (m_MainCamera == null)
            {
                return;
            }
        }

        for (int i = 0; i < m_Views.Count; i++)
        {
            SetClickThroughPosition(m_Views[i]);
        }

        bool isClick = Input.GetMouseButtonDown(0);

        if (!m_SystemHasFocusedView &&
            !isClick && !m_HasClickOnCameraView)
        {
            // Do nothing if the left mouse button isn't clicked
            // (and there is no focused view; if there is, we need to track the mouse)
            return;
        }

        //if (m_IsMouseOnView)
        if (m_IsGazerOnView)
        {
            if (m_HasClickOnCameraView)
            {
                bool  hasFocusedView       = false;
                float lastViewDepth        = float.MinValue;
                int   lastEnabledViewIndex = -1;
                // Reset input processing for all views except for the clicked view
                for (int i = 0; i < m_Views.Count; i++)
                {
                    if (!m_Views [i].ClickToFocus)
                    {
                        continue;
                    }

                    if (m_Views[i].RenderingCamera &&
                        m_Views[i].View.IsMouseOnView() &&
                        m_Views[i].RenderingCamera.depth > lastViewDepth)
                    {
                        if (hasFocusedView)
                        {
                            m_Views[lastEnabledViewIndex].ReceivesInput = false;
                        }

                        m_Views[i].ReceivesInput = true;
                        hasFocusedView           = true;
                        lastViewDepth            = m_Views[i].RenderingCamera.depth;
                        lastEnabledViewIndex     = i;
                    }
                    else
                    {
                        m_Views[i].ReceivesInput = false;
                    }
                }

                SetViewFocused(hasFocusedView);
            }
        }

        m_HasClickOnCameraView = isClick && m_IsGazerOnView;

        if (m_IsGazerOnView)
        {
            return;
        }

        // Activate input processing for the view below the mouse cursor
        RaycastHit hitInfo;

        if (Physics.Raycast(m_MainCamera.ScreenPointToRay(Input.mousePosition), out hitInfo))

        /* if (Physics.Raycast(
         *   Camera.main.transform.position,
         *   cursorPosition - Camera.main.transform.position,
         *   out hitInfo,
         *   20.0f,
         *   Physics.DefaultRaycastLayers
         *   ))*/
        {
            CoherentUIGTView viewComponent = null;

            Transform hitTransform = hitInfo.collider.transform;

            for (int i = 0; i < m_Views.Count; i++)
            {
                if (m_Views[i].transform.IsChildOf(hitTransform))
                {
                    viewComponent = m_Views[i];
                }
            }

            if (viewComponent != null && viewComponent.ClickToFocus)
            {
                if (isClick)
                {
                    // Reset input processing for all views
                    for (int i = 0; i < m_Views.Count; i++)
                    {
                        m_Views[i].ReceivesInput = false;
                    }
                    // Set input to the clicked view
                    viewComponent.ReceivesInput = true;
                    Debug.Log("In viewComponent.ReceivesInput = true;");
                    SetViewFocused(true);
                }

                viewComponent.SetMousePosition(
                    (int)(hitInfo.textureCoord.x * viewComponent.Width),
                    (int)(hitInfo.textureCoord.y * viewComponent.Height));

                return;
            }
        }

        // If neither the HUD nor an object was clicked, clear the focus
        if (m_SystemHasFocusedView && isClick)
        {
            // Reset input processing for all views
            for (int i = 0; i < m_Views.Count; i++)
            {
                m_Views[i].ReceivesInput = false;
            }
            SetViewFocused(false);
        }
    }
Example #18
0
 internal bool RemoveView(CoherentUIGTView view)
 {
     return(m_Views.Remove(view));
 }
Example #19
0
 internal void AddView(CoherentUIGTView view)
 {
     m_Views.Add(view);
 }
Example #20
0
 void Start()
 {
     m_View = GetComponent <CoherentUIGTView>();
     m_View.Listener.ReadyForBindings += HandleReadyForBindings;
 }
Example #21
0
 public UnityGTViewListener(CoherentUIGTView component, int width, int height)
 {
     m_ViewComponent = component;
 }