Example #1
0
    // Create a player object
    public GameObject createPlayer()
    {
        GameObject pref = ABU.LoadAsset <GameObject> ("core", "Player");
        GameObject inst = Instantiate <GameObject> (pref);

        _player = inst;
        if (playerData != null)
        {
            RegisteredObject ro = _player.GetComponent <RegisteredObject> ();
            ro.Sow(playerData);
        }
        HUDManager.GetInstance().SetSubject(_player.GetComponent <Entity>());

        switch (playerSpawnType)
        {
        case SPAWN_AT_DOOR:
            //find destination and spawn there
            SceneDoor door = SceneDoor.getDoor(prevScene);
            door.StartTransitionIn(inst);
            break;

        case SPAWN_AT_SVPNT:
            CameraManager.scene_cam.setTarget(inst.transform);
            //TODO spawn at savepoint ?
            break;

        default:
            throw new ArgumentException("Invalid spawn type code: " + playerSpawnType);
        }

        return(inst);
    }
Example #2
0
    // For respawning a prefab in the sow cycle
    public static GameObject Recreate(string prefabPath, string prefabName, string registeredID, string parentID)
    {
        if (prefabPath == "" || prefabName == "")
        {
            throw new ArgumentException("Cannot create prefab with empty path and/or name");
        }

        GameObject go = ABU.LoadAsset <GameObject> (prefabPath, prefabName);
        GameObject inst;

        if (parentID == "")
        {
            inst = Instantiate(go, Vector3.zero, Quaternion.identity);
        }
        else
        {
            RegisteredObject parent = RegisteredObject.FindObject(parentID);
            if (parent == null)
            {
                throw new ArgumentException("[RO] " + parentID + " does not exist!");
            }
            inst = Instantiate(go, Vector3.zero, Quaternion.identity, parent.transform);
        }
        RegisteredObject ro = inst.GetComponent <RegisteredObject> ();

        ro.registeredID = registeredID;
        ro.prefabPath   = prefabPath;
        ro.prefabName   = prefabName;
        return(inst);
    }
Example #3
0
    public static GameSummary Create(RectTransform parent, GameManager.Save data)
    {
        GameObject  pref    = ABU.LoadAsset <GameObject> ("core", "GameSummary");
        GameObject  inst    = Instantiate <GameObject> (pref, parent, false);
        GameSummary summary = inst.GetComponent <GameSummary> ();

        summary.SetName(data.gameName);
        summary.SetDifficulty(data.difficulty);
        summary.SetTime(data.gameTime);
        summary.SetArea(data.currScene);

        for (int i = 0; i < summary.damageTypes.Length; i++)
        {
            if ((data.dtUnlocks & (1 << (i + 1))) == 0)
            {
                summary.damageTypes [i].color = Color.clear;
            }
        }

        for (int i = 0; i < summary.abilities.Length; i++)
        {
            if ((data.abilities & (1 << i)) == 0)
            {
                summary.abilities [i].color = Color.clear;
            }
        }

        summary.data = data;

        return(summary);
    }
Example #4
0
    /* Static Methods */
    public static AbilityDisplay Create(RectTransform parent, Ability subject)
    {
        GameObject pref = ABU.LoadAsset <GameObject> (PREF_DIR, "AbilityDisplay");
        GameObject inst = Instantiate <GameObject> (pref, parent, false);

        AbilityDisplay ad = inst.GetComponent <AbilityDisplay> ();

        ad.SetSubject(subject);

        //fill charge list
        GameObject c_pref = ABU.LoadAsset <GameObject>(PREF_DIR, "ChargeIndicator");

        for (int i = 0; i < subject.ChargesMax; i++)
        {
            GameObject c_inst = Instantiate <GameObject> (c_pref, ad.chargeList, false);
            Image      icon   = c_inst.GetComponent <Image> ();
            if (i < subject.Charges)
            {
                icon.fillAmount = 1f;
            }
            else if (i == subject.Charges)
            {
                icon.fillAmount = 1 - subject.CooldownPercentage;
            }
            else
            {
                icon.fillAmount = 0f;
            }
        }

        return(ad);
    }
