작업 조건 분석 기능 개발
This commit is contained in:
30
Assets/Chart And Graph/Script/BarChart/BarChart.Extra.cs
Normal file
30
Assets/Chart And Graph/Script/BarChart/BarChart.Extra.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
public partial class BarChart
|
||||
{
|
||||
partial void StackedStage1(ref float elevation, double prevIntep)
|
||||
{
|
||||
if (Stacked)
|
||||
elevation = (float)prevIntep * HeightRatio;
|
||||
}
|
||||
|
||||
partial void StackedStage2(ref double prevIntep, double interp)
|
||||
{
|
||||
if (Stacked)
|
||||
prevIntep = interp;
|
||||
}
|
||||
partial void StackedStage3(ref double interp, double amount, double min, double total)
|
||||
{
|
||||
if (Stacked)
|
||||
{
|
||||
interp = (amount - min) / total;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95fd0ed42f0ce34459cd9abe796dbbce
|
||||
timeCreated: 1560592679
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1409
Assets/Chart And Graph/Script/BarChart/BarChart.cs
Normal file
1409
Assets/Chart And Graph/Script/BarChart/BarChart.cs
Normal file
File diff suppressed because it is too large
Load Diff
12
Assets/Chart And Graph/Script/BarChart/BarChart.cs.meta
Normal file
12
Assets/Chart And Graph/Script/BarChart/BarChart.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5bcc7a36d1f7adf46a882749324dca81
|
||||
timeCreated: 1472816162
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
56
Assets/Chart And Graph/Script/BarChart/BarContentFiller.cs
Normal file
56
Assets/Chart And Graph/Script/BarChart/BarContentFiller.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using ChartAndGraph;
|
||||
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
[RequireComponent(typeof(CanvasBarChart))]
|
||||
public class BarContentFiller : MonoBehaviour
|
||||
{
|
||||
public float FixedAxisMarign = 40f;
|
||||
public float FixedGroupSpacing = 25f;
|
||||
public float FixedBarSeperation = 10f;
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
}
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
var bar = GetComponent<BarChart>();
|
||||
bar.Invalidate();
|
||||
}
|
||||
|
||||
public virtual void Match()
|
||||
{
|
||||
var rect = GetComponent<RectTransform>();
|
||||
var totalWidth = rect.rect.width;
|
||||
var bar = GetComponent<CanvasBarChart>();
|
||||
bool Stacked = bar.ViewType == BarChart.BarType.Stacked;
|
||||
int columnCount = bar.DataSource.TotalCategories;
|
||||
int rowCount = bar.DataSource.TotalGroups;
|
||||
|
||||
int rowLimit = rowCount - 1;
|
||||
double groupSize = (totalWidth - FixedAxisMarign * 2 - FixedGroupSpacing * rowLimit) / rowCount;
|
||||
double groupSeperation = groupSize + FixedGroupSpacing;
|
||||
double barSize = (groupSize - FixedBarSeperation * (columnCount - 1)) / columnCount;
|
||||
if (Stacked)
|
||||
barSize = groupSize;
|
||||
|
||||
bar.AxisSeperation = FixedAxisMarign;
|
||||
if (Stacked)
|
||||
bar.BarSeperation = 0;
|
||||
else
|
||||
bar.BarSeperation = FixedBarSeperation + (float)barSize;
|
||||
|
||||
bar.GroupSeperation = (float)groupSeperation;
|
||||
bar.BarSize = (float)barSize;// (float)(RatioBarSize * factor);
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34c39007aa076f64b88e21ac326ff50d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
54
Assets/Chart And Graph/Script/BarChart/BarContentFitter.cs
Normal file
54
Assets/Chart And Graph/Script/BarChart/BarContentFitter.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using ChartAndGraph;
|
||||
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
[RequireComponent(typeof(CanvasBarChart))]
|
||||
public class BarContentFitter : MonoBehaviour
|
||||
{
|
||||
public float RatioAxisMarign = 1f;
|
||||
public float FixedBarSize = 30f;
|
||||
public float RatioGroupSeperation = 5f;
|
||||
public float RatioBarSeperation = 2f;
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
}
|
||||
|
||||
void OnValidate()
|
||||
{
|
||||
var bar = GetComponent<BarChart>();
|
||||
bar.Invalidate();
|
||||
}
|
||||
|
||||
public virtual void Match()
|
||||
{
|
||||
var rect = GetComponent<RectTransform>();
|
||||
var totalWidth = rect.rect.width;
|
||||
var bar = GetComponent<CanvasBarChart>();
|
||||
int columnCount = bar.DataSource.TotalCategories;
|
||||
int rowCount = bar.DataSource.TotalGroups;
|
||||
|
||||
int rowLimit = rowCount - 1;
|
||||
double barGroupSeprationSize = RatioBarSeperation * (columnCount - 1);
|
||||
double barGroupSize = barGroupSeprationSize;// + RatioBarSize;
|
||||
double totalSize = RatioGroupSeperation * rowLimit;
|
||||
double baseSize = totalSize + 2* RatioAxisMarign + barGroupSize;
|
||||
|
||||
double factor = totalWidth / baseSize;
|
||||
|
||||
bar.HeightRatio = rect.rect.height;
|
||||
bar.AxisSeperation = (float)(RatioAxisMarign * factor);
|
||||
bar.BarSeperation = (float)(RatioBarSeperation * factor);
|
||||
bar.GroupSeperation = (float)(RatioGroupSeperation * factor);
|
||||
bar.BarSize = FixedBarSize;// (float)(RatioBarSize * factor);
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cd0887944b07804e8103d5070b1cf3b
|
||||
timeCreated: 1579111521
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
589
Assets/Chart And Graph/Script/BarChart/BarData.cs
Normal file
589
Assets/Chart And Graph/Script/BarChart/BarData.cs
Normal file
@@ -0,0 +1,589 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using ChartAndGraph.DataSource;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using ChartAndGraph.Exceptions;
|
||||
using System.Linq;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
/// <summary>
|
||||
/// data source for bar charts
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class BarData : AbstractChartData,IInternalBarData, IChartData
|
||||
{
|
||||
[Serializable]
|
||||
class CategoryData
|
||||
{
|
||||
public string Name;
|
||||
public ChartDynamicMaterial Materials;
|
||||
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
class DataEntry
|
||||
{
|
||||
public string GroupName;
|
||||
public string ColumnName;
|
||||
public double Amount;
|
||||
}
|
||||
|
||||
private ChartSparseDataSource mDataSource = new ChartSparseDataSource();
|
||||
ChartSparseDataSource IInternalBarData.InternalDataSource { get { return mDataSource; } }
|
||||
[SerializeField]
|
||||
private CategoryData[] mCategories = new CategoryData[0];
|
||||
[SerializeField]
|
||||
private string[] mGroups = new string[0];
|
||||
[SerializeField]
|
||||
private DataEntry[] mData = new DataEntry[0];
|
||||
|
||||
|
||||
public event Action ProperyUpdated;
|
||||
|
||||
protected void RaisePropertyUpdated()
|
||||
{
|
||||
if (ProperyUpdated != null)
|
||||
ProperyUpdated();
|
||||
}
|
||||
/// <summary>
|
||||
/// the number of categories in the data source
|
||||
/// </summary>
|
||||
public int TotalCategories { get { return mDataSource.Columns.Count; } }
|
||||
/// <summary>
|
||||
/// the number of groups in the data source
|
||||
/// </summary>
|
||||
public int TotalGroups { get { return mDataSource.Rows.Count; } }
|
||||
/// <summary>
|
||||
/// set this to true to automatically detect the highest bar value int the chart. This value will be used to scale all other bars
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
private bool automaticMaxValue = true;
|
||||
|
||||
public void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// renames a category. throw an exception on error
|
||||
/// </summary>
|
||||
/// <param name="prevName"></param>
|
||||
/// <param name="newName"></param>
|
||||
public void RenameCategory(string prevName,string newName)
|
||||
{
|
||||
mDataSource.Columns[prevName].Name = newName;
|
||||
RaisePropertyUpdated();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// renames a group. throw an exception on error
|
||||
/// </summary>
|
||||
/// <param name="prevName"></param>
|
||||
/// <param name="newName"></param>
|
||||
public void RenameGroup(string prevName,string newName)
|
||||
{
|
||||
mDataSource.Rows[prevName].Name = newName;
|
||||
RaisePropertyUpdated();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// set this to true to automatically detect the highest bar value int the chart. This value will be used to scale all other bars
|
||||
/// </summary>
|
||||
public bool AutomaticMaxValue
|
||||
{
|
||||
get { return automaticMaxValue; }
|
||||
set
|
||||
{
|
||||
automaticMaxValue = value;
|
||||
RaisePropertyUpdated();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Mannualy set the maximum value , all bars will be scaled based on this value. If a bar value is larger than this value it will be clamped
|
||||
/// Note: set AutomaticMaxValue to false in order to use this field
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
private double maxValue = 10;
|
||||
|
||||
/// <summary>
|
||||
/// Mannualy set the maximum value , all bars will be scaled based on this value. If a bar value is larger than this value it will be clamped
|
||||
/// Note: set AutomaticMaxValue to false in order to use this field
|
||||
/// </summary>
|
||||
public double MaxValue
|
||||
{
|
||||
get { return maxValue; }
|
||||
set
|
||||
{
|
||||
maxValue = value;
|
||||
RaisePropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasGroup(string groupName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var row = mDataSource.Rows[groupName];
|
||||
if (row != null)
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool HasCategory(string category)
|
||||
{
|
||||
try
|
||||
{
|
||||
var col = mDataSource.Columns[category];
|
||||
if (col != null)
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// set this to true to automatically detect the lowest bar value int the chart. This value will be used to scale all other bars
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
private bool automaticMinValue = false;
|
||||
|
||||
/// <summary>
|
||||
/// set this to true to automatically detect the lowest bar value int the chart. This value will be used to scale all other bars
|
||||
/// </summary>
|
||||
public bool AutomaticMinValue
|
||||
{
|
||||
get { return automaticMinValue; }
|
||||
set
|
||||
{
|
||||
automaticMinValue = value;
|
||||
RaisePropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mannualy set the minimum value , all bars will be scaled based on this value. If a bar value is larger than this value it will be clamped
|
||||
/// Note: set AutomaticMinValue to false in order to use this field
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
private double minValue = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Mannualy set the minimum value , all bars will be scaled based on this value. If a bar value is larger than this value it will be clamped
|
||||
/// Note: set AutomaticMinValue to false in order to use this field
|
||||
/// </summary>
|
||||
public double MinValue
|
||||
{
|
||||
get { return minValue; }
|
||||
set
|
||||
{
|
||||
minValue = value;
|
||||
RaisePropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
void IInternalBarData.Update()
|
||||
{
|
||||
UpdateSliders();
|
||||
}
|
||||
/// <summary>
|
||||
/// call this to suspend chart redrawing while updating the data of the chart
|
||||
/// </summary>
|
||||
public void StartBatch()
|
||||
{
|
||||
mDataSource.SuspendEvents = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// call this after StartBatch , this will apply all the changed made between the StartBatch call to this call
|
||||
/// </summary>
|
||||
public void EndBatch()
|
||||
{
|
||||
mDataSource.SuspendEvents = false;
|
||||
}
|
||||
|
||||
public double GetMinValue()
|
||||
{
|
||||
double min = MinValue;
|
||||
double? rawMin = mDataSource.getRawMinValue();
|
||||
|
||||
if (AutomaticMinValue && rawMin.HasValue)
|
||||
min = rawMin.Value;
|
||||
return min;
|
||||
}
|
||||
|
||||
public double GetMaxValue()
|
||||
{
|
||||
double max = MaxValue;
|
||||
double? rawMax = mDataSource.getRawMaxValue();
|
||||
|
||||
if (AutomaticMaxValue && rawMax.HasValue)
|
||||
max = rawMax.Value;
|
||||
return max;
|
||||
|
||||
}
|
||||
|
||||
public string GetCategoryName(int index)
|
||||
{
|
||||
return mDataSource.Columns[index].Name;
|
||||
}
|
||||
|
||||
public string GetGroupName(int index)
|
||||
{
|
||||
return mDataSource.Rows[index].Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// used intenally , do not call
|
||||
/// </summary>
|
||||
/// <param name="cats"></param>
|
||||
public object[] StoreAllCategoriesinOrder()
|
||||
{
|
||||
return mCategories.ToArray();
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
int totalColumns = mDataSource.Columns.Count;
|
||||
mCategories = new CategoryData[totalColumns];
|
||||
|
||||
for (int i = 0; i < totalColumns; i++)
|
||||
{
|
||||
CategoryData data = new CategoryData();
|
||||
data.Name = mDataSource.Columns[i].Name;
|
||||
data.Materials = mDataSource.Columns[i].Material;
|
||||
mCategories[i] = data;
|
||||
}
|
||||
|
||||
int totalRows = mDataSource.Rows.Count;
|
||||
mGroups = new string[totalRows];
|
||||
for(int i=0; i< totalRows; i++)
|
||||
mGroups[i] = mDataSource.Rows[i].Name;
|
||||
|
||||
double[,] raw = mDataSource.getRawData();
|
||||
int current = 0;
|
||||
mData = new DataEntry[raw.GetLength(0) * raw.GetLength(1)];
|
||||
for (int i = 0; i < raw.GetLength(0); ++i)
|
||||
{
|
||||
for (int j = 0; j < raw.GetLength(1); ++j)
|
||||
{
|
||||
DataEntry entry = new DataEntry();
|
||||
entry.ColumnName = mDataSource.Columns[j].Name;
|
||||
entry.GroupName = mDataSource.Rows[i].Name;
|
||||
entry.Amount = raw[i, j];
|
||||
mData[current++] = entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
mDataSource = new ChartSparseDataSource();
|
||||
mDataSource.SuspendEvents = true;
|
||||
mDataSource.Clear();
|
||||
if (mCategories == null)
|
||||
mCategories = new CategoryData[0];
|
||||
if (mGroups == null)
|
||||
mGroups = new string[0];
|
||||
if (mData == null)
|
||||
mData = new DataEntry[0];
|
||||
for (int i = 0; i < mCategories.Length; i++)
|
||||
{
|
||||
AddCategory(mCategories[i].Name, mCategories[i].Materials);
|
||||
}
|
||||
for (int i = 0; i < mGroups.Length; i++)
|
||||
AddGroup(mGroups[i]);
|
||||
|
||||
for(int i=0; i< mData.Length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
DataEntry entry = mData[i];
|
||||
mDataSource.SetValue(entry.ColumnName, entry.GroupName, entry.Amount);
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
mDataSource.SuspendEvents = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new category to the bar chart. Each category has it's own material and name.
|
||||
/// Note: you must also have at least one group on the bar chart
|
||||
/// Example: you can set the categories to "Player 1","Player 2","Player 3" and the groups to "Gold","Wood","Oil","Total"
|
||||
/// in order to compare the resources the players have gather during a level
|
||||
/// </summary>
|
||||
/// <param name="name">the name of the category</param>
|
||||
/// <param name="material">the material of the category</param>
|
||||
public void AddCategory(string name, Material material)
|
||||
{
|
||||
AddCategory(name, new ChartDynamicMaterial(material));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// clears all groups in the bar chart
|
||||
/// </summary>
|
||||
public void ClearGroups()
|
||||
{
|
||||
string[] groups = mDataSource.Rows.Select(x => x.Name).ToArray();
|
||||
foreach(string s in groups)
|
||||
{
|
||||
RemoveGroup(s);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sets all values to the value parameted
|
||||
/// </summary>
|
||||
public void ClearValues(double value = 0.0)
|
||||
{
|
||||
string[] catgories = mDataSource.Columns.Select(x => x.Name).ToArray();
|
||||
string[] groups = mDataSource.Rows.Select(x => x.Name).ToArray();
|
||||
foreach (string g in groups)
|
||||
{
|
||||
foreach (string c in catgories)
|
||||
{
|
||||
SetValue(c, g, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// clears alll categories in the bar chart
|
||||
/// </summary>
|
||||
public void ClearCategories()
|
||||
{
|
||||
string[] catgories = mDataSource.Columns.Select(x => x.Name).ToArray();
|
||||
foreach (string s in catgories)
|
||||
{
|
||||
RemoveCategory(s);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new category to the bar chart. Each category has it's own material and name.
|
||||
/// Note: you must also add groups to the bar data.
|
||||
/// Example: you can set the chart categories to be "Player 1","Player 2","Player 3" in order to compare player achivments
|
||||
/// </summary>
|
||||
/// <param name="name">the name of the category</param>
|
||||
/// <param name="material">the dynamic material of the category. dynamic materials allows setting the material for different events</param>
|
||||
public void AddCategory(string name, ChartDynamicMaterial material,int position)
|
||||
{
|
||||
ChartDataColumn column = new ChartDataColumn(name);
|
||||
column.Material = material;
|
||||
mDataSource.mColumns.Insert(position,column);
|
||||
}
|
||||
/// <summary>
|
||||
/// moves the category to a new position
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="newPosition"></param>
|
||||
public void MoveCategory(string name,int newPosition)
|
||||
{
|
||||
mDataSource.mColumns.Move(name, newPosition);
|
||||
}
|
||||
|
||||
public void SwitchCategoryPositions(string firstCategory,string secondCategory)
|
||||
{
|
||||
mDataSource.mColumns.SwitchPositions(firstCategory, secondCategory);
|
||||
}
|
||||
/// <summary>
|
||||
/// Adds a new category to the bar chart. Each category has it's own material and name.
|
||||
/// Note: you must also add groups to the bar data.
|
||||
/// Example: you can set the chart categories to be "Player 1","Player 2","Player 3" in order to compare player achivments
|
||||
/// </summary>
|
||||
/// <param name="name">the name of the category</param>
|
||||
/// <param name="material">the dynamic material of the category. dynamic materials allows setting the material for different events</param>
|
||||
public void AddCategory(string name, ChartDynamicMaterial material)
|
||||
{
|
||||
ChartDataColumn column = new ChartDataColumn(name);
|
||||
column.Material = material;
|
||||
mDataSource.mColumns.Add(column);
|
||||
}
|
||||
|
||||
public void SetCategoryIndex(string name,int index)
|
||||
{
|
||||
ChartDataColumn col = mDataSource.mColumns[name];
|
||||
double[] values = new double[TotalGroups];
|
||||
for(int i=0; i<TotalGroups; i++)
|
||||
{
|
||||
string g = GetGroupName(i);
|
||||
values[i] = GetValue(name, g);
|
||||
}
|
||||
|
||||
mDataSource.Columns.Remove(col);
|
||||
mDataSource.Columns.Insert(index, col);
|
||||
for (int i = 0; i < TotalGroups; i++)
|
||||
{
|
||||
string g = GetGroupName(i);
|
||||
SetValue(name, g, values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sets the material for the specified category
|
||||
/// </summary>
|
||||
/// <param name="category">the name of the category</param>
|
||||
/// <param name="material">the material of the category</param>
|
||||
public void SetMaterial(string category,Material material)
|
||||
{
|
||||
SetMaterial(category, new ChartDynamicMaterial(material));
|
||||
}
|
||||
|
||||
public ChartDynamicMaterial GetMaterial(string category)
|
||||
{
|
||||
return mDataSource.Columns[category].Material;
|
||||
}
|
||||
/// <summary>
|
||||
/// sets the material for the specified category
|
||||
/// </summary>
|
||||
/// <param name="category">the name of the category</param>
|
||||
/// <param name="material">the dynamic material of the category. dynamic materials allows setting the material for different events</param>
|
||||
public void SetMaterial(string category,ChartDynamicMaterial material)
|
||||
{
|
||||
mDataSource.Columns[category].Material = material;
|
||||
RaisePropertyUpdated();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// removes a category from the bar chart
|
||||
/// </summary>
|
||||
/// <param name="name">the name of the category to remove</param>
|
||||
public void RemoveCategory(string name)
|
||||
{
|
||||
ChartDataColumn column = mDataSource.Columns[name];
|
||||
RemoveSliderForCategory(name);
|
||||
mDataSource.Columns.Remove(column);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// removes a group from the bar chart
|
||||
/// </summary>
|
||||
/// <param name="name">the name of the group to remove</param>
|
||||
public void RemoveGroup(string name)
|
||||
{
|
||||
ChartDataRow row = mDataSource.Rows[name];
|
||||
RemoveSliderForGroup(name);
|
||||
mDataSource.Rows.Remove(row);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a group to the bar chart. Each group holds a double value for each category.
|
||||
/// Note: you must also add at least one category to the bar chart
|
||||
/// Example: you can set the categories to "Player 1","Player 2","Player 3" and the groups to "Gold","Wood","Oil","Total"
|
||||
/// in order to compare the resources the players have gather during a level
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
public void AddGroup(string name)
|
||||
{
|
||||
mDataSource.Rows.Add(new ChartDataRow(name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the value for the specified group and category
|
||||
/// </summary>
|
||||
/// <param name="category">the category name</param>
|
||||
/// <param name="group">the group name</param>
|
||||
/// <returns></returns>
|
||||
public double GetValue(string category,string group)
|
||||
{
|
||||
return mDataSource.GetValue(category, group);
|
||||
}
|
||||
|
||||
public bool CheckAnimationEnded(float time, AnimationCurve curve)
|
||||
{
|
||||
if (curve.length == 0)
|
||||
return true;
|
||||
return time > curve.keys[curve.length - 1].time;
|
||||
}
|
||||
|
||||
private void FixEaseFunction(AnimationCurve curve)
|
||||
{
|
||||
curve.postWrapMode = WrapMode.Once;
|
||||
curve.preWrapMode = WrapMode.Once;
|
||||
}
|
||||
public void RestoreCategory(string name,object obj)
|
||||
{
|
||||
var cat = (CategoryData)obj;
|
||||
SetMaterial(name, cat.Materials);
|
||||
}
|
||||
public void SlideValue(string category, string group, double slideTo,float totalTime, AnimationCurve curve)
|
||||
{
|
||||
try
|
||||
{
|
||||
RemoveSlider(category, group);
|
||||
curve.postWrapMode = WrapMode.Once;
|
||||
curve.preWrapMode = WrapMode.Once;
|
||||
float time = 0f;
|
||||
if (curve.length > 0)
|
||||
time = curve.keys[curve.length - 1].time;
|
||||
Slider s = new Slider();
|
||||
s.category = category;
|
||||
s.group = group;
|
||||
s.from = GetValue(category, group);
|
||||
s.to = slideTo;
|
||||
s.startTime = Time.time;
|
||||
s.timeScale = time / totalTime;
|
||||
s.totalTime = time;
|
||||
s.curve = curve;
|
||||
mSliders.Add(s);
|
||||
}
|
||||
catch (ChartException e)
|
||||
{
|
||||
Debug.LogWarning(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public void SlideValue(string category,string group,double slideTo,float time)
|
||||
{
|
||||
try
|
||||
{
|
||||
RemoveSlider(category, group);
|
||||
Slider s = new Slider();
|
||||
s.category = category;
|
||||
s.group = group;
|
||||
s.from = GetValue(category, group);
|
||||
s.to = slideTo;
|
||||
s.startTime = Time.time;
|
||||
s.totalTime = time;
|
||||
mSliders.Add(s);
|
||||
}
|
||||
catch (ChartException e)
|
||||
{
|
||||
Debug.LogWarning(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sets the value for the specified group and category
|
||||
/// </summary>
|
||||
/// <param name="category">the category name</param>
|
||||
/// <param name="group">the group name</param>
|
||||
/// <param name="amount">the value fo the bar</param>
|
||||
public void SetValue(string category,string group,double amount)
|
||||
{
|
||||
RemoveSlider(category, group);
|
||||
SetValueInternal(category, group, amount);
|
||||
}
|
||||
protected override void SetValueInternal(string category, string group, double amount)
|
||||
{
|
||||
try
|
||||
{
|
||||
mDataSource.SetValue(category, group, amount);
|
||||
}
|
||||
catch (ChartException e)
|
||||
{
|
||||
Debug.LogWarning(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Script/BarChart/BarData.cs.meta
Normal file
12
Assets/Chart And Graph/Script/BarChart/BarData.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83cafb2eb9779f3468aad148987eb4bc
|
||||
timeCreated: 1473966108
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
Assets/Chart And Graph/Script/BarChart/BarGenerator.cs
Normal file
24
Assets/Chart And Graph/Script/BarChart/BarGenerator.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
public abstract class BarGenerator : MonoBehaviour, IBarGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// generates a bar within the specified rect. The rect is in local coordinates
|
||||
/// </summary>
|
||||
/// <param name="rect">A rect that specifies the bounds of the bar. the rect is in local coordinates</param>
|
||||
/// <param name="normalizedSize">a value between 0 to 1 representing the size of the rect relative to the size of the chart</param>
|
||||
public abstract void Generate(float normalizedSize,float scale);
|
||||
/// <summary>
|
||||
/// clears the bar the was generated be the Generate method.
|
||||
/// </summary>
|
||||
public abstract void Clear();
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Script/BarChart/BarGenerator.cs.meta
Normal file
12
Assets/Chart And Graph/Script/BarChart/BarGenerator.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe88eea2abcbbb0439344abc5d2f6a1b
|
||||
timeCreated: 1472816163
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
80
Assets/Chart And Graph/Script/BarChart/BarInfo.cs
Normal file
80
Assets/Chart And Graph/Script/BarChart/BarInfo.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
public class BarInfo : MonoBehaviour
|
||||
{
|
||||
public BarChart.BarObject BarObject {get; set;}
|
||||
|
||||
/// <summary>
|
||||
/// gets the item label for this bar, or null if no item label is assigned to it
|
||||
/// </summary>
|
||||
public GameObject ItemLabel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BarObject == null)
|
||||
return null;
|
||||
if (BarObject.ItemLabel == null)
|
||||
return null;
|
||||
return BarObject.ItemLabel.UIText;
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject CategoryLabel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BarObject == null)
|
||||
return null;
|
||||
if (BarObject.CategoryLabel == null)
|
||||
return null;
|
||||
return BarObject.CategoryLabel.UIText;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the value of the bar
|
||||
/// </summary>
|
||||
public double Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BarObject == null)
|
||||
return 0.0;
|
||||
return BarObject.Value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// gets the category of the bar
|
||||
/// </summary>
|
||||
public string Category
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BarObject == null)
|
||||
return "";
|
||||
return BarObject.Category;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// gets the group of the bar
|
||||
/// </summary>
|
||||
public string Group
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BarObject == null)
|
||||
return "";
|
||||
return BarObject.Group;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Script/BarChart/BarInfo.cs.meta
Normal file
12
Assets/Chart And Graph/Script/BarChart/BarInfo.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77680f04204076142818a77ae4c9a124
|
||||
timeCreated: 1478381852
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
Assets/Chart And Graph/Script/BarChart/BarMaterialFit.cs
Normal file
20
Assets/Chart And Graph/Script/BarChart/BarMaterialFit.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
public enum BarMaterialFit
|
||||
{
|
||||
/// <summary>
|
||||
/// Stretch the material along the bar.
|
||||
/// </summary>
|
||||
Stretch,
|
||||
/// <summary>
|
||||
/// If the bar is small , the material will be cut to match it's size. If the bar is at maximum size , all the material will be visible
|
||||
/// </summary>
|
||||
Trim
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3acd3aa78306f2145b6a366a02c3daa6
|
||||
timeCreated: 1472816161
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
232
Assets/Chart And Graph/Script/BarChart/BarMesh2D.cs
Normal file
232
Assets/Chart And Graph/Script/BarChart/BarMesh2D.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains functionallity for generating 3d and 2d bar meshes
|
||||
/// </summary
|
||||
class BarMesh
|
||||
{
|
||||
private static Mesh m2DStrechMesh;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A lazy loaded 2d stretch mesh. This mesh is always the same
|
||||
/// </summary>
|
||||
public static Mesh StrechMesh2D
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m2DStrechMesh == null)
|
||||
m2DStrechMesh = Generate2DMesh(1.0f);
|
||||
return m2DStrechMesh;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// updates the uv of a mesh generated with Generate2DMesh
|
||||
/// </summary>
|
||||
/// <param name="m"></param>
|
||||
/// <param name="maxV"></param>
|
||||
public static void Update2DMeshUv(Mesh m,float maxV)
|
||||
{
|
||||
Vector2[] uv = m.uv;
|
||||
uv[4] = uv[0] = new Vector2(0f, 0f);
|
||||
uv[5] = uv[1] = new Vector2(1f, 0f);
|
||||
uv[6] = uv[2] = new Vector2(1f, maxV);
|
||||
uv[7] = uv[3] = new Vector2(0f, maxV);
|
||||
m.uv = uv;
|
||||
}
|
||||
/// <summary>
|
||||
/// generates a 2d bar mesh with the specified maximum V coord. (used with trim material fit)
|
||||
/// </summary>
|
||||
/// <param name="maxV"></param>
|
||||
/// <returns></returns>
|
||||
public static Mesh Generate2DMesh(float maxV)
|
||||
{
|
||||
Vector3[] vertices = new Vector3[8];
|
||||
Vector2[] uv = new Vector2[8];
|
||||
int[] tringles = new int[12];
|
||||
|
||||
vertices[4] = vertices[0] = new Vector3(-0.5f, 0f, 0f);
|
||||
vertices[5] = vertices[1] = new Vector3(0.5f, 0f, 0f);
|
||||
vertices[6] = vertices[2] = new Vector3(0.5f, 1f, 0f);
|
||||
vertices[7] = vertices[3] = new Vector3(-0.5f, 1f, 0f);
|
||||
|
||||
uv[4] = uv[0] = new Vector2(0f, 0f);
|
||||
uv[5] = uv[1] = new Vector2(1f, 0f);
|
||||
uv[6] = uv[2] = new Vector2(1f, maxV);
|
||||
uv[7] = uv[3] = new Vector2(0f, maxV);
|
||||
|
||||
WriteRect(tringles, 0, 1, 2, 0, 3, false);
|
||||
WriteRect(tringles, 2, 5, 6, 4, 7, true);
|
||||
|
||||
Mesh mesh = new Mesh();
|
||||
mesh.hideFlags = HideFlags.DontSave;
|
||||
mesh.vertices = vertices;
|
||||
mesh.uv = uv;
|
||||
mesh.triangles = tringles;
|
||||
mesh.RecalculateNormals();
|
||||
return mesh;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// writes a single rectangle to the tringles array
|
||||
/// </summary>
|
||||
/// <param name="tringles"></param>
|
||||
/// <param name="tringleIndex">this value is multiplied by 3 in order to find the real array index</param>
|
||||
/// <param name="a"> index of the first vertex</param>
|
||||
/// <param name="b"> index of the second vertex</param>
|
||||
/// <param name="c"> index of the third vertex</param>
|
||||
/// <param name="d"> index of the forth vertex</param>
|
||||
static void WriteRect(int[] tringles,int tringleIndex,int a,int b,int c,int d,bool flip)
|
||||
{
|
||||
if (flip)
|
||||
{
|
||||
WriteTringle(tringles, tringleIndex++, a, b, c);
|
||||
WriteTringle(tringles, tringleIndex, d, c, b);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteTringle(tringles, tringleIndex++, c, b, a);
|
||||
WriteTringle(tringles, tringleIndex, b, c, d);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// writes a single tringle to the tringle array
|
||||
/// </summary>
|
||||
/// <param name="tringles"></param>
|
||||
/// <param name="tringleIndex">this value is multiplied by 3 in order to find the real array index</param>
|
||||
/// <param name="a">index of the first vertex</param>
|
||||
/// <param name="b">index of the second vertex</param>
|
||||
/// <param name="c">index of the third vertex</param>
|
||||
static void WriteTringle(int[] tringles,int tringleIndex,int a,int b,int c)
|
||||
{
|
||||
int index = tringleIndex*3;
|
||||
tringles[index++] = a;
|
||||
tringles[index++] = b;
|
||||
tringles[index++] = c;
|
||||
}
|
||||
private static Mesh m3DStretchMesh;
|
||||
|
||||
/// <summary>
|
||||
/// A lazy loaded 3d stretch mesh. This mesh is always the same
|
||||
/// </summary>
|
||||
public static Mesh StrechMesh3D
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m3DStretchMesh == null)
|
||||
m3DStretchMesh = Generate3DMesh(1.0f);
|
||||
return m3DStretchMesh;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// updates the uv of a mesh created with Generate3DMesh
|
||||
/// </summary>
|
||||
/// <param name="m"></param>
|
||||
/// <param name="maxV"></param>
|
||||
public static void Update3DMeshUv(Mesh m, float maxV)
|
||||
{
|
||||
Vector2[] uv = m.uv;
|
||||
uv[0] = new Vector2(0f, 0f);
|
||||
uv[1] = new Vector2(1f, 0f);
|
||||
uv[2] = new Vector2(1f, maxV);
|
||||
uv[3] = new Vector2(0f, maxV);
|
||||
|
||||
uv[4] = new Vector2(1f, 0f);
|
||||
uv[5] = new Vector2(0f, 0f);
|
||||
uv[6] = new Vector2(0f, maxV);
|
||||
uv[7] = new Vector2(1f, maxV);
|
||||
|
||||
uv[8] = new Vector2(0f, 0f);
|
||||
uv[9] = new Vector2(1f, 0f);
|
||||
uv[10] = new Vector2(1f, 1f);
|
||||
uv[11] = new Vector2(0f, 1f);
|
||||
|
||||
uv[12] = new Vector2(1f, 0f);
|
||||
uv[13] = new Vector2(0f, 0f);
|
||||
uv[14] = new Vector2(0f, 1f);
|
||||
uv[15] = new Vector2(1f, 1f); m.uv = uv;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// generates a 3d bar mesh with the specified maximum V coord. (used with trim material fit)
|
||||
/// </summary>
|
||||
/// <param name="maxV"></param>
|
||||
/// <returns></returns>
|
||||
public static Mesh Generate3DMesh(float maxV)
|
||||
{
|
||||
Vector3[] vertices = new Vector3[16];
|
||||
Vector2[] uv = new Vector2[16];
|
||||
int[] tringles = new int[36];
|
||||
|
||||
vertices[0] = new Vector3(-0.5f, 0f, -0.5f);
|
||||
vertices[1] = new Vector3(0.5f, 0f, -0.5f);
|
||||
vertices[2] = new Vector3(0.5f, 1f, -0.5f);
|
||||
vertices[3] = new Vector3(-0.5f, 1f, -0.5f);
|
||||
|
||||
vertices[4] = new Vector3(-0.5f, 0f, 0.5f);
|
||||
vertices[5] = new Vector3(0.5f, 0f, 0.5f);
|
||||
vertices[6] = new Vector3(0.5f, 1f, 0.5f);
|
||||
vertices[7] = new Vector3(-0.5f, 1f, 0.5f);
|
||||
|
||||
vertices[8] = new Vector3(-0.5f, 0f, -0.5f);
|
||||
vertices[9] = new Vector3(0.5f, 0f, -0.5f);
|
||||
vertices[10] = new Vector3(0.5f, 1f, -0.5f);
|
||||
vertices[11] = new Vector3(-0.5f, 1f, -0.5f);
|
||||
|
||||
vertices[12] = new Vector3(-0.5f, 0f, 0.5f);
|
||||
vertices[13] = new Vector3(0.5f, 0f, 0.5f);
|
||||
vertices[14] = new Vector3(0.5f, 1f, 0.5f);
|
||||
vertices[15] = new Vector3(-0.5f, 1f, 0.5f);
|
||||
|
||||
uv[0] = new Vector2(0f, 0f);
|
||||
uv[1] = new Vector2(1f, 0f);
|
||||
uv[2] = new Vector2(1f, maxV);
|
||||
uv[3] = new Vector2(0f, maxV);
|
||||
|
||||
uv[4] = new Vector2(1f, 0f);
|
||||
uv[5] = new Vector2(0f, 0f);
|
||||
uv[6] = new Vector2(0f, maxV);
|
||||
uv[7] = new Vector2(1f, maxV);
|
||||
|
||||
uv[8] = new Vector2(0f, 0f);
|
||||
uv[9] = new Vector2(1f, 0f);
|
||||
uv[10] = new Vector2(1f, 1f);
|
||||
uv[11] = new Vector2(0f, 1f);
|
||||
|
||||
uv[12] = new Vector2(1f, 0f);
|
||||
uv[13] = new Vector2(0f, 0f);
|
||||
uv[14] = new Vector2(0f, 1f);
|
||||
uv[15] = new Vector2(1f, 1f);
|
||||
|
||||
WriteRect(tringles, 0, 1, 2, 0, 3, false);
|
||||
WriteRect(tringles, 2, 5, 6, 4, 7, true);
|
||||
|
||||
WriteRect(tringles, 4, 8, 9, 12, 13, true);
|
||||
WriteRect(tringles, 6, 10, 11, 14, 15, true);
|
||||
|
||||
WriteRect(tringles, 8, 6, 5, 2, 1, true);
|
||||
WriteRect(tringles, 10, 7, 4, 3, 0, false);
|
||||
|
||||
Mesh mesh = new Mesh();
|
||||
mesh.hideFlags = HideFlags.DontSave;
|
||||
mesh.vertices = vertices;
|
||||
mesh.uv = uv;
|
||||
mesh.triangles = tringles;
|
||||
mesh.RecalculateNormals();
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Script/BarChart/BarMesh2D.cs.meta
Normal file
12
Assets/Chart And Graph/Script/BarChart/BarMesh2D.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78e63bbfee62a1f4db007c2147bd8177
|
||||
timeCreated: 1472893291
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Chart And Graph/Script/BarChart/BarMesh3D.cs
Normal file
17
Assets/Chart And Graph/Script/BarChart/BarMesh3D.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using UnityEngine;
|
||||
|
||||
//namespace ChartAndGraph
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// This class contains functionallity for generating 3d and 2d bar meshes
|
||||
// /// </summary
|
||||
// partial class BarMesh
|
||||
// {
|
||||
|
||||
// }
|
||||
//}
|
||||
12
Assets/Chart And Graph/Script/BarChart/BarMesh3D.cs.meta
Normal file
12
Assets/Chart And Graph/Script/BarChart/BarMesh3D.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2901fb0eecf53045ae83755f482ad62
|
||||
timeCreated: 1560535998
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
106
Assets/Chart And Graph/Script/BarChart/BarMeshGenerator.cs
Normal file
106
Assets/Chart And Graph/Script/BarChart/BarMeshGenerator.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
[RequireComponent(typeof(MeshRenderer))]
|
||||
[RequireComponent(typeof(MeshFilter))]
|
||||
class BarMeshGenerator : BarGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the dimention of the generated mesh. can be either 2d or 3d
|
||||
/// </summary>
|
||||
public MeshDimention MeshDimention = MeshDimention._2D;
|
||||
/// <summary>
|
||||
/// Sets the way materials are fit to the bar mesh
|
||||
/// </summary>
|
||||
public BarMaterialFit MaterialFit = BarMaterialFit.Stretch;
|
||||
/// <summary>
|
||||
/// Contains a mesh that was generate for this object only and should be destoryed once the object is cleaned
|
||||
/// </summary>
|
||||
Mesh mCleanMesh = null;
|
||||
/// <summary>
|
||||
/// the mesh filter for this object
|
||||
/// </summary>
|
||||
MeshFilter mFilter;
|
||||
|
||||
MeshDimention mCurrentDimention;
|
||||
BarMaterialFit mCurrentMaterialFit;
|
||||
|
||||
private bool EnsureMeshFilter()
|
||||
{
|
||||
if (mFilter == null)
|
||||
mFilter = GetComponent<MeshFilter>();
|
||||
if (mFilter == null)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="rect"></param>
|
||||
/// <param name="normalizedSize"></param>
|
||||
public override void Generate(float normalizedSize,float scale)
|
||||
{
|
||||
if (EnsureMeshFilter() == false) // No mesh filter attached
|
||||
return;
|
||||
|
||||
if(mFilter.sharedMesh != null)
|
||||
{
|
||||
if(MaterialFit == BarMaterialFit.Trim && mCurrentMaterialFit == BarMaterialFit.Trim)
|
||||
{
|
||||
if(MeshDimention == mCurrentDimention)
|
||||
{
|
||||
if (MeshDimention == ChartAndGraph.MeshDimention._2D)
|
||||
BarMesh.Update2DMeshUv(mFilter.sharedMesh, normalizedSize);
|
||||
else
|
||||
BarMesh.Update3DMeshUv(mFilter.sharedMesh, normalizedSize);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
mCurrentDimention = MeshDimention;
|
||||
mCurrentMaterialFit = MaterialFit;
|
||||
if(MaterialFit == BarMaterialFit.Stretch)
|
||||
{
|
||||
if (MeshDimention == ChartAndGraph.MeshDimention._2D)
|
||||
mFilter.sharedMesh = BarMesh.StrechMesh2D;
|
||||
else
|
||||
mFilter.sharedMesh = BarMesh.StrechMesh3D;
|
||||
ChartCommon.CleanMesh(null, ref mCleanMesh);
|
||||
return;
|
||||
}
|
||||
|
||||
if (MaterialFit == BarMaterialFit.Trim)
|
||||
{
|
||||
Mesh newMesh = null;
|
||||
if (MeshDimention == ChartAndGraph.MeshDimention._2D)
|
||||
newMesh = BarMesh.Generate2DMesh(normalizedSize);
|
||||
else
|
||||
newMesh = BarMesh.Generate3DMesh(normalizedSize);
|
||||
mFilter.sharedMesh = newMesh;
|
||||
ChartCommon.CleanMesh(newMesh, ref mCleanMesh);
|
||||
}
|
||||
else
|
||||
return; // should not happen ever
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public override void Clear()
|
||||
{
|
||||
ChartCommon.CleanMesh(null, ref mCleanMesh);
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bff5a247b0442474daa4fc07d33bdeab
|
||||
timeCreated: 1472816163
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
349
Assets/Chart And Graph/Script/BarChart/CanvasBarChart.cs
Normal file
349
Assets/Chart And Graph/Script/BarChart/CanvasBarChart.cs
Normal file
@@ -0,0 +1,349 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
public class CanvasBarChart : BarChart, ICanvas
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The seperation between the axis and the chart bars.
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
private bool fitToContainer = false;
|
||||
public bool FitToContainer
|
||||
{
|
||||
get { return fitToContainer; }
|
||||
set
|
||||
{
|
||||
fitToContainer = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private ChartMagin fitMargin;
|
||||
public ChartMagin FitMargin
|
||||
{
|
||||
get { return fitMargin; }
|
||||
set
|
||||
{
|
||||
fitMargin = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
protected override ChartMagin MarginLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return fitMargin;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
/// <summary>
|
||||
/// prefab for the bar elements of the chart. must be the size of one unit with a pivot at the middle bottom
|
||||
/// </summary>
|
||||
[Tooltip("Prefab for the bar elements of the chart. must be the size of one unit with a pivot at the middle bottom")]
|
||||
private CanvasRenderer barPrefab;
|
||||
|
||||
/// <summary>
|
||||
/// prefab for the bar elements of the chart. must be the size of one unit with a pivot at the middle bottom
|
||||
/// </summary>
|
||||
public CanvasRenderer BarPrefab
|
||||
{
|
||||
get { return barPrefab; }
|
||||
set
|
||||
{
|
||||
barPrefab = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsCanvas
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The seperation between the axis and the chart bars.
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
[Tooltip("The seperation between the axis and the chart bars")]
|
||||
private float axisSeperation = 20f;
|
||||
protected override float TotalDepthLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The seperation between the axis and the chart bars.
|
||||
/// </summary>
|
||||
public float AxisSeperation
|
||||
{
|
||||
get { return axisSeperation; }
|
||||
set
|
||||
{
|
||||
axisSeperation = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// seperation between bar of the same group
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
[Tooltip("seperation between bar of the same group")]
|
||||
private float barSeperation = 45f;
|
||||
|
||||
/// <summary>
|
||||
/// seperation between bars of the same group.
|
||||
/// </summary>
|
||||
public float BarSeperation
|
||||
{
|
||||
get { return barSeperation; }
|
||||
set
|
||||
{
|
||||
barSeperation = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// seperation between bar groups
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
[Tooltip("seperation between bar groups")]
|
||||
private float groupSeperation = 220f;
|
||||
|
||||
/// <summary>
|
||||
/// The seperation between bar groups.
|
||||
/// <summary>
|
||||
public float GroupSeperation
|
||||
{
|
||||
get { return groupSeperation; }
|
||||
set
|
||||
{
|
||||
groupSeperation = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
public override bool SupportRealtimeGeneration
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// the width of each bar in the chart
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
[Tooltip("the width of each bar in the chart")]
|
||||
private float barSize = 20f;
|
||||
|
||||
/// <summary>
|
||||
/// the width of each bar in the chart
|
||||
/// </summary>
|
||||
public float BarSize
|
||||
{
|
||||
get { return barSize; }
|
||||
set
|
||||
{
|
||||
barSize = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
protected override ChartOrientedSize AxisSeperationLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ChartOrientedSize(AxisSeperation);
|
||||
}
|
||||
}
|
||||
|
||||
protected override ChartOrientedSize BarSeperationLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ChartOrientedSize(BarSeperation);
|
||||
}
|
||||
}
|
||||
|
||||
protected override ChartOrientedSize GroupSeperationLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ChartOrientedSize(GroupSeperation);
|
||||
}
|
||||
}
|
||||
|
||||
protected override ChartOrientedSize BarSizeLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ChartOrientedSize(BarSize);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetBarSize(GameObject bar, Vector3 size,float elevation)
|
||||
{
|
||||
RectTransform rect = bar.GetComponent<RectTransform>();
|
||||
|
||||
if (rect != null)
|
||||
{
|
||||
float ySize = size.y;
|
||||
float yAnchor = 0f;
|
||||
if (ySize < 0)
|
||||
{
|
||||
ySize = -ySize;
|
||||
yAnchor = 1;
|
||||
}
|
||||
rect.pivot = new Vector2(0.5f, yAnchor);
|
||||
rect.sizeDelta = new Vector2(size.x, ySize);
|
||||
Vector2 v = rect.localPosition;
|
||||
v.y = elevation;
|
||||
rect.localPosition = v;
|
||||
}
|
||||
else
|
||||
base.SetBarSize(bar, size,elevation);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
}
|
||||
//protected override Vector3 CanvasFitOffset
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return new Vector3();
|
||||
// }
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
///
|
||||
[SerializeField]
|
||||
[Tooltip("")]
|
||||
private FitOrientation barFitDirection = FitOrientation.Normal;
|
||||
|
||||
/// <summary>
|
||||
/// the width of each bar in the chart
|
||||
/// </summary
|
||||
public FitOrientation BarFitDirection
|
||||
{
|
||||
get { return barFitDirection; }
|
||||
set
|
||||
{
|
||||
barFitDirection = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("")]
|
||||
private FitType barFitType = FitType.Aspect;
|
||||
|
||||
/// <summary>
|
||||
/// the width of each bar in the chart
|
||||
/// </summary
|
||||
public FitType BarFitType
|
||||
{
|
||||
get { return barFitType; }
|
||||
set
|
||||
{
|
||||
barFitType = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
[Tooltip("")]
|
||||
private FitAlign barFitAlign = FitAlign.CenterXCenterY;
|
||||
|
||||
/// <summary>
|
||||
/// the width of each bar in the chart
|
||||
/// </summary
|
||||
public FitAlign BarFitAlign
|
||||
{
|
||||
get { return barFitAlign; }
|
||||
set
|
||||
{
|
||||
barFitAlign = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
protected override float FitZRotationCanvas
|
||||
{
|
||||
get { return (barFitDirection == FitOrientation.Vertical) ? -90 :(barFitDirection == FitOrientation.VerticalOpopsite ? 90 : 0); }
|
||||
}
|
||||
|
||||
protected override FitType FitAspectCanvas { get { return BarFitType; } }
|
||||
protected override FitAlign FitAlignCanvas { get { return BarFitAlign; } }
|
||||
[ContextMenu("Refresh chart")]
|
||||
public override void InternalGenerateChart()
|
||||
{
|
||||
RectTransform trans = GetComponent<RectTransform>();
|
||||
|
||||
if (FitToContainer)
|
||||
{
|
||||
if (barFitDirection == FitOrientation.Normal)
|
||||
{
|
||||
float width = MessureWidth();
|
||||
heightRatio = width * (trans.rect.size.y / trans.rect.size.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
float width = MessureWidth();
|
||||
heightRatio = width * (trans.rect.size.x / trans.rect.size.y);
|
||||
}
|
||||
}
|
||||
|
||||
base.InternalGenerateChart();
|
||||
//if (TextController != null && TextController.gameObject)
|
||||
// TextController.gameObject.transform.SetAsLastSibling();
|
||||
//float widthScale = trans.rect.size.x / TotalWidth;
|
||||
//float heightScale = trans.rect.size.y / HeightRatio;
|
||||
//GameObject fixPosition = new GameObject();
|
||||
//ChartCommon.HideObject(fixPosition, hideHierarchy);
|
||||
//fixPosition.AddComponent<ChartItem>();
|
||||
//fixPosition.transform.position = transform.position;
|
||||
//while (gameObject.transform.childCount > 0)
|
||||
// transform.GetChild(0).SetParent(fixPosition.transform, false);
|
||||
//fixPosition.transform.SetParent(transform, false);
|
||||
//fixPosition.transform.localScale = new Vector3(1f, 1f, 1f);
|
||||
//float uniformScale = Math.Min(widthScale, heightScale);
|
||||
//fixPosition.transform.localScale = new Vector3(uniformScale, uniformScale, uniformScale);
|
||||
//fixPosition.transform.localPosition = new Vector3(-TotalWidth * uniformScale * 0.5f, -HeightRatio * uniformScale * 0.5f, 0f);
|
||||
}
|
||||
|
||||
protected override GameObject BarPrefabLink
|
||||
{
|
||||
get
|
||||
{
|
||||
if (BarPrefab == null)
|
||||
return null;
|
||||
return BarPrefab.gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: acb1d1c592b0c794d8bff6d0a590986e
|
||||
timeCreated: 1478565292
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Chart And Graph/Script/BarChart/IBarGenerator.cs
Normal file
14
Assets/Chart And Graph/Script/BarChart/IBarGenerator.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
public interface IBarGenerator
|
||||
{
|
||||
void Generate(float normalizedSize,float scale);
|
||||
void Clear();
|
||||
}
|
||||
}
|
||||
12
Assets/Chart And Graph/Script/BarChart/IBarGenerator.cs.meta
Normal file
12
Assets/Chart And Graph/Script/BarChart/IBarGenerator.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 890470d3be0138e408ab56d25c63b82f
|
||||
timeCreated: 1499880160
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
234
Assets/Chart And Graph/Script/BarChart/WorldSpaceBarChart.cs
Normal file
234
Assets/Chart And Graph/Script/BarChart/WorldSpaceBarChart.cs
Normal file
@@ -0,0 +1,234 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using ChartAndGraph.Axis;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ChartAndGraph
|
||||
{
|
||||
public class WorldSpaceBarChart : BarChart
|
||||
{
|
||||
/// <summary>
|
||||
/// If this value is set all the text in the chart will be rendered to this specific camera. otherwise text is rendered to the main camera
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
[Tooltip("If this value is set all the text in the chart will be rendered to this specific camera. otherwise text is rendered to the main camera")]
|
||||
private Camera textCamera;
|
||||
|
||||
/// <summary>
|
||||
/// If this value is set all the text in the chart will be rendered to this specific camera. otherwise text is rendered to the main camera
|
||||
/// </summary>
|
||||
public Camera TextCamera
|
||||
{
|
||||
get { return textCamera; }
|
||||
set
|
||||
{
|
||||
textCamera = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsCanvas
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The distance from the camera at which the text is at it's original size.
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
[Tooltip("The distance from the camera at which the text is at it's original size")]
|
||||
private float textIdleDistance = 20f;
|
||||
|
||||
/// <summary>
|
||||
/// The distance from the camera at which the text is at it's original size.
|
||||
/// </summary>
|
||||
public float TextIdleDistance
|
||||
{
|
||||
get { return textIdleDistance; }
|
||||
set
|
||||
{
|
||||
textIdleDistance = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// prefab for all the bar elements of the chart. must be one unit size and with a bottom middle pivot
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
[Tooltip("prefab for all the bar elements of the chart. must be one unit size and with a bottom middle pivot")]
|
||||
private GameObject barPrefab;
|
||||
|
||||
/// <summary>
|
||||
/// prefab for all the bar elements of the chart. must be one unit size and with a bottom middle pivot
|
||||
/// </summary>
|
||||
public GameObject BarPrefab
|
||||
{
|
||||
get
|
||||
{
|
||||
return barPrefab;
|
||||
}
|
||||
set
|
||||
{
|
||||
barPrefab = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The seperation between the axis and the chart bars.
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
[Tooltip("The seperation between the axis and the chart bars")]
|
||||
private ChartOrientedSize AxisSeperation = new ChartOrientedSize();
|
||||
|
||||
/// <summary>
|
||||
/// The seperation between the axis and the chart bars
|
||||
/// </summary>
|
||||
public ChartOrientedSize axisSeperation
|
||||
{
|
||||
get { return AxisSeperation; }
|
||||
set
|
||||
{
|
||||
AxisSeperation = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The seperation between bars of the same group.
|
||||
/// Use cases:
|
||||
/// 1. set the depth to 0 to make each group look more 2d.
|
||||
/// 2. set the breadth to 0 to make align the bars of each group along the z axis
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
[Tooltip("The seperation between bars of the same group")]
|
||||
private ChartOrientedSize barSeperation = new ChartOrientedSize();
|
||||
|
||||
/// <summary>
|
||||
/// The seperation between bars of the same group.
|
||||
/// Use cases:
|
||||
/// 1. set the depth to 0 to make each group look more 2d.
|
||||
/// 2. set the breadth to 0 to make align the bars of each group along the z axis
|
||||
/// </summary>
|
||||
public ChartOrientedSize BarSeperation
|
||||
{
|
||||
get { return barSeperation; }
|
||||
set
|
||||
{
|
||||
barSeperation = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The seperation between bar groups.
|
||||
/// Use cases:
|
||||
/// 1.set the depth to 0 for a more 2d look.
|
||||
/// 2.set the breadth to 0 to align the groups on the z axis
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
[Tooltip("seperation between bar groups")]
|
||||
private ChartOrientedSize groupSeperation = new ChartOrientedSize();
|
||||
|
||||
/// <summary>
|
||||
/// The seperation between bar groups.
|
||||
/// Use cases:
|
||||
/// 1.set the depth to 0 for a more 2d look.
|
||||
/// 2.set the breadth to 0 to align the groups on the z axis
|
||||
/// <summary>
|
||||
public ChartOrientedSize GroupSeperation
|
||||
{
|
||||
get { return groupSeperation; }
|
||||
set
|
||||
{
|
||||
groupSeperation = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// the size of each bar in the chart
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
[Tooltip("the size of each bar in the chart")]
|
||||
private ChartOrientedSize barSize = new ChartOrientedSize(1f, 1f);
|
||||
/// <summary>
|
||||
/// the size of each bar in the chart
|
||||
/// </summary>
|
||||
public ChartOrientedSize BarSize
|
||||
{
|
||||
get { return barSize; }
|
||||
set
|
||||
{
|
||||
barSize = value;
|
||||
OnPropertyUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
protected override ChartOrientedSize AxisSeperationLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return AxisSeperation;
|
||||
}
|
||||
}
|
||||
|
||||
protected override ChartOrientedSize BarSeperationLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return BarSeperation;
|
||||
}
|
||||
}
|
||||
protected override ChartOrientedSize GroupSeperationLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return GroupSeperation;
|
||||
}
|
||||
}
|
||||
protected override ChartOrientedSize BarSizeLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return BarSize;
|
||||
}
|
||||
}
|
||||
protected override Camera TextCameraLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return TextCamera;
|
||||
}
|
||||
}
|
||||
|
||||
protected override float TextIdleDistanceLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return TextIdleDistance;
|
||||
}
|
||||
}
|
||||
|
||||
protected override GameObject BarPrefabLink
|
||||
{
|
||||
get
|
||||
{
|
||||
return BarPrefab;
|
||||
}
|
||||
}
|
||||
protected override void ValidateProperties()
|
||||
{
|
||||
base.ValidateProperties();
|
||||
if (barSize.Breadth < 0f)
|
||||
barSize.Breadth = 0f;
|
||||
if (barSize.Depth < 0f)
|
||||
barSize.Depth = 0f;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82d167234d2aa7746a9618de50700879
|
||||
timeCreated: 1478712963
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
70
Assets/Chart And Graph/Script/BarChart/customBarSelection.cs
Normal file
70
Assets/Chart And Graph/Script/BarChart/customBarSelection.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using ChartAndGraph;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class customBarSelection : MonoBehaviour
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
try
|
||||
{
|
||||
//register with MasterBarRotation when started
|
||||
var master = GetComponentInParent<masterBarSelection>();
|
||||
if(master != null)
|
||||
master.Register(this);
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
try
|
||||
{
|
||||
//unregister when destroyed
|
||||
GetComponentInParent<masterBarSelection>().Unregister(this);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void ToogleSelection(string category, string group)
|
||||
{
|
||||
// get the bar info of the prefab
|
||||
var barInfo = GetComponent<BarInfo>();
|
||||
// check for a category match
|
||||
if (barInfo.Category != category)
|
||||
return;
|
||||
//check for a group match
|
||||
if (barInfo.Group != group)
|
||||
return;
|
||||
|
||||
// get the bar info of the prefab
|
||||
var control = GetComponent<ChartMaterialController>();
|
||||
control.Selected = !control.Selected;
|
||||
control.Refresh();
|
||||
}
|
||||
// when rotate is called . a check is performed to see if this bar is the bar that should be rotated
|
||||
public void SetSelection(string category, string group,bool selected)
|
||||
{
|
||||
// get the bar info of the prefab
|
||||
var barInfo = GetComponent<BarInfo>();
|
||||
// check for a category match
|
||||
if (barInfo.Category != category)
|
||||
return;
|
||||
//check for a group match
|
||||
if (barInfo.Group != group)
|
||||
return;
|
||||
|
||||
// get the bar info of the prefab
|
||||
var control = GetComponent<ChartMaterialController>();
|
||||
control.Selected = selected;
|
||||
control.Refresh();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 318aea3d62e67744686f7d54f7a0d448
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
36
Assets/Chart And Graph/Script/BarChart/masterBarSelection.cs
Normal file
36
Assets/Chart And Graph/Script/BarChart/masterBarSelection.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
#define Graph_And_Chart_PRO
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class masterBarSelection : MonoBehaviour
|
||||
{
|
||||
List<customBarSelection> mSelections = new List<customBarSelection>();
|
||||
|
||||
public void Register(customBarSelection sel)
|
||||
{
|
||||
mSelections.Add(sel);
|
||||
}
|
||||
|
||||
public void Unregister(customBarSelection sel)
|
||||
{
|
||||
mSelections.Remove(sel);
|
||||
}
|
||||
|
||||
public void ToogleBar(string category, string group)
|
||||
{
|
||||
foreach (customBarSelection s in mSelections)
|
||||
s.ToogleSelection(category, group);
|
||||
}
|
||||
public void SelectBar(string category, string group)
|
||||
{
|
||||
foreach(customBarSelection s in mSelections)
|
||||
s.SetSelection(category, group,true);
|
||||
}
|
||||
|
||||
public void DeselectBar(string category, string group)
|
||||
{
|
||||
foreach (customBarSelection s in mSelections)
|
||||
s.SetSelection(category, group, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97b157f297f96804bbf422855adfb335
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user