Unityscript : Instantinate TouchController? - input

I am currently creating a joystick and therefore I want to replace the Get Axis method.
Here is my code
function UpdateSmoothedMovementDirection () {
var h = TouchController.GetAxisRaw("Horizontal");
But Unity gives me this error :
An instance of type 'TouchController' is required to access non static member 'GetAxisRaw'.
How can I call an instance ?

Add public variable of type TouchController to your script. Then add game object with TouchController script to your scene. If your script is derived from MonoBehaviour, in Hierarchy tab in Unity Editor drag and drop game object with TouchController onto your variable.
If your script is not a MonoBehaviour script, than you'll have to set this variable manually from some other MonoBehaviour script.

Related

How to iterate Apache velocity template variable attributes

As title, is there any way to iterate or display Apache velocity template attributes?
for example, I have following code :
<code>
${ctx.messages.headerMessage}
</code>
And I want to know how many other attributes the variable ${ctx} has
It's only possible to discover and to loop on an object properties (that is, the ones with getters and/or setters) if you can add a new tool to your Velocity context. If you can't, you're rather stuck.
There are several ways to do this, I illustrate below how to do this with commons-beanutils.
First, add Apache commons-beanutils in your class path, and add it to your Velocity context from Java:
import org.apache.commons.beanutils.PropertyUtils;
...
context.put("beans", new PropertyUtils());
...
One remark: if you do not have access to the Java part, but if by chance commons-beanutils is already in the classpath, there is one hakish way of having access to it: #set($beans = $foo.class.forName('org.apache.commons.beanutils.PropertyUtils').newInstance()).
Then, let's say that I have the following object:
class Foo
{
public boolean isSomething() { return true; }
public String getName() { return "Nestor"; }
}
which is present in my context under $foo. Using your newly $beans properties introspector, you can do:
#set ($properties = $beans.getPropertyDescriptors($foo.class))
#foreach ($property in $properties)
$property.name ($property.propertyType) = $property.readMethod.invoke($foo)
#end
This will produce:
bar (boolean) = true
class (class java.lang.Class) = class Foo
name (class java.lang.String) = Robert
(you'll need to filter out the class property, of course)
One last remark, though. Templates are for coding the View layer of an MVC application, and doing such a generic introspection of objects in them is rather inadequate in the view layer. You're far better of moving all this introspection code on the Java side.

Declare global variable in action script?

I want to create a variable(possible global variable) in one action script file and want to use the same variable across all other action script files in the project. How to create such a variable and how to use the same variable across all .as files??
One simple way is to define a static variable in a Class (either create a new Class or use one of your existing classes):
// in MyConfig.as
class MyConfig {
static var myVariable:String = "Hi";
}
// You can access / set the value from any class using MyConfig.myVariable
trace(MyConfig.myVariable); // prints Hi
MyConfig.myVariable = "Hello";
trace(MyConfig.myVariable); // prints Hello
Create one public class (lets assume GlobalVariables.as)
No need to add its instance.
Now declare all the variables that you want to use across multiple classes as STATIC.
(you can also declare and create instances of classes in that class to avoid multiple instances of classes)
Also you can add common methods to this class
So whenever you want to access that variable declared in GlobalVariables class
you need to access using reference e.g GlobalVariables.variableName
sample code:
package classes{
public class GlobalVariables{
public static var strURL:String;
public static function setExternalLinks(){
strURL = "http://demourl.asmx/";
}
}
}

design pattern to use for changing object properties from property inspector

I have this problem at hand and wanted some inputs on best way to approach it -
In my application, i have different set of objects and each object has some properties associated with them.
For eg: objects like, say, shapes , which has some common properties like color and specific properties ( for eg: circle has radius and center has its specific property )
The user can change object properties through a property inspector.
Currently, the PI holds a object ID and uses that to talk to DOM for anything related to object it currently refers. like say, if it wants to change the property of object it will call DOM Api
ChangeObjectProperty(objectID , *);
(I hope using object ID to refer to objects inside the DOM is right way. (is there a better way to do this ?))
What should i pass as the second argument ?
Should it be a single opaque object ( say, IObjProps) where each objects provides its own structure ?
For example the circle will have following structure of its own -
class CircleProps extends CommonProps
{
public var radius:Number;
public var center:Point;
}
class CommonProps extends IObjProps
{
public function clone();
public var color:Number;
}
The DOM will pass on this structure to the object and object takes care of applying the change.
So ChangeObjectProperty(objectID , *); function will be implemented as -
function ChangeObjectProperty(objectID , props:IObjProps)
{
var object:Object = GetObjectFromID(objectID);
object.SetProperty(iObjProps)
}
The problem with the above approach is that - its kind of difficult to know what specific property changed since its a single structure -
The alternative is to have property dictionary - the client inserts only the properties which got changed into the dictionary.
I wanted to know what is design pattern followed for such use cases.
Adding more info - this is actionscript -

RTTI ?? create multiple object at runtime wxwidgets?

hi
sorry for my stupid question
what are the right way to create multiple control object from a list of array of label of object ...?
thank
The function wxCreateDynamicObject can be used to construct a new object of a given type, by supplying a string name. If you have a pointer to the wxClassInfo object instead, then you can simply call wxClassInfo::CreateObject.
You must include the IMPLEMENT_DYNAMIC_CLASS macro in every class you want to be able to dynamically create objects. IMPLEMENT_DYNAMIC_CLASS is a macro that not only initialises the static wxClassInfo member, but defines a global function capable of creating a dynamic object of the class in question.
Example
In a header file:
class wxFrame : public wxWindow
{
DECLARE_DYNAMIC_CLASS(wxFrame)
private:
wxString m_title;
public:
...
};
In a C++ file:
IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
wxFrame::wxFrame()
{
...
}

Flex 3 to Flex 4 Conversion and Undefined Methods

I have an application I am attempting to convert from a flex 3 air application to a flex 4 air application.
I am running into an issue in my main class. When calling the Instance method on the class I am getting an error:
Access of possibly undefined property Instance through a reference with static type Class.
My main class is pretty complex but the problem could be broken down to a simple example.
MyClass.mxml
<mx:WindowedApplication>
<mx:Script>
private static var instance:MyClass = null;
public static function get Instance():MyClass {
return instance;
}
</mx:Script>
<mx:Canvas></mx:Canvas>
</mx:WindowedApplication>
For some reason when calling MyClass.Instance in another file I get the above error.
The Outline window in flash builder does not show the static methods of this class, and typing MyClass into a code window the code completion does not show any of my static methods being accessible.
Is there another place I need to define static members outside of the mx:Script bock?
The simple answer is that it is no-longer mx:Script, the namespace for the Script attribute is now fx:Script.