Beispiel #1
0
    public void Update()
    {
        if (tile.IsProxy)
        {
            transform.position = GraphicsUnity.CubeWorldVector3ToVector3(tile.position);
        }

        TilePosition tilePos = GraphicsUnity.Vector3ToTilePosition(transform.position);

        if (gameManagerUnity.world.tileManager.IsValidTile(tilePos))
        {
            Tile tileInfo = gameManagerUnity.world.tileManager.GetTile(tilePos);

            if (tile.Invalidated)
            {
                currentAmbientLuminance       = tileInfo.AmbientLuminance;
                currentLightSourceLuminance   = tileInfo.LightSourceLuminance;
                currentGlobalAmbientLuminance = gameManagerUnity.world.dayCycleManager.ambientLightLuminance;

                UpdateMesh();

                tile.Invalidated = false;
            }
            else if (tileInfo.AmbientLuminance != currentAmbientLuminance ||
                     tileInfo.LightSourceLuminance != currentLightSourceLuminance ||
                     gameManagerUnity.world.dayCycleManager.ambientLightLuminance != currentGlobalAmbientLuminance)
            {
                currentAmbientLuminance       = tileInfo.AmbientLuminance;
                currentLightSourceLuminance   = tileInfo.LightSourceLuminance;
                currentGlobalAmbientLuminance = gameManagerUnity.world.dayCycleManager.ambientLightLuminance;

                UpdateLight();
            }
        }
    }
    public void CreateObject(CWObject cwobject)
    {
        GameObject go = CreateGameObjectFromObject(cwobject);

        go.transform.position = GraphicsUnity.CubeWorldVector3ToVector3(cwobject.position);
        createdGO[cwobject]   = go;
    }
Beispiel #3
0
 public void PlaySound(string soundId, CWObject fromObject)
 {
     if (sounds.ContainsKey(soundId))
     {
         PlayAudioClip(soundId, GraphicsUnity.CubeWorldVector3ToVector3(fromObject.position), 1.0f);
     }
     else
     {
         Debug.Log("Unknown sound: " + soundId);
     }
 }
Beispiel #4
0
 public void PlayEffect(string effectId, CubeWorld.Utils.Vector3 position)
 {
     if (effects.ContainsKey(effectId))
     {
         ((GameObject)GameObject.Instantiate(effects[effectId], GraphicsUnity.CubeWorldVector3ToVector3(position), Quaternion.identity)).transform.parent = goContainer.transform;
     }
     else
     {
         Debug.Log("Unknown effect: " + effectId);
     }
 }
Beispiel #5
0
    private void UpdatePlayerPosition()
    {
        if (firstUpdate ||
            transform.position != GraphicsUnity.CubeWorldVector3ToVector3(avatar.position))
        {
            firstUpdate = false;

            transform.position = GraphicsUnity.CubeWorldVector3ToVector3(avatar.position);
            gameManagerUnity.sectorManagerUnity.UpdateVisibleSectors();
        }
    }
Beispiel #6
0
    private void UpdateAvatarPosition()
    {
        if (firstUpdate ||
            transform.position != GraphicsUnity.CubeWorldVector3ToVector3(avatar.position) ||
            lastRotation != GraphicsUnity.CubeWorldVector3ToVector3(avatar.rotation))
        {
            firstUpdate             = false;
            transform.position      = GraphicsUnity.CubeWorldVector3ToVector3(avatar.position);
            transform.localRotation = Quaternion.Euler(0, avatar.rotation.y, 0);

            lastRotation = GraphicsUnity.CubeWorldVector3ToVector3(avatar.rotation);
        }
    }
Beispiel #7
0
    void Start()
    {
        currentLightSourceLuminance = Tile.MAX_LUMINANCE - 1;
        currentAmbientLuminance     = Tile.MAX_LUMINANCE - 1;

        transform.position      = GraphicsUnity.CubeWorldVector3ToVector3(item.position);
        transform.localScale    = new Vector3(ITEM_TILE_SCALE, ITEM_TILE_SCALE, ITEM_TILE_SCALE);
        transform.localRotation = Quaternion.Euler(45.0f, 0.0f, 0.0f);

        TilePosition tilePos = GraphicsUnity.Vector3ToTilePosition(GraphicsUnity.CubeWorldVector3ToVector3(item.position));

        if (gameManagerUnity.world.tileManager.IsValidTile(tilePos))
        {
            Tile tileInfo = gameManagerUnity.world.tileManager.GetTile(tilePos);

            currentAmbientLuminance       = tileInfo.AmbientLuminance;
            currentLightSourceLuminance   = tileInfo.LightSourceLuminance;
            currentGlobalAmbientLuminance = gameManagerUnity.world.dayCycleManager.ambientLightLuminance;
        }

        UpdateMesh();
    }
