void OnShapeAttached(DecentralandEntity entity)
        {
            if (entity == null)
            {
                return;
            }

            entity.EnsureMeshGameObject(componentName + " mesh");

            if (currentMesh == null)
            {
                currentMesh = GenerateGeometry();
            }

            MeshFilter   meshFilter   = entity.meshRootGameObject.AddComponent <MeshFilter>();
            MeshRenderer meshRenderer = entity.meshRootGameObject.AddComponent <MeshRenderer>();

            entity.meshesInfo.renderers    = new Renderer[] { meshRenderer };
            entity.meshesInfo.currentShape = this;

            meshFilter.sharedMesh = currentMesh;

            if (Configuration.ParcelSettings.VISUAL_LOADING_ENABLED)
            {
                MaterialTransitionController transition = entity.meshRootGameObject.AddComponent <MaterialTransitionController>();
                Material finalMaterial = Utils.EnsureResourcesMaterial("Materials/Default");
                transition.delay         = 0;
                transition.useHologram   = false;
                transition.fadeThickness = 20;
                transition.OnDidFinishLoading(finalMaterial);

                transition.onFinishedLoading += () => { entity.OnShapeUpdated?.Invoke(entity); };
            }
            else
            {
                meshRenderer.sharedMaterial = Utils.EnsureResourcesMaterial("Materials/Default");
            }

            visibilityDirty = true;
            collisionsDirty = true;
            UpdateRenderer(entity);

            entity.OnShapeUpdated?.Invoke(entity);
        }
Example #2
0
    public static void ApplyToLoadedObject(GameObject meshContainer, bool useHologram = true, float fadeThickness = 20, float delay = 0)
    {
        Renderer[] renderers = meshContainer.GetComponentsInChildren <Renderer>();

        for (int i = 0; i < renderers.Length; i++)
        {
            Renderer r = renderers[i];

            if (r.gameObject.GetComponent <MaterialTransitionController>() != null)
            {
                continue;
            }

            MaterialTransitionController transition = r.gameObject.AddComponent <MaterialTransitionController>();
            Material finalMaterial = r.sharedMaterial;
            transition.delay         = delay;
            transition.useHologram   = useHologram;
            transition.fadeThickness = fadeThickness;
            transition.OnDidFinishLoading(finalMaterial);
        }
    }