(source: http://wango911.deviantart.com/)
using UnityEngine;
using System.Collections;
/*
* Actor for the Yacht player type
* Used in mission 3 where a wizard turns the player into a yacht
*/
// Note: all components we need are "Required"
[RequireComponent(typeof(Collider))]
[RequireComponent(typeof(RigidBody))]
[RequireComponent(typeof(Damagable))]
[RequireComponent(typeof(PlayerInput))]
[RequireComponent(typeof(WeaponController))]
public class ActorPlayerYacht : MonoBehaviour
{
// use serializefield instead of public where possible
[SerializeField] ActorYachtWeapon[] weapons;
// Always cache off required components on awake.
Damagable damagable;
PlayerInput playerInput;
WeaponController weaponController;
// Awake is only for setting up this object's values.
//
// Initializing in awake leads to horrible order of
// initialization/existance problems
void Awake()
{
damagable = GetComponent<Damagable>();
playerInput = GetComponent<PayerInput>();
weaponController = GetComponent<WeaponController>();
}
// Start is for initalizing this object and others
void Start()
{
foreach(var weapon in weapons)
{
weaponController.Add(weapon);
}
}
}
// All shared code is required
[RequireComponent(typeof(Damagable))]
[RequireComponent(typeof(PlayerInput))]
[RequireComponent(typeof(WeaponController))]
[RequireComponent(typeof(RigidBody))]
[RequireComponent(typeof(Collider))]
public class ActorPlayerYacht : MonoBehaviour
{
// Always cache your required components, especially on mobile!
// GetComponent isn't free. And overusing makes code harder to read.
Damagable damagable;
PlayerInput playerInput;
WeaponController weaponController;
// Awake is for setting up this object's values.
// Always cache off required components on awake.
void Awake()
{
damagable = GetComponent<Damagable>();
playerInput = GetComponent<PlayerInput>();
weaponController = GetComponent<WeaponController>();
}
}
using UnityEngine;
using System.Collections;
public class SerializeExample : MonoBehaviour
{
// Class doens't need to be public.
// But won't be acessable outside SerializeExample if it's not.
// (Depends on what you want to do with it)
[System.Serializable]
public class SerializeClass
{
// if you're just storing data, your parameters here should be public
public SerializeExample objectParam;
public float floatParam;
}
// example uses of our class
[SerializeField] SerializeClass singleParam;
[SerializeField] SerializeClass[] arrayParam;
}
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(NR_UIDisableOnHide))]
[RequireComponent(typeof(NR_UIView))]
public class NR_DredgeMinigameManager : MonoSingleton<NR_DredgeMinigameManager>
{
System.Action onDone;
public class State
{
public virtual void OnEnter() {}
public virtual void OnUpdate() {}
public virtual void OnExit() {}
public NR_DredgeMinigameManager manager
{
get { return NR_DredgeMinigameManager.Instance; }
}
}
[System.Serializable]
public class StateIntroduction : State
{
public NR_PopupOldMan oldGuy;
public override void OnEnter ()
{
oldGuy.Show(new string[]
{ "Lets find some of the things you lost"}, delegate {
//Debug.Log("We should start the dredge game here");
manager.SetState(manager.gameState);
});
}
}
public StateIntroduction introductionState;
[System.Serializable]
public class StateGame : State
{
public NR_DredgeMinigame minigame;
int numCoins = 0;
int givePieceWhenTurnsRemaining = -1;
public void Init(int numCoins, int givePieceWhenTurnsRemaining)
{
this.numCoins = numCoins;
this.givePieceWhenTurnsRemaining = givePieceWhenTurnsRemaining;
}
public override void OnEnter ()
{
minigame.StartMinigame(manager.tilesToRecover, numCoins, givePieceWhenTurnsRemaining, delegate {
manager.SetState(manager.resultsState);
});
}
}
public StateGame gameState;
public RaftTileDataManager.RaftCellData[] tilesToRecover
{
get; private set;
}
[System.Serializable]
public class StateResults : State
{
public NR_PopupOldMan oldGuy;
public override void OnEnter ()
{
oldGuy.Show(new string[]{ "All Done?\nLet's go!"}, delegate {
manager.EndDredgeGame();
});
}
}
public StateResults resultsState;
public bool CheckItemsToDredge(RaftTileDataManager.RaftCellData[] tilesToRecover)
{
return gameState.minigame.CheckPiecesToRecover(tilesToRecover);
}
public void StartDredgeGame(RaftTileDataManager.RaftCellData[] tilesToRecover, int numberOfCoins, int givePieceWhenTurnsRemaining, System.Action onDone)
{
// Debug.Log ("Starting dredge game");
this.onDone = onDone;
this.tilesToRecover = tilesToRecover;
gameObject.SetActive(true);
gameState.Init(numberOfCoins, givePieceWhenTurnsRemaining);
SetState(introductionState);
}
public void EndDredgeGame()
{
// Debug.Log ("Ending dredge game");
if(onDone!=null)
{
onDone();
onDone = null;
}
gameObject.SetActive(false);
this.tilesToRecover = null;
}
State m_currentState;
public void SetState(State newState)
{
if(m_currentState!=null)
{
// Debug.Log("Dredge ending state: "+m_currentState.GetType().Name);
m_currentState.OnExit();
}
m_currentState = newState;
if(newState!=null)
{
// Debug.Log("Dredge starting state: "+m_currentState.GetType().Name);
m_currentState.OnEnter();
}
}
void Update()
{
if(m_currentState!=null)
{
m_currentState.OnUpdate();
}
}
}
using UnityEngine;
// Custom assets have to derive from ScriptableObject
public class ExampleCustomAsset : ScriptableObject
{
// like serialized classes,
// if it's just data storage make the variables public
public float floatParam;
public ExampleCustomAsset objectParam;
#if UNITY_EDITOR
// Now we need a builder
[UnityEditor.MenuItem("Assets/Create/ExampleCustomAsset")]
public static void BuildAsset()
{
CustomAssetUtil.CreateTheAsset<ExampleCustomAsset>();
}
#endif
}
#if UNITY_EDITOR
public static class CustomAssetUtil
{
public static void CreateTheAsset<T> () where T : ScriptableObject
{
T asset = ScriptableObject.CreateInstance<T> ();
string path = UnityEditor.AssetDatabase.GetAssetPath (UnityEditor.Selection.activeObject);
if (path == "")
{
path = "Assets";
}
else if (System.IO.Path.GetExtension (path) != "")
{
path = path.Replace (System.IO.Path.GetFileName (UnityEditor.AssetDatabase.GetAssetPath (UnityEditor.Selection.activeObject)), "");
}
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath (path + "/New " + typeof(T).ToString() + ".asset");
UnityEditor.AssetDatabase.CreateAsset (asset, assetPathAndName);
UnityEditor.AssetDatabase.SaveAssets ();
UnityEditor.EditorUtility.FocusProjectWindow ();
UnityEditor.Selection.activeObject = asset;
}
}
#endif
(https://s3.amazonaws.com/cratesmith/CustomAssetBuilder.unitypackage)