Beispiel #8
0
    public void Update()
    {
        transform.position      = GraphicsUnity.CubeWorldVector3ToVector3(item.position);
        transform.localRotation = Quaternion.Euler(0.0f, ROTATION_SPEED * Time.deltaTime, 0.0f) * transform.localRotation;

        TilePosition tilePos = GraphicsUnity.Vector3ToTilePosition(transform.position);

        if (gameManagerUnity.world.tileManager.IsValidTile(tilePos))
        {
            Tile tileInfo = gameManagerUnity.world.tileManager.GetTile(tilePos);

            if (tileInfo.AmbientLuminance != currentAmbientLuminance ||
                tileInfo.LightSourceLuminance != currentLightSourceLuminance ||
                gameManagerUnity.world.dayCycleManager.ambientLightLuminance != currentGlobalAmbientLuminance)
            {
                currentAmbientLuminance       = tileInfo.AmbientLuminance;
                currentLightSourceLuminance   = tileInfo.LightSourceLuminance;
                currentGlobalAmbientLuminance = gameManagerUnity.world.dayCycleManager.ambientLightLuminance;

                UpdateLight();
            }
        }
    }
Beispiel #9
0
    public void PlayEffect(string effectId, CWObject fromObject)
    {
        if (effects.ContainsKey(effectId))
        {
            ((GameObject)GameObject.Instantiate(effects[effectId], GraphicsUnity.CubeWorldVector3ToVector3(fromObject.position), Quaternion.identity)).transform.parent = goContainer.transform;
        }
        else if (effectsComponents.ContainsKey(effectId))
        {
            GameObject go = gameManagerUnity.objectsManagerUnity.FindGameObject(fromObject);

            if (go)
            {
                go.AddComponent(effectsComponents[effectId]);
            }
            else
            {
                Debug.Log("Effect " + effectId + " found but GameObject to add sound to not found");
            }
        }
        else
        {
            Debug.Log("Unknown effect: " + effectId);
        }
    }
    static private Mesh GetBaseMeshForDefinition(CWVisualDefinition visualDefinition)
    {
        Mesh mesh;

        if (cacheBaseMeshes.TryGetValue(visualDefinition, out mesh) == false)
        {
            float   pixelScale = 1.0f / (float)visualDefinition.scale;
            Vector3 pivot      = GraphicsUnity.CubeWorldVector3ToVector3(visualDefinition.pivot);

            mesh = new Mesh();
            Texture2D[] images = LoadImages(visualDefinition);

            colors.Clear();
            vertices.Clear();
            normals.Clear();
            trianglesNormal.Clear();

            int index = 0;

            TilePosition mainNormal;
            TilePosition d1Normal;
            TilePosition d2Normal;

            switch (visualDefinition.plane)
            {
            case "x":
                mainNormal = new TilePosition(1, 0, 0);
                d1Normal   = new TilePosition(0, 0, 1);
                d2Normal   = new TilePosition(0, 1, 0);
                break;

            case "y":
                mainNormal = new TilePosition(0, 1, 0);
                d1Normal   = new TilePosition(1, 0, 0);
                d2Normal   = new TilePosition(0, 0, 1);
                break;

            case "z":
            default:
                mainNormal = new TilePosition(0, 0, 1);
                d1Normal   = new TilePosition(1, 0, 0);
                d2Normal   = new TilePosition(0, 1, 0);
                break;
            }

            float halfDmain = images.Length / 2.0f;
            float halfD1    = images[0].width / 2.0f;
            float halfD2    = images[0].height / 2.0f;

            for (int dmain = 0; dmain < images.Length; dmain++)
            {
                Texture2D image = images[dmain];

                for (int d1 = 0; d1 < image.width; d1++)
                {
                    for (int d2 = 0; d2 < image.height; d2++)
                    {
                        Color colorPixel = image.GetPixel(d1, d2);

                        if (colorPixel.a == 0.0f)
                        {
                            continue;
                        }

                        Vector3 offset = new Vector3();

                        offset += GraphicsUnity.TilePositionToVector3(d1Normal) * (((d1Normal * d1).GetSumComponents() - halfD1) - halfD1 * pivot.x);
                        offset += GraphicsUnity.TilePositionToVector3(d2Normal) * (((d2Normal * d2).GetSumComponents() - halfD2) - halfD2 * pivot.y);
                        offset += GraphicsUnity.TilePositionToVector3(mainNormal) * (((mainNormal * dmain).GetSumComponents() - halfDmain) - halfDmain * pivot.z);

                        offset += new Vector3(CubeWorld.Utils.Graphics.HALF_TILE_SIZE, CubeWorld.Utils.Graphics.HALF_TILE_SIZE, CubeWorld.Utils.Graphics.HALF_TILE_SIZE);

                        offset *= pixelScale;

                        for (int face = 0; face < 6; face++)
                        {
                            TilePosition normalInt = MeshUtils.faceNormalsTile[face];

                            int near1    = d1 + (d1Normal * normalInt).GetSumComponents();
                            int near2    = d2 + (d2Normal * normalInt).GetSumComponents();
                            int nearMain = dmain + (mainNormal * normalInt).GetSumComponents();

                            if (near1 >= 0 && near2 >= 0 && nearMain >= 0 &&
                                near1 < image.width && near2 < image.height && nearMain < images.Length)
                            {
                                if (images[nearMain].GetPixel(near1, near2).a == 1.0f)
                                {
                                    continue;
                                }
                            }

                            Color faceColor = colorPixel * MeshUtils.faceBright[face];

                            Vector3 faceNormal = MeshUtils.faceNormals[face];

                            for (int i = 0; i < 4; i++)
                            {
                                vertices.Add(MeshUtils.faceVectorsNormal[(face << 2) + i] * pixelScale + offset);
                                normals.Add(faceNormal);
                                colors.Add(faceColor);
                            }

                            trianglesNormal.Add(index + 0);
                            trianglesNormal.Add(index + 1);
                            trianglesNormal.Add(index + 2);

                            trianglesNormal.Add(index + 2);
                            trianglesNormal.Add(index + 3);
                            trianglesNormal.Add(index + 0);

                            index += 4;
                        }
                    }
                }
            }

            mesh.vertices  = vertices.ToArray();
            mesh.colors    = colors.ToArray();
            mesh.normals   = normals.ToArray();
            mesh.triangles = trianglesNormal.ToArray();

            cacheBaseMeshes[visualDefinition] = mesh;
        }

        return(mesh);
    }
