Example #1
0
 protected virtual void SaveAsText(string path, InputTransform transform)
 {
     System.Text.StringBuilder sb = new System.Text.StringBuilder();
     for (int i = 0, imax = transform.maxButtons; i < imax; ++i)
     {
         sb.AppendLine(
             m_EnumFrom.ToString(transform.buttonMasksFrom[i])
             + "," +
             m_EnumTo.ToString(transform.buttonMasksTo[i])
             );
     }
     File.WriteAllText(path, sb.ToString());
     AssetDatabase.Refresh(ImportAssetOptions.Default);
 }
Example #2
0
 protected virtual void LoadAsText(string path, InputTransform transform)
 {
     string[] lines = File.ReadAllLines(path), csvData;
     System.Collections.Generic.List <int> list0 = new System.Collections.Generic.List <int>();
     System.Collections.Generic.List <int> list1 = new System.Collections.Generic.List <int>();
     for (int i = 0, imax = lines.Length; i < imax; ++i)
     {
         if (!string.IsNullOrEmpty(lines[i]))
         {
             csvData = lines[i].Split(',');
             if (csvData.Length >= 2)
             {
                 list0.Add(m_EnumFrom.Parse(csvData[0]));
                 list1.Add(m_EnumTo.Parse(csvData[1]));
             }
         }
     }
     transform.buttonMasksFrom = list0.ToArray();
     transform.buttonMasksTo   = list1.ToArray();
 }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            InputTransform target_ = target as InputTransform;

            if (target_.maxButtons > target_.buttonMasksFrom.Length)
            {
                if (target_.buttonMasksFrom == null)
                {
                    target_.buttonMasksFrom = new int[target_.maxButtons];
                    target_.buttonMasksTo   = new int[target_.maxButtons];
                }
                else
                {
                    System.Array.Resize(ref target_.buttonMasksFrom, target_.maxButtons);
                    System.Array.Resize(ref target_.buttonMasksTo, target_.maxButtons);
                }
            }
            //
            if (!EnsureEnum(target_.enumTypeFrom, ref m_EnumFrom))
            {
                return;
            }
            if (!EnsureEnum(target_.enumTypeTo, ref m_EnumTo))
            {
                return;
            }
            EditorGUILayout.Space();
            //
            if (m_HeaderStyle == null)
            {
                m_HeaderStyle           = new GUIStyle(GUI.skin.label);
                m_HeaderStyle.fontStyle = FontStyle.Bold;
                m_HeaderStyle.fontSize  = 12;
            }
            EditorGUILayout.LabelField("Buttons", m_HeaderStyle);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Save"))
            {
                string path = EditorUtility.SaveFilePanel("Save", "", target_.name, "txt");
                if (!string.IsNullOrEmpty(path))
                {
                    SaveAsText(path, target_);
                }
            }
            if (GUILayout.Button("Load"))
            {
                string path = EditorUtility.OpenFilePanel("Load", "", "txt");
                if (!string.IsNullOrEmpty(path))
                {
                    LoadAsText(path, target_);
                }
            }
            GUILayout.EndHorizontal();
            //
            if (m_IsFoldout = EditorGUILayout.Foldout(m_IsFoldout, "Transform"))
            {
                GUILayoutOption myWidth = null;
                GUILayout.BeginHorizontal();
                GUILayout.BeginVertical(); myWidth = GUILayout.MinWidth(100f);
                EditorGUILayout.LabelField("From(" + target_.enumTypeFrom + ")", myWidth);
                for (int i = 0, imax = target_.maxButtons; i < imax; ++i)
                {
                    m_EnumFrom.OnGUI(target_, ref target_.buttonMasksFrom[i], myWidth);
                }
                GUILayout.EndVertical();
                GUILayout.BeginVertical(); myWidth = GUILayout.Width(24f);
                EditorGUILayout.LabelField("", myWidth);
                for (int i = 0, imax = target_.maxButtons; i < imax; ++i)
                {
                    EditorGUILayout.LabelField("=>", myWidth);
                }
                GUILayout.EndVertical();
                GUILayout.BeginHorizontal();
                GUILayout.BeginVertical(); myWidth = GUILayout.MinWidth(100f);
                EditorGUILayout.LabelField("To(" + target_.enumTypeTo + ")", myWidth);
                for (int i = 0, imax = target_.maxButtons; i < imax; ++i)
                {
                    m_EnumTo.OnGUI(target_, ref target_.buttonMasksTo[i], myWidth);
                }
                GUILayout.EndVertical();
                GUILayout.EndHorizontal();
            }
        }