Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Valthalin · Aug 20, 2015 at 07:47 PM · arrayinspectorvariablesclass

View script variables within an array of scripts in Inspector

Problem: My problem is an interconnected two parter, fist I need to be able to edit variables of a script within an array in the inspector. Second I need to be able to call said scripts functions from the inspector.

Solutions I know of:

problem 1:

  • Serialize the script and remove the MonoBehaviour from the script to reveal it's variables in the inspector.

  • don't use an array of scripts and manually add all instances of the script where needed.

problem 2:

  • Use sendMessage("functionName", value) or invoke("functionName", value).

  • hard code the use of each function for all possible uses.

You may already see the conflict. both sendMessage and invoke are part of MonoBehaviour, I remove mono I can edit the scripts variables as needed, but I loose the ability to call it's functions.

Thus far I've spent two days looking for an answer with no results. I need the ability to edit the variables in the inspector AND I need some way of invoking the scripts functions from the inspector.

Scripts:

The scrip within the array:

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class BaseAttribute : MonoBehaviour
 {
     public string name;
     public float normal;
     public float augmented;
     public float cap;
     public float current
     public float max;
 
     public float CalcResult()//one of  the functions for clarity
     {
         current += -current + (normal + augmented);
         Manager();
         return current;
     }
     //other functions...
 }

the script containing the array:

 using UnityEngine;
 using System.Collections;
 
 public class CCM : MonoBehaviour
 {
     public BaseAttribute[] attributes;
 
     void Awake()
     {
         for(int i = 0; i < attributes.Length; i++)
             attributes[i] = new BaseAttribute() as BaseAttribute;//gameObject.AddComponent<BaseAttribute>() as BaseAttribute;
     }
 }

A Script Using the Container 'for full exposure'

A test script acting on the script array, added to the object sometime during runtime The reason for the 'for' and 'foreach' discrepancy, my custom dictionary class is not itterable and I'm not sure how/where to implement IEnumerator. The many examples I've seen where not very helpful. But that is not pertinent to this question.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Condition: MonoBehaviour {
     private CCM target;
     public string name;
     public float lifeTime;
     public float timeBorn;
 
     public funcKeyValue[] effected;
 
     [System.Serializable]
     public class funcKeyValue
     {
         public string name;
         public string[] key;
         public int[] amount;
     }
 
     void Awake()
     {
         target = gameObject.GetComponent<CCM>() as CCM;
         timeBorn = Time.time;
         for(int i = 0; i < effected.Length; i++){
             for(int k = 0; k < effected[i].key.Length; i++){
                 target.SendMessage(effected[i].key[k], effected[i].amount[k]);
             }
         }
     }
 
     void Update()
     {
         if(Time.time - timeBorn >= lifeTime)
         {
             foreach(funcKeyValue item in effected)
             {
                 foreach(funcKeyValue subItem in item)
                     target.SendMessage(subItem.key, subItem.amount);
             }
             Destroy(this);
         }
     }
 }
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
0

Answer by FortisVenaliter · Aug 20, 2015 at 09:26 PM

Sounds like you need a custom inspector. I suggest reading up on the Unity.Editor namespace, specifically the Editor class and CustomEditor attribute. You can derive from that and define exactly how your inspector should look for the parent class, including making an array of scripts openable for editing. The downside is that you have to define it all for yourself instead of using Unity's built in serialization inspector. It's not super-intuitive, but if you search for "Unity CustomEditor" you should be able to find a bunch of tutorials.

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

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

2 People are following this question.

avatar image avatar image

Related Questions

How to use if statements for inspector in class? 1 Answer

How do I save an array of all different variables? 0 Answers

[SOLVED]How to use attributes from array of custom class instances? 1 Answer

Problem with variables and inspector 1 Answer

Convert class of int vars into an array 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