Beispiel #11
0
    public virtual void Start()
    {
        Vector3 sizeInTiles = GraphicsUnity.TilePositionToVector3(((AvatarDefinition)avatar.definition).sizeInTiles);

        //float halfX = sizeInTiles.x / 2.0f;
        float halfY = sizeInTiles.y / 2.0f;

        //float halfZ = sizeInTiles.z / 2.0f;

        body                         = new GameObject();
        body.name                    = "Body";
        body.transform.parent        = transform;
        body.transform.localPosition = new Vector3(
            0,
            halfY - CubeWorld.Utils.Graphics.HALF_TILE_SIZE,
            0);

        body.transform.localRotation = Quaternion.identity;
        body.transform.localScale    = new Vector3(1, 1, 1);

        foreach (AvatarPartDefinition avatarPart in ((AvatarDefinition)avatar.definition).parts)
        {
            Vector3 offset = new Vector3(
                avatarPart.offset.x,
                avatarPart.offset.y,
                avatarPart.offset.z);

            Vector3 rotation = GraphicsUnity.CubeWorldVector3ToVector3(avatarPart.rotation);

            GameObject goPart = new GameObject();
            goPart.name                    = avatarPart.id;
            goPart.transform.parent        = body.transform;
            goPart.transform.localPosition = offset;
            goPart.transform.localRotation = Quaternion.Euler(rotation);
            goPart.transform.localScale    = new Vector3(1, 1, 1);

            VisualDefinitionRenderUnity visualDefinitionRenderer = goPart.AddComponent <VisualDefinitionRenderUnity>();
            visualDefinitionRenderer.world            = gameManagerUnity.world;
            visualDefinitionRenderer.material         = gameManagerUnity.materialItems;
            visualDefinitionRenderer.visualDefinition = avatarPart.visualDefinition;

            switch (avatarPart.id)
            {
            case "head":
                heads.Add(goPart);
                break;

            case "arm":
                arms.Add(goPart);
                break;

            case "leg":
                legs.Add(goPart);
                break;
            }

            goPart.GetComponent <Renderer>().enabled = bodyRenderEnabled;

            parts.Add(goPart);
        }
    }