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 crazyKnight · Nov 08, 2011 at 11:53 AM · javascriptarrayssyntax2d array

Public 2D array, accessed through the editor ??

I am trying to declare a public multidimensional array of GameObjects(Using JavaScript not c#) that I can access through the editor. However it would appear that only single dimension arrays are usable through the property inspector.

can anyone please help me out with this i know it is easily possible with c# but i want to know how it can be achieved using javascript.

Thanks in Advance

Comment
Add comment · Show 9
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 crazyKnight · Nov 08, 2011 at 11:58 AM 0
Share

anyone looking for the c# code for the same problem http://forum.unity3d.com/threads/54707-2D-Arrays-in-C

avatar image syclamoth · Nov 08, 2011 at 12:06 PM 1
Share

You can't use multidimensional arrays in the inspector by default. I could show you how to do something which can be used like a multidimensional array in code, but which can be accessed properly in the inspector, but I only know how to do that in C#, and you've forbidden me from doing that. Sorry!

avatar image crazyKnight · Nov 08, 2011 at 12:09 PM 0
Share

well i have kept that as a last option if i dont get any solution,because my entire project is in java scripts and i dont want to mix it with c# scripts...i know it sounds a bit silly but i always try to complete the entire project using just one language, except for the plugins i always use c# for them....

avatar image crazyKnight · Nov 08, 2011 at 12:12 PM 0
Share

@syclamoth : thanks for your help i know it is very easily possible with c#,but i am still trying to do it with javascript....if i don't get any solution then i will have to go by your way(c# rules)....

avatar image moghes · May 20, 2014 at 12:59 PM 1
Share

@syclamoth please provide the method you mentioned.

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Cherno · May 20, 2014 at 02:43 PM

What I have done is declare a custom class that has an array as a variable. Declare a new array of this class and you have your multi-dimensional array that can be viewed in the editor without any fuzz. Here's an example in UnityScript, but it should be easily convertible to C#.

 class Array2D {
     var subArray : GameObject[] = new GameObject [12];
 }
 
 var my2DArray: Array2D [] = new Array2D [12];
 
 
 
 
 function PrintArrayContent() {
      if(my2DArray[0].subArray[0] != null) {
            Print(my2DArray[0].subArray[0].name);
 }
     
 }
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
avatar image
0

Answer by Minchuilla · Aug 02, 2014 at 03:36 PM

You could also write your own Custom Editor/Inspector code or use this code as a reference:

In know its in c# but just use this its not that hard to convert and just look at the docs for a custom editor.

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 
 [CustomEditor(typeof(BackgroundMaster))]
 public class BackgroundEditor : Editor {
 
     bool isShowing;
     bool[] b;
 
     bool a;
 
     void Start()
     {
         BackgroundMaster myBGMaster = (BackgroundMaster)target;
         b = new bool[2/*myBGMaster.backgroundItems.GetLength(0)*/];
     }
 
     public override void OnInspectorGUI()
     {
         base.OnInspectorGUI();
         BackgroundMaster myBGMaster = (BackgroundMaster)target;
 
         isShowing = EditorGUILayout.Foldout(isShowing, "Background Items");
         if(isShowing)
         {
             //Debug.Log(b.Length + (b[0]?"T":"F") + (b[1]?"T":"F"));
             if(b != null && b.Length > 0)
             {
                 for(int i = 0; i < b.Length; i++)
                 {
                     string s = "";
                     if(i == 0)
                         s = "    Foreground";
                     else if(i == 1)
                         s = "    Midground";
                     else 
                         s = "    Background";
 
                     b[i] = EditorGUILayout.Foldout(b[i], s);
 
                     if(b[i])
                     {
                         for(int j = 0; j < myBGMaster.backgroundItems.GetLength(1); j++)
                         {
                             if(myBGMaster.backgroundItems[i, j])
                                 EditorGUILayout.LabelField("          ", myBGMaster.backgroundItems[i, j].name);
                             else
                                 EditorGUILayout.LabelField("          N/A");
                         }
                     }
                 }
             }
             else
             {
                 EditorGUILayout.LabelField("    N/A");
                 EditorGUILayout.LabelField(("    [" + myBGMaster.backgroundItems.GetLength(0)) + ", " + myBGMaster.backgroundItems.GetLength(1) + "]");
             }
         }
     }
 }

Or you could have a look at this Unity tutorial

Hope this helps later viewers,

Minchuilla

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
avatar image
0

Answer by sumeetkhobare · Jul 13, 2015 at 10:39 AM

Hey,

I stumbled in this same issue a month ago and after solving it, I have made a solution to this, now. I have made a grid view for a 2D array.

You can find it here: https://youtu.be/uoHc-Lz9Lsc

Its in c# though.

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

6 People are following this question.

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

Related Questions

Javascript 2d array Help 0 Answers

What is a good Javascript editor, with Syntax highlighting and checking? 5 Answers

Help with #pragma strict Arrays? 1 Answer

Array Not Appering In The Inspector 2 Answers

How to Manually write a 2 dimensional array in javascript 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