Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by MojtabaM · Jul 12, 2013 at 05:30 PM · propertiesextension

Anything like "Extension Methods" for Properties ?

Hi everybody Is there anything like "Extension Methods" for class Properties ?

Here's what I looking for :

 in (Object1) >> Script : Animations.cs 
 
 - List of Animates;
 
 in Script : Animate.cs
 
 - Play()
 ...
 
 in (Object 2)Script : sample1.cs
  //this is what I want
  Object1.Anims.Walk.Play();

Can it be done ? and if yes , HOW?!??!?! Thanks a lot(thousands) .

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Bunny83 · Jul 12, 2013 at 07:00 PM

No, there is nothing like extension properties. As far as i know it is planned for a future C# version, but since Unity uses a quite old implementation of Mono I wouldn't expect such a feature in the near future (2-x years at least).

The question is if it actually makes sense to implement them. Extension methods are just normal methods which work on a specific object type. All they allow is to have a simpler way of calling them.

Properties usually describe, well, properties of an object. To me it makes no sense to kind of "inject" new properties into a foreign object. Why don't you just use Methods instead of properties? Properties are just a pair of functions.

Actually i don't really get your pseudo example. What is "Walk" ? It look like that "Walk" is more data then a property. What you might want is an indexer. Before you ask, no, you can't implement an "extension indexer", it has to be declared inside the class itself.

Indexers are actually properties with "indexing" parameters. For example:

 public class SomeClass
 {
     public Transform this[string aName]
     {
        get { return /*Do some fancy stuff with "aName" and return a Transform reference*/; }
        set { /*Here you have the "value" and the "aName" parameter*/}
     }
 }
 
 // ...
 public SomeClass instance;
 
 instance["SomeName"].position = Vector3.zero;

Comment
Add comment · Show 1 · 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 MojtabaM · Jul 13, 2013 at 07:12 AM 0
Share

Thanks for your reply .

"Walk" is an instance of a class itself.

and has methodes and properties .

I think you say this is last and best solution , maybe . but i try it .

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

16 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

Related Questions

How to expose script properties in C# ? 3 Answers

What built-in shader properties are there? 0 Answers

Making a paper like object on Unity. 2 Answers

Photon JoinRandomRoom customGameProperties? Load proper scene 0 Answers

Property drawer stops variables from being read 0 Answers


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