Exemplo n.º 1
0
    /// <summary>
    /// For meshes...
    /// </summary>
    /// <param name="assetLoaderContext"></param>
    public void OnModelLoaded(object sender, ImportedMeshEventArgs args)
    {
        if (args.Name != this.GetId())
        {
            return;
        }

        bool outlineWasHighlighted = outlineOnClick.Highlighted;

        if (Model != null)
        {
            outlineOnClick.UnHighlight();
            outlineOnClick.ClearRenderers();

            Model.SetActive(false);
            Destroy(Model);
        }

        Model = args.RootGameObject;

        Model.gameObject.transform.parent        = Visual.transform;
        Model.gameObject.transform.localPosition = Vector3.zero;
        Model.gameObject.transform.localRotation = Quaternion.identity;

        gameObject.GetComponent <BindParentToChild>().ChildToBind = Model;

        foreach (Renderer child in Model.GetComponentsInChildren <Renderer>(true))
        {
            child.gameObject.AddComponent <OnClickCollider>().Target = gameObject;
            child.gameObject.AddComponent <MeshCollider>();
        }

        aoRenderers.Clear();
        Colliders.Clear();
        aoRenderers.AddRange(Model.GetComponentsInChildren <Renderer>(true));
        Colliders.AddRange(Model.GetComponentsInChildren <MeshCollider>(true));
        outlineOnClick.InitRenderers(aoRenderers);
        outlineOnClick.InitMaterials();

        //transparent = false; //needs to be set before 1st call of SetVisibility after model loading
        SetVisibility(visibility, forceShaderChange: true);

        if (outlineWasHighlighted)
        {
            outlineOnClick.Highlight();
            if (SelectorMenu.Instance.ManuallySelected)
            {
                DisplayOffscreenIndicator(true);
            }
        }

        MeshImporter.Instance.OnMeshImported -= OnModelLoaded;
    }
Exemplo n.º 2
0
        private async void RobotModelLoaded()
        {
            RobotModel.RobotModelGameObject.transform.parent        = transform;
            RobotModel.RobotModelGameObject.transform.localPosition = Vector3.zero;
            RobotModel.RobotModelGameObject.transform.localRotation = Quaternion.identity;

            // retarget OnClickCollider target to receive OnClick events
            foreach (OnClickCollider onCLick in RobotModel.RobotModelGameObject.GetComponentsInChildren <OnClickCollider>(true))
            {
                onCLick.Target = gameObject;
            }

            RobotModel.SetActiveAllVisuals(true);

            bool outlineWasHighlighted = outlineOnClick.Highlighted;

            outlineOnClick.UnHighlight();
            outlineOnClick.ClearRenderers();
            RobotPlaceholder.SetActive(false);
            Destroy(RobotPlaceholder);

            robotColliders.Clear();
            robotRenderers.Clear();
            robotRenderers.AddRange(RobotModel.RobotModelGameObject.GetComponentsInChildren <Renderer>(true));
            robotColliders.AddRange(RobotModel.RobotModelGameObject.GetComponentsInChildren <Collider>(true));
            outlineOnClick.InitRenderers(robotRenderers);
            outlineOnClick.OutlineShaderType = OutlineOnClick.OutlineType.TwoPassShader;
            outlineOnClick.InitMaterials();

            SetOutlineSizeBasedOnScale();

            SetVisibility(visibility, forceShaderChange: true);
            UpdateColor();

            SetDefaultJoints();

            Target target = GetComponent <Target>();

            if (target != null)
            {
                target.ChangeTarget(RobotModel.RobotModelGameObject);
            }

            if (outlineWasHighlighted)
            {
                outlineOnClick.Highlight();
                if (SelectorMenu.Instance.ManuallySelected)
                {
                    DisplayOffscreenIndicator(true);
                }
            }

            // Show or hide the robot based on global settings of displaying ActionObjects.
            // Needs to be called additionally, because when global setting is called, robot model is not loaded and only its placeholder is active.

            /*if (robotVisible) {
             *  Show();
             * } else {
             *  Hide();
             * }
             */
            if (GameManager.Instance.GetGameState() != GameManager.GameStateEnum.PackageRunning || GameManager.Instance.GetGameState() != GameManager.GameStateEnum.LoadingPackage)
            {
                await WebsocketManager.Instance.RegisterForRobotEvent(GetId(), true, RegisterForRobotEventRequestArgs.WhatEnum.Joints);
            }
        }