p02greengrocer
N00b
- 124
- 24
Spamming the balls out of every outlet you can find
If its good, it'll go viral
alright, i think i got this. i'm really good at spamming
now i just gotta get good at game making!
- 1
Spamming the balls out of every outlet you can find
If its good, it'll go viral
If you want the title of this thread to be your future, you will purchase this right now. You have until Aug 14th.
Pass the Unity Certified Developer Exam - Lifetime Access
I definitely am, hella cheap, why not, get a cert, and obtain some knowledge that I didn't get while teaching myself to build eqbrowser.
It's 30-40hr commitment involved.
Would you recommend this to indie devs or someone fresh out of school from a practical perspective?
So how was your experience with the cert exam and course material?
Was it worth it in your view?
Any thoughts to share on tangible benefits over just solo training experience?
Would you recommend this to indie devs or someone fresh out of school from a practical perspective?
How about a seasoned programmer or developer perspective?
using System;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
namespace Gumps
{
internal class Bag
{
//parent of all the other parts
GameObject mBagFrame;
PointerListener mPL; //track this to unregister event
Canvas mCanvas;
string mTitle;
int mNumSlots;
int mBagSlot; //which slot number is this? (bag slots on character)
internal event EventHandler eClosed;
internal Bag(Canvas canv, string title, int numSlots, int bagSlot)
{
mCanvas =canv;
mNumSlots =numSlots;
mTitle =title;
mBagSlot =bagSlot;
GameObject closeButton =null;
GameObject tit =null;
foreach(GameObject go in Toolbox.Instance.mUIBits)
{
if(go.name == "CloseButton")
{
closeButton =MakeCloseButton(go);
}
else if(go.name == "BagFrame")
{
mBagFrame =MakeBagFrame(go);
}
else if(go.name == "BagSlot")
{
MakeBagSlots(go, mBagFrame);
}
else if(go.name == "TitleBar")
{
tit =MakeBagTitle(go, mBagFrame);
}
}
closeButton.transform.SetParent(mBagFrame.transform, false);
mPL =tit.GetComponent<PointerListener>();
mPL.eDrag +=OnDrag;
}
internal int GetBagSlot()
{
return mBagSlot;
}
GameObject MakeBagTitle(GameObject tit, GameObject parent)
{
GameObject titClone =GameObject.Instantiate(tit);
//make a child to hold the text
GameObject kid =new GameObject("TextHolder");
//find a font for debug
Font []fonts =Resources.FindObjectsOfTypeAll<Font>();
Font dbgFont =fonts[0];
SetUpTextField(kid, dbgFont);
Text tx =kid.GetComponent<Text>();
tx.text =mTitle;
tx.rectTransform.position =Vector3.up;
kid.transform.SetParent(titClone.transform, false);
int w, h;
CalcSize(out w, out h);
//set width
RectTransform rt =titClone.GetComponent<RectTransform>();
int width =w * 43 - 20;
rt.sizeDelta =new Vector2(width, 30);
rt.position =new Vector3(-13, 4);
titClone.transform.SetParent(parent.transform, false);
Button bt =titClone.GetComponent<Button>();
return titClone;
}
void MakeBagSlots(GameObject slot, GameObject parent)
{
int w, h;
CalcSize(out w, out h);
int numBoxes =0;
for(int y=0;y < h;y++)
{
for(int x=0;x < w;x++)
{
GameObject s =GameObject.Instantiate(slot);
//wire click listener
Button bt =s.GetComponent<Button>();
bt.onClick.AddListener(this.OnClickInventorySlot);
int xCoord =-4 + (x * -43);
int yCoord =4 + (y * 43);
s.name ="Slot" + x + "" + y;
s.transform.position =new Vector3(xCoord, yCoord);
s.transform.SetParent(parent.transform, false);
numBoxes++;
if(numBoxes == mNumSlots)
{
return; //done!
}
}
}
}
GameObject MakeBagFrame(GameObject go)
{
GameObject clone =GameObject.Instantiate(go);
clone.transform.SetParent(mCanvas.transform, false);
RectTransform rt =clone.GetComponent<RectTransform>();
int w, h;
CalcSize(out w, out h);
//mul by bag slot size
w *=43;
h *=43;
//add border
w +=5;
h +=30;
rt.sizeDelta =new Vector2(w, h);
return clone;
}
void CalcSize(out int width, out int height)
{
//figure out a good number to do the bag dimensions
//favour a wider base
width =Mathf.CeilToInt(Mathf.Sqrt(mNumSlots));
height =mNumSlots / width;
int remainder =mNumSlots % width;
if(remainder > 0)
{
height++;
}
}
GameObject MakeCloseButton(GameObject go)
{
GameObject clone =GameObject.Instantiate(go);
Button bt =clone.GetComponent<Button>();
bt.onClick.AddListener(this.OnClickClose);
return clone;
}
Text SetUpTextField(GameObject go, Font font)
{
go.AddComponent<Text>();
Text tx =go.GetComponent<Text>();
tx.color =Color.magenta;
tx.raycastTarget =false;
tx.alignment =TextAnchor.MiddleCenter;
tx.fontSize =14;
tx.color =Color.white;
tx.fontStyle =FontStyle.Bold;
tx.font =font;
return tx;
}
void SetUpRectTransform(GameObject go, Vector2 pos, Vector2 sizeDelta)
{
//see if already have a recttransform
RectTransform rc =go.GetComponent<RectTransform>();
if(rc == null)
{
//add an empty rect transform
go.AddComponent<RectTransform>();
}
//grab a pointer
rc =go.GetComponent<RectTransform>();
rc.localRotation =Quaternion.identity;
rc.localPosition =new Vector3(pos.x, pos.y);
rc.localScale =Vector3.one;
rc.anchorMin =Vector2.one * 0.5f;
rc.anchorMax =Vector2.one * 0.5f;
rc.anchoredPosition =pos;
rc.sizeDelta =sizeDelta;
rc.pivot =Vector2.one * 0.5f;
}
void KeepInRect(RectTransform bigRect, RectTransform smallRect)
{
Vector3 smallPos =smallRect.localPosition;
Vector3 min =bigRect.rect.min - smallRect.rect.min;
Vector3 max =bigRect.rect.max - smallRect.rect.max;
smallPos.x =Mathf.Clamp(smallRect.localPosition.x, min.x, max.x);
smallPos.y =Mathf.Clamp(smallRect.localPosition.y, min.y, max.y);
smallRect.localPosition =smallPos;
}
//adjust the position of the overall gump
//so that it is all in view
void ClampFrame()
{
//get the frame rect
RectTransform bfrt =mBagFrame.GetComponent<RectTransform>();
//get the canvas rect
RectTransform crt =mCanvas.GetComponent<RectTransform>();
KeepInRect(crt, bfrt);
}
void OnDrag(object sender, EventArgs ea)
{
Vector3 deltaPos =(Vector3)sender;
if(deltaPos == null)
{
Debug.Log("Null deltaPos in OnDrag()");
}
mBagFrame.transform.position +=deltaPos;
ClampFrame();
}
void OnClickInventorySlot()
{
Debug.Log("Inv slot clicked!" + UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject);
}
void OnClickBagTitle()
{
Debug.Log("Bag Title Clicked!");
}
internal void OnClickClose()
{
mPL.eDrag -=OnDrag;
GameObject.Destroy(mBagFrame);
UtilityLib.Misc.SafeInvoke(eClosed, this);
}
}
}
So how was your experience with the cert exam and course material? Was it worth it in your view? Any thoughts to share on tangible benefits over just solo training experience?
Would you recommend this to indie devs or someone fresh out of school from a practical perspective?
How about a seasoned programmer or developer perspective?
Anyone else take this and have anything to share wrt Unity experiences ?