작업 조건 분석 기능 개발
This commit is contained in:
32
Assets/Chart And Graph/Editor/AutoFloatInspector.cs
Normal file
32
Assets/Chart And Graph/Editor/AutoFloatInspector.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(AutoFloat))]
|
||||
class AutoFloatInspector : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
label = EditorGUI.BeginProperty(position, label, property);
|
||||
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
||||
SerializedProperty auto = property.FindPropertyRelative("Automatic");
|
||||
SerializedProperty val = property.FindPropertyRelative("Value");
|
||||
int indent = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 0;
|
||||
bool res = EditorGUI.ToggleLeft(position,"Auto",auto.boolValue);
|
||||
EditorGUI.indentLevel = indent;
|
||||
EditorGUI.indentLevel++;
|
||||
if (auto.boolValue == false && EditorGUI.showMixedValue == false)
|
||||
val.floatValue = EditorGUILayout.FloatField("Value",val.floatValue);
|
||||
auto.boolValue = res;
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/AutoFloatInspector.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/AutoFloatInspector.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c989bbf118ca01e4aab213559170875f
|
||||
timeCreated: 1479209594
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
275
Assets/Chart And Graph/Editor/AxisInspector.cs
Normal file
275
Assets/Chart And Graph/Editor/AxisInspector.cs
Normal file
@@ -0,0 +1,275 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using ChartAndGraph;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
[CustomEditor(typeof(AxisBase), true)]
|
||||
class AxisInspector : Editor
|
||||
{
|
||||
bool mMain = false;
|
||||
bool mSub = false;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
AxisBase axis = (AxisBase)target;
|
||||
|
||||
if (axis.gameObject == null)
|
||||
return;
|
||||
|
||||
AnyChart chart = axis.gameObject.GetComponent<AnyChart>();
|
||||
if (chart == null)
|
||||
return;
|
||||
if((chart is AxisChart) == false)
|
||||
{
|
||||
EditorGUILayout.LabelField(string.Format("Chart of type {0} does not support axis",chart.GetType().Name));
|
||||
return;
|
||||
}
|
||||
SerializedProperty simpleViewProp = serializedObject.FindProperty("SimpleView");
|
||||
if (simpleViewProp == null)
|
||||
return;
|
||||
|
||||
Type canvasType = (chart is ICanvas) ? typeof(CanvasAttribute) : typeof(NonCanvasAttribute);
|
||||
|
||||
EditorGUILayout.BeginVertical();
|
||||
bool negate = false;
|
||||
if (simpleViewProp.boolValue == true)
|
||||
negate = GUILayout.Button("Advanced View");
|
||||
else
|
||||
negate = GUILayout.Button("Simple View");
|
||||
if (negate)
|
||||
simpleViewProp.boolValue = !simpleViewProp.boolValue;
|
||||
bool simple = simpleViewProp.boolValue;
|
||||
|
||||
|
||||
SerializedProperty depth = serializedObject.FindProperty("depth");
|
||||
if (depth != null)
|
||||
EditorGUILayout.PropertyField(depth);
|
||||
SerializedProperty format= serializedObject.FindProperty("format");
|
||||
EditorGUILayout.PropertyField(format);
|
||||
if (simple)
|
||||
DoSimpleView(canvasType);
|
||||
else
|
||||
DoAdvanvedView(canvasType,true);
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
serializedObject.Update();
|
||||
}
|
||||
|
||||
void SetValue(SerializedProperty assignTo,SerializedProperty from)
|
||||
{
|
||||
|
||||
if(assignTo.propertyType != from.propertyType)
|
||||
{
|
||||
Debug.LogWarning("type does not match");
|
||||
return;
|
||||
}
|
||||
|
||||
if (assignTo.type == "AutoFloat")
|
||||
{
|
||||
SerializedProperty auto = assignTo.FindPropertyRelative("Automatic");
|
||||
SerializedProperty val = assignTo.FindPropertyRelative("Value");
|
||||
SerializedProperty autofrom = from.FindPropertyRelative("Automatic");
|
||||
SerializedProperty valfrom = from.FindPropertyRelative("Value");
|
||||
auto.boolValue = autofrom.boolValue;
|
||||
val.floatValue = valfrom.floatValue;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (assignTo.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Float:
|
||||
assignTo.floatValue = from.floatValue;
|
||||
break;
|
||||
case SerializedPropertyType.Integer:
|
||||
assignTo.intValue = from.intValue;
|
||||
break;
|
||||
case SerializedPropertyType.Enum:
|
||||
assignTo.enumValueIndex = from.enumValueIndex;
|
||||
break;
|
||||
case SerializedPropertyType.Boolean:
|
||||
assignTo.boolValue = from.boolValue;
|
||||
break;
|
||||
case SerializedPropertyType.String:
|
||||
assignTo.stringValue = from.stringValue;
|
||||
break;
|
||||
case SerializedPropertyType.ObjectReference:
|
||||
assignTo.objectReferenceValue = from.objectReferenceValue;
|
||||
break;
|
||||
default:
|
||||
Debug.LogWarning("type cannot be set");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Type getTypeFromField(Type type,string fieldName)
|
||||
{
|
||||
FieldInfo inf = type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
if (inf == null)
|
||||
return null;
|
||||
return inf.FieldType;
|
||||
}
|
||||
|
||||
bool CompareValues(Type type,string fieldName,object a,object b)
|
||||
{
|
||||
FieldInfo inf= type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
object valA = inf.GetValue(a);
|
||||
object valB = inf.GetValue(b);
|
||||
if(valA is UnityEngine.Object && valB is UnityEngine.Object)
|
||||
{
|
||||
if(((UnityEngine.Object)valA) == ((UnityEngine.Object)valB))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
if (valA == null && valB == null)
|
||||
return true;
|
||||
if (valA == null || valB == null)
|
||||
return false;
|
||||
return valA.Equals(valB);
|
||||
}
|
||||
|
||||
void DoSimpleView(Type canvasType)
|
||||
{
|
||||
SerializedProperty it = serializedObject.FindProperty("mainDivisions");
|
||||
SerializedProperty SubDivisions = serializedObject.FindProperty("subDivisions");
|
||||
object mainDivision = ((AxisBase)target).MainDivisions;
|
||||
object subDivision = ((AxisBase)target).SubDivisions;
|
||||
if (it == null || SubDivisions == null)
|
||||
return;
|
||||
SerializedProperty end = it.GetEndProperty();
|
||||
while(it.NextVisible(true) && SerializedProperty.EqualContents(end,it) == false)
|
||||
{
|
||||
if (it.name == "SimpleView")
|
||||
continue;
|
||||
if (ChartEditorCommon.HasAttributeOfType(typeof(ChartDivisionInfo), it.name, canvasType) == false)
|
||||
if (ChartEditorCommon.HasAttributeOfType(typeof(AxisBase), it.name, canvasType) == false)
|
||||
continue;
|
||||
if (ChartEditorCommon.HasAttributeOfType(typeof(AxisBase), it.name, typeof(SimpleAttribute)) == false)
|
||||
if (ChartEditorCommon.HasAttributeOfType(typeof(ChartDivisionInfo), it.name, typeof(SimpleAttribute)) == false)
|
||||
continue;
|
||||
SerializedProperty clone = SubDivisions.FindPropertyRelative(it.name);
|
||||
if (clone == null)
|
||||
Debug.LogWarning("can't find property " + it.name);
|
||||
bool equal = CompareValues(typeof(ChartDivisionInfo), clone.name, mainDivision, subDivision);
|
||||
Type t = getTypeFromField(typeof(ChartDivisionInfo), clone.name);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.showMixedValue = !equal;
|
||||
DoMixedFiled(it, t);
|
||||
EditorGUI.showMixedValue = false;
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
SetValue(clone, it);
|
||||
}
|
||||
DoAdvanvedView(canvasType,false);
|
||||
}
|
||||
public void DoMixedFiled(SerializedProperty prop,Type type)
|
||||
{
|
||||
if(prop.type == "AutoFloat")
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.PrefixLabel(prop.displayName);
|
||||
SerializedProperty auto = prop.FindPropertyRelative("Automatic");
|
||||
SerializedProperty val = prop.FindPropertyRelative("Value");
|
||||
auto.boolValue = EditorGUILayout.ToggleLeft("Auto", auto.boolValue);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUI.indentLevel++;
|
||||
if (auto.boolValue == false && EditorGUI.showMixedValue == false)
|
||||
val.floatValue = EditorGUILayout.FloatField("Value",val.floatValue);
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
return;
|
||||
}
|
||||
switch(prop.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Float:
|
||||
if(prop.name == "FontSharpness")
|
||||
prop.floatValue = EditorGUILayout.Slider(prop.displayName, prop.floatValue,1f,3f);
|
||||
else
|
||||
prop.floatValue = EditorGUILayout.FloatField(prop.displayName,prop.floatValue);
|
||||
break;
|
||||
case SerializedPropertyType.Integer:
|
||||
if (prop.name == "FractionDigits")
|
||||
prop.intValue = EditorGUILayout.IntSlider(prop.displayName, prop.intValue,0,7);
|
||||
else
|
||||
prop.intValue = EditorGUILayout.IntField(prop.displayName, prop.intValue);
|
||||
break;
|
||||
case SerializedPropertyType.Enum:
|
||||
ChartDivisionAligment selected = (ChartDivisionAligment)Enum.Parse( typeof(ChartDivisionAligment), prop.enumNames[prop.enumValueIndex]);
|
||||
Enum res = EditorGUILayout.EnumPopup(prop.displayName, selected);
|
||||
string newName= Enum.GetName(typeof(ChartDivisionAligment), res);
|
||||
for (int i = 0; i < prop.enumNames.Length; ++i)
|
||||
{
|
||||
if (prop.enumNames[i] == newName)
|
||||
{
|
||||
prop.enumValueIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SerializedPropertyType.String:
|
||||
prop.stringValue = EditorGUILayout.TextField(prop.displayName, prop.stringValue);
|
||||
break;
|
||||
case SerializedPropertyType.Boolean:
|
||||
prop.boolValue = EditorGUILayout.Toggle(prop.displayName, prop.boolValue);
|
||||
break;
|
||||
case SerializedPropertyType.ObjectReference:
|
||||
if(type != null)
|
||||
prop.objectReferenceValue = EditorGUILayout.ObjectField(prop.displayName, prop.objectReferenceValue, type, true);
|
||||
break;
|
||||
default:
|
||||
Debug.LogWarning("type cannot be set");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DoAdvanvedView(Type canvasType,bool includeSimple)
|
||||
{
|
||||
SerializedProperty mainDivisions = serializedObject.FindProperty("mainDivisions");
|
||||
SerializedProperty subDivisions = serializedObject.FindProperty("subDivisions");
|
||||
mMain =mainDivisions.isExpanded = EditorGUILayout.Foldout(mainDivisions.isExpanded, "Main Divisions");
|
||||
if (mMain)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
SerializedProperty end = mainDivisions.GetEndProperty();
|
||||
while (mainDivisions.NextVisible(true) && SerializedProperty.EqualContents(mainDivisions, end) == false)
|
||||
{
|
||||
if (ChartEditorCommon.HasAttributeOfType(typeof(ChartDivisionInfo), mainDivisions.name, canvasType) == false)
|
||||
if (ChartEditorCommon.HasAttributeOfType(typeof(AxisBase), mainDivisions.name, canvasType) == false)
|
||||
continue;
|
||||
if (includeSimple == false)
|
||||
{
|
||||
if (ChartEditorCommon.HasAttributeOfType(typeof(ChartDivisionInfo), mainDivisions.name, typeof(SimpleAttribute)))
|
||||
continue;
|
||||
}
|
||||
EditorGUILayout.PropertyField(mainDivisions);
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
mSub = subDivisions.isExpanded = EditorGUILayout.Foldout(subDivisions.isExpanded, "Sub Divisions");
|
||||
if (mSub)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
SerializedProperty end = subDivisions.GetEndProperty();
|
||||
while (subDivisions.NextVisible(true) && SerializedProperty.EqualContents(subDivisions, end) == false)
|
||||
{
|
||||
if (ChartEditorCommon.HasAttributeOfType(typeof(ChartDivisionInfo), subDivisions.name, canvasType) == false)
|
||||
if (ChartEditorCommon.HasAttributeOfType(typeof(AxisBase), subDivisions.name, canvasType) == false)
|
||||
continue;
|
||||
if (includeSimple == false)
|
||||
{
|
||||
if (ChartEditorCommon.HasAttributeOfType(typeof(ChartDivisionInfo), subDivisions.name, typeof(SimpleAttribute)))
|
||||
continue;
|
||||
}
|
||||
EditorGUILayout.PropertyField(subDivisions);
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/AxisInspector.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/AxisInspector.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 898567b381452e94794158c16012f617
|
||||
timeCreated: 1479124371
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
364
Assets/Chart And Graph/Editor/BarChartInspetor.cs
Normal file
364
Assets/Chart And Graph/Editor/BarChartInspetor.cs
Normal file
@@ -0,0 +1,364 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
|
||||
using ChartAndGraph;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[CustomEditor(typeof(BarChart),true)]
|
||||
class BarChartInspetor : Editor
|
||||
{
|
||||
bool mCategories = false;
|
||||
bool mGroups = false;
|
||||
string mCategoryError = null;
|
||||
string mNewCategoryName = "";
|
||||
string mNewGroupName = "";
|
||||
string mGroupError = null;
|
||||
GUIStyle mRedStyle;
|
||||
GUIStyle mBold;
|
||||
HashSet<string> mAllNames = new HashSet<string>();
|
||||
GUIStyle mSplitter;
|
||||
List<int> mToRemove = new List<int>();
|
||||
List<int> mToUp = new List<int>();
|
||||
Dictionary<string, string> mOperations = new Dictionary<string, string>();
|
||||
ChartDataEditor mWindow;
|
||||
bool mUpdateWindow = false;
|
||||
Texture mSettings;
|
||||
GUIContent MaxBarValue = new GUIContent("Max Bar Value :", "All the bars are scaled according to this value, Bars that are larger then this value are clamped");
|
||||
GUIContent MinBarValue = new GUIContent("Min Bar Value :", "All the bars are scaled according to this value, Bars that are lower then this value are clamped");
|
||||
RenameWindow mRenameWindow;
|
||||
public void OnEnable()
|
||||
{
|
||||
mRedStyle = new GUIStyle();
|
||||
mRedStyle.normal.textColor = Color.red;
|
||||
|
||||
mSplitter = new GUIStyle();
|
||||
mSplitter.normal.background = EditorGUIUtility.whiteTexture;
|
||||
mSplitter.stretchWidth = true;
|
||||
mSplitter.margin = new RectOffset(0, 0, 7, 7);
|
||||
}
|
||||
|
||||
public void Splitter()
|
||||
{
|
||||
Rect position = GUILayoutUtility.GetRect(GUIContent.none, mSplitter, GUILayout.Height(1f));
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
Color restoreColor = GUI.color;
|
||||
GUI.color = new Color(0.5f, 0.5f, 0.5f);
|
||||
mSplitter.Draw(position, false, false, false, false);
|
||||
GUI.color = restoreColor;
|
||||
}
|
||||
}
|
||||
|
||||
private void DoOperations(SerializedProperty items,int size,string type)
|
||||
{
|
||||
mToRemove.Clear();
|
||||
mToUp.Clear();
|
||||
bool up = false;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
SerializedProperty entry = items.GetArrayElementAtIndex(i);
|
||||
if (entry == null)
|
||||
continue;
|
||||
SerializedProperty nameProp = entry.FindPropertyRelative("Name");
|
||||
string name = null;
|
||||
if (nameProp == null)
|
||||
name = entry.stringValue;
|
||||
else
|
||||
name = nameProp.stringValue;
|
||||
|
||||
string arg = type + "|" + name;
|
||||
string res = null;
|
||||
if (up == true)
|
||||
{
|
||||
mToUp.Add(i);
|
||||
up = false;
|
||||
}
|
||||
if (mOperations.TryGetValue(arg, out res))
|
||||
{
|
||||
if (res == "remove")
|
||||
mToRemove.Add(i);
|
||||
if (res == "up" && i > 0)
|
||||
mToUp.Add(i);
|
||||
if (res == "down")
|
||||
up = true;
|
||||
mOperations.Remove(arg);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < mToRemove.Count; i++)
|
||||
items.DeleteArrayElementAtIndex(mToRemove[i]);
|
||||
for (int i = 0; i < mToUp.Count; i++)
|
||||
{
|
||||
int cur = mToUp[i];
|
||||
items.MoveArrayElement(cur, cur - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void NamedItemEditor(SerializedProperty data, string type, string property, string caption, ref string errorMessage, ref bool foldout, ref string newName)
|
||||
{
|
||||
SerializedProperty items = data.FindPropertyRelative(property);
|
||||
items.isExpanded = EditorGUILayout.Foldout(items.isExpanded, caption);
|
||||
//bool up, down;
|
||||
mAllNames.Clear();
|
||||
int size = items.arraySize;
|
||||
if (Event.current.type == EventType.Layout)
|
||||
DoOperations(items, size, type);
|
||||
size = items.arraySize;
|
||||
if (items.isExpanded)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
SerializedProperty entry = items.GetArrayElementAtIndex(i);
|
||||
if (entry == null)
|
||||
continue;
|
||||
SerializedProperty nameProp = entry.FindPropertyRelative("Name");
|
||||
string name = null;
|
||||
if (nameProp == null)
|
||||
name = entry.stringValue;
|
||||
else
|
||||
name = nameProp.stringValue;
|
||||
mAllNames.Add(name);
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
bool toogle = false;
|
||||
if (nameProp != null)
|
||||
toogle = entry.isExpanded = EditorGUILayout.Foldout(entry.isExpanded, name);
|
||||
else
|
||||
{
|
||||
toogle = false;
|
||||
EditorGUILayout.LabelField(name);
|
||||
}
|
||||
GUILayout.FlexibleSpace();
|
||||
if(GUILayout.Button("..."))
|
||||
DoContext(type, name);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if (toogle)
|
||||
{
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
if (nameProp != null)
|
||||
{
|
||||
SerializedProperty end = entry.GetEndProperty(true);
|
||||
entry.Next(true);
|
||||
if (SerializedProperty.EqualContents(entry, end) == false)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (entry.name != "Name")
|
||||
EditorGUILayout.PropertyField(entry, true);
|
||||
}
|
||||
while (entry.Next(entry.name == "Materials") && SerializedProperty.EqualContents(entry, end) == false);
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (errorMessage != null)
|
||||
EditorGUILayout.LabelField(errorMessage, mRedStyle);
|
||||
EditorGUILayout.LabelField(string.Format("Add new {0} :", type));
|
||||
//Rect indentAdd = EditorGUI.IndentedRect(new Rect(0f, 0f, 1000f, 1000f));
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
newName = EditorGUILayout.TextField(newName);
|
||||
//GUILayout.Space(indentAdd.xMin);
|
||||
if (GUILayout.Button("Add"))
|
||||
{
|
||||
bool error = false;
|
||||
if (newName.Trim().Length == 0)
|
||||
{
|
||||
errorMessage = "Name can't be empty";
|
||||
error = true;
|
||||
}
|
||||
else if (ChartEditorCommon.IsAlphaNum(newName) == false)
|
||||
{
|
||||
errorMessage = "Name conatins invalid characters";
|
||||
error = true;
|
||||
}
|
||||
else if (mAllNames.Contains(newName))
|
||||
{
|
||||
errorMessage = string.Format("A {0} named {1} already exists in this chart", type, newName);
|
||||
error = true;
|
||||
}
|
||||
if (error == false)
|
||||
{
|
||||
errorMessage = null;
|
||||
items.InsertArrayElementAtIndex(size);
|
||||
SerializedProperty newItem = items.GetArrayElementAtIndex(size);
|
||||
SerializedProperty newItemName = newItem.FindPropertyRelative("Name");
|
||||
if (newItemName == null)
|
||||
newItem.stringValue = newName;
|
||||
else
|
||||
newItemName.stringValue = newName;
|
||||
newName = "";
|
||||
UpdateWindow();
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessage = null;
|
||||
}
|
||||
UpdateWindow();
|
||||
}
|
||||
|
||||
void callback(object val)
|
||||
{
|
||||
KeyValuePair<string, string> pair = (KeyValuePair<string, string>)val;
|
||||
mOperations[pair.Key] = pair.Value;
|
||||
}
|
||||
|
||||
bool RenameGroup(string fromName, string toName)
|
||||
{
|
||||
BarChart barChart = (BarChart)serializedObject.targetObject;
|
||||
try
|
||||
{
|
||||
barChart.DataSource.RenameGroup(fromName, toName);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
serializedObject.Update();
|
||||
if (barChart.gameObject.activeInHierarchy)
|
||||
barChart.GenerateChart();
|
||||
else
|
||||
EditorUtility.SetDirty(barChart);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenameCategory(string fromName,string toName)
|
||||
{
|
||||
BarChart barChart = (BarChart)serializedObject.targetObject;
|
||||
try
|
||||
{
|
||||
barChart.DataSource.RenameCategory(fromName, toName);
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
serializedObject.Update();
|
||||
if(barChart.gameObject.activeInHierarchy)
|
||||
barChart.GenerateChart();
|
||||
else
|
||||
EditorUtility.SetDirty(barChart);
|
||||
return true;
|
||||
}
|
||||
void RenameCalled(object val)
|
||||
{
|
||||
var data = (KeyValuePair<string, string>)val;
|
||||
RenameWindow window = EditorWindow.GetWindow<RenameWindow>();
|
||||
mRenameWindow = window;
|
||||
if(data.Key == "category")
|
||||
window.ShowDialog(data.Value, data.Key, RenameCategory);
|
||||
else if(data.Key == "group")
|
||||
window.ShowDialog(data.Value, data.Key, RenameGroup);
|
||||
}
|
||||
void DoContext(string type,string name)
|
||||
{
|
||||
string arg = type + "|" + name;
|
||||
GenericMenu menu = new GenericMenu();
|
||||
menu.AddItem(new GUIContent("Move Up"), false,callback, new KeyValuePair<string, string>(arg, "up"));
|
||||
menu.AddItem(new GUIContent("Move Down"), false, callback, new KeyValuePair<string, string>(arg, "down"));
|
||||
menu.AddItem(new GUIContent("Remove"), false, callback, new KeyValuePair<string, string>(arg, "remove"));
|
||||
menu.AddItem(new GUIContent("Rename.."), false, RenameCalled, new KeyValuePair<string, string>(type, name));
|
||||
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
void UpdateWindow()
|
||||
{
|
||||
mUpdateWindow = true;
|
||||
}
|
||||
void OnDisable()
|
||||
{
|
||||
if(mRenameWindow != null)
|
||||
{
|
||||
mRenameWindow.Close();
|
||||
mRenameWindow = null;
|
||||
}
|
||||
if (mWindow != null)
|
||||
{
|
||||
mWindow.Close();
|
||||
mWindow = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
serializedObject.Update();
|
||||
SerializedProperty barData = serializedObject.FindProperty("Data");
|
||||
EditorGUILayout.BeginVertical();
|
||||
Splitter();
|
||||
if(mBold == null)
|
||||
{
|
||||
mBold = new GUIStyle(EditorStyles.foldout);
|
||||
//mBold.fontStyle = FontStyle.Bold;
|
||||
}
|
||||
// EditorStyles.foldout.fontStyle = FontStyle.Bold;
|
||||
// fold = EditorGUILayout.Foldout(fold,"Bar Data", EditorStyles.foldout);
|
||||
//EditorStyles.foldout.fontStyle = FontStyle.Normal;
|
||||
// if (fold)
|
||||
// {
|
||||
EditorGUILayout.LabelField("Data", EditorStyles.boldLabel);
|
||||
EditorGUI.indentLevel++;
|
||||
NamedItemEditor(barData, "category", "mCategories", "Categories", ref mCategoryError, ref mCategories, ref mNewCategoryName);
|
||||
NamedItemEditor(barData, "group", "mGroups", "Groups", ref mGroupError, ref mGroups, ref mNewGroupName);
|
||||
|
||||
SerializedProperty maxProp = barData.FindPropertyRelative("maxValue");
|
||||
SerializedProperty minProp = barData.FindPropertyRelative("minValue");
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField(MinBarValue, EditorStyles.boldLabel);
|
||||
SerializedProperty automaticProp = barData.FindPropertyRelative("automaticMinValue");
|
||||
bool automatic = automaticProp.boolValue;
|
||||
automatic = GUILayout.Toggle(automatic, "Auto");
|
||||
GUILayout.FlexibleSpace();
|
||||
automaticProp.boolValue = automatic;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if (automatic == false)
|
||||
{
|
||||
EditorGUILayout.PropertyField(minProp);
|
||||
if (minProp.doubleValue > maxProp.doubleValue)
|
||||
minProp.doubleValue = maxProp.doubleValue - 0.1;
|
||||
}
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField(MaxBarValue, EditorStyles.boldLabel);
|
||||
automaticProp = barData.FindPropertyRelative("automaticMaxValue");
|
||||
automatic = automaticProp.boolValue;
|
||||
automatic = GUILayout.Toggle(automatic, "Auto");
|
||||
GUILayout.FlexibleSpace();
|
||||
automaticProp.boolValue = automatic;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if (automatic == false)
|
||||
{
|
||||
|
||||
EditorGUILayout.PropertyField(maxProp);
|
||||
if (minProp.doubleValue > maxProp.doubleValue)
|
||||
maxProp.doubleValue = minProp.doubleValue + 0.1;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Edit Values...") && mWindow == null)
|
||||
mWindow = ChartDataEditor.ShowForObject(serializedObject);
|
||||
//}
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUILayout.EndVertical();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
if (mUpdateWindow == true)
|
||||
{
|
||||
mUpdateWindow = false;
|
||||
if (mWindow != null)
|
||||
{
|
||||
mWindow.SetEditedObject(serializedObject);
|
||||
mWindow.Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/BarChartInspetor.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/BarChartInspetor.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 056f0fff5e172de468df8c3392cabaac
|
||||
timeCreated: 1473969758
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "Bitsplash.GraphAndChart.Editor",
|
||||
"references": [
|
||||
"GUID:aa9320822a6e56c41a6d780e3d208040"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6b78e7ca51d6ea40a07a6f0f01838a7
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
408
Assets/Chart And Graph/Editor/CandleChartInspector.cs
Normal file
408
Assets/Chart And Graph/Editor/CandleChartInspector.cs
Normal file
@@ -0,0 +1,408 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
[CustomEditor(typeof(CandleChart), true)]
|
||||
class CandleChartInspector : Editor
|
||||
{
|
||||
bool mCategories = false;
|
||||
string mCategoryError = null;
|
||||
string mNewCategoryName = "";
|
||||
GUIStyle mRedStyle;
|
||||
GUIStyle mBold;
|
||||
HashSet<string> mAllNames = new HashSet<string>();
|
||||
GUIStyle mSplitter;
|
||||
List<int> mToRemove = new List<int>();
|
||||
List<int> mToUp = new List<int>();
|
||||
Dictionary<string, string> mOperations = new Dictionary<string, string>();
|
||||
ChartDataEditor mWindow;
|
||||
Texture mSettings;
|
||||
|
||||
RenameWindow mRenameWindow = null;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
mRedStyle = new GUIStyle();
|
||||
mRedStyle.normal.textColor = Color.red;
|
||||
|
||||
mSplitter = new GUIStyle();
|
||||
mSplitter.normal.background = EditorGUIUtility.whiteTexture;
|
||||
mSplitter.stretchWidth = true;
|
||||
mSplitter.margin = new RectOffset(0, 0, 7, 7);
|
||||
}
|
||||
|
||||
public void Splitter()
|
||||
{
|
||||
Rect position = GUILayoutUtility.GetRect(GUIContent.none, mSplitter, GUILayout.Height(1f));
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
Color restoreColor = GUI.color;
|
||||
GUI.color = new Color(0.5f, 0.5f, 0.5f);
|
||||
mSplitter.Draw(position, false, false, false, false);
|
||||
GUI.color = restoreColor;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsAlphaNum(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < str.Length; i++)
|
||||
{
|
||||
if (!(char.IsLetter(str[i])) && (!(char.IsNumber(str[i]))) && str[i] != ' ')
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void DoOperations(SerializedProperty items, int size, string type)
|
||||
{
|
||||
mToRemove.Clear();
|
||||
mToUp.Clear();
|
||||
bool up = false;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
SerializedProperty entry = items.GetArrayElementAtIndex(i);
|
||||
if (entry == null)
|
||||
continue;
|
||||
SerializedProperty nameProp = entry.FindPropertyRelative("Name");
|
||||
string name = null;
|
||||
if (nameProp == null)
|
||||
name = entry.stringValue;
|
||||
else
|
||||
name = nameProp.stringValue;
|
||||
|
||||
string arg = type + "|" + name;
|
||||
string res = null;
|
||||
|
||||
if (up == true)
|
||||
{
|
||||
mToUp.Add(i);
|
||||
up = false;
|
||||
}
|
||||
|
||||
if (mOperations.TryGetValue(arg, out res))
|
||||
{
|
||||
if (res == "remove")
|
||||
mToRemove.Add(i);
|
||||
if (res == "up" && i > 0)
|
||||
mToUp.Add(i);
|
||||
if (res == "down")
|
||||
up = true;
|
||||
mOperations.Remove(arg);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < mToRemove.Count; i++)
|
||||
{
|
||||
items.DeleteArrayElementAtIndex(mToRemove[i]);
|
||||
}
|
||||
for (int i = 0; i < mToUp.Count; i++)
|
||||
{
|
||||
int cur = mToUp[i];
|
||||
items.MoveArrayElement(cur, cur - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void CandleSettings(SerializedProperty item)
|
||||
{
|
||||
SerializedProperty entry = item.Copy();
|
||||
EditorGUILayout.LabelField(entry.name);
|
||||
EditorGUI.indentLevel++;
|
||||
SerializedProperty end = entry.GetEndProperty(true);
|
||||
entry.Next(true);
|
||||
if (SerializedProperty.EqualContents(entry, end) == false)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (target is CandleChart) // canvas graph chart
|
||||
{
|
||||
if ((entry.name == "CandlePrefab"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (entry.name == "CandleHoverPrefab")
|
||||
continue;
|
||||
}
|
||||
EditorGUILayout.PropertyField(entry, true);
|
||||
}
|
||||
while (entry.Next(false) && SerializedProperty.EqualContents(entry, end) == false);
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
private void NamedItemEditor(SerializedProperty data, string type, string property, string caption, ref string errorMessage, ref bool foldout, ref string newName)
|
||||
{
|
||||
SerializedProperty items = data.FindPropertyRelative(property);
|
||||
items.isExpanded = EditorGUILayout.Foldout(items.isExpanded, caption);
|
||||
//bool up, down;
|
||||
mAllNames.Clear();
|
||||
int size = items.arraySize;
|
||||
if (Event.current.type == EventType.Layout)
|
||||
DoOperations(items, size, type);
|
||||
size = items.arraySize;
|
||||
if (items.isExpanded)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
SerializedProperty entry = items.GetArrayElementAtIndex(i);
|
||||
if (entry == null)
|
||||
continue;
|
||||
|
||||
SerializedProperty nameProp = entry.FindPropertyRelative("Name");
|
||||
string name = null;
|
||||
if (nameProp == null)
|
||||
name = entry.stringValue;
|
||||
else
|
||||
name = nameProp.stringValue;
|
||||
mAllNames.Add(name);
|
||||
bool toogle = false;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (nameProp != null)
|
||||
toogle = entry.isExpanded = EditorGUILayout.Foldout(entry.isExpanded, name);
|
||||
else
|
||||
{
|
||||
toogle = false;
|
||||
EditorGUILayout.LabelField(name);
|
||||
}
|
||||
GUILayout.FlexibleSpace();
|
||||
if (GUILayout.Button("..."))
|
||||
DoContext(type, name);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if (toogle)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
if (nameProp != null)
|
||||
{
|
||||
SerializedProperty end = entry.GetEndProperty(true);
|
||||
entry.Next(true);
|
||||
if (SerializedProperty.EqualContents(entry, end) == false)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (entry.name != "Name" && entry.name != "Data")
|
||||
{
|
||||
if (target is CandleChart) // canvas graph chart
|
||||
{
|
||||
if ((entry.name == "LinePrefab") || (entry.name == "FillPrefab") || (entry.name == "DotPrefab") || (entry.name == "Depth"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((entry.name == "LineHoverPrefab") || (entry.name == "PointHoverPrefab"))
|
||||
continue;
|
||||
}
|
||||
if (entry.name == "UpCandle" || entry.name == "DownCandle")
|
||||
CandleSettings(entry);
|
||||
else
|
||||
EditorGUILayout.PropertyField(entry, true);
|
||||
}
|
||||
}
|
||||
while (entry.Next(false) && SerializedProperty.EqualContents(entry, end) == false);
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
|
||||
if (errorMessage != null)
|
||||
EditorGUILayout.LabelField(errorMessage, mRedStyle);
|
||||
EditorGUILayout.LabelField(string.Format("Add new {0} :", type));
|
||||
//Rect indentAdd = EditorGUI.IndentedRect(new Rect(0f, 0f, 1000f, 1000f));
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
newName = EditorGUILayout.TextField(newName);
|
||||
//GUILayout.Space(indentAdd.xMin);
|
||||
if (GUILayout.Button("Add"))
|
||||
{
|
||||
bool error = false;
|
||||
if (newName.Trim().Length == 0)
|
||||
{
|
||||
errorMessage = "Name can't be empty";
|
||||
error = true;
|
||||
}
|
||||
else if (IsAlphaNum(newName) == false)
|
||||
{
|
||||
errorMessage = "Name conatins invalid characters";
|
||||
error = true;
|
||||
}
|
||||
else if (mAllNames.Contains(newName))
|
||||
{
|
||||
errorMessage = string.Format("A {0} named {1} already exists in this chart", type, newName);
|
||||
error = true;
|
||||
}
|
||||
if (error == false)
|
||||
{
|
||||
errorMessage = null;
|
||||
items.InsertArrayElementAtIndex(size);
|
||||
SerializedProperty newItem = items.GetArrayElementAtIndex(size);
|
||||
SerializedProperty newItemName = newItem.FindPropertyRelative("Name");
|
||||
if (newItemName == null)
|
||||
newItem.stringValue = newName;
|
||||
else
|
||||
newItemName.stringValue = newName;
|
||||
newName = "";
|
||||
UpdateWindow();
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessage = null;
|
||||
}
|
||||
UpdateWindow();
|
||||
}
|
||||
void callback(object val)
|
||||
{
|
||||
KeyValuePair<string, string> pair = (KeyValuePair<string, string>)val;
|
||||
mOperations[pair.Key] = pair.Value;
|
||||
}
|
||||
bool RenameCategory(string oldName, string newName)
|
||||
{
|
||||
CandleChart graph = (CandleChart)serializedObject.targetObject;
|
||||
try
|
||||
{
|
||||
graph.DataSource.RenameCategory(oldName, newName);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
serializedObject.Update();
|
||||
if (graph.gameObject.activeInHierarchy)
|
||||
graph.GenerateChart();
|
||||
else
|
||||
EditorUtility.SetDirty(graph);
|
||||
return true;
|
||||
}
|
||||
void RenameCalled(object val)
|
||||
{
|
||||
var data = (KeyValuePair<string, string>)val;
|
||||
RenameWindow window = EditorWindow.GetWindow<RenameWindow>();
|
||||
mRenameWindow = window;
|
||||
window.ShowDialog(data.Value, data.Key, RenameCategory);
|
||||
}
|
||||
void DoContext(string type, string name)
|
||||
{
|
||||
string arg = type + "|" + name;
|
||||
GenericMenu menu = new GenericMenu();
|
||||
menu.AddItem(new GUIContent("Move Up"), false, callback, new KeyValuePair<string, string>(arg, "up"));
|
||||
menu.AddItem(new GUIContent("Move Down"), false, callback, new KeyValuePair<string, string>(arg, "down"));
|
||||
menu.AddItem(new GUIContent("Remove"), false, callback, new KeyValuePair<string, string>(arg, "remove"));
|
||||
menu.AddItem(new GUIContent("Rename.."), false, RenameCalled, new KeyValuePair<string, string>(type, name));
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
void UpdateWindow()
|
||||
{
|
||||
}
|
||||
void OnDisable()
|
||||
{
|
||||
if (mRenameWindow != null)
|
||||
{
|
||||
mRenameWindow.Close();
|
||||
mRenameWindow = null;
|
||||
}
|
||||
if (mWindow != null)
|
||||
{
|
||||
mWindow.Close();
|
||||
mWindow = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
SerializedProperty autoScrollHorizontally = serializedObject.FindProperty("autoScrollHorizontally");
|
||||
SerializedProperty horizontalScrolling = serializedObject.FindProperty("horizontalScrolling");
|
||||
SerializedProperty autoScrollVertically = serializedObject.FindProperty("autoScrollVertically");
|
||||
SerializedProperty verticalScrolling = serializedObject.FindProperty("verticalScrolling");
|
||||
// SerializedProperty scrollable = serializedObject.FindProperty("scrollable");
|
||||
// EditorGUILayout.PropertyField(scrollable);
|
||||
// if (scrollable.boolValue == true)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(autoScrollHorizontally);
|
||||
if (autoScrollHorizontally.boolValue == false)
|
||||
EditorGUILayout.PropertyField(horizontalScrolling);
|
||||
EditorGUILayout.PropertyField(autoScrollVertically);
|
||||
if (autoScrollVertically.boolValue == false)
|
||||
EditorGUILayout.PropertyField(verticalScrolling);
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
SerializedProperty graphData = serializedObject.FindProperty("Data");
|
||||
EditorGUILayout.BeginVertical();
|
||||
Splitter();
|
||||
if (mBold == null)
|
||||
mBold = new GUIStyle(EditorStyles.foldout);
|
||||
EditorGUILayout.LabelField("Data", EditorStyles.boldLabel);
|
||||
EditorGUI.indentLevel++;
|
||||
NamedItemEditor(graphData, "category", "mSerializedData", "Categories", ref mCategoryError, ref mCategories, ref mNewCategoryName);
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
SerializedProperty horizontalOrigin = graphData.FindPropertyRelative("horizontalViewOrigin");
|
||||
SerializedProperty horizontalSize = graphData.FindPropertyRelative("horizontalViewSize");
|
||||
SerializedProperty automaticcHorizontaViewGap = graphData.FindPropertyRelative("automaticcHorizontaViewGap");
|
||||
|
||||
SerializedProperty verticalOrigin = graphData.FindPropertyRelative("verticalViewOrigin");
|
||||
SerializedProperty verticalSize = graphData.FindPropertyRelative("verticalViewSize");
|
||||
SerializedProperty automaticVerticalViewGap = graphData.FindPropertyRelative("automaticVerticalViewGap");
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField("Horizontal View", EditorStyles.boldLabel);
|
||||
SerializedProperty automaticProp = graphData.FindPropertyRelative("automaticHorizontalView");
|
||||
bool automatic = automaticProp.boolValue;
|
||||
automatic = GUILayout.Toggle(automatic, "Auto");
|
||||
GUILayout.FlexibleSpace();
|
||||
automaticProp.boolValue = automatic;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if (automatic == false)
|
||||
{
|
||||
EditorGUILayout.PropertyField(horizontalOrigin);
|
||||
EditorGUILayout.PropertyField(horizontalSize);
|
||||
// if (horizontalSize.doubleValue < 0.0)
|
||||
// horizontalSize.doubleValue = 0.0001;
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.PropertyField(automaticcHorizontaViewGap, new GUIContent("Horizontal Gap"));
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField("Vertical View", EditorStyles.boldLabel);
|
||||
automaticProp = graphData.FindPropertyRelative("automaticVerticallView");
|
||||
automatic = automaticProp.boolValue;
|
||||
automatic = GUILayout.Toggle(automatic, "Auto");
|
||||
GUILayout.FlexibleSpace();
|
||||
automaticProp.boolValue = automatic;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if (automatic == false)
|
||||
{
|
||||
EditorGUILayout.PropertyField(verticalOrigin);
|
||||
EditorGUILayout.PropertyField(verticalSize);
|
||||
// if (verticalSize.doubleValue < 0.0)
|
||||
// verticalSize.doubleValue = 0.0001;
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.PropertyField(automaticVerticalViewGap, new GUIContent("Vertical Gap"));
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
serializedObject.Update();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/CandleChartInspector.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/CandleChartInspector.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e95afd72773c44d4ab4ccd60a38ac39e
|
||||
timeCreated: 1504187754
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
67
Assets/Chart And Graph/Editor/CategoryDataEditor.cs
Normal file
67
Assets/Chart And Graph/Editor/CategoryDataEditor.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(GraphDataFiller.CategoryData))]
|
||||
class CategoryDataEditor : PropertyDrawer
|
||||
{
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return -2f;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
var enabled = property.FindPropertyRelative("Enabled");
|
||||
|
||||
property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, property.displayName);
|
||||
if(property.isExpanded)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(enabled);
|
||||
if (enabled.boolValue == true)
|
||||
{
|
||||
var dataType = property.FindPropertyRelative("DataType");
|
||||
EditorGUILayout.PropertyField(dataType);
|
||||
int item = dataType.enumValueIndex;
|
||||
var iterator = property.Copy();
|
||||
var end = iterator.GetEndProperty();
|
||||
bool hasNext = iterator.NextVisible(true);
|
||||
Type t = typeof(GraphDataFiller.CategoryData);
|
||||
while (hasNext)
|
||||
{
|
||||
if ((SerializedProperty.EqualContents(iterator, end)))
|
||||
break;
|
||||
bool show = false;
|
||||
|
||||
foreach (object attrb in t.GetField(iterator.name).GetCustomAttributes(false))
|
||||
{
|
||||
var cast = attrb as ChartFillerEditorAttribute;
|
||||
if (cast != null)
|
||||
{
|
||||
if ((int)cast.ShowForType == item)
|
||||
{
|
||||
show = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (show)
|
||||
EditorGUILayout.PropertyField(iterator);
|
||||
// Debug.Log(iterator.displayName);
|
||||
hasNext = iterator.NextVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/CategoryDataEditor.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/CategoryDataEditor.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7ad20a161538c146aa76559c3f89754
|
||||
timeCreated: 1536697084
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
26
Assets/Chart And Graph/Editor/CategoryLabelsInspector.cs
Normal file
26
Assets/Chart And Graph/Editor/CategoryLabelsInspector.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
[CustomEditor(typeof(CategoryLabels))]
|
||||
class CategoryLabelsLabelsInspector : ItemLabelsBaseEditor
|
||||
{
|
||||
protected override string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "category labels";
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool isSupported(AnyChart chart)
|
||||
{
|
||||
return ((IInternalUse)chart).InternalSupportsCategoryLables;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31ece195e6c596940a2dd7720c53058e
|
||||
timeCreated: 1480254476
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
96
Assets/Chart And Graph/Editor/ChartDataEditor.cs
Normal file
96
Assets/Chart And Graph/Editor/ChartDataEditor.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public class ChartDataEditor : UnityEditor.EditorWindow
|
||||
{
|
||||
SerializedObject mEditedObject;
|
||||
SerializedProperty mBarData;
|
||||
SerializedProperty mCategories;
|
||||
SerializedProperty mGroups;
|
||||
SerializedProperty mData;
|
||||
Dictionary<string, SerializedProperty> mValues;
|
||||
|
||||
public static ChartDataEditor ShowForObject(SerializedObject obj)
|
||||
{
|
||||
ChartDataEditor window = (ChartDataEditor)EditorWindow.GetWindow(typeof(ChartDataEditor));
|
||||
window.SetEditedObject(obj);
|
||||
return window;
|
||||
}
|
||||
|
||||
public void SetEditedObject(SerializedObject obj)
|
||||
{
|
||||
mEditedObject = obj;
|
||||
mBarData = mEditedObject.FindProperty("Data");
|
||||
mCategories = mBarData.FindPropertyRelative("mCategories");
|
||||
mGroups = mBarData.FindPropertyRelative("mGroups");
|
||||
mData = mBarData.FindPropertyRelative("mData");
|
||||
LoadData();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void LoadData()
|
||||
{
|
||||
if(mValues == null)
|
||||
mValues = new Dictionary<string, SerializedProperty>();
|
||||
mValues.Clear();
|
||||
int size = mData.arraySize;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
SerializedProperty prop = mData.GetArrayElementAtIndex(i);
|
||||
string columnName = prop.FindPropertyRelative("ColumnName").stringValue;
|
||||
string rowName = prop.FindPropertyRelative("GroupName").stringValue;
|
||||
SerializedProperty amount = prop.FindPropertyRelative("Amount");
|
||||
string keyName = getKey(columnName, rowName);
|
||||
mValues[keyName] = amount;
|
||||
}
|
||||
}
|
||||
|
||||
string getKey(string column,string row)
|
||||
{
|
||||
return string.Format("{0}|{1}", column, row);
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
GUILayout.Label("Edit Values", EditorStyles.boldLabel);
|
||||
GUILayout.BeginVertical();
|
||||
int categoryCount = mCategories.arraySize;
|
||||
int groupCount = mGroups.arraySize;
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUILayout.Label(" ",GUILayout.Width(EditorGUIUtility.fieldWidth));
|
||||
for (int i = 0; i < groupCount; i++)
|
||||
{
|
||||
string group = mGroups.GetArrayElementAtIndex(i).stringValue;
|
||||
GUILayout.Label(group, GUILayout.Width(EditorGUIUtility.fieldWidth));
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
for (int i=0; i<categoryCount; i++)
|
||||
{
|
||||
SerializedProperty catProp = mCategories.GetArrayElementAtIndex(i);
|
||||
string category = catProp.FindPropertyRelative("Name").stringValue;
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label(category, GUILayout.Width(EditorGUIUtility.fieldWidth));
|
||||
for (int j=0; j<groupCount; j++)
|
||||
{
|
||||
string group = mGroups.GetArrayElementAtIndex(j).stringValue;
|
||||
string keyName = getKey(category, group);
|
||||
double value =0.0;
|
||||
SerializedProperty prop;
|
||||
if (mValues.TryGetValue(keyName, out prop))
|
||||
value = prop.doubleValue;
|
||||
else
|
||||
prop = null;
|
||||
double newVal = EditorGUILayout.DoubleField(value, GUILayout.Width(EditorGUIUtility.fieldWidth));
|
||||
if(newVal != value)
|
||||
prop.doubleValue = newVal;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
mEditedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/ChartDataEditor.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/ChartDataEditor.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b917e1b2904ebf348a64f64b59a51908
|
||||
timeCreated: 1474501984
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
38
Assets/Chart And Graph/Editor/ChartEditorCommon.cs
Normal file
38
Assets/Chart And Graph/Editor/ChartEditorCommon.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
class ChartEditorCommon
|
||||
{
|
||||
internal static bool IsAlphaNum(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < str.Length; i++)
|
||||
{
|
||||
if (!(char.IsLetter(str[i])) && (!(char.IsNumber(str[i]))) && str[i] != ' ')
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
internal static bool HasAttributeOfType(Type type, string fieldName, Type attributeType)
|
||||
{
|
||||
FieldInfo inf = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
if (inf == null)
|
||||
return false;
|
||||
object[] attrb = inf.GetCustomAttributes(attributeType, true);
|
||||
if (attrb == null)
|
||||
return false;
|
||||
return attrb.Length > 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/ChartEditorCommon.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/ChartEditorCommon.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7fc5bc09e01eda34da606695525bf023
|
||||
timeCreated: 1479124371
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
58
Assets/Chart And Graph/Editor/ChartOrientedSizeInspector.cs
Normal file
58
Assets/Chart And Graph/Editor/ChartOrientedSizeInspector.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using ChartAndGraph;
|
||||
using UnityEngine;
|
||||
|
||||
[CustomPropertyDrawer(typeof(ChartOrientedSize))]
|
||||
class ChartOrientedSizeInspector : PropertyDrawer
|
||||
{
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 2;
|
||||
}
|
||||
|
||||
void DoField(SerializedProperty prop, string label, Rect position)
|
||||
{
|
||||
float size = GUI.skin.label.CalcSize(new GUIContent(label)).x;
|
||||
Rect labelRect = new Rect(position.x, position.y, size, position.height);
|
||||
Rect FieldRect = new Rect(labelRect.xMax, position.y, position.width - size, position.height);
|
||||
EditorGUI.LabelField(labelRect, label);
|
||||
float val = prop.floatValue;
|
||||
EditorGUI.LabelField(labelRect, label);
|
||||
float labelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 5;
|
||||
val = EditorGUI.FloatField(FieldRect, " ", val);
|
||||
EditorGUIUtility.labelWidth = labelWidth;
|
||||
prop.floatValue = val;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
|
||||
label = EditorGUI.BeginProperty(position, label, property);
|
||||
EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
||||
|
||||
position = EditorGUI.IndentedRect(position);
|
||||
|
||||
float halfWidth = position.width *0.5f;
|
||||
float y = position.y + EditorGUIUtility.singleLineHeight;
|
||||
float height = position.height - EditorGUIUtility.singleLineHeight;
|
||||
Rect breadthRect = new Rect(position.x, y, halfWidth, height);
|
||||
Rect depthRect = new Rect(breadthRect.xMax, y, halfWidth, height);
|
||||
|
||||
int indent = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel=0;
|
||||
SerializedProperty breadth = property.FindPropertyRelative("Breadth");
|
||||
SerializedProperty depth = property.FindPropertyRelative("Depth");
|
||||
DoField(breadth, "Breadth:", breadthRect);
|
||||
DoField(depth, "Depth:", depthRect);
|
||||
EditorGUI.indentLevel = indent;
|
||||
// EditorGUILayout.EndVertical();
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f48c9091dc0c084595117abe8222c22
|
||||
timeCreated: 1473684701
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
60
Assets/Chart And Graph/Editor/EditorMenu.Full.cs
Normal file
60
Assets/Chart And Graph/Editor/EditorMenu.Full.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
|
||||
partial class EditorMenu
|
||||
{
|
||||
private static void InstanciateWorldSpace(string path)
|
||||
{
|
||||
GameObject obj = Resources.Load<GameObject>(path);
|
||||
// GameObject obj = AssetDatabase.LoadAssetAtPath<GameObject>(path);
|
||||
GameObject newObj = (GameObject)GameObject.Instantiate(obj);
|
||||
newObj.name = newObj.name.Replace("(Clone)", "");
|
||||
Undo.RegisterCreatedObjectUndo(newObj, "Create Object");
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Charts/Radar/3D")]
|
||||
public static void AddRadarChartWorldSpace()
|
||||
{
|
||||
InstanciateWorldSpace("MenuPrefabs/3DRadar");
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Charts/Bar/3D/Simple")]
|
||||
public static void AddBarChartSimple3D()
|
||||
{
|
||||
InstanciateWorldSpace("MenuPrefabs/Bar3DSimple");
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Charts/Bar/3D/Multiple Groups")]
|
||||
public static void AddBarChartMultiple3D()
|
||||
{
|
||||
InstanciateWorldSpace("MenuPrefabs/Bar3DMultiple");
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Charts/Torus/3D")]
|
||||
public static void AddTorusChart3D()
|
||||
{
|
||||
InstanciateWorldSpace("MenuPrefabs/Torus3D");
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Charts/Pie/3D")]
|
||||
public static void AddPieChart3D()
|
||||
{
|
||||
InstanciateWorldSpace("MenuPrefabs/Pie3D");
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Charts/Graph/3D")]
|
||||
public static void AddGraph3D()
|
||||
{
|
||||
InstanciateWorldSpace("MenuPrefabs/3DGraph");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/EditorMenu.Full.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/EditorMenu.Full.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 128e6b85597fded4f886f1f5aea62b53
|
||||
timeCreated: 1560597478
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
154
Assets/Chart And Graph/Editor/EditorMenu.cs
Normal file
154
Assets/Chart And Graph/Editor/EditorMenu.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
partial class EditorMenu
|
||||
{
|
||||
private static void InstanciateCanvas(string path)
|
||||
{
|
||||
Canvas[] canvases = GameObject.FindObjectsOfType<Canvas>();
|
||||
if (canvases == null || canvases.Length == 0)
|
||||
{
|
||||
EditorUtility.DisplayDialog("No canvas in scene", "Please add a canvas to the scene and try again", "Ok");
|
||||
return;
|
||||
}
|
||||
Canvas canvas = null;
|
||||
foreach(Canvas c in canvases)
|
||||
{
|
||||
if(c.transform.parent == null)
|
||||
{
|
||||
canvas = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (canvas == null)
|
||||
{
|
||||
EditorUtility.DisplayDialog("No canvas in scene", "Please add a canvas to the scene and try again", "Ok");
|
||||
return;
|
||||
}
|
||||
GameObject obj = Resources.Load<GameObject>(path);
|
||||
GameObject newObj = (GameObject)GameObject.Instantiate(obj);
|
||||
newObj.transform.SetParent(canvas.transform,false);
|
||||
newObj.name = newObj.name.Replace("(Clone)","");
|
||||
Undo.RegisterCreatedObjectUndo(newObj, "Create Object");
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Charts/Clear All")]
|
||||
public static void ClearChartGarbage()
|
||||
{
|
||||
ChartItem[] children = GameObject.FindObjectsOfType<ChartItem>();
|
||||
for (int i = 0; i < children.Length; ++i)
|
||||
{
|
||||
if (children[i] != null)
|
||||
{
|
||||
ChartCommon.SafeDestroy(children[i].gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
[MenuItem("Tools/Charts/Fix prefabs")]
|
||||
public static void ClearPrefabs()
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Warning", "Make sure to backup your project before calling Fix Prefabs", "OK", "Cancel") == false)
|
||||
return;
|
||||
string[] prefabs = AssetDatabase.FindAssets("t:prefab");
|
||||
|
||||
foreach (var guid in prefabs)
|
||||
{
|
||||
var path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
// Load the contents of the Prefab Asset.
|
||||
try
|
||||
{
|
||||
GameObject contentsRoot = UnityEditor.PrefabUtility.LoadPrefabContents(path);
|
||||
if (contentsRoot.GetComponentInChildren<AnyChart>() != null)
|
||||
{
|
||||
Debug.Log("Fixing " + path);
|
||||
bool save = false;
|
||||
// Modify Prefab contents.
|
||||
foreach (var item in contentsRoot.GetComponentsInChildren<ChartItem>())
|
||||
{
|
||||
if (item == null)
|
||||
continue;
|
||||
if (item.gameObject != null)
|
||||
{
|
||||
save = true;
|
||||
GameObject.DestroyImmediate(item.gameObject);
|
||||
}
|
||||
}
|
||||
if (save)
|
||||
{
|
||||
Debug.Log("Saving " + path);
|
||||
UnityEditor.PrefabUtility.SaveAsPrefabAsset(contentsRoot, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("No change to prefab " + path);
|
||||
}
|
||||
}
|
||||
UnityEditor.PrefabUtility.UnloadPrefabContents(contentsRoot);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Debug.Log("Failed " + path);
|
||||
}
|
||||
}
|
||||
}
|
||||
[MenuItem("Tools/Charts/Radar/Canvas")]
|
||||
public static void AddRadarChartCanvas()
|
||||
{
|
||||
InstanciateCanvas("MenuPrefabs/2DRadar");
|
||||
}
|
||||
|
||||
|
||||
|
||||
[MenuItem("Tools/Charts/Bar/Canvas/Simple")]
|
||||
public static void AddBarChartSimpleCanvas()
|
||||
{
|
||||
InstanciateCanvas("MenuPrefabs/BarCanvasSimple");
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Charts/Bar/Canvas/Multiple Groups")]
|
||||
public static void AddBarChartMultipleCanvas()
|
||||
{
|
||||
InstanciateCanvas("MenuPrefabs/BarCanvasMultiple");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
[MenuItem("Tools/Charts/Torus/Canvas")]
|
||||
public static void AddTorusChartCanvas()
|
||||
{
|
||||
InstanciateCanvas("MenuPrefabs/TorusCanvas");
|
||||
}
|
||||
|
||||
[MenuItem("Tools/Charts/Pie/Canvas")]
|
||||
public static void AddPieChartCanvas()
|
||||
{
|
||||
InstanciateCanvas("MenuPrefabs/PieCanvas");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[MenuItem("Tools/Charts/Graph/Canvas")]
|
||||
public static void AddGraphMultiple()
|
||||
{
|
||||
InstanciateCanvas("MenuPrefabs/GraphMultiple");
|
||||
}
|
||||
|
||||
|
||||
[MenuItem("Tools/Charts/Legend")]
|
||||
public static void AddChartLegend()
|
||||
{
|
||||
InstanciateCanvas("MenuPrefabs/Legend");
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/EditorMenu.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/EditorMenu.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57e0bbe359ea30c4d814819575d1a81d
|
||||
timeCreated: 1481803595
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
399
Assets/Chart And Graph/Editor/GraphChartInspector.cs
Normal file
399
Assets/Chart And Graph/Editor/GraphChartInspector.cs
Normal file
@@ -0,0 +1,399 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
[CustomEditor(typeof(GraphChartBase), true)]
|
||||
class GraphChartInspector : Editor
|
||||
{
|
||||
string mEditedCategory = "";
|
||||
bool mCategories = false;
|
||||
string mCategoryError = null;
|
||||
string mNewCategoryName = "";
|
||||
GUIStyle mRedStyle;
|
||||
GUIStyle mBold;
|
||||
HashSet<string> mAllNames = new HashSet<string>();
|
||||
GUIStyle mSplitter;
|
||||
List<int> mToRemove = new List<int>();
|
||||
List<int> mToUp = new List<int>();
|
||||
Dictionary<string, string> mOperations = new Dictionary<string, string>();
|
||||
Texture mSettings;
|
||||
GraphDataEditor mWindow;
|
||||
RenameWindow mRenameWindow = null;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
mRedStyle = new GUIStyle();
|
||||
mRedStyle.normal.textColor = Color.red;
|
||||
|
||||
mSplitter = new GUIStyle();
|
||||
mSplitter.normal.background = EditorGUIUtility.whiteTexture;
|
||||
mSplitter.stretchWidth = true;
|
||||
mSplitter.margin = new RectOffset(0, 0, 7, 7);
|
||||
}
|
||||
|
||||
public void Splitter()
|
||||
{
|
||||
Rect position = GUILayoutUtility.GetRect(GUIContent.none, mSplitter, GUILayout.Height(1f));
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
Color restoreColor = GUI.color;
|
||||
GUI.color = new Color(0.5f, 0.5f, 0.5f);
|
||||
mSplitter.Draw(position, false, false, false, false);
|
||||
GUI.color = restoreColor;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsAlphaNum(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < str.Length; i++)
|
||||
{
|
||||
if (!(char.IsLetter(str[i])) && (!(char.IsNumber(str[i]))) && str[i] != ' ')
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void DoOperations(SerializedProperty items, int size, string type)
|
||||
{
|
||||
mToRemove.Clear();
|
||||
mToUp.Clear();
|
||||
bool up = false;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
SerializedProperty entry = items.GetArrayElementAtIndex(i);
|
||||
if (entry == null)
|
||||
continue;
|
||||
SerializedProperty nameProp = entry.FindPropertyRelative("Name");
|
||||
string name = null;
|
||||
if (nameProp == null)
|
||||
name = entry.stringValue;
|
||||
else
|
||||
name = nameProp.stringValue;
|
||||
|
||||
string arg = type + "|" + name;
|
||||
string res = null;
|
||||
|
||||
if (up == true)
|
||||
{
|
||||
mToUp.Add(i);
|
||||
up = false;
|
||||
}
|
||||
|
||||
if (mOperations.TryGetValue(arg, out res))
|
||||
{
|
||||
if (res == "remove")
|
||||
mToRemove.Add(i);
|
||||
if (res == "up" && i > 0)
|
||||
mToUp.Add(i);
|
||||
if (res == "down")
|
||||
up = true;
|
||||
mOperations.Remove(arg);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < mToRemove.Count; i++)
|
||||
{
|
||||
items.DeleteArrayElementAtIndex(mToRemove[i]);
|
||||
}
|
||||
for (int i = 0; i < mToUp.Count; i++)
|
||||
{
|
||||
int cur = mToUp[i];
|
||||
items.MoveArrayElement(cur, cur - 1);
|
||||
}
|
||||
}
|
||||
private void DataEditor(SerializedProperty data, string type, string property, string caption)
|
||||
{
|
||||
|
||||
}
|
||||
private void NamedItemEditor(SerializedProperty data, string type, string property, string caption, ref string errorMessage, ref bool foldout, ref string newName)
|
||||
{
|
||||
SerializedProperty items = data.FindPropertyRelative(property);
|
||||
items.isExpanded = EditorGUILayout.Foldout(items.isExpanded, caption);
|
||||
//bool up, down;
|
||||
mAllNames.Clear();
|
||||
int size = items.arraySize;
|
||||
if (Event.current.type == EventType.Layout)
|
||||
DoOperations(items, size, type);
|
||||
size = items.arraySize;
|
||||
if (items.isExpanded)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
SerializedProperty entry = items.GetArrayElementAtIndex(i);
|
||||
if (entry == null)
|
||||
continue;
|
||||
|
||||
SerializedProperty nameProp = entry.FindPropertyRelative("Name");
|
||||
string name = null;
|
||||
if (nameProp == null)
|
||||
name = entry.stringValue;
|
||||
else
|
||||
name = nameProp.stringValue;
|
||||
mAllNames.Add(name);
|
||||
bool toogle = false;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (nameProp != null)
|
||||
toogle = entry.isExpanded = EditorGUILayout.Foldout(entry.isExpanded, name);
|
||||
else
|
||||
{
|
||||
toogle = false;
|
||||
EditorGUILayout.LabelField(name);
|
||||
}
|
||||
GUILayout.FlexibleSpace();
|
||||
if (GUILayout.Button("..."))
|
||||
DoContext(type, name);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if (toogle)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
if (nameProp != null)
|
||||
{
|
||||
SerializedProperty end = entry.GetEndProperty(true);
|
||||
entry.Next(true);
|
||||
if (SerializedProperty.EqualContents(entry, end) == false)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (entry.name != "Name" && entry.name != "data")
|
||||
{
|
||||
if (entry.name == "ViewOrder")
|
||||
continue;
|
||||
if (target is GraphChart) // canvas graph chart
|
||||
{
|
||||
if ((entry.name == "LinePrefab") || (entry.name == "FillPrefab") || (entry.name == "DotPrefab") || (entry.name == "Depth"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((entry.name == "LineHoverPrefab") || (entry.name == "PointHoverPrefab"))
|
||||
continue;
|
||||
}
|
||||
EditorGUILayout.PropertyField(entry, true);
|
||||
}
|
||||
}
|
||||
while (entry.Next(false) && SerializedProperty.EqualContents(entry, end) == false);
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space(EditorGUI.IndentedRect(EditorGUILayout.GetControlRect()).xMin);
|
||||
if (GUILayout.Button("Edit Values..."))
|
||||
{
|
||||
mEditedCategory = name;
|
||||
if (mWindow == null)
|
||||
mWindow = GraphDataEditor.ShowForObject(serializedObject, mEditedCategory);
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
|
||||
if (errorMessage != null)
|
||||
EditorGUILayout.LabelField(errorMessage, mRedStyle);
|
||||
EditorGUILayout.LabelField(string.Format("Add new {0} :", type));
|
||||
//Rect indentAdd = EditorGUI.IndentedRect(new Rect(0f, 0f, 1000f, 1000f));
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
newName = EditorGUILayout.TextField(newName);
|
||||
//GUILayout.Space(indentAdd.xMin);
|
||||
if (GUILayout.Button("Add"))
|
||||
{
|
||||
bool error = false;
|
||||
if (newName.Trim().Length == 0)
|
||||
{
|
||||
errorMessage = "Name can't be empty";
|
||||
error = true;
|
||||
}
|
||||
else if (IsAlphaNum(newName) == false)
|
||||
{
|
||||
errorMessage = "Name conatins invalid characters";
|
||||
error = true;
|
||||
}
|
||||
else if (mAllNames.Contains(newName))
|
||||
{
|
||||
errorMessage = string.Format("A {0} named {1} already exists in this chart", type, newName);
|
||||
error = true;
|
||||
}
|
||||
if (error == false)
|
||||
{
|
||||
errorMessage = null;
|
||||
items.InsertArrayElementAtIndex(size);
|
||||
SerializedProperty newItem = items.GetArrayElementAtIndex(size);
|
||||
SerializedProperty newItemName = newItem.FindPropertyRelative("Name");
|
||||
if (newItemName == null)
|
||||
newItem.stringValue = newName;
|
||||
else
|
||||
newItemName.stringValue = newName;
|
||||
newName = "";
|
||||
UpdateWindow();
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessage = null;
|
||||
}
|
||||
UpdateWindow();
|
||||
}
|
||||
void callback(object val)
|
||||
{
|
||||
KeyValuePair<string, string> pair = (KeyValuePair<string, string>)val;
|
||||
mOperations[pair.Key] = pair.Value;
|
||||
}
|
||||
bool RenameCategory(string oldName, string newName)
|
||||
{
|
||||
GraphChartBase graph = (GraphChartBase)serializedObject.targetObject;
|
||||
try
|
||||
{
|
||||
graph.DataSource.RenameCategory(oldName, newName);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
serializedObject.Update();
|
||||
if (graph.gameObject.activeInHierarchy)
|
||||
graph.GenerateChart();
|
||||
else
|
||||
EditorUtility.SetDirty(graph);
|
||||
return true;
|
||||
}
|
||||
void RenameCalled(object val)
|
||||
{
|
||||
var data = (KeyValuePair<string, string>)val;
|
||||
RenameWindow window = EditorWindow.GetWindow<RenameWindow>();
|
||||
mRenameWindow = window;
|
||||
window.ShowDialog(data.Value, data.Key, RenameCategory);
|
||||
}
|
||||
void DoContext(string type, string name)
|
||||
{
|
||||
string arg = type + "|" + name;
|
||||
GenericMenu menu = new GenericMenu();
|
||||
menu.AddItem(new GUIContent("Move Up"), false, callback, new KeyValuePair<string, string>(arg, "up"));
|
||||
menu.AddItem(new GUIContent("Move Down"), false, callback, new KeyValuePair<string, string>(arg, "down"));
|
||||
menu.AddItem(new GUIContent("Remove"), false, callback, new KeyValuePair<string, string>(arg, "remove"));
|
||||
menu.AddItem(new GUIContent("Rename.."), false, RenameCalled, new KeyValuePair<string, string>(type, name));
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
void UpdateWindow()
|
||||
{
|
||||
}
|
||||
void OnDisable()
|
||||
{
|
||||
if (mRenameWindow != null)
|
||||
{
|
||||
mRenameWindow.Close();
|
||||
mRenameWindow = null;
|
||||
}
|
||||
if (mWindow != null)
|
||||
{
|
||||
mWindow.Close();
|
||||
mWindow = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
//serializedObject.Update();
|
||||
DrawDefaultInspector();
|
||||
|
||||
SerializedProperty autoScrollHorizontally = serializedObject.FindProperty("autoScrollHorizontally");
|
||||
SerializedProperty horizontalScrolling = serializedObject.FindProperty("horizontalScrolling");
|
||||
SerializedProperty autoScrollVertically = serializedObject.FindProperty("autoScrollVertically");
|
||||
SerializedProperty verticalScrolling = serializedObject.FindProperty("verticalScrolling");
|
||||
// SerializedProperty scrollable = serializedObject.FindProperty("scrollable");
|
||||
// EditorGUILayout.PropertyField(scrollable);
|
||||
// if (scrollable.boolValue == true)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(autoScrollHorizontally);
|
||||
if (autoScrollHorizontally.boolValue == false)
|
||||
EditorGUILayout.PropertyField(horizontalScrolling);
|
||||
EditorGUILayout.PropertyField(autoScrollVertically);
|
||||
if (autoScrollVertically.boolValue == false)
|
||||
EditorGUILayout.PropertyField(verticalScrolling);
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
SerializedProperty graphData = serializedObject.FindProperty("Data");
|
||||
EditorGUILayout.BeginVertical();
|
||||
Splitter();
|
||||
if (mBold == null)
|
||||
mBold = new GUIStyle(EditorStyles.foldout);
|
||||
EditorGUILayout.LabelField("Data", EditorStyles.boldLabel);
|
||||
|
||||
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
NamedItemEditor(graphData, "category", "mSerializedData", "Categories", ref mCategoryError, ref mCategories, ref mNewCategoryName);
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
SerializedProperty horizontalOrigin = graphData.FindPropertyRelative("horizontalViewOrigin");
|
||||
SerializedProperty horizontalSize = graphData.FindPropertyRelative("horizontalViewSize");
|
||||
SerializedProperty automaticcHorizontaViewGap = graphData.FindPropertyRelative("automaticcHorizontaViewGap");
|
||||
|
||||
SerializedProperty verticalOrigin = graphData.FindPropertyRelative("verticalViewOrigin");
|
||||
SerializedProperty verticalSize = graphData.FindPropertyRelative("verticalViewSize");
|
||||
SerializedProperty automaticVerticalViewGap = graphData.FindPropertyRelative("automaticVerticalViewGap");
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField("Horizontal View", EditorStyles.boldLabel);
|
||||
SerializedProperty automaticProp = graphData.FindPropertyRelative("automaticHorizontalView");
|
||||
EditorGUILayout.PropertyField(automaticProp, new GUIContent("Auto"));
|
||||
bool automatic = automaticProp.boolValue;
|
||||
GUILayout.FlexibleSpace();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if (automatic == false)
|
||||
{
|
||||
EditorGUILayout.PropertyField(horizontalOrigin);
|
||||
EditorGUILayout.PropertyField(horizontalSize);
|
||||
// if (horizontalSize.doubleValue < 0.0)
|
||||
// horizontalSize.doubleValue = 0.0001;
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.PropertyField(automaticcHorizontaViewGap, new GUIContent("Horizontal Gap"));
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField("Vertical View", EditorStyles.boldLabel);
|
||||
automaticProp = graphData.FindPropertyRelative("automaticVerticallView");
|
||||
EditorGUILayout.PropertyField(automaticProp, new GUIContent("Auto"));
|
||||
automatic = automaticProp.boolValue;
|
||||
GUILayout.FlexibleSpace();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if (automatic == false)
|
||||
{
|
||||
EditorGUILayout.PropertyField(verticalOrigin);
|
||||
EditorGUILayout.PropertyField(verticalSize);
|
||||
// if (verticalSize.doubleValue < 0.0)
|
||||
// verticalSize.doubleValue = 0.0001;
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.PropertyField(automaticVerticalViewGap, new GUIContent("Vertical Gap"));
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
if (mWindow != null)
|
||||
{
|
||||
mWindow.SetEditedObject(serializedObject, mEditedCategory);
|
||||
mWindow.Repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/GraphChartInspector.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/GraphChartInspector.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8671bd55b44fd0d46ad162bc055df077
|
||||
timeCreated: 1480533379
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
128
Assets/Chart And Graph/Editor/GraphDataEditor.cs
Normal file
128
Assets/Chart And Graph/Editor/GraphDataEditor.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
class GraphDataEditor : UnityEditor.EditorWindow
|
||||
{
|
||||
SerializedObject mThisObject;
|
||||
SerializedObject mEditedObject;
|
||||
string category;
|
||||
SerializedProperty mGraphData;
|
||||
SerializedProperty mCategories;
|
||||
SerializedProperty mCategory;
|
||||
Dictionary<string, SerializedProperty> mValues;
|
||||
SerializedObject mObject;
|
||||
|
||||
[SerializeField]
|
||||
Vector2[] Data;
|
||||
public static GraphDataEditor ShowForObject(SerializedObject obj,string category)
|
||||
{
|
||||
GraphDataEditor window = (GraphDataEditor)EditorWindow.GetWindow(typeof(GraphDataEditor));
|
||||
window.SetEditedObject(obj, category);
|
||||
return window;
|
||||
}
|
||||
|
||||
int FindCategoryIndex(string category)
|
||||
{
|
||||
for(int i=0; i<mCategories.arraySize; i++)
|
||||
{
|
||||
string name = mCategories.GetArrayElementAtIndex(i).FindPropertyRelative("Name").stringValue;
|
||||
if (name == category)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public void SetEditedObject(SerializedObject obj,string categoryName)
|
||||
{
|
||||
category = categoryName;
|
||||
mEditedObject = obj;
|
||||
|
||||
mGraphData = mEditedObject.FindProperty("Data");
|
||||
mCategories = mGraphData.FindPropertyRelative("mSerializedData");
|
||||
// LoadData();
|
||||
|
||||
int catIndex = FindCategoryIndex(categoryName);
|
||||
if (catIndex == -1)
|
||||
{
|
||||
mCategory = null;
|
||||
return;
|
||||
}
|
||||
mCategory = mCategories.GetArrayElementAtIndex(catIndex);
|
||||
|
||||
var arr = mCategory.FindPropertyRelative("InitialData");
|
||||
|
||||
mThisObject = new SerializedObject(this);
|
||||
SerializedProperty serialProp = mThisObject.FindProperty("Data");
|
||||
SetArray(arr, serialProp);
|
||||
}
|
||||
|
||||
string getKey(string column, string row)
|
||||
{
|
||||
return string.Format("{0}|{1}", column, row);
|
||||
}
|
||||
|
||||
void ShowCategoryArray()
|
||||
{
|
||||
|
||||
}
|
||||
void SetArray(SerializedProperty from,SerializedProperty to)
|
||||
{
|
||||
to.arraySize = from.arraySize;
|
||||
for (int i = 0; i < from.arraySize; i++)
|
||||
{
|
||||
Vector2 val = from.GetArrayElementAtIndex(i).vector2Value;
|
||||
to.GetArrayElementAtIndex(i).vector2Value = val;
|
||||
}
|
||||
}
|
||||
void SetArray(Vector2[] from, SerializedProperty to)
|
||||
{
|
||||
to.arraySize = from.Length;
|
||||
for (int i = 0; i < from.Length; i++)
|
||||
{
|
||||
Vector2 val = from[i];
|
||||
to.GetArrayElementAtIndex(i).vector2Value = val;
|
||||
}
|
||||
}
|
||||
Vector2[] FillDataCustomCodeImplementation()
|
||||
{
|
||||
return new Vector2[] { new Vector2(1, 1), new Vector2(2, 2), new Vector2(3, 3), new Vector2(4, 4) };
|
||||
}
|
||||
Func<Vector2[]> FillDataCustomCode = null;
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
|
||||
SerializedProperty serialProp = mThisObject.FindProperty("Data");
|
||||
|
||||
GUILayout.Label("Edit Values - " + category, EditorStyles.boldLabel);
|
||||
|
||||
if (mCategory == null)
|
||||
return;
|
||||
Vector2[] customArr = null;
|
||||
//FillDataCustomCode = FillDataCustomCodeImplementation;
|
||||
if (FillDataCustomCode != null)
|
||||
{
|
||||
if (GUILayout.Button("Fill Data From Custom Code"))
|
||||
{
|
||||
customArr = FillDataCustomCode();
|
||||
}
|
||||
}
|
||||
EditorGUILayout.PropertyField(serialProp, true);
|
||||
|
||||
var arr = mCategory.FindPropertyRelative("InitialData");
|
||||
if (customArr != null)
|
||||
{
|
||||
SetArray(customArr, arr);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mThisObject.ApplyModifiedProperties())
|
||||
SetArray(serialProp, arr);
|
||||
}
|
||||
mEditedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/GraphDataEditor.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/GraphDataEditor.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03f0eb5ac4118424f8d68f32ef5ffa1b
|
||||
timeCreated: 1584550686
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
36
Assets/Chart And Graph/Editor/GraphDataFillerEditor.cs
Normal file
36
Assets/Chart And Graph/Editor/GraphDataFillerEditor.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
[CustomEditor(typeof(GraphDataFiller), true)]
|
||||
class GraphDataFillerEditor : Editor
|
||||
{
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* This is a work around and must not be deleteed
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* */
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
// var cats = serializedObject.FindProperty("Categories");
|
||||
// EditorGUILayout.PropertyField(cats);
|
||||
// CategoryDataEditor
|
||||
// Categories
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/GraphDataFillerEditor.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/GraphDataFillerEditor.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05791da4c4a2fc44281046536e32e237
|
||||
timeCreated: 1560715350
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
26
Assets/Chart And Graph/Editor/GroupLabelsInspector.cs
Normal file
26
Assets/Chart And Graph/Editor/GroupLabelsInspector.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
[CustomEditor(typeof(GroupLabels))]
|
||||
class GroupLabelsInspector : ItemLabelsBaseEditor
|
||||
{
|
||||
protected override string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "group labels";
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool isSupported(AnyChart chart)
|
||||
{
|
||||
return ((IInternalUse)chart).InternalSupportsGroupLabels;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/GroupLabelsInspector.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/GroupLabelsInspector.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a56a06b898a879418ba574600eaf84a
|
||||
timeCreated: 1480254476
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Chart And Graph/Editor/ItemLabelsBaseEditor.cs
Normal file
35
Assets/Chart And Graph/Editor/ItemLabelsBaseEditor.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
abstract class ItemLabelsBaseEditor : Editor
|
||||
{
|
||||
protected abstract string Name { get; }
|
||||
protected abstract bool isSupported(AnyChart chart);
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
|
||||
|
||||
ItemLabelsBase labels = (ItemLabelsBase)target;
|
||||
|
||||
if (labels.gameObject == null)
|
||||
return;
|
||||
|
||||
AnyChart chart = labels.gameObject.GetComponent<AnyChart>();
|
||||
if (chart == null)
|
||||
return;
|
||||
if (isSupported(chart) == false)
|
||||
{
|
||||
EditorGUILayout.HelpBox(string.Format("Chart of type {0} does not support {1}", chart.GetType().Name,Name),MessageType.Warning);
|
||||
return;
|
||||
}
|
||||
base.OnInspectorGUI();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/ItemLabelsBaseEditor.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/ItemLabelsBaseEditor.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67d1379f880dde846adec8a6157669d1
|
||||
timeCreated: 1480254476
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
26
Assets/Chart And Graph/Editor/ItemLabelsInspector.cs
Normal file
26
Assets/Chart And Graph/Editor/ItemLabelsInspector.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
[CustomEditor(typeof(ItemLabels))]
|
||||
class ItemLabelsLabelsInspector : ItemLabelsBaseEditor
|
||||
{
|
||||
protected override string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "item labels";
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool isSupported(AnyChart chart)
|
||||
{
|
||||
return ((IInternalUse)chart).InternalSupportsItemLabels;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/ItemLabelsInspector.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/ItemLabelsInspector.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12cb0562684057a448410b90a0e565f8
|
||||
timeCreated: 1480254476
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
40
Assets/Chart And Graph/Editor/MaterialTilingInspector.cs
Normal file
40
Assets/Chart And Graph/Editor/MaterialTilingInspector.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(MaterialTiling))]
|
||||
class MaterialTilingInspector : PropertyDrawer
|
||||
{
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
label = EditorGUI.BeginProperty(position, label, property);
|
||||
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
||||
SerializedProperty auto = property.FindPropertyRelative("EnableTiling");
|
||||
SerializedProperty val = property.FindPropertyRelative("TileFactor");
|
||||
int indent = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 0;
|
||||
bool res = !EditorGUI.ToggleLeft(position,"Stretch", !auto.boolValue);
|
||||
EditorGUI.indentLevel = indent;
|
||||
//EditorGUILayout.EndHorizontal();
|
||||
EditorGUI.indentLevel++;
|
||||
if (auto.boolValue == true && EditorGUI.showMixedValue == false)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Remember to enable texture repeat mode in order to make tiling work !",MessageType.Warning,true);
|
||||
EditorGUILayout.HelpBox("For the best results on canvas , set the tiling factor to the pixel size of the textre", MessageType.Info, true);
|
||||
val.floatValue = EditorGUILayout.FloatField("Tiling Factor",val.floatValue);
|
||||
if (val.floatValue <= 0f)
|
||||
val.floatValue = 0.01f;
|
||||
}
|
||||
auto.boolValue = res;
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c894d939d8cec94fa27b4e6b437e6bc
|
||||
timeCreated: 1479370450
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
326
Assets/Chart And Graph/Editor/PieChartInspector.cs
Normal file
326
Assets/Chart And Graph/Editor/PieChartInspector.cs
Normal file
@@ -0,0 +1,326 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
|
||||
using ChartAndGraph;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[CustomEditor(typeof(PieChart), true)]
|
||||
class PieChartInspetor : Editor
|
||||
{
|
||||
bool mCategories = false;
|
||||
string mCategoryError = null;
|
||||
string mNewCategoryName = "";
|
||||
GUIStyle mRedStyle;
|
||||
GUIStyle mBold;
|
||||
HashSet<string> mAllNames = new HashSet<string>();
|
||||
GUIStyle mSplitter;
|
||||
List<int> mToRemove = new List<int>();
|
||||
List<int> mToUp = new List<int>();
|
||||
Dictionary<string, string> mOperations = new Dictionary<string, string>();
|
||||
ChartDataEditor mWindow;
|
||||
bool mUpdateWindow = false;
|
||||
Texture mSettings;
|
||||
|
||||
RenameWindow mRenameWindow = null;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
mRedStyle = new GUIStyle();
|
||||
mRedStyle.normal.textColor = Color.red;
|
||||
|
||||
mSplitter = new GUIStyle();
|
||||
mSplitter.normal.background = EditorGUIUtility.whiteTexture;
|
||||
mSplitter.stretchWidth = true;
|
||||
mSplitter.margin = new RectOffset(0, 0, 7, 7);
|
||||
}
|
||||
|
||||
public void Splitter()
|
||||
{
|
||||
Rect position = GUILayoutUtility.GetRect(GUIContent.none, mSplitter, GUILayout.Height(1f));
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
Color restoreColor = GUI.color;
|
||||
GUI.color = new Color(0.5f, 0.5f, 0.5f);
|
||||
mSplitter.Draw(position, false, false, false, false);
|
||||
GUI.color = restoreColor;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsAlphaNum(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < str.Length; i++)
|
||||
{
|
||||
if (!(char.IsLetter(str[i])) && (!(char.IsNumber(str[i]))) && str[i] != ' ')
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void DoOperations(SerializedProperty items, int size, string type)
|
||||
{
|
||||
mToRemove.Clear();
|
||||
mToUp.Clear();
|
||||
bool up = false;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
SerializedProperty entry = items.GetArrayElementAtIndex(i);
|
||||
if (entry == null)
|
||||
continue;
|
||||
SerializedProperty nameProp = entry.FindPropertyRelative("Name");
|
||||
string name = null;
|
||||
if (nameProp == null)
|
||||
name = entry.stringValue;
|
||||
else
|
||||
name = nameProp.stringValue;
|
||||
|
||||
string arg = type + "|" + name;
|
||||
string res = null;
|
||||
if (up == true)
|
||||
{
|
||||
mToUp.Add(i);
|
||||
up = false;
|
||||
}
|
||||
if (mOperations.TryGetValue(arg, out res))
|
||||
{
|
||||
if (res == "remove")
|
||||
mToRemove.Add(i);
|
||||
if (res == "up" && i > 0)
|
||||
mToUp.Add(i);
|
||||
if (res == "down")
|
||||
up = true;
|
||||
mOperations.Remove(arg);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < mToRemove.Count; i++)
|
||||
items.DeleteArrayElementAtIndex(mToRemove[i]);
|
||||
for (int i = 0; i < mToUp.Count; i++)
|
||||
{
|
||||
int cur = mToUp[i];
|
||||
items.MoveArrayElement(cur, cur - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private SerializedProperty getArrayCategory(SerializedProperty arr, string name)
|
||||
{
|
||||
for (int i = 0; i < arr.arraySize; i++)
|
||||
{
|
||||
SerializedProperty prop = arr.GetArrayElementAtIndex(i);
|
||||
if (prop.FindPropertyRelative("ColumnName").stringValue == name)
|
||||
return prop.FindPropertyRelative("Amount");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void NamedItemEditor(SerializedProperty data, string type, string property, string caption, ref string errorMessage, ref bool foldout, ref string newName)
|
||||
{
|
||||
SerializedProperty items = data.FindPropertyRelative(property);
|
||||
SerializedProperty dataValues = data.FindPropertyRelative("mData");
|
||||
items.isExpanded = EditorGUILayout.Foldout(items.isExpanded, caption);
|
||||
//bool up, down;
|
||||
mAllNames.Clear();
|
||||
int size = items.arraySize;
|
||||
if (Event.current.type == EventType.Layout)
|
||||
DoOperations(items, size, type);
|
||||
size = items.arraySize;
|
||||
if (items.isExpanded)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
SerializedProperty entry = items.GetArrayElementAtIndex(i);
|
||||
if (entry == null)
|
||||
continue;
|
||||
SerializedProperty nameProp = entry.FindPropertyRelative("Name");
|
||||
string name = null;
|
||||
if (nameProp == null)
|
||||
name = entry.stringValue;
|
||||
else
|
||||
name = nameProp.stringValue;
|
||||
mAllNames.Add(name);
|
||||
|
||||
bool toogle = false;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (nameProp != null)
|
||||
toogle = entry.isExpanded =EditorGUILayout.Foldout(entry.isExpanded, name);
|
||||
else
|
||||
{
|
||||
toogle = false;
|
||||
EditorGUILayout.LabelField(name);
|
||||
}
|
||||
SerializedProperty valueProp = getArrayCategory(dataValues, name);
|
||||
GUILayout.FlexibleSpace();
|
||||
if(valueProp != null)
|
||||
EditorGUILayout.PropertyField(valueProp);
|
||||
if (GUILayout.Button("..."))
|
||||
DoContext(type, name);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if (toogle)
|
||||
{
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
if (nameProp != null)
|
||||
{
|
||||
SerializedProperty end = entry.GetEndProperty(true);
|
||||
entry.Next(true);
|
||||
if (SerializedProperty.EqualContents(entry, end) == false)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (entry.name != "Name")
|
||||
EditorGUILayout.PropertyField(entry, true);
|
||||
}
|
||||
while (entry.Next(entry.name == "Materials") && SerializedProperty.EqualContents(entry, end) == false);
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (errorMessage != null)
|
||||
EditorGUILayout.LabelField(errorMessage, mRedStyle);
|
||||
EditorGUILayout.LabelField(string.Format("Add new {0} :", type));
|
||||
//Rect indentAdd = EditorGUI.IndentedRect(new Rect(0f, 0f, 1000f, 1000f));
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
newName = EditorGUILayout.TextField(newName);
|
||||
//GUILayout.Space(indentAdd.xMin);
|
||||
if (GUILayout.Button("Add"))
|
||||
{
|
||||
bool error = false;
|
||||
if (newName.Trim().Length == 0)
|
||||
{
|
||||
errorMessage = "Name can't be empty";
|
||||
error = true;
|
||||
}
|
||||
else if (IsAlphaNum(newName) == false)
|
||||
{
|
||||
errorMessage = "Name conatins invalid characters";
|
||||
error = true;
|
||||
}
|
||||
else if (mAllNames.Contains(newName))
|
||||
{
|
||||
errorMessage = string.Format("A {0} named {1} already exists in this chart", type, newName);
|
||||
error = true;
|
||||
}
|
||||
if (error == false)
|
||||
{
|
||||
errorMessage = null;
|
||||
items.InsertArrayElementAtIndex(size);
|
||||
SerializedProperty newItem = items.GetArrayElementAtIndex(size);
|
||||
SerializedProperty newItemName = newItem.FindPropertyRelative("Name");
|
||||
if (newItemName == null)
|
||||
newItem.stringValue = newName;
|
||||
else
|
||||
newItemName.stringValue = newName;
|
||||
newName = "";
|
||||
UpdateWindow();
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessage = null;
|
||||
}
|
||||
UpdateWindow();
|
||||
}
|
||||
|
||||
void callback(object val)
|
||||
{
|
||||
KeyValuePair<string, string> pair = (KeyValuePair<string, string>)val;
|
||||
mOperations[pair.Key] = pair.Value;
|
||||
}
|
||||
|
||||
bool RenameCategory(string fromName, string toName)
|
||||
{
|
||||
PieChart pieChart = (PieChart)serializedObject.targetObject;
|
||||
try
|
||||
{
|
||||
pieChart.DataSource.RenameCategory(fromName, toName);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
serializedObject.Update();
|
||||
if (pieChart.gameObject.activeInHierarchy)
|
||||
pieChart.GenerateChart();
|
||||
else
|
||||
EditorUtility.SetDirty(pieChart);
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenameCalled(object val)
|
||||
{
|
||||
var data = (KeyValuePair<string, string>)val;
|
||||
RenameWindow window = EditorWindow.GetWindow<RenameWindow>();
|
||||
mRenameWindow = window;
|
||||
if (data.Key == "category")
|
||||
window.ShowDialog(data.Value, data.Key, RenameCategory);
|
||||
}
|
||||
void DoContext(string type, string name)
|
||||
{
|
||||
string arg = type + "|" + name;
|
||||
GenericMenu menu = new GenericMenu();
|
||||
menu.AddItem(new GUIContent("Move Up"), false, callback, new KeyValuePair<string, string>(arg, "up"));
|
||||
menu.AddItem(new GUIContent("Move Down"), false, callback, new KeyValuePair<string, string>(arg, "down"));
|
||||
menu.AddItem(new GUIContent("Remove"), false, callback, new KeyValuePair<string, string>(arg, "remove"));
|
||||
menu.AddItem(new GUIContent("Rename.."), false, RenameCalled, new KeyValuePair<string, string>(type, name));
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
void UpdateWindow()
|
||||
{
|
||||
mUpdateWindow = true;
|
||||
}
|
||||
void OnDisable()
|
||||
{
|
||||
if(mRenameWindow != null)
|
||||
{
|
||||
mRenameWindow.Close();
|
||||
mRenameWindow = null;
|
||||
}
|
||||
if (mWindow != null)
|
||||
{
|
||||
mWindow.Close();
|
||||
mWindow = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
serializedObject.Update();
|
||||
SerializedProperty barData = serializedObject.FindProperty("Data");
|
||||
EditorGUILayout.BeginVertical();
|
||||
Splitter();
|
||||
if (mBold == null)
|
||||
mBold = new GUIStyle(EditorStyles.foldout);
|
||||
EditorGUILayout.LabelField("Data", EditorStyles.boldLabel);
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
NamedItemEditor(barData, "category", "mCategories", "Categories", ref mCategoryError, ref mCategories, ref mNewCategoryName);
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUILayout.EndVertical();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
if (mUpdateWindow == true)
|
||||
{
|
||||
mUpdateWindow = false;
|
||||
if (mWindow != null)
|
||||
{
|
||||
mWindow.SetEditedObject(serializedObject);
|
||||
mWindow.Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/PieChartInspector.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/PieChartInspector.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcc024b6935dfff44aece802ded95e9a
|
||||
timeCreated: 1480008753
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
83
Assets/Chart And Graph/Editor/PrefabOverrideChart.cs
Normal file
83
Assets/Chart And Graph/Editor/PrefabOverrideChart.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
//#if UNITY_2018_3_OR_NEWER
|
||||
//#if UNITY_EDITOR
|
||||
//using UnityEngine;
|
||||
//using System.Collections;
|
||||
//using UnityEditor;
|
||||
//using ChartAndGraph;
|
||||
|
||||
//public class PrefabOverrideChart : UnityEditor.AssetPostprocessor
|
||||
//{
|
||||
// static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
|
||||
// {
|
||||
// foreach (string path in importedAssets)
|
||||
// {
|
||||
// string lowPath = path.ToLower();
|
||||
// if (lowPath.EndsWith(".prefab"))
|
||||
// {
|
||||
// if (ContainsPath(lowPath) == false)
|
||||
// {
|
||||
// // Debug.Log(lowPath);
|
||||
// EditorApplication.delayCall += () => CleanPrefab(path);
|
||||
// AddPath(lowPath);
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
// foreach (string path in deletedAssets)
|
||||
// {
|
||||
// RemovePath(path.ToLower());
|
||||
// }
|
||||
// }
|
||||
// [MenuItem("EditorPrefs/Clear all Editor Preferences")]
|
||||
// static void deleteAllExample()
|
||||
// {
|
||||
|
||||
// EditorPrefs.DeleteAll();
|
||||
// }
|
||||
// static bool ContainsPath(string path)
|
||||
// {
|
||||
// return EditorPrefs.GetBool("GraphAndChartPrefabOverride$" + path, false);
|
||||
// }
|
||||
// static void RemovePath(string path)
|
||||
// {
|
||||
// EditorPrefs.DeleteKey("GraphAndChartPrefabOverride$" + path);
|
||||
// }
|
||||
// static void AddPath(string path)
|
||||
// {
|
||||
// EditorPrefs.SetBool("GraphAndChartPrefabOverride$" + path, true);
|
||||
// }
|
||||
// static void CleanPrefab(string path)
|
||||
// {
|
||||
// GameObject obj = PrefabUtility.LoadPrefabContents(path);
|
||||
// //AssetDatabase.DeleteAsset(path);
|
||||
// bool savePrefab = false;
|
||||
// foreach (var item in obj.GetComponentsInChildren<AnyChart>(true))
|
||||
// {
|
||||
// savePrefab = true;
|
||||
// // if (item == null)
|
||||
// // continue;
|
||||
// // if (item.gameObject == null)
|
||||
// // continue;
|
||||
// // Debug.Log("destroy " + item.gameObject.name);
|
||||
// while (item.gameObject.transform.childCount > 0)
|
||||
// {
|
||||
// var innerObj = item.gameObject.transform.GetChild(0).gameObject;
|
||||
// if (innerObj != null)
|
||||
// {
|
||||
// // Debug.Log("destroy inner" + innerObj.name);
|
||||
|
||||
// GameObject.DestroyImmediate(innerObj);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
// if (savePrefab)
|
||||
// PrefabUtility.SaveAsPrefabAsset(obj, path);
|
||||
// PrefabUtility.UnloadPrefabContents(obj);
|
||||
// }
|
||||
|
||||
//}
|
||||
//#endif
|
||||
//#endif
|
||||
12
Assets/Chart And Graph/Editor/PrefabOverrideChart.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/PrefabOverrideChart.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb3ccf7dc2806314e99c1bbc160aabec
|
||||
timeCreated: 1579105195
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
328
Assets/Chart And Graph/Editor/PyramidChartInspector.cs
Normal file
328
Assets/Chart And Graph/Editor/PyramidChartInspector.cs
Normal file
@@ -0,0 +1,328 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
|
||||
using ChartAndGraph;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[CustomEditor(typeof(PyramidChart), true)]
|
||||
class PyramidChartInspetor : Editor
|
||||
{
|
||||
bool mCategories = false;
|
||||
string mCategoryError = null;
|
||||
string mNewCategoryName = "";
|
||||
GUIStyle mRedStyle;
|
||||
GUIStyle mBold;
|
||||
HashSet<string> mAllNames = new HashSet<string>();
|
||||
GUIStyle mSplitter;
|
||||
List<int> mToRemove = new List<int>();
|
||||
List<int> mToUp = new List<int>();
|
||||
Dictionary<string, string> mOperations = new Dictionary<string, string>();
|
||||
ChartDataEditor mWindow;
|
||||
bool mUpdateWindow = false;
|
||||
Texture mSettings;
|
||||
|
||||
RenameWindow mRenameWindow = null;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
mRedStyle = new GUIStyle();
|
||||
mRedStyle.normal.textColor = Color.red;
|
||||
|
||||
mSplitter = new GUIStyle();
|
||||
mSplitter.normal.background = EditorGUIUtility.whiteTexture;
|
||||
mSplitter.stretchWidth = true;
|
||||
mSplitter.margin = new RectOffset(0, 0, 7, 7);
|
||||
}
|
||||
|
||||
public void Splitter()
|
||||
{
|
||||
Rect position = GUILayoutUtility.GetRect(GUIContent.none, mSplitter, GUILayout.Height(1f));
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
Color restoreColor = GUI.color;
|
||||
GUI.color = new Color(0.5f, 0.5f, 0.5f);
|
||||
mSplitter.Draw(position, false, false, false, false);
|
||||
GUI.color = restoreColor;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsAlphaNum(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < str.Length; i++)
|
||||
{
|
||||
if (!(char.IsLetter(str[i])) && (!(char.IsNumber(str[i]))) && str[i] != ' ')
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void DoOperations(SerializedProperty items, int size, string type)
|
||||
{
|
||||
mToRemove.Clear();
|
||||
mToUp.Clear();
|
||||
bool up = false;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
SerializedProperty entry = items.GetArrayElementAtIndex(i);
|
||||
if (entry == null)
|
||||
continue;
|
||||
SerializedProperty nameProp = entry.FindPropertyRelative("Name");
|
||||
string name = null;
|
||||
if (nameProp == null)
|
||||
name = entry.stringValue;
|
||||
else
|
||||
name = nameProp.stringValue;
|
||||
|
||||
string arg = type + "|" + name;
|
||||
string res = null;
|
||||
if (up == true)
|
||||
{
|
||||
mToUp.Add(i);
|
||||
up = false;
|
||||
}
|
||||
if (mOperations.TryGetValue(arg, out res))
|
||||
{
|
||||
if (res == "remove")
|
||||
mToRemove.Add(i);
|
||||
if (res == "up" && i > 0)
|
||||
mToUp.Add(i);
|
||||
if (res == "down")
|
||||
up = true;
|
||||
mOperations.Remove(arg);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < mToRemove.Count; i++)
|
||||
items.DeleteArrayElementAtIndex(mToRemove[i]);
|
||||
for (int i = 0; i < mToUp.Count; i++)
|
||||
{
|
||||
int cur = mToUp[i];
|
||||
items.MoveArrayElement(cur, cur - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private SerializedProperty getArrayCategory(SerializedProperty arr, string name)
|
||||
{
|
||||
for (int i = 0; i < arr.arraySize; i++)
|
||||
{
|
||||
SerializedProperty prop = arr.GetArrayElementAtIndex(i);
|
||||
if (prop.FindPropertyRelative("ColumnName").stringValue == name)
|
||||
return prop.FindPropertyRelative("Amount");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void NamedItemEditor(SerializedProperty data, string type, string property, string caption, ref string errorMessage, ref bool foldout, ref string newName)
|
||||
{
|
||||
SerializedProperty items = data.FindPropertyRelative(property);
|
||||
SerializedProperty dataValues = data.FindPropertyRelative("mData");
|
||||
items.isExpanded = EditorGUILayout.Foldout(items.isExpanded, caption);
|
||||
//bool up, down;
|
||||
mAllNames.Clear();
|
||||
int size = items.arraySize;
|
||||
if (Event.current.type == EventType.Layout)
|
||||
DoOperations(items, size, type);
|
||||
size = items.arraySize;
|
||||
if (items.isExpanded)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
SerializedProperty entry = items.GetArrayElementAtIndex(i);
|
||||
if (entry == null)
|
||||
continue;
|
||||
SerializedProperty nameProp = entry.FindPropertyRelative("Name");
|
||||
string name = null;
|
||||
if (nameProp == null)
|
||||
name = entry.stringValue;
|
||||
else
|
||||
name = nameProp.stringValue;
|
||||
mAllNames.Add(name);
|
||||
|
||||
bool toogle = false;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (nameProp != null)
|
||||
toogle = entry.isExpanded =EditorGUILayout.Foldout(entry.isExpanded, name);
|
||||
else
|
||||
{
|
||||
toogle = false;
|
||||
EditorGUILayout.LabelField(name);
|
||||
}
|
||||
SerializedProperty valueProp = getArrayCategory(dataValues, name);
|
||||
GUILayout.FlexibleSpace();
|
||||
// if(valueProp != null)
|
||||
// EditorGUILayout.PropertyField(valueProp);
|
||||
if (GUILayout.Button("..."))
|
||||
DoContext(type, name);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if (toogle)
|
||||
{
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
if (nameProp != null)
|
||||
{
|
||||
SerializedProperty end = entry.GetEndProperty(true);
|
||||
entry.Next(true);
|
||||
if (SerializedProperty.EqualContents(entry, end) == false)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (entry.name != "Name")
|
||||
EditorGUILayout.PropertyField(entry, true);
|
||||
if (entry.name == "HeightRatio" && valueProp != null)
|
||||
valueProp.floatValue = entry.floatValue;
|
||||
|
||||
}
|
||||
while (entry.Next(entry.name == "Materials") && SerializedProperty.EqualContents(entry, end) == false);
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (errorMessage != null)
|
||||
EditorGUILayout.LabelField(errorMessage, mRedStyle);
|
||||
EditorGUILayout.LabelField(string.Format("Add new {0} :", type));
|
||||
//Rect indentAdd = EditorGUI.IndentedRect(new Rect(0f, 0f, 1000f, 1000f));
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
newName = EditorGUILayout.TextField(newName);
|
||||
//GUILayout.Space(indentAdd.xMin);
|
||||
if (GUILayout.Button("Add"))
|
||||
{
|
||||
bool error = false;
|
||||
if (newName.Trim().Length == 0)
|
||||
{
|
||||
errorMessage = "Name can't be empty";
|
||||
error = true;
|
||||
}
|
||||
else if (IsAlphaNum(newName) == false)
|
||||
{
|
||||
errorMessage = "Name conatins invalid characters";
|
||||
error = true;
|
||||
}
|
||||
else if (mAllNames.Contains(newName))
|
||||
{
|
||||
errorMessage = string.Format("A {0} named {1} already exists in this chart", type, newName);
|
||||
error = true;
|
||||
}
|
||||
if (error == false)
|
||||
{
|
||||
errorMessage = null;
|
||||
items.InsertArrayElementAtIndex(size);
|
||||
SerializedProperty newItem = items.GetArrayElementAtIndex(size);
|
||||
SerializedProperty newItemName = newItem.FindPropertyRelative("Name");
|
||||
if (newItemName == null)
|
||||
newItem.stringValue = newName;
|
||||
else
|
||||
newItemName.stringValue = newName;
|
||||
newName = "";
|
||||
UpdateWindow();
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessage = null;
|
||||
}
|
||||
UpdateWindow();
|
||||
}
|
||||
|
||||
void callback(object val)
|
||||
{
|
||||
KeyValuePair<string, string> pair = (KeyValuePair<string, string>)val;
|
||||
mOperations[pair.Key] = pair.Value;
|
||||
}
|
||||
|
||||
bool RenameCategory(string fromName, string toName)
|
||||
{
|
||||
PyramidChart pyramidChart = (PyramidChart)serializedObject.targetObject;
|
||||
try
|
||||
{
|
||||
pyramidChart.DataSource.RenameCategory(fromName, toName);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
serializedObject.Update();
|
||||
if (pyramidChart.gameObject.activeInHierarchy)
|
||||
pyramidChart.GenerateChart();
|
||||
else
|
||||
EditorUtility.SetDirty(pyramidChart);
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenameCalled(object val)
|
||||
{
|
||||
var data = (KeyValuePair<string, string>)val;
|
||||
RenameWindow window = EditorWindow.GetWindow<RenameWindow>();
|
||||
mRenameWindow = window;
|
||||
if (data.Key == "category")
|
||||
window.ShowDialog(data.Value, data.Key, RenameCategory);
|
||||
}
|
||||
void DoContext(string type, string name)
|
||||
{
|
||||
string arg = type + "|" + name;
|
||||
GenericMenu menu = new GenericMenu();
|
||||
menu.AddItem(new GUIContent("Move Up"), false, callback, new KeyValuePair<string, string>(arg, "up"));
|
||||
menu.AddItem(new GUIContent("Move Down"), false, callback, new KeyValuePair<string, string>(arg, "down"));
|
||||
menu.AddItem(new GUIContent("Remove"), false, callback, new KeyValuePair<string, string>(arg, "remove"));
|
||||
menu.AddItem(new GUIContent("Rename.."), false, RenameCalled, new KeyValuePair<string, string>(type, name));
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
void UpdateWindow()
|
||||
{
|
||||
mUpdateWindow = true;
|
||||
}
|
||||
void OnDisable()
|
||||
{
|
||||
if(mRenameWindow != null)
|
||||
{
|
||||
mRenameWindow.Close();
|
||||
mRenameWindow = null;
|
||||
}
|
||||
if (mWindow != null)
|
||||
{
|
||||
mWindow.Close();
|
||||
mWindow = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
SerializedProperty barData = serializedObject.FindProperty("Data");
|
||||
EditorGUILayout.BeginVertical();
|
||||
Splitter();
|
||||
if (mBold == null)
|
||||
mBold = new GUIStyle(EditorStyles.foldout);
|
||||
EditorGUILayout.LabelField("Data", EditorStyles.boldLabel);
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
NamedItemEditor(barData, "category", "mCategories", "Categories", ref mCategoryError, ref mCategories, ref mNewCategoryName);
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUILayout.EndVertical();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
serializedObject.Update();
|
||||
if (mUpdateWindow == true)
|
||||
{
|
||||
mUpdateWindow = false;
|
||||
if (mWindow != null)
|
||||
{
|
||||
mWindow.SetEditedObject(serializedObject);
|
||||
mWindow.Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/PyramidChartInspector.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/PyramidChartInspector.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79e4c0b8020ab4a42a6d990ae8dc88c3
|
||||
timeCreated: 1579446121
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
392
Assets/Chart And Graph/Editor/RadarChartInspector.cs
Normal file
392
Assets/Chart And Graph/Editor/RadarChartInspector.cs
Normal file
@@ -0,0 +1,392 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using ChartAndGraph;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets
|
||||
{
|
||||
[CustomEditor(typeof(RadarChart), true)]
|
||||
class RadarChartInspector : Editor
|
||||
{
|
||||
bool mCategories = false;
|
||||
bool mGroups = false;
|
||||
string mCategoryError = null;
|
||||
string mNewCategoryName = "";
|
||||
string mNewGroupName = "";
|
||||
string mGroupError = null;
|
||||
GUIStyle mRedStyle;
|
||||
GUIStyle mBold;
|
||||
HashSet<string> mAllNames = new HashSet<string>();
|
||||
GUIStyle mSplitter;
|
||||
List<int> mToRemove = new List<int>();
|
||||
List<int> mToUp = new List<int>();
|
||||
Dictionary<string, string> mOperations = new Dictionary<string, string>();
|
||||
ChartDataEditor mWindow;
|
||||
bool mUpdateWindow = false;
|
||||
Texture mSettings;
|
||||
GUIContent MaxRadarValue = new GUIContent("Max Value :", "All radar values are scale according to this value");
|
||||
GUIContent MinRadarValue = new GUIContent("Min Value :", "All radar values are scale according to this value");
|
||||
RenameWindow mRenameWindow;
|
||||
|
||||
string[] NonCanvas = new string[]
|
||||
{
|
||||
"LinePrefab",
|
||||
"PointPrefab",
|
||||
"Seperation",
|
||||
"Curve",
|
||||
"FillSmoothing"
|
||||
};
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
|
||||
mRedStyle = new GUIStyle();
|
||||
mRedStyle.normal.textColor = Color.red;
|
||||
|
||||
mSplitter = new GUIStyle();
|
||||
mSplitter.normal.background = EditorGUIUtility.whiteTexture;
|
||||
mSplitter.stretchWidth = true;
|
||||
mSplitter.margin = new RectOffset(0, 0, 7, 7);
|
||||
}
|
||||
|
||||
public void Splitter()
|
||||
{
|
||||
Rect position = GUILayoutUtility.GetRect(GUIContent.none, mSplitter, GUILayout.Height(1f));
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
Color restoreColor = GUI.color;
|
||||
GUI.color = new Color(0.5f, 0.5f, 0.5f);
|
||||
mSplitter.Draw(position, false, false, false, false);
|
||||
GUI.color = restoreColor;
|
||||
}
|
||||
}
|
||||
|
||||
private void DoOperations(SerializedProperty items, int size, string type)
|
||||
{
|
||||
mToRemove.Clear();
|
||||
mToUp.Clear();
|
||||
bool up = false;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
SerializedProperty entry = items.GetArrayElementAtIndex(i);
|
||||
if (entry == null)
|
||||
continue;
|
||||
SerializedProperty nameProp = entry.FindPropertyRelative("Name");
|
||||
string name = null;
|
||||
if (nameProp == null)
|
||||
name = entry.stringValue;
|
||||
else
|
||||
name = nameProp.stringValue;
|
||||
|
||||
string arg = type + "|" + name;
|
||||
string res = null;
|
||||
if (up == true)
|
||||
{
|
||||
mToUp.Add(i);
|
||||
up = false;
|
||||
}
|
||||
if (mOperations.TryGetValue(arg, out res))
|
||||
{
|
||||
if (res == "remove")
|
||||
mToRemove.Add(i);
|
||||
if (res == "up" && i > 0)
|
||||
mToUp.Add(i);
|
||||
if (res == "down")
|
||||
up = true;
|
||||
mOperations.Remove(arg);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < mToRemove.Count; i++)
|
||||
items.DeleteArrayElementAtIndex(mToRemove[i]);
|
||||
for (int i = 0; i < mToUp.Count; i++)
|
||||
{
|
||||
int cur = mToUp[i];
|
||||
items.MoveArrayElement(cur, cur - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void NamedItemEditor(SerializedProperty data, string type, string property, string caption, ref string errorMessage, ref bool foldout, ref string newName)
|
||||
{
|
||||
SerializedProperty items = data.FindPropertyRelative(property);
|
||||
items.isExpanded = EditorGUILayout.Foldout(items.isExpanded, caption);
|
||||
//bool up, down;
|
||||
mAllNames.Clear();
|
||||
int size = items.arraySize;
|
||||
if (Event.current.type == EventType.Layout)
|
||||
DoOperations(items, size, type);
|
||||
size = items.arraySize;
|
||||
if (items.isExpanded)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
SerializedProperty entry = items.GetArrayElementAtIndex(i);
|
||||
if (entry == null)
|
||||
continue;
|
||||
SerializedProperty nameProp = entry.FindPropertyRelative("Name");
|
||||
string name = null;
|
||||
if (nameProp == null)
|
||||
name = entry.stringValue;
|
||||
else
|
||||
name = nameProp.stringValue;
|
||||
mAllNames.Add(name);
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
bool toogle = false;
|
||||
if (nameProp != null)
|
||||
toogle = entry.isExpanded = EditorGUILayout.Foldout(entry.isExpanded, name);
|
||||
else
|
||||
{
|
||||
toogle = false;
|
||||
EditorGUILayout.LabelField(name);
|
||||
}
|
||||
GUILayout.FlexibleSpace();
|
||||
if (GUILayout.Button("..."))
|
||||
DoContext(type, name);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if (toogle)
|
||||
{
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
if (nameProp != null)
|
||||
{
|
||||
SerializedProperty end = entry.GetEndProperty(true);
|
||||
entry.Next(true);
|
||||
if (SerializedProperty.EqualContents(entry, end) == false)
|
||||
{
|
||||
do
|
||||
{
|
||||
if (entry.name != "Name")
|
||||
{
|
||||
if(target is CanvasRadarChart)
|
||||
{
|
||||
|
||||
if (NonCanvas.Contains(entry.name))
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (entry.name == "LineHover" || entry.name == "PointHover")
|
||||
continue;
|
||||
}
|
||||
EditorGUILayout.PropertyField(entry, true);
|
||||
}
|
||||
|
||||
}
|
||||
while (entry.Next(entry.name == "Materials") && SerializedProperty.EqualContents(entry, end) == false);
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (errorMessage != null)
|
||||
EditorGUILayout.LabelField(errorMessage, mRedStyle);
|
||||
EditorGUILayout.LabelField(string.Format("Add new {0} :", type));
|
||||
//Rect indentAdd = EditorGUI.IndentedRect(new Rect(0f, 0f, 1000f, 1000f));
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
newName = EditorGUILayout.TextField(newName);
|
||||
//GUILayout.Space(indentAdd.xMin);
|
||||
if (GUILayout.Button("Add"))
|
||||
{
|
||||
bool error = false;
|
||||
if (newName.Trim().Length == 0)
|
||||
{
|
||||
errorMessage = "Name can't be empty";
|
||||
error = true;
|
||||
}
|
||||
else if (ChartEditorCommon.IsAlphaNum(newName) == false)
|
||||
{
|
||||
errorMessage = "Name conatins invalid characters";
|
||||
error = true;
|
||||
}
|
||||
else if (mAllNames.Contains(newName))
|
||||
{
|
||||
errorMessage = string.Format("A {0} named {1} already exists in this chart", type, newName);
|
||||
error = true;
|
||||
}
|
||||
if (error == false)
|
||||
{
|
||||
errorMessage = null;
|
||||
items.InsertArrayElementAtIndex(size);
|
||||
SerializedProperty newItem = items.GetArrayElementAtIndex(size);
|
||||
SerializedProperty newItemName = newItem.FindPropertyRelative("Name");
|
||||
if (newItemName == null)
|
||||
newItem.stringValue = newName;
|
||||
else
|
||||
newItemName.stringValue = newName;
|
||||
newName = "";
|
||||
UpdateWindow();
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessage = null;
|
||||
}
|
||||
UpdateWindow();
|
||||
}
|
||||
|
||||
void callback(object val)
|
||||
{
|
||||
KeyValuePair<string, string> pair = (KeyValuePair<string, string>)val;
|
||||
mOperations[pair.Key] = pair.Value;
|
||||
}
|
||||
|
||||
bool RenameGroup(string fromName, string toName)
|
||||
{
|
||||
RadarChart radarChart = (RadarChart)serializedObject.targetObject;
|
||||
try
|
||||
{
|
||||
radarChart.DataSource.RenameGroup(fromName, toName);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
serializedObject.Update();
|
||||
if (radarChart.gameObject.activeInHierarchy)
|
||||
radarChart.GenerateChart();
|
||||
else
|
||||
EditorUtility.SetDirty(radarChart);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RenameCategory(string fromName, string toName)
|
||||
{
|
||||
RadarChart radarChart = (RadarChart)serializedObject.targetObject;
|
||||
try
|
||||
{
|
||||
radarChart.DataSource.RenameCategory(fromName, toName);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
serializedObject.Update();
|
||||
if (radarChart.gameObject.activeInHierarchy)
|
||||
radarChart.GenerateChart();
|
||||
else
|
||||
EditorUtility.SetDirty(radarChart);
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenameCalled(object val)
|
||||
{
|
||||
var data = (KeyValuePair<string, string>)val;
|
||||
RenameWindow window = EditorWindow.GetWindow<RenameWindow>();
|
||||
mRenameWindow = window;
|
||||
if (data.Key == "category")
|
||||
window.ShowDialog(data.Value, data.Key, RenameCategory);
|
||||
else if (data.Key == "group")
|
||||
window.ShowDialog(data.Value, data.Key, RenameGroup);
|
||||
}
|
||||
|
||||
void DoContext(string type, string name)
|
||||
{
|
||||
string arg = type + "|" + name;
|
||||
GenericMenu menu = new GenericMenu();
|
||||
menu.AddItem(new GUIContent("Move Up"), false, callback, new KeyValuePair<string, string>(arg, "up"));
|
||||
menu.AddItem(new GUIContent("Move Down"), false, callback, new KeyValuePair<string, string>(arg, "down"));
|
||||
menu.AddItem(new GUIContent("Remove"), false, callback, new KeyValuePair<string, string>(arg, "remove"));
|
||||
menu.AddItem(new GUIContent("Rename.."), false, RenameCalled, new KeyValuePair<string, string>(type, name));
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
||||
void UpdateWindow()
|
||||
{
|
||||
mUpdateWindow = true;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (mRenameWindow != null)
|
||||
{
|
||||
mRenameWindow.Close();
|
||||
mRenameWindow = null;
|
||||
}
|
||||
if (mWindow != null)
|
||||
{
|
||||
mWindow.Close();
|
||||
mWindow = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
serializedObject.Update();
|
||||
SerializedProperty radarData = serializedObject.FindProperty("Data");
|
||||
EditorGUILayout.BeginVertical();
|
||||
Splitter();
|
||||
if (mBold == null)
|
||||
{
|
||||
mBold = new GUIStyle(EditorStyles.foldout);
|
||||
}
|
||||
|
||||
EditorGUILayout.LabelField("Data", EditorStyles.boldLabel);
|
||||
EditorGUI.indentLevel++;
|
||||
NamedItemEditor(radarData, "category", "mCategories", "Categories", ref mCategoryError, ref mCategories, ref mNewCategoryName);
|
||||
NamedItemEditor(radarData, "group", "mGroups", "Groups", ref mGroupError, ref mGroups, ref mNewGroupName);
|
||||
|
||||
SerializedProperty maxProp = radarData.FindPropertyRelative("maxValue");
|
||||
SerializedProperty minProp = radarData.FindPropertyRelative("minValue");
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField(MaxRadarValue, EditorStyles.boldLabel);
|
||||
SerializedProperty automaticProp = radarData.FindPropertyRelative("automaticMaxValue");
|
||||
bool automatic = automaticProp.boolValue;
|
||||
automatic = GUILayout.Toggle(automatic, "Auto");
|
||||
GUILayout.FlexibleSpace();
|
||||
automaticProp.boolValue = automatic;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if (automatic == false)
|
||||
{
|
||||
|
||||
EditorGUILayout.PropertyField(maxProp);
|
||||
if (0f > maxProp.doubleValue)
|
||||
maxProp.doubleValue = 0.001f;
|
||||
}
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField(MinRadarValue, EditorStyles.boldLabel);
|
||||
automaticProp = radarData.FindPropertyRelative("automaticMinValue");
|
||||
automatic = automaticProp.boolValue;
|
||||
automatic = GUILayout.Toggle(automatic, "Auto");
|
||||
GUILayout.FlexibleSpace();
|
||||
automaticProp.boolValue = automatic;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
if (automatic == false)
|
||||
{
|
||||
|
||||
EditorGUILayout.PropertyField(minProp);
|
||||
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Edit Values...") && mWindow == null)
|
||||
mWindow = ChartDataEditor.ShowForObject(serializedObject);
|
||||
//}
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUILayout.EndVertical();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
if (mUpdateWindow == true)
|
||||
{
|
||||
mUpdateWindow = false;
|
||||
if (mWindow != null)
|
||||
{
|
||||
mWindow.SetEditedObject(serializedObject);
|
||||
mWindow.Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/RadarChartInspector.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/RadarChartInspector.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec3a557017cfb7040b5a426cb7f71a47
|
||||
timeCreated: 1489858254
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
71
Assets/Chart And Graph/Editor/RenameWindow.cs
Normal file
71
Assets/Chart And Graph/Editor/RenameWindow.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
class RenameWindow :EditorWindow
|
||||
{
|
||||
string mStartName;
|
||||
string mValue = "";
|
||||
string mType;
|
||||
Func<string, string, bool> mRenameMethod;
|
||||
string mMessage = null;
|
||||
|
||||
public void ShowDialog(string currentName,string type,Func<string,string, bool> renameMethod)
|
||||
{
|
||||
mStartName = currentName;
|
||||
mValue = currentName;
|
||||
mType = type;
|
||||
mRenameMethod = renameMethod;
|
||||
float height = (float)(EditorGUIUtility.singleLineHeight * 6f);
|
||||
minSize = maxSize = new Vector2(300, height);
|
||||
Show();
|
||||
|
||||
}
|
||||
void OnGUI()
|
||||
{
|
||||
EditorGUILayout.LabelField(string.Format("Select a new {0} name",mType));
|
||||
mValue = EditorGUILayout.TextField(mValue);
|
||||
bool disabled = false;
|
||||
if (mValue.Trim().Length == 0)
|
||||
{
|
||||
mMessage = null;
|
||||
EditorGUILayout.LabelField("Name can't be empty");
|
||||
disabled = true;
|
||||
}
|
||||
else
|
||||
if (ChartEditorCommon.IsAlphaNum(mValue) == false)
|
||||
{
|
||||
mMessage = null;
|
||||
EditorGUILayout.LabelField("Name contains invalid charecters");
|
||||
disabled = true;
|
||||
}
|
||||
if (mMessage != null)
|
||||
EditorGUILayout.LabelField(mMessage);
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUI.enabled = !disabled;
|
||||
if (GUILayout.Button("Rename"))
|
||||
{
|
||||
if (mStartName == mValue)
|
||||
Close();
|
||||
else
|
||||
{
|
||||
if (mRenameMethod(mStartName,mValue))
|
||||
Close();
|
||||
else
|
||||
mMessage = string.Format("A {0} by the name {1} already exists", mType, mValue);
|
||||
}
|
||||
}
|
||||
GUI.enabled = true;
|
||||
GUILayout.FlexibleSpace();
|
||||
if (GUILayout.Button("Cancel"))
|
||||
Close();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Editor/RenameWindow.cs.meta
Normal file
12
Assets/Chart And Graph/Editor/RenameWindow.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66d4769f533803d49a88420cd97553f9
|
||||
timeCreated: 1481046854
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user