Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by komodor · Dec 04, 2013 at 01:16 PM · c#objectstaticproperties

pre generated static Object in C#

i need static property, which will be more or less complicated object, which propertis might be array, float, int and string

in flash/as3 i would do it by json:

static Object o = {property:1, property2:{subproperty:"text", subproperty:[{subP:1, subP:2}]}};

is there way in c# ?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ArkaneX · Dec 04, 2013 at 01:48 PM 0
Share

Do you mean it can contain any properties? Isn't it possible to define a class with all possible properties and fill only part of them when initializing? If it's possible, then you can initialize an instance by deserializing JSON.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Fornoreason1000 · Dec 04, 2013 at 01:42 PM

you can use constructors in your Object to achieve this

 public class MyObject {
 string text;
 float num;
 int num2;
 int[] sub; 

 
 public MyObject(string text, float num, int num2, int[] subprop) {
  this.text = text;
 this.num = num;
 this.num2 = num2;
 this.sub = subprop;
 //code goes here
 
 }}



to create the static object, you can now use this constructor

 static MyObject obj = new MyObject("blurzdfasdf", 69f, 69, new int[] {6,9});
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image komodor · Dec 04, 2013 at 05:36 PM 0
Share

is there way to do it without particular Class but only with Object ?

i mean, this works, but is there way to do it as in AS3 with JSON?

avatar image Fornoreason1000 · Dec 05, 2013 at 05:17 AM 0
Share

don't confuse Object with object...Object is unity specific, object is basically everything. object is the base class for absolutely everything inclusig UnityEngine.Object

yes you can, but its slightly different, object can't have properties, because the properties are object. everything is cast able to object, even Arrays!

this code will work straight out the box

    static object obj =  new object[] {"blurzdfasdf", 69f, 69, new int[] {6,9}};

however the problem with this is that the compiler no longer understands that there are parameter there so you ight want an object[] ins$$anonymous$$d of object.

No there is no way to create an object like that in C#. see the thing is, that is basically a "class" in terms of true JS(which is pretty much AS3) your defining an object with properties. when Javascipt programmers (not Unity Script!!) want a "class" they use that code. so the only way is to create a class or struct with the properties you want.

avatar image komodor · Dec 05, 2013 at 05:07 PM 0
Share

too bad

well the 1st answer works well for my case, i just wanted to know if it's possible ... i miss JSON the native way it works in AS3

thx a lot guys!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Do you have to set a object reference for every script? 0 Answers

Where is the Mistake in my Coin System? 1 Answer

an object reference is required for the non static field error 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges