Beispiel #1
0
    //=====================================================

    public static Object GetModel(eCollectable type, int index)
    {
        Init();

        var path = GetModelPath(type, index);

        if (string.IsNullOrEmpty(path) == false)
        {
            //Debug.Log( "Model path: " + path );
            var model = Resources.Load(path);

            if (model != null)
            {
                return(model);
            }
        }

        Debug.Log("Collectable not found in resources: " + " [" + index + "]");
        return(null);
    }
Beispiel #2
0
    //=====================================================

    private static string GetModelPath(eCollectable type, int index)
    {
        var path = new StringBuilder();

        path.Append("Prefabs/Collectables/");

        switch (type)
        {
        case eCollectable.GEM:
            SetModelPathLocation(ref path, _gems, "Gem", index);
            break;

        case eCollectable.RED_GEM:
            SetModelPathLocation(ref path, _redGems, "RedGem", index);
            break;

        case eCollectable.KEY:
            SetModelPathLocation(ref path, _keys, "Key", index);
            break;
        }

        return(string.IsNullOrEmpty(path.ToString()) == false ? path.ToString() : string.Empty);
    }
Beispiel #3
0
    //=====================================================

    private static void AddCollectableOfType(eCollectable type, ePuzzleKeyType keyType = ePuzzleKeyType.NULL)
    {
        var    pfb = ResourcesCollectables.GetPrefab();
        Object mdl = null;

        mdl = ResourcesCollectables.GetModel(type, (type == eCollectable.KEY) ? (int)keyType : 0);

        if (pfb == null)
        {
            return;
        }

        // Create containers for collectables if they don't already exist
        var container = GameObject.Find("Collectables");
        var gems      = GameObject.Find("Gems");
        var redGems   = GameObject.Find("RedGems");
        var keys      = GameObject.Find("Keys");

        if (container == null)
        {
            container = CreateContainer("Collectables");

            if (gems == null)
            {
                gems = CreateContainer("Gems", container);
            }

            if (redGems == null)
            {
                redGems = CreateContainer("RedGems", container);
            }

            if (keys == null)
            {
                keys = CreateContainer("Keys", container);
            }
        }

        var prefab = PrefabUtility.InstantiatePrefab(pfb) as GameObject;

        if (prefab == null)
        {
            return;
        }

        var script = prefab.GetComponent <Collectable>();

        switch (type)
        {
        case eCollectable.GEM:
            prefab.name             = "Gem";
            prefab.transform.parent = gems.transform;
            break;

        case eCollectable.RED_GEM:
            prefab.name             = "RedGem";
            prefab.transform.parent = redGems.transform;
            break;

        case eCollectable.KEY:
            switch (keyType)
            {
            default:
                prefab.name = "Key";
                break;

            case ePuzzleKeyType.KEY_GEM_RED:
                prefab.name = "Red Gem Key";
                break;

            case ePuzzleKeyType.KEY_GEM_100:
                prefab.name = "100 Gem Key";
                break;
            }

            prefab.transform.parent = keys.transform;
            break;
        }

        if (script != null)
        {
            script.Type = type;

            if (mdl != null)
            {
                var model = PrefabUtility.InstantiatePrefab(mdl) as GameObject;

                script.Init(model);

                if (type == eCollectable.KEY)
                {
                    switch (keyType)
                    {
                    default:
                        script.KeyId = ePuzzleKeyType.KEY_001;
                        break;

                    case ePuzzleKeyType.KEY_GEM_RED:
                        script.KeyId = ePuzzleKeyType.KEY_GEM_RED;
                        break;

                    case ePuzzleKeyType.KEY_GEM_100:
                        script.KeyId = ePuzzleKeyType.KEY_GEM_100;
                        break;
                    }
                }

                script.Refresh();
            }
        }

        PositionObjectAndSelect(prefab);
    }