2015-01-19 2 views
1

일련 번호가 지정된 속성 경로 등을 이해하지 못해서 도움이 필요합니다. 필자는 하나의 사용자 정의 편집기와 하나의 일반 스크립트를 2 개의 스크립트로 작성했습니다. 누구든지 접을 수있는 상태로 유지하면서 편집기 스크립트에서 첫 번째 스크립트의 slotContents 변수를 참조 할 수있는 방법을 알고 있습니다. 감사 : D사용자 정의 편집기에서 변수를 정의하는 방법, 배열을 정의해야합니까?

using UnityEngine; 
using System.Collections; 

public class Inventory : MonoBehaviour { 
    public GUISkin mainDesignSkin; 
    public GUISkin craftDesignSkin; 
    public bool enableCraftingMenu = true; 
    public int craftSlot1; 
    public int craftSlot2; 
    public int craftResult; //Make this private users do not need to see this it will clutter editor. 
    public int [] slotContents; 
} 

그리고 두 번째 스크립트.

using UnityEngine; 
using System.Collections; 
using UnityEditor; 
//Decalres type for editor. 
[CustomEditor(typeof(Inventory))] 
public class InventoryUiCustomEditor : Editor { 
    public override void OnInspectorGUI() 
    { 
     base.OnInspectorGUI(); 
     Inventory ItemReference = (Inventory)target; 
     EditorGUILayout.LabelField("First we need to set our skin look in the skins folder or assign your own designs."); 
     EditorGUILayout.LabelField("Please assign even if crafting is disabled to avoid accidental null reference errors."); 
     EditorGUILayout.Separator(); 
     ItemReference.mainDesignSkin = (GUISkin) EditorGUILayout.ObjectField("Apply the skin entitled 'Main' here.", ItemReference.mainDesignSkin, typeof (GUISkin), false); 
     ItemReference.craftDesignSkin = (GUISkin) EditorGUILayout.ObjectField("Apply the skin entitled 'Craft' here.", ItemReference.craftDesignSkin, typeof (GUISkin), false); 
     EditorGUILayout.Separator(); 
     EditorGUILayout.LabelField("Should the crafting menu be enabled in this Scene?"); 
     EditorGUILayout.Separator(); 
     ItemReference.enableCraftingMenu = EditorGUILayout.Toggle("Enable Crafting", ItemReference.enableCraftingMenu); 
     if (ItemReference.enableCraftingMenu == true){ 
      EditorGUILayout.Separator(); 
      EditorGUILayout.LabelField("The below fields are for your testing only they will be automatically overridden."); 
      EditorGUILayout.LabelField("The following fields can be used as a tester however will only work on valid recipes check the"); 
      EditorGUILayout.LabelField("documentation video for a tutorial on this."); 
      EditorGUILayout.Separator(); 
      ItemReference.craftSlot1 = EditorGUILayout.IntField("Item 1", ItemReference.craftSlot1); 
      ItemReference.craftSlot2 = EditorGUILayout.IntField("Item 2", ItemReference.craftSlot2); 
      ItemReference.craftResult = EditorGUILayout.IntField("Result of mixing above two items.", ItemReference.craftResult); 


     } 
    } 
} 
+0

'slotContents' 배열보다'[Serializable]'을 사용하려고 했습니까? – Varaquilex

+0

이 위대한 코드를 공유해 주셔서 감사합니다. 열거 형 값을 선택하여 관리자보기를 사용자 정의하는 방법을 찾고 있었고 코드가 올바른 방향으로 나를 가리켰습니다. 시원한! – CHaP

답변

0

확인이 링크 : 또한 http://docs.unity3d.com/ScriptReference/Serializable.html과 가까운을 가지고 사용자 Varaquilex

Serialize.Field

검색 : http://answers.unity3d.com/questions/571411/is-it-possible-to-make-a-c-script-variable-changea.html

이것은 당신의 대답에 세부 사항을 가지고 당신이 읽어야 링크입니다 에 자리가 없다면 :

코드는 다음과 같습니다.

using UnityEngine; 
using System.Collections; 

[System.Serializable] 
public class Inventory : MonoBehaviour 
{ 
    public GUISkin mainDesignSkin; 
    public GUISkin craftDesignSkin; 
    public bool enableCraftingMenu = true; 
    public int craftSlot1; 
    public int craftSlot2; 
    public int craftResult; //Make this private users do not need to see this it will clutter editor. 
    [SerializeField] 
    public int [] slotContents; 
} 
+0

그런데 편집기에서 참조하는 방법은 편집자 측이 아닌 기본 스크립트 일 뿐이라고 나에게 말한 것입니다. – Luke