Example #5
0
    public static GameObject Create(string prefabPath, string prefabName, Vector3 position, Quaternion rotation, Transform parent)
    {
        if (prefabPath == "" || prefabName == "")
        {
            throw new ArgumentException("Cannot create prefab with empty path and/or name");
        }

        GameObject go = ABU.LoadAsset <GameObject> (prefabPath, prefabName);
        GameObject inst;

        if (parent == null)
        {
            inst = Instantiate(go, position, rotation);
        }
        else
        {
            inst = Instantiate(go, position, rotation, parent);
        }
        RegisteredObject ro = inst.GetComponent <RegisteredObject> ();

        ro.GenerateID();
        ro.prefabPath = prefabPath;
        ro.prefabName = prefabName;
        return(inst);
    }
Example #6
0
 public static HUDManager GetInstance()
 {
     if (instance == null)
     {
         GameObject pref = ABU.LoadAsset <GameObject> ("core", "HUD");
         instance = Instantiate <GameObject> (pref).GetComponent <HUDManager>();
     }
     return(instance);
 }
Example #7
0
    public static StatusDisplay create(RectTransform parent, Status subject)
    {
        GameObject    pref = ABU.LoadAsset <GameObject> ("core", "StatusDisplay");
        GameObject    inst = Instantiate <GameObject> (pref, parent, false);
        StatusDisplay sd   = inst.GetComponent <StatusDisplay> ();

        sd.SetSubject(subject);

        return(sd);
    }
Example #8
0
    public void AddOption(Option option)
    {
        GameObject butPref = ABU.LoadAsset <GameObject> ("core", "TempButton");        //TODO replace with final button version
        GameObject inst    = Instantiate(butPref, optionList, false);

        inst.transform.GetChild(0).GetComponent <Text> ().text = option.text;
        if (option.function == null)
        {
            option.function = DestroySelf;
        }
        inst.GetComponent <Button> ().onClick.AddListener(option.function);
    }
Example #9
0
    // Create a text prompt with a given text value and duration
    public static TextPrompt Create(RectTransform parent, string title, string caption, float duration)
    {
        GameObject pref = ABU.LoadAsset <GameObject> ("core", "TextPrompt");
        GameObject inst = Instantiate <GameObject> (pref, parent, false);
        TextPrompt tp   = inst.GetComponent <TextPrompt> ();

        tp.header.text  = title;
        tp.subText.text = caption;

        Destroy(inst, Mathf.Abs(duration));

        return(tp);
    }
Example #10
0
    public static Prompt Create(RectTransform parent, string description, params Option[] options)
    {
        GameObject pref = ABU.LoadAsset <GameObject> ("core", "Prompt");
        GameObject inst = Instantiate(pref, parent, false);
        Prompt     p    = inst.GetComponent <Prompt> ();

        p.description.text = description;

        foreach (Option o in options)
        {
            p.AddOption(o);
        }

        return(p);
    }
Example #11
0
    private Ability(string name, string desc, string iconPath, float cooldownMax, int chargesMax, string effect, string prereq = "", string preAnim = "", string postAnim = "")
    {
        this.id       = -1;
        this.name     = name;
        this.desc     = desc;
        this.iconPath = iconPath;
        if (iconPath != "")
        {
            icon = ABU.LoadAsset <Sprite> (ICON_DIR, iconPath);
        }
        else
        {
            icon = null;
        }

        this.CooldownMax = cooldownMax;
        _cooldownCurr    = cooldownMax;

        this.ChargesMax = chargesMax;
        _charges        = 0;

        effectName  = effect;
        this.effect = (UseEffect)Delegate.CreateDelegate(
            typeof(UseEffect),
            this,
            typeof(Ability).GetMethod(effectName, BindingFlags.NonPublic | BindingFlags.Instance));

        checkName = prereq;
        if (checkName != "")
        {
            check = (PrereqCheck)Delegate.CreateDelegate(
                typeof(PrereqCheck),
                this,
                typeof(Ability).GetMethod(checkName, BindingFlags.NonPublic | BindingFlags.Instance));
        }
        else
        {
            check = null;
        }

        this.preAnim  = preAnim;
        this.postAnim = postAnim;

        Active    = false;
        Available = true;

        persData = null;
    }
