So apparently MonoBehaviours should be able to be in a namespace in U4. However, I get a lot of warnings about the “The class defined in script file ‘x’ does not match the filename” - is there something I can do about this?
EDIT: Just to be clear
- The warning only happens if the class is in a namespace
With the namespace:
[5690-screen+shot+2012-12-11+at+09.02.30.jpg|5690]
Without the namespace:
[5691-screen+shot+2012-12-11+at+09.03.17.jpg|5691]
The code (with the namespace):
Here’s the code:
using System;
using UnityEngine;
namespace RadicalLibrary
{
public class ActivatedObject : StateMachineBehaviour, IMessage, IAmActivated
{
public string message;
public string activatedMessage;
public string Name = "Take 001";
public bool touchEnabled = true;
public float Speed = 1;
private StateMachine _sm;
public GameObject targetObject;
public bool IsActivated()
{
return Activated;
}
private bool _activated;
public bool Activated {
get {
return _activated;
}
set {
_activated = value;
var go = targetObject == null ? gameObject : targetObject;
if (!String.IsNullOrEmpty (Name)) {
if (value) {
go.animation [Name].speed = Speed;
go.animation.Play (Name);
} else {
if (go.animation [Name].time == 0) {
go.animation [Name].time = go.animation [Name].length;
}
go.animation [Name].speed = -Speed;
go.animation.Play (Name);
}
}
}
}
void TouchActivated()
{
Activated = !Activated;
}
#region IMessage implementation
public string GetMessage ()
{
return Activated ? activatedMessage : message;
}
#endregion
}
public class WaitForRelease : State
{
private Action _action;
public WaitForRelease (Action actionOnRelease = null)
{
_action = actionOnRelease;
}
public override void OnUpdate ()
{
if (TouchInterface.TouchCount == 0) {
SetState (StateMachine.Inactive);
if (_action != null) {
_action ();
}
}
}
}
}