Example #12
0
	/* Static Methods */
	public static AbilitySelector Create(Transform parent, string abilityName, int abilityIndex, ToggleGroup tg)
	{
		GameObject pref = ABU.LoadAsset<GameObject> (PREF_DIR, "AbilityToggle");
		GameObject inst = Instantiate<GameObject> (pref, parent, false);
		AbilitySelector aSel = inst.GetComponent<AbilitySelector> ();
		aSel.abilityName = abilityName;
		aSel.abilityIndex = abilityIndex;
		aSel.SetAbility ();

		aSel.activeSet = true;

		Toggle t = inst.GetComponent<Toggle> ();
		t.group = tg;

		return aSel;
	}
Example #13
0
    public Status(string name, string desc, string iconPath, DecayType dt, int stacksMax, float duration, params StatusComponent[] components)
    {
        this.name     = name;
        this.desc     = desc;
        this.iconPath = iconPath;
        this.icon     = ABU.LoadAsset <Sprite> (ICON_DIR, iconPath);

        decayType     = dt;
        initDuration  = duration;
        this.Duration = initDuration;

        this.StacksMax = stacksMax;
        Stacks         = 1;

        this.components = components;
        for (int i = 0; i < components.Length; i++)
        {
            this.components [i].SetParent(this).stacks = Stacks;
        }
    }
Example #14
0
    public Ability(SerializationInfo info, StreamingContext context)
    {
        id       = info.GetInt32("id");
        name     = info.GetString("name");
        desc     = info.GetString("desc");
        iconPath = info.GetString("iconPath");
        icon     = ABU.LoadAsset <Sprite> (ICON_DIR, iconPath);

        CooldownMax   = info.GetSingle("cooldownMax");
        _cooldownCurr = info.GetSingle("cooldownCurr");

        ChargesMax = info.GetInt32("chargesMax");
        _charges   = info.GetInt32("charges");

        effectName = info.GetString("effect");
        effect     = (UseEffect)Delegate.CreateDelegate(
            typeof(UseEffect),
            this,
            typeof(Ability).GetMethod(effectName, BindingFlags.NonPublic | BindingFlags.Instance));

        checkName = info.GetString("prereq");
        if (checkName != "")
        {
            check = (PrereqCheck)Delegate.CreateDelegate(
                typeof(PrereqCheck),
                this,
                typeof(Ability).GetMethod(checkName, BindingFlags.NonPublic | BindingFlags.Instance));
        }
        else
        {
            check = null;
        }

        preAnim   = info.GetString("preAnim");
        postAnim  = info.GetString("postAnim");
        Available = info.GetBoolean("available");
        Active    = info.GetBoolean("active");

        persData = (ISerializable)info.GetValue("persData", typeof(ISerializable));
    }
Example #15
0
    public Status(SerializationInfo info, StreamingContext context)
    {
        name     = info.GetString("name");
        desc     = info.GetString("desc");
        iconPath = info.GetString("icon");
        icon     = ABU.LoadAsset <Sprite> (ICON_DIR, iconPath);

        decayType    = (DecayType)info.GetInt32("decayType");
        initDuration = info.GetSingle("initDuration");
        Duration     = info.GetSingle("duration");

        StacksMax = info.GetInt32("stacksMax");
        Stacks    = info.GetInt32("stacks");

        int numComponents = info.GetInt32("numComponents");

        this.components = new StatusComponent[numComponents];
        for (int i = 0; i < numComponents; i++)
        {
            components[i] = ((StatusComponent)info.GetValue("component" + i, typeof(StatusComponent))).SetParent(this);
        }
    }
Example #16
0
    public static Bullet Create(string prefabName, Entity source, Faction faction = Faction.NEUTRAL)
    {
        GameObject go = ABU.LoadAsset <GameObject> (PREF_DIR, prefabName);

        return(Create(go, source, faction));
    }