迭代UIManager代码
This commit is contained in:
parent
aadfa7e03b
commit
419ced920a
8
Unity/Assets/Plugins/Assisstant.meta
Normal file
8
Unity/Assets/Plugins/Assisstant.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ab28e96908a69045b2ca3acc5e89eeb
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1355
Unity/Assets/Plugins/Assisstant/UnityAssisstant.cs
Normal file
1355
Unity/Assets/Plugins/Assisstant/UnityAssisstant.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
Unity/Assets/Plugins/Assisstant/UnityAssisstant.cs.meta
Normal file
11
Unity/Assets/Plugins/Assisstant/UnityAssisstant.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb76c226ec86fbe4fba8fa9bf955539d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Unity/Assets/Plugins/UnityComponent.meta
Normal file
8
Unity/Assets/Plugins/UnityComponent.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e53e04f247eab0e4a86a053b9e2c1979
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
90
Unity/Assets/Plugins/UnityComponent/AnimationManager.cs
Normal file
90
Unity/Assets/Plugins/UnityComponent/AnimationManager.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class AnimationNode
|
||||
{
|
||||
public GameObject node;
|
||||
public Animation animation;
|
||||
public string clipName;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class AnimationGroup
|
||||
{
|
||||
public string groupKey;
|
||||
public List<AnimationNode> nodes = new List<AnimationNode>();
|
||||
}
|
||||
|
||||
public class AnimationManager : MonoBehaviour
|
||||
{
|
||||
public List<AnimationGroup> groups = new List<AnimationGroup>();
|
||||
ViTimeNode1 _showTimeNode = new ViTimeNode1();
|
||||
|
||||
public bool HasGroup(string groupKey)
|
||||
{
|
||||
var group = GetGroup(groupKey);
|
||||
return group != null;
|
||||
}
|
||||
|
||||
public AnimationGroup GetGroup(string groupKey)
|
||||
{
|
||||
return groups.Find(g => g.groupKey == groupKey);
|
||||
}
|
||||
|
||||
public void Play(string groupKey, bool force = false, ViTimeNode1.Callback callback = null)
|
||||
{
|
||||
_showTimeNode.Detach();
|
||||
var group = GetGroup(groupKey);
|
||||
if (group == null) return;
|
||||
float animationTime = 0;
|
||||
foreach (AnimationNode node in group.nodes)
|
||||
{
|
||||
Animation animationComp = node.animation;
|
||||
string clipName = node.clipName;
|
||||
if (animationComp && !string.IsNullOrEmpty(clipName))
|
||||
{
|
||||
animationTime = Math.Max(animationComp[clipName].length, animationTime);
|
||||
if (force)
|
||||
{
|
||||
animationComp.Stop();
|
||||
animationComp[clipName].time = 0f;
|
||||
animationComp[clipName].enabled = true;
|
||||
animationComp[clipName].weight = 1f;
|
||||
animationComp.Sample();
|
||||
animationComp[clipName].enabled = false;
|
||||
}
|
||||
animationComp.Play(clipName);
|
||||
}
|
||||
}
|
||||
|
||||
if (callback != null)
|
||||
{
|
||||
ViTimerInstance.SetTime(_showTimeNode, animationTime, callback);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTime(string groupKey, float time)
|
||||
{
|
||||
var group = GetGroup(groupKey);
|
||||
if (group == null) return;
|
||||
foreach (var node in group.nodes)
|
||||
{
|
||||
if (node.animation && !string.IsNullOrEmpty(node.clipName))
|
||||
{
|
||||
node.animation.Stop();
|
||||
node.animation[node.clipName].time = node.animation[node.clipName].length * time;
|
||||
node.animation[node.clipName].enabled = true;
|
||||
node.animation[node.clipName].weight = 1f;
|
||||
node.animation.Sample();
|
||||
node.animation[node.clipName].enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_showTimeNode.Detach();
|
||||
}
|
||||
}
|
||||
11
Unity/Assets/Plugins/UnityComponent/AnimationManager.cs.meta
Normal file
11
Unity/Assets/Plugins/UnityComponent/AnimationManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40c51ec8b0614912b900012e95175f44
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
113
Unity/Assets/Plugins/UnityComponent/UIAutoBindRuleHelper.cs
Normal file
113
Unity/Assets/Plugins/UnityComponent/UIAutoBindRuleHelper.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
public class UIAutoBindRuleHelper
|
||||
{
|
||||
//如果新类型的插件/新的类型简称在此添加 生成注入代码
|
||||
public enum AutoBindType
|
||||
{
|
||||
None = 0,
|
||||
GameObject = 1,
|
||||
Transform = 2,
|
||||
Image = 3,
|
||||
Button = 4,
|
||||
RectTransform = 5,
|
||||
Toggle = 6,
|
||||
Text = 7,
|
||||
Slider = 8,
|
||||
Animation = 9,
|
||||
Animator = 10,
|
||||
RawImage = 11,
|
||||
ScrollRect = 12,
|
||||
Input = 13
|
||||
}
|
||||
|
||||
public static readonly Dictionary<AutoBindType, Type> TypeDict = new()
|
||||
{
|
||||
{AutoBindType.None, typeof(GameObject)},
|
||||
{AutoBindType.GameObject, typeof(GameObject)},
|
||||
{AutoBindType.Transform, typeof(Transform)},
|
||||
{AutoBindType.Image, typeof(Image)},
|
||||
{AutoBindType.Button, typeof(Button)},
|
||||
{AutoBindType.RectTransform, typeof(RectTransform)},
|
||||
{AutoBindType.Toggle, typeof(Toggle)},
|
||||
{AutoBindType.Text, typeof(Text)},
|
||||
{AutoBindType.Slider, typeof(Slider)},
|
||||
{AutoBindType.Animation, typeof(Animation)},
|
||||
{AutoBindType.Animator, typeof(Animator)},
|
||||
{AutoBindType.RawImage, typeof(RawImage)},
|
||||
{AutoBindType.ScrollRect, typeof(ScrollRect)},
|
||||
{AutoBindType.Input, typeof(InputField)}
|
||||
};
|
||||
|
||||
public static readonly Dictionary<AutoBindType, string> TypeToName = new()
|
||||
{
|
||||
{AutoBindType.None, "none"},
|
||||
{AutoBindType.GameObject, "go"},
|
||||
{AutoBindType.Transform, "tran"},
|
||||
{AutoBindType.Image, "img"},
|
||||
{AutoBindType.Button, "btn"},
|
||||
{AutoBindType.RectTransform, "rect"},
|
||||
{AutoBindType.Toggle, "tog"},
|
||||
{AutoBindType.Text, "text"},
|
||||
{AutoBindType.Slider, "sli"},
|
||||
{AutoBindType.Animation, "ani"},
|
||||
{AutoBindType.Animator, "anr"},
|
||||
{AutoBindType.RawImage, "raw"},
|
||||
{AutoBindType.ScrollRect, "scr"},
|
||||
{AutoBindType.Input, "input"}
|
||||
};
|
||||
|
||||
/*private static string GetOptionName(AutoBindType type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case AutoBindType.None:
|
||||
return "None";
|
||||
case AutoBindType.GameObject:
|
||||
return "GameObject";
|
||||
case AutoBindType.Transform:
|
||||
return "Transform";
|
||||
case AutoBindType.Image:
|
||||
return "Image";
|
||||
case AutoBindType.Button:
|
||||
return "Button";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}*/
|
||||
|
||||
// 动态生成下拉菜单选项
|
||||
public static string[] GeneratePopupOptions()
|
||||
{
|
||||
string[] options = new string[Enum.GetValues(typeof(AutoBindType)).Length];
|
||||
int index = 0;
|
||||
foreach (AutoBindType type in Enum.GetValues(typeof(AutoBindType)))
|
||||
{
|
||||
// options[index++] = GetOptionName(type);
|
||||
options[index++] = type.ToString();
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
public static string GetRuleTips()
|
||||
{
|
||||
StringBuilder content = new StringBuilder();
|
||||
foreach (AutoBindType type in Enum.GetValues(typeof(AutoBindType)))
|
||||
{
|
||||
if (type.ToString() == "None")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
content.Append(type.ToString());
|
||||
content.Append(" => ");
|
||||
content.Append(TypeToName[type]);
|
||||
content.Append("\n");
|
||||
}
|
||||
return content.ToString();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00be75d087df488f8aecbff52e61972a
|
||||
timeCreated: 1749732961
|
||||
189
Unity/Assets/Plugins/UnityComponent/UIWindowProperty.cs
Normal file
189
Unity/Assets/Plugins/UnityComponent/UIWindowProperty.cs
Normal file
@ -0,0 +1,189 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class UIWindowProperty : MonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
public struct NodeElement
|
||||
{
|
||||
public string Key;
|
||||
public GameObject Object;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct NodeElement2
|
||||
{
|
||||
public string Key;
|
||||
public List<GameObject> ObjectList;
|
||||
}
|
||||
|
||||
// public enum AutoBindType
|
||||
// {
|
||||
// GameObject = 0,
|
||||
// Transform = 1,
|
||||
// Btn = 2,
|
||||
// Image = 3
|
||||
// }
|
||||
|
||||
[System.Serializable]
|
||||
public struct NodeElementAuto
|
||||
{
|
||||
public string Key;
|
||||
public GameObject Object;
|
||||
public UIAutoBindRuleHelper.AutoBindType type;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct ValueElement
|
||||
{
|
||||
public string Key;
|
||||
public float Value;
|
||||
}
|
||||
|
||||
public List<NodeElementAuto> GameObjectList = new List<NodeElementAuto>();
|
||||
public List<NodeElement2> GameObjectList2 = new List<NodeElement2>();
|
||||
public List<NodeElementAuto> AutoGameObjectList = new List<NodeElementAuto>();
|
||||
//
|
||||
public List<ValueElement> ValueList = new List<ValueElement>();
|
||||
//
|
||||
public string ClassName;
|
||||
|
||||
public float GetValue(string key, float defaultValue)
|
||||
{
|
||||
for (int iter = 0; iter < ValueList.Count; ++iter)
|
||||
{
|
||||
ValueElement iterElement = ValueList[iter];
|
||||
if (string.Compare(iterElement.Key, key, true) == 0)
|
||||
{
|
||||
return iterElement.Value;
|
||||
}
|
||||
}
|
||||
//
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
public GameObject GetGameObject(string key)
|
||||
{
|
||||
return GetGameObject(key, true);
|
||||
}
|
||||
public GameObject GetGameObject(string key, bool logMessage)
|
||||
{
|
||||
for (int iter = 0; iter < GameObjectList.Count; ++iter)
|
||||
{
|
||||
NodeElementAuto iterElement = GameObjectList[iter];
|
||||
if (string.Compare(iterElement.Key, key, true) == 0)
|
||||
{
|
||||
return iterElement.Object;
|
||||
}
|
||||
}
|
||||
for (int iter = 0; iter < AutoGameObjectList.Count; ++iter)
|
||||
{
|
||||
NodeElementAuto iterElement = AutoGameObjectList[iter];
|
||||
if (string.Compare(iterElement.Key, key, true) == 0)
|
||||
{
|
||||
return iterElement.Object;
|
||||
}
|
||||
}
|
||||
if (logMessage)
|
||||
{
|
||||
ViDebuger.Error("WindowProperty[" + name + "].GameObject[" + key + "] not exist!");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public T GetComponent<T>(string key) where T : Component
|
||||
{
|
||||
return GetComponent<T>(key, true);
|
||||
}
|
||||
public T GetComponent<T>(string key, bool logMessage) where T : Component
|
||||
{
|
||||
GameObject obj = GetGameObject(key, logMessage);
|
||||
if (obj != null)
|
||||
{
|
||||
T component = obj.GetComponent<T>();
|
||||
if (System.Object.ReferenceEquals(component, null))
|
||||
{
|
||||
ViDebuger.Error("WindowProperty[" + name + "]." + typeof(T).Name + "[" + key + "] not exist!");
|
||||
}
|
||||
return component;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public T GetComponentInChildren<T>(string key) where T : Component
|
||||
{
|
||||
GameObject obj = GetGameObject(key);
|
||||
if (obj != null)
|
||||
{
|
||||
T component = obj.GetComponentInChildren<T>();
|
||||
if (System.Object.ReferenceEquals(component, null))
|
||||
{
|
||||
ViDebuger.Error("WindowProperty[" + name + "]." + typeof(T).Name + "[" + key + "] not exist!");
|
||||
}
|
||||
return component;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public T GetComponentInChildren<T>(string key, bool includeInactive) where T : Component
|
||||
{
|
||||
GameObject obj = GetGameObject(key);
|
||||
if (obj != null)
|
||||
{
|
||||
T component = obj.GetComponentInChildren<T>(includeInactive);
|
||||
if (System.Object.ReferenceEquals(component, null))
|
||||
{
|
||||
ViDebuger.Error("WindowProperty[" + name + "]." + typeof(T).Name + "[" + key + "] not exist!");
|
||||
}
|
||||
return component;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
public List<GameObject> GetGameObjectList(string key)
|
||||
{
|
||||
for (int iter = 0; iter < GameObjectList2.Count; ++iter)
|
||||
{
|
||||
NodeElement2 iterElement = GameObjectList2[iter];
|
||||
if (string.Compare(iterElement.Key, key, true) == 0)
|
||||
{
|
||||
return iterElement.ObjectList;
|
||||
}
|
||||
}
|
||||
ViDebuger.Error("WindowProperty[" + name + "].GameObjectList[" + key + "] not exist!");
|
||||
return null;
|
||||
}
|
||||
|
||||
public void GetComponentList<T>(string key, List<T> resultList) where T : Component
|
||||
{
|
||||
List<GameObject> objList = GetGameObjectList(key);
|
||||
if (objList != null)
|
||||
{
|
||||
for (int iter = 0; iter < objList.Count; ++iter)
|
||||
{
|
||||
GameObject iterObj = objList[iter];
|
||||
if (iterObj != null)
|
||||
{
|
||||
T component = iterObj.GetComponent<T>();
|
||||
if (System.Object.ReferenceEquals(component, null))
|
||||
{
|
||||
ViDebuger.Error("WindowProperty[" + name + "].GameObject[" + iterObj.name + "]." + typeof(T).Name + "[" + key + "] not exist!");
|
||||
}
|
||||
resultList.Add(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Unity/Assets/Plugins/UnityComponent/UIWindowProperty.cs.meta
Normal file
12
Unity/Assets/Plugins/UnityComponent/UIWindowProperty.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dba07edb0e077114b8d1d67f0a1eaadd
|
||||
timeCreated: 1516341188
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Unity/Assets/Plugins/ViSDK.meta
Normal file
8
Unity/Assets/Plugins/ViSDK.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce9be699e5f349447ae70ba4142353a8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Unity/Assets/Plugins/ViSDK/ViBaseStruct.meta
Normal file
9
Unity/Assets/Plugins/ViSDK/ViBaseStruct.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 685ef1f047e71b0448410af863bba6c4
|
||||
folderAsset: yes
|
||||
timeCreated: 1453717661
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViActiveValue.cs
Normal file
50
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViActiveValue.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
|
||||
public class ViActiveValue<T>
|
||||
where T : struct
|
||||
{
|
||||
public bool Active { get { return _active; } }
|
||||
public ViActiveValue(bool active, T value)
|
||||
{
|
||||
_active = active;
|
||||
_value = value;
|
||||
}
|
||||
public void Set(T value)
|
||||
{
|
||||
_value = value;
|
||||
_active = true;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_active = false;
|
||||
}
|
||||
|
||||
public bool GetValue(ref T value)
|
||||
{
|
||||
if (_active)
|
||||
{
|
||||
value = _value;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public T Value(T value)
|
||||
{
|
||||
if (_active)
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
bool _active;
|
||||
T _value;
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea6da385316aa1f43a3512d2ffae1ba4
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
84
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViConstValue.cs
Normal file
84
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViConstValue.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ViConstValue<T>
|
||||
{
|
||||
public ViConstValue(string key, T defaultValue)
|
||||
{
|
||||
_node.Data = defaultValue;
|
||||
ViConstValueList<T>.Attach(key, _node);
|
||||
}
|
||||
public static implicit operator T(ViConstValue<T> data)
|
||||
{
|
||||
return data.Value;
|
||||
}
|
||||
public T Value { get { return _node.Data; } }
|
||||
ViDoubleLinkNode2<T> _node = new ViDoubleLinkNode2<T>();
|
||||
}
|
||||
//
|
||||
internal class ValueList<T>
|
||||
{
|
||||
public T _value;
|
||||
public bool _init = false;
|
||||
public ViDoubleLink2<T> _list = new ViDoubleLink2<T>();
|
||||
}
|
||||
//
|
||||
public static class ViConstValueList<T>
|
||||
{
|
||||
public static void AddValue(string key, T value)
|
||||
{
|
||||
ValueList<T> list;
|
||||
if (_values.TryGetValue(key, out list))
|
||||
{
|
||||
list._value = value;
|
||||
list._init = true;
|
||||
list._list.SetValue(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
list = new ValueList<T>();
|
||||
list._value = value;
|
||||
list._init = true;
|
||||
list._list.SetValue(value);
|
||||
_values.Add(key, list);
|
||||
}
|
||||
}
|
||||
internal static void Attach(string key, ViDoubleLinkNode2<T> node)
|
||||
{
|
||||
ValueList<T> list;
|
||||
if (_values.TryGetValue(key, out list))
|
||||
{
|
||||
if (list._init)
|
||||
{
|
||||
node.Data = list._value;
|
||||
}
|
||||
list._list.PushBack(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
list = new ValueList<T>();
|
||||
list._list.PushBack(node);
|
||||
_values.Add(key, list);
|
||||
}
|
||||
}
|
||||
private static Dictionary<string, ValueList<T>> _values = new Dictionary<string, ValueList<T>>();
|
||||
}
|
||||
|
||||
public class Demo_ConstValue
|
||||
{
|
||||
#pragma warning disable 0219
|
||||
static ViConstValue<int> ScriptConstValue = new ViConstValue<int>("INT", 1);
|
||||
//
|
||||
static void Func()
|
||||
{
|
||||
int value = ScriptConstValue;
|
||||
}
|
||||
//
|
||||
public static void Test()
|
||||
{
|
||||
Func();
|
||||
ViConstValueList<int>.AddValue("INT", 100);
|
||||
Func();
|
||||
}
|
||||
#pragma warning restore 0219
|
||||
}
|
||||
12
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViConstValue.cs.meta
Normal file
12
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViConstValue.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9086ec33e32039478ddf7844398eed4
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
75
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViDictionaryScale.cs
Normal file
75
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViDictionaryScale.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ViDictionaryScale
|
||||
{
|
||||
public delegate void DeleUpdated(float oldValue, float newValue);
|
||||
public DeleUpdated UpdatedExec;
|
||||
|
||||
public float Value { get { return _value; } }
|
||||
public float DefaultValue
|
||||
{
|
||||
get { return _defaultValue; }
|
||||
set
|
||||
{
|
||||
_defaultValue = value;
|
||||
OnUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateNotify()
|
||||
{
|
||||
if (UpdatedExec != null)
|
||||
{
|
||||
float value = Value;
|
||||
UpdatedExec(value, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(string name, float value)
|
||||
{
|
||||
if (_scaleModList.ContainsKey(name))
|
||||
{
|
||||
_scaleModList[name] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
_scaleModList.Add(name, value);
|
||||
}
|
||||
//
|
||||
OnUpdate();
|
||||
}
|
||||
|
||||
public void Del(string name)
|
||||
{
|
||||
if (_scaleModList.ContainsKey(name))
|
||||
{
|
||||
_scaleModList.Remove(name);
|
||||
}
|
||||
//
|
||||
OnUpdate();
|
||||
}
|
||||
|
||||
void OnUpdate()
|
||||
{
|
||||
float oldValue = _value;
|
||||
//
|
||||
_value = DefaultValue;
|
||||
foreach (KeyValuePair<string, float> iter in _scaleModList)
|
||||
{
|
||||
_value += iter.Value;
|
||||
}
|
||||
//
|
||||
if (_value != oldValue)
|
||||
{
|
||||
if (UpdatedExec != null)
|
||||
{
|
||||
UpdatedExec(oldValue, _value);
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
float _value = 1.0f;
|
||||
float _defaultValue = 1.0f;
|
||||
Dictionary<string, float> _scaleModList = new Dictionary<string, float>();
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6f24e7d6d73f3b4fa04295bde2b6250
|
||||
timeCreated: 1512984724
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
250
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViDoubleLink1.cs
Normal file
250
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViDoubleLink1.cs
Normal file
@ -0,0 +1,250 @@
|
||||
using System;
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViDoubleLinkNode1<T>
|
||||
{
|
||||
public bool IsAttach()
|
||||
{
|
||||
return (_pre != null);
|
||||
}
|
||||
public void Detach()
|
||||
{
|
||||
if (_pre != null)
|
||||
{
|
||||
_pre._next = _next;
|
||||
_next._pre = _pre;
|
||||
_pre = null;
|
||||
_next = null;
|
||||
}
|
||||
}
|
||||
internal ViDoubleLinkNode1<T> _pre;
|
||||
internal ViDoubleLinkNode1<T> _next;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViDoubleLink1<T>
|
||||
{
|
||||
//+-----------------------------------------------------------------------------------------------------------------------------
|
||||
public static void Next(ref ViDoubleLinkNode1<T> node)
|
||||
{
|
||||
ViDebuger.AssertError(node != null && node._next != null);
|
||||
node = node._next;
|
||||
}
|
||||
public static void Pre(ref ViDoubleLinkNode1<T> node)
|
||||
{
|
||||
ViDebuger.AssertError(node != null && node._pre != null);
|
||||
node = node._pre;
|
||||
}
|
||||
public static void PushAfter(ViDoubleLinkNode1<T> before, ViDoubleLinkNode1<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
_PushAfter(before, node);
|
||||
}
|
||||
public static void PushBefore(ViDoubleLinkNode1<T> after, ViDoubleLinkNode1<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
_PushBefore(after, node);
|
||||
}
|
||||
public static void PushAfter(ViDoubleLinkNode1<T> before, ViDoubleLink1<T> list)
|
||||
{
|
||||
if (before.IsAttach() == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (list.IsEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_PushAfter(before, list);
|
||||
}
|
||||
public static void PushBefore(ViDoubleLinkNode1<T> after, ViDoubleLink1<T> list)
|
||||
{
|
||||
if (after.IsAttach() == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (list.IsEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_PushBefore(after, list);
|
||||
}
|
||||
//+-----------------------------------------------------------------------------------------------------------------------------
|
||||
public ViDoubleLink1()
|
||||
{
|
||||
_Init();
|
||||
}
|
||||
//+-----------------------------------------------------------------------------------------------------------------------------
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return _root._next == _root;
|
||||
}
|
||||
public bool IsNotEmpty()
|
||||
{
|
||||
return _root._next != _root;
|
||||
}
|
||||
public bool Contain(ViDoubleLinkNode1<T> node)
|
||||
{
|
||||
if (!node.IsAttach())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ViDoubleLinkNode1<T> next = _root._next;
|
||||
while (next != _root)
|
||||
{
|
||||
if (System.Object.ReferenceEquals(next, node))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
next = next._next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool IsEnd(ViDoubleLinkNode1<T> node)
|
||||
{
|
||||
return node == _root;
|
||||
}
|
||||
public ViDoubleLinkNode1<T> GetHead()
|
||||
{
|
||||
return _root._next;
|
||||
}
|
||||
public ViDoubleLinkNode1<T> GetTail()
|
||||
{
|
||||
return _root._pre;
|
||||
}
|
||||
//+-----------------------------------------------------------------------------------------------------------------------------
|
||||
public void PushBack(ViDoubleLinkNode1<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
_PushBefore(_root, node);
|
||||
}
|
||||
public void PushFront(ViDoubleLinkNode1<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
_PushAfter(_root, node);
|
||||
}
|
||||
public void PushBack(ViDoubleLink1<T> list)
|
||||
{
|
||||
_PushBefore(_root, list);
|
||||
}
|
||||
public void PushFront(ViDoubleLink1<T> list)
|
||||
{
|
||||
_PushAfter(_root, list);
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
ViDoubleLinkNode1<T> next = _root._next;
|
||||
while (next != _root)
|
||||
{
|
||||
ViDoubleLinkNode1<T> nextCopy = next._next;
|
||||
next._pre = null;
|
||||
next._next = null;
|
||||
next = nextCopy;
|
||||
}
|
||||
_Init();
|
||||
}
|
||||
//+-----------------------------------------------------------------------------------------------------------------------------
|
||||
static void _PushAfter(ViDoubleLinkNode1<T> before, ViDoubleLinkNode1<T> node)
|
||||
{
|
||||
ViDoubleLinkNode1<T> next = before._next;
|
||||
ViDebuger.AssertError(next);
|
||||
_Link(before, node);
|
||||
_Link(node, next);
|
||||
}
|
||||
static void _PushBefore(ViDoubleLinkNode1<T> after, ViDoubleLinkNode1<T> node)
|
||||
{
|
||||
ViDoubleLinkNode1<T> pre = after._pre;
|
||||
ViDebuger.AssertError(pre);
|
||||
_Link(pre, node);
|
||||
_Link(node, after);
|
||||
}
|
||||
static void _PushAfter(ViDoubleLinkNode1<T> before, ViDoubleLink1<T> list)
|
||||
{
|
||||
if (list.IsEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ViDoubleLinkNode1<T> first = list._root._next;
|
||||
ViDoubleLinkNode1<T> back = list._root._pre;
|
||||
ViDoubleLinkNode1<T> next = before._next;
|
||||
_Link(before, first);
|
||||
_Link(back, next);
|
||||
list._Init();
|
||||
}
|
||||
static void _PushBefore(ViDoubleLinkNode1<T> after, ViDoubleLink1<T> list)
|
||||
{
|
||||
if (list.IsEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ViDoubleLinkNode1<T> first = list._root._next;
|
||||
ViDoubleLinkNode1<T> back = list._root._pre;
|
||||
ViDoubleLinkNode1<T> pre = after._pre;
|
||||
_Link(pre, first);
|
||||
_Link(back, after);
|
||||
list._Init();
|
||||
}
|
||||
static void _Link(ViDoubleLinkNode1<T> pre, ViDoubleLinkNode1<T> next)
|
||||
{
|
||||
pre._next = next;
|
||||
next._pre = pre;
|
||||
}
|
||||
private void _Init()
|
||||
{
|
||||
_Link(_root, _root);
|
||||
}
|
||||
//+-----------------------------------------------------------------------------------------------------------------------------
|
||||
internal ViDoubleLinkNode1<T> _root = new ViDoubleLinkNode1<T>();
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class Demo_ViDoubleLink1
|
||||
{
|
||||
#pragma warning disable 0219
|
||||
public static void Test()
|
||||
{
|
||||
ViDoubleLink1<int> list = new ViDoubleLink1<int>();
|
||||
{
|
||||
ViDoubleLinkNode1<int> node1 = new ViDoubleLinkNode1<int>();
|
||||
ViDoubleLinkNode1<int> node2 = new ViDoubleLinkNode1<int>();
|
||||
list.PushBack(node1);
|
||||
list.PushBack(node2);
|
||||
|
||||
{///<正向迭代>
|
||||
ViDoubleLinkNode1<int> iter = list.GetHead();
|
||||
while (!list.IsEnd(iter))
|
||||
{
|
||||
ViDoubleLink1<int>.Next(ref iter);
|
||||
///<使用>
|
||||
///</使用>
|
||||
}
|
||||
}
|
||||
{///<正向迭代>
|
||||
for (ViDoubleLinkNode1<int> iter = list.GetHead(); !list.IsEnd(iter); ViDoubleLink1<int>.Next(ref iter))
|
||||
{
|
||||
///<使用>
|
||||
///</使用>
|
||||
}
|
||||
}
|
||||
{///<反向迭代>
|
||||
ViDoubleLinkNode1<int> iter = list.GetTail();
|
||||
while (!list.IsEnd(iter))
|
||||
{
|
||||
ViDoubleLink1<int>.Pre(ref iter);
|
||||
///<使用>
|
||||
///</使用>
|
||||
}
|
||||
}
|
||||
{///<反向迭代>
|
||||
for (ViDoubleLinkNode1<int> iter = list.GetTail(); !list.IsEnd(iter); ViDoubleLink1<int>.Pre(ref iter))
|
||||
{
|
||||
///<使用>
|
||||
///</使用>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore 0219
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e7dc700dd0de2a4d9d7c5e3544b7dde
|
||||
timeCreated: 1453717662
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
297
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViDoubleLink2.cs
Normal file
297
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViDoubleLink2.cs
Normal file
@ -0,0 +1,297 @@
|
||||
using System;
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViDoubleLinkNode2<T>
|
||||
{
|
||||
public ViDoubleLinkNode2()
|
||||
{
|
||||
|
||||
}
|
||||
public ViDoubleLinkNode2(T data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
public bool IsAttach()
|
||||
{
|
||||
return (_pre != null);
|
||||
}
|
||||
public void Detach()
|
||||
{
|
||||
if (_pre != null)
|
||||
{
|
||||
_pre._next = _next;
|
||||
_next._pre = _pre;
|
||||
_pre = null;
|
||||
_next = null;
|
||||
}
|
||||
}
|
||||
//
|
||||
public void DetachEx(T emptyData)
|
||||
{
|
||||
Detach();
|
||||
Data = emptyData;
|
||||
}
|
||||
//
|
||||
public T Data;
|
||||
//
|
||||
internal ViDoubleLinkNode2<T> _pre;
|
||||
internal ViDoubleLinkNode2<T> _next;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViDoubleLink2<T>
|
||||
{
|
||||
//+-----------------------------------------------------------------------------------------------------------------------------
|
||||
public static void Next(ref ViDoubleLinkNode2<T> node)
|
||||
{
|
||||
ViDebuger.AssertError(node != null && node._next != null);
|
||||
node = node._next;
|
||||
}
|
||||
public static void Pre(ref ViDoubleLinkNode2<T> node)
|
||||
{
|
||||
ViDebuger.AssertError(node != null && node._pre != null);
|
||||
node = node._pre;
|
||||
}
|
||||
public static void PushAfter(ViDoubleLinkNode2<T> before, ViDoubleLinkNode2<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
_PushAfter(before, node);
|
||||
}
|
||||
public static void PushBefore(ViDoubleLinkNode2<T> after, ViDoubleLinkNode2<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
_PushBefore(after, node);
|
||||
}
|
||||
public static void PushAfter(ViDoubleLinkNode2<T> before, ViDoubleLink2<T> list)
|
||||
{
|
||||
if (before.IsAttach() == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (list.IsEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_PushAfter(before, list);
|
||||
}
|
||||
public static void PushBefore(ViDoubleLinkNode2<T> after, ViDoubleLink2<T> list)
|
||||
{
|
||||
if (after.IsAttach() == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (list.IsEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_PushBefore(after, list);
|
||||
}
|
||||
//+-----------------------------------------------------------------------------------------------------------------------------
|
||||
public ViDoubleLink2()
|
||||
{
|
||||
_Init();
|
||||
}
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return _root._next == _root;
|
||||
}
|
||||
public bool IsNotEmpty()
|
||||
{
|
||||
return _root._next != _root;
|
||||
}
|
||||
public bool Contain(ViDoubleLinkNode2<T> node)
|
||||
{
|
||||
if (!node.IsAttach())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ViDoubleLinkNode2<T> next = _root._next;
|
||||
while (next != _root)
|
||||
{
|
||||
if (System.Object.ReferenceEquals(next, node))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
next = next._next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool IsEnd(ViDoubleLinkNode2<T> node)
|
||||
{
|
||||
return node == _root;
|
||||
}
|
||||
public ViDoubleLinkNode2<T> GetHead()
|
||||
{
|
||||
return _root._next;
|
||||
}
|
||||
public ViDoubleLinkNode2<T> GetTail()
|
||||
{
|
||||
return _root._pre;
|
||||
}
|
||||
public void PushBack(ViDoubleLinkNode2<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
_PushBefore(_root, node);
|
||||
}
|
||||
public void PushBackEx(ViDoubleLinkNode2<T> node, T data)
|
||||
{
|
||||
node.Detach();
|
||||
node.Data = data;
|
||||
_PushBefore(_root, node);
|
||||
}
|
||||
public void PushFront(ViDoubleLinkNode2<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
_PushAfter(_root, node);
|
||||
}
|
||||
public void PushBack(ViDoubleLink2<T> list)
|
||||
{
|
||||
_PushBefore(_root, list);
|
||||
}
|
||||
public void PushFront(ViDoubleLink2<T> list)
|
||||
{
|
||||
_PushAfter(_root, list);
|
||||
}
|
||||
public void SetValue(T value)
|
||||
{
|
||||
ViDoubleLinkNode2<T> next = _root._next;
|
||||
while (next != _root)
|
||||
{
|
||||
next.Data = value;
|
||||
next = next._next;
|
||||
}
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
ViDoubleLinkNode2<T> next = _root._next;
|
||||
while (next != _root)
|
||||
{
|
||||
ViDoubleLinkNode2<T> nextCopy = next._next;
|
||||
next._pre = null;
|
||||
next._next = null;
|
||||
next = nextCopy;
|
||||
}
|
||||
_Init();
|
||||
}
|
||||
public void ClearAndClearContent()
|
||||
{
|
||||
ViDoubleLinkNode2<T> next = _root._next;
|
||||
while (next != _root)
|
||||
{
|
||||
ViDoubleLinkNode2<T> nextCopy = next._next;
|
||||
next._pre = null;
|
||||
next._next = null;
|
||||
next.Data = default(T);
|
||||
next = nextCopy;
|
||||
}
|
||||
_Init();
|
||||
}
|
||||
//+-----------------------------------------------------------------------------------------------------------------------------
|
||||
static void _PushAfter(ViDoubleLinkNode2<T> before, ViDoubleLinkNode2<T> node)
|
||||
{
|
||||
ViDoubleLinkNode2<T> next = before._next;
|
||||
ViDebuger.AssertError(next);
|
||||
_Link(before, node);
|
||||
_Link(node, next);
|
||||
}
|
||||
static void _PushBefore(ViDoubleLinkNode2<T> after, ViDoubleLinkNode2<T> node)
|
||||
{
|
||||
ViDoubleLinkNode2<T> pre = after._pre;
|
||||
ViDebuger.AssertError(pre);
|
||||
_Link(pre, node);
|
||||
_Link(node, after);
|
||||
}
|
||||
static void _PushAfter(ViDoubleLinkNode2<T> before, ViDoubleLink2<T> list)
|
||||
{
|
||||
if (list.IsEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ViDoubleLinkNode2<T> first = list._root._next;
|
||||
ViDoubleLinkNode2<T> back = list._root._pre;
|
||||
ViDoubleLinkNode2<T> next = before._next;
|
||||
_Link(before, first);
|
||||
_Link(back, next);
|
||||
list._Init();
|
||||
}
|
||||
static void _PushBefore(ViDoubleLinkNode2<T> after, ViDoubleLink2<T> list)
|
||||
{
|
||||
if (list.IsEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ViDoubleLinkNode2<T> first = list._root._next;
|
||||
ViDoubleLinkNode2<T> back = list._root._pre;
|
||||
ViDoubleLinkNode2<T> pre = after._pre;
|
||||
_Link(pre, first);
|
||||
_Link(back, after);
|
||||
list._Init();
|
||||
}
|
||||
static void _Link(ViDoubleLinkNode2<T> pre, ViDoubleLinkNode2<T> next)
|
||||
{
|
||||
pre._next = next;
|
||||
next._pre = pre;
|
||||
}
|
||||
private void _Init()
|
||||
{
|
||||
_Link(_root, _root);
|
||||
}
|
||||
//+-----------------------------------------------------------------------------------------------------------------------------
|
||||
internal ViDoubleLinkNode2<T> _root = new ViDoubleLinkNode2<T>();
|
||||
}
|
||||
|
||||
public class Demo_ViDoubleLink2
|
||||
{
|
||||
#pragma warning disable 0219
|
||||
public static void Test()
|
||||
{
|
||||
ViDoubleLink2<int> list = new ViDoubleLink2<int>();
|
||||
{
|
||||
ViDoubleLinkNode2<int> node1 = new ViDoubleLinkNode2<int>();
|
||||
node1.Data = 1;
|
||||
ViDoubleLinkNode2<int> node2 = new ViDoubleLinkNode2<int>();
|
||||
node2.Data = 2;
|
||||
list.PushBack(node1);
|
||||
list.PushBack(node2);
|
||||
|
||||
{///<正向迭代>
|
||||
ViDoubleLinkNode2<int> iter = list.GetHead();
|
||||
while (!list.IsEnd(iter))
|
||||
{
|
||||
int value = iter.Data;
|
||||
ViDoubleLink2<int>.Next(ref iter);
|
||||
///<使用>
|
||||
///</使用>
|
||||
}
|
||||
}
|
||||
{///<正向迭代>
|
||||
for (ViDoubleLinkNode2<int> iter = list.GetHead(); !list.IsEnd(iter); ViDoubleLink2<int>.Next(ref iter))
|
||||
{
|
||||
int value = iter.Data;
|
||||
///<使用>
|
||||
///</使用>
|
||||
}
|
||||
}
|
||||
{///<反向迭代>
|
||||
ViDoubleLinkNode2<int> iter = list.GetTail();
|
||||
while (!list.IsEnd(iter))
|
||||
{
|
||||
int value = iter.Data;
|
||||
ViDoubleLink2<int>.Pre(ref iter);
|
||||
///<使用>
|
||||
///</使用>
|
||||
}
|
||||
}
|
||||
{///<反向迭代>
|
||||
for (ViDoubleLinkNode2<int> iter = list.GetTail(); !list.IsEnd(iter); ViDoubleLink2<int>.Pre(ref iter))
|
||||
{
|
||||
int value = iter.Data;
|
||||
///<使用>
|
||||
///</使用>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore 0219
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 883f9037963df12459292bed6858f6d9
|
||||
timeCreated: 1453717662
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
427
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViDoubleLink3.cs
Normal file
427
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViDoubleLink3.cs
Normal file
@ -0,0 +1,427 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViDoubleLinkNode3<T>
|
||||
{
|
||||
public ViDoubleLinkNode3()
|
||||
{
|
||||
|
||||
}
|
||||
public ViDoubleLinkNode3(T data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
internal void _Detach()
|
||||
{
|
||||
if (_pre != null)
|
||||
{
|
||||
_pre._next = _next;
|
||||
_next._pre = _pre;
|
||||
_pre = null;
|
||||
_next = null;
|
||||
}
|
||||
}
|
||||
public T Data;
|
||||
//
|
||||
internal ViDoubleLinkNode3<T> _pre;
|
||||
internal ViDoubleLinkNode3<T> _next;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViDoubleLink3<T> : IEnumerable<T>
|
||||
{
|
||||
//+-----------------------------------------------------------------------------------------------------------------------------
|
||||
public static void Next(ref ViDoubleLinkNode3<T> node)
|
||||
{
|
||||
//ViDebuger.AssertError(node != null && node._next != null);
|
||||
node = node._next;
|
||||
}
|
||||
public static void Pre(ref ViDoubleLinkNode3<T> node)
|
||||
{
|
||||
//ViDebuger.AssertError(node != null && node._pre != null);
|
||||
node = node._pre;
|
||||
}
|
||||
public static void PushAfter(ViDoubleLinkNode3<T> before, T value)
|
||||
{
|
||||
ViDoubleLinkNode3<T> node = new ViDoubleLinkNode3<T>(value);
|
||||
_PushAfter(before, node);
|
||||
}
|
||||
public static void PushBefore(ViDoubleLinkNode3<T> after, T value)
|
||||
{
|
||||
ViDoubleLinkNode3<T> node = new ViDoubleLinkNode3<T>(value);
|
||||
_PushBefore(after, node);
|
||||
}
|
||||
//public static void PushAfter(ViDoubleLinkNode3<T> before, ViDoubleLink3<T> list)
|
||||
//{
|
||||
// if (before.IsAttach() == false)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// if (list.IsEmpty())
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// _PushAfter(before, list);
|
||||
//}
|
||||
//public static void PushBefore(ViDoubleLinkNode3<T> after, ViDoubleLink3<T> list)
|
||||
//{
|
||||
// if (after.IsAttach() == false)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// if (list.IsEmpty())
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// _PushBefore(after, list);
|
||||
//}
|
||||
//+-----------------------------------------------------------------------------------------------------------------------------
|
||||
public ViDoubleLink3()
|
||||
{
|
||||
_Init();
|
||||
}
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return _root._next == _root;
|
||||
}
|
||||
public bool IsNotEmpty()
|
||||
{
|
||||
return _root._next != _root;
|
||||
}
|
||||
public bool IsEnd(ViDoubleLinkNode3<T> node)
|
||||
{
|
||||
return node == _root;
|
||||
}
|
||||
public ViDoubleLinkNode3<T> GetHead()
|
||||
{
|
||||
return _root._next;
|
||||
}
|
||||
public ViDoubleLinkNode3<T> GetTail()
|
||||
{
|
||||
return _root._pre;
|
||||
}
|
||||
public void PushBack(T value)
|
||||
{
|
||||
ViDoubleLinkNode3<T> node = new ViDoubleLinkNode3<T>(value);
|
||||
++_count;
|
||||
_PushBefore(_root, node);
|
||||
}
|
||||
public void PushFront(T value)
|
||||
{
|
||||
ViDoubleLinkNode3<T> node = new ViDoubleLinkNode3<T>(value);
|
||||
++_count;
|
||||
_PushAfter(_root, node);
|
||||
}
|
||||
public T GetFront(T defaultValue)
|
||||
{
|
||||
if (IsEmpty())
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _root._next.Data;
|
||||
}
|
||||
}
|
||||
public T GetBack(T defaultValue)
|
||||
{
|
||||
if (IsEmpty())
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _root._pre.Data;
|
||||
}
|
||||
}
|
||||
public void PopFront()
|
||||
{
|
||||
if (!IsEmpty())
|
||||
{
|
||||
--_count;
|
||||
_root._next._Detach();
|
||||
}
|
||||
}
|
||||
public void PopBack()
|
||||
{
|
||||
if (!IsEmpty())
|
||||
{
|
||||
--_count;
|
||||
_root._pre._Detach();
|
||||
}
|
||||
}
|
||||
public bool Has(T value)
|
||||
{
|
||||
EqualityComparer<T> comparer = EqualityComparer<T>.Default;
|
||||
ViDoubleLinkNode3<T> next = _root._next;
|
||||
while (next != _root)
|
||||
{
|
||||
if (comparer.Equals(next.Data, value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
next = next._next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void Remove(ViDoubleLinkNode3<T> node)
|
||||
{
|
||||
_IsChild(node);
|
||||
node._Detach();
|
||||
--_count;
|
||||
}
|
||||
//public void PushBack(ViDoubleLink3<T> list)
|
||||
//{
|
||||
// _PushBefore(_root, list);
|
||||
//}
|
||||
//public void PushFront(ViDoubleLink3<T> list)
|
||||
//{
|
||||
// _PushAfter(_root, list);
|
||||
//}
|
||||
public void SetValue(T value)
|
||||
{
|
||||
ViDoubleLinkNode3<T> next = _root._next;
|
||||
while (next != _root)
|
||||
{
|
||||
next.Data = value;
|
||||
next = next._next;
|
||||
}
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
ViDoubleLinkNode3<T> next = _root._next;
|
||||
while (next != _root)
|
||||
{
|
||||
ViDoubleLinkNode3<T> nextCopy = next._next;
|
||||
next._pre = null;
|
||||
next._next = null;
|
||||
next = nextCopy;
|
||||
}
|
||||
_Init();
|
||||
}
|
||||
public UInt32 Count { get { return _count; } }
|
||||
//+-----------------------------------------------------------------------------------------------------------------------------
|
||||
static void _PushAfter(ViDoubleLinkNode3<T> before, ViDoubleLinkNode3<T> node)
|
||||
{
|
||||
ViDoubleLinkNode3<T> next = before._next;
|
||||
ViDebuger.AssertError(next);
|
||||
_Link(before, node);
|
||||
_Link(node, next);
|
||||
}
|
||||
static void _PushBefore(ViDoubleLinkNode3<T> after, ViDoubleLinkNode3<T> node)
|
||||
{
|
||||
ViDoubleLinkNode3<T> pre = after._pre;
|
||||
ViDebuger.AssertError(pre);
|
||||
_Link(pre, node);
|
||||
_Link(node, after);
|
||||
}
|
||||
static void _PushAfter(ViDoubleLinkNode3<T> before, ViDoubleLink3<T> list)
|
||||
{
|
||||
if (list.IsEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ViDoubleLinkNode3<T> first = list._root._next;
|
||||
ViDoubleLinkNode3<T> back = list._root._pre;
|
||||
ViDoubleLinkNode3<T> next = before._next;
|
||||
_Link(before, first);
|
||||
_Link(back, next);
|
||||
list._Init();
|
||||
}
|
||||
static void _PushBefore(ViDoubleLinkNode3<T> after, ViDoubleLink3<T> list)
|
||||
{
|
||||
if (list.IsEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ViDoubleLinkNode3<T> first = list._root._next;
|
||||
ViDoubleLinkNode3<T> back = list._root._pre;
|
||||
ViDoubleLinkNode3<T> pre = after._pre;
|
||||
_Link(pre, first);
|
||||
_Link(back, after);
|
||||
list._Init();
|
||||
}
|
||||
static void _Link(ViDoubleLinkNode3<T> pre, ViDoubleLinkNode3<T> next)
|
||||
{
|
||||
pre._next = next;
|
||||
next._pre = pre;
|
||||
}
|
||||
private void _Init()
|
||||
{
|
||||
_Link(_root, _root);
|
||||
_count = 0;
|
||||
}
|
||||
private bool _IsChild(ViDoubleLinkNode3<T> node)
|
||||
{
|
||||
ViDoubleLinkNode3<T> next = _root._next;
|
||||
while (next != _root)
|
||||
{
|
||||
if (node == next)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
next = next._next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//+-----------------------------------------------------------------------------------------------------------------------------
|
||||
private ViDoubleLinkNode3<T> _root = new ViDoubleLinkNode3<T>();
|
||||
private UInt32 _count;
|
||||
|
||||
///<foreach>
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
return new Enumerator(this);
|
||||
}
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator()
|
||||
{
|
||||
return this.GetEnumerator();
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return this.GetEnumerator();
|
||||
}
|
||||
internal struct Enumerator : IEnumerator<T>, IEnumerator
|
||||
{
|
||||
private ViDoubleLinkNode3<T> _root;
|
||||
private ViDoubleLinkNode3<T> _node;
|
||||
private T _current;
|
||||
internal Enumerator(ViDoubleLink3<T> list)
|
||||
{
|
||||
_root = list._root;
|
||||
_node = list._root._next;
|
||||
_current = default(T);
|
||||
}
|
||||
T IEnumerator<T>.Current { get { return _current; } }
|
||||
object IEnumerator.Current { get { return _current; } }
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (_node != _root)
|
||||
{
|
||||
_current = _node.Data;
|
||||
_node = _node._next;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void Reset() { _node = _root._next; }
|
||||
public void Dispose() { }
|
||||
}
|
||||
}
|
||||
|
||||
public class Demo_ViDoubleLink3
|
||||
{
|
||||
#pragma warning disable 0219
|
||||
public static void Test()
|
||||
{
|
||||
ViDoubleLink3<int> list = new ViDoubleLink3<int>();
|
||||
list.PushBack(1);
|
||||
list.PushBack(3);
|
||||
|
||||
{///<正向迭代>
|
||||
ViDoubleLinkNode3<int> iter = list.GetHead();
|
||||
while (!list.IsEnd(iter))
|
||||
{
|
||||
int value = iter.Data;
|
||||
ViDoubleLink3<int>.Next(ref iter);
|
||||
///<使用>
|
||||
Console.WriteLine(value);
|
||||
///</使用>
|
||||
}
|
||||
}
|
||||
{///<反向迭代>
|
||||
ViDoubleLinkNode3<int> iter = list.GetTail();
|
||||
while (!list.IsEnd(iter))
|
||||
{
|
||||
int value = iter.Data;
|
||||
ViDoubleLink3<int>.Pre(ref iter);
|
||||
///<使用>
|
||||
Console.WriteLine(value);
|
||||
///</使用>
|
||||
}
|
||||
}
|
||||
|
||||
foreach (int value in list)
|
||||
{
|
||||
Console.WriteLine(value);
|
||||
}
|
||||
}
|
||||
#pragma warning restore 0219
|
||||
}
|
||||
public class Performance_ViDoubleLink3
|
||||
{
|
||||
#pragma warning disable 0219
|
||||
public static void Test0()
|
||||
{
|
||||
Console.WriteLine("Performance_ViDoubleLink3.Test0");
|
||||
ViDoubleLink3<UInt32> list = new ViDoubleLink3<UInt32>();
|
||||
UInt32 cnt = 10000000;
|
||||
UInt32 round = 100;
|
||||
Console.WriteLine(DateTime.Now);
|
||||
for (UInt32 idx = 0; idx < cnt; ++idx)
|
||||
{
|
||||
list.PushBack(idx);
|
||||
}
|
||||
Console.WriteLine(DateTime.Now);
|
||||
for (UInt32 idx = 0; idx < round; ++idx)
|
||||
{
|
||||
ViDoubleLinkNode3<UInt32> iter = list.GetHead();
|
||||
while (!list.IsEnd(iter))
|
||||
{
|
||||
UInt32 value = iter.Data;
|
||||
ViDoubleLink3<UInt32>.Next(ref iter);
|
||||
///<使用>
|
||||
///</使用>
|
||||
}
|
||||
}
|
||||
Console.WriteLine(DateTime.Now);
|
||||
}
|
||||
public static void Test1()
|
||||
{
|
||||
Console.WriteLine("Performance_ViDoubleLink3.Test1");
|
||||
ViDoubleLink3<UInt32> list = new ViDoubleLink3<UInt32>();
|
||||
UInt32 cnt = 10000000;
|
||||
UInt32 round = 100;
|
||||
Console.WriteLine(DateTime.Now);
|
||||
for (UInt32 idx = 0; idx < cnt; ++idx)
|
||||
{
|
||||
list.PushBack(idx);
|
||||
}
|
||||
Console.WriteLine(DateTime.Now);
|
||||
for (UInt32 idx = 0; idx < round; ++idx)
|
||||
{
|
||||
foreach (UInt32 value in list)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Console.WriteLine(DateTime.Now);
|
||||
}
|
||||
|
||||
public static void Test2()
|
||||
{
|
||||
Console.WriteLine("Performance_ViDoubleLink3.Test2");
|
||||
LinkedList<UInt32> list = new LinkedList<UInt32>();
|
||||
UInt32 cnt = 10000000;
|
||||
UInt32 round = 100;
|
||||
Console.WriteLine(DateTime.Now);
|
||||
for (UInt32 idx = 0; idx < cnt; ++idx)
|
||||
{
|
||||
list.AddLast(idx);
|
||||
}
|
||||
Console.WriteLine(DateTime.Now);
|
||||
for (UInt32 idx = 0; idx < round; ++idx)
|
||||
{
|
||||
foreach (UInt32 value in list)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Console.WriteLine(DateTime.Now);
|
||||
}
|
||||
#pragma warning restore 0219
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94947a867bbb2e945870f35ce46d43de
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
160
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViPriorityValue.cs
Normal file
160
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViPriorityValue.cs
Normal file
@ -0,0 +1,160 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ViPriorityValue<T>
|
||||
{
|
||||
public delegate void DeleUpdated(T oldValue, T newValue);
|
||||
public DeleUpdated UpdatedExec;
|
||||
|
||||
public ViPriorityValue()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ViPriorityValue(T defaultValue)
|
||||
{
|
||||
_defaultValue = defaultValue;
|
||||
_value = defaultValue;
|
||||
}
|
||||
|
||||
public T Value { get { return _value; } }
|
||||
public T DefaultValue
|
||||
{
|
||||
get { return _defaultValue; }
|
||||
set
|
||||
{
|
||||
_defaultValue = value;
|
||||
Update();
|
||||
}
|
||||
}
|
||||
public int Count { get { return _list.Count; } }
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_list.Clear();
|
||||
_value = DefaultValue;
|
||||
}
|
||||
|
||||
public void Add(string name, Int32 weight, T value)
|
||||
{
|
||||
for (int iter = 0; iter < _list.Count; ++iter)
|
||||
{
|
||||
Node iterNode = _list[iter];
|
||||
if (iterNode.Name == name)
|
||||
{
|
||||
iterNode.Weight = weight;
|
||||
iterNode.Value = value;
|
||||
//
|
||||
Update();
|
||||
return;
|
||||
}
|
||||
}
|
||||
//
|
||||
Node node = new Node();
|
||||
node.Name = name;
|
||||
node.Weight = weight;
|
||||
node.Value = value;
|
||||
_list.Add(node);
|
||||
//
|
||||
Update();
|
||||
}
|
||||
|
||||
public bool Del(string name)
|
||||
{
|
||||
for (int iter = 0; iter < _list.Count; ++iter)
|
||||
{
|
||||
Node iterNode = _list[iter];
|
||||
if (iterNode.Name == name)
|
||||
{
|
||||
_list.RemoveAt(iter);
|
||||
Update();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void DelAll()
|
||||
{
|
||||
_list.Clear();
|
||||
Update();
|
||||
}
|
||||
|
||||
public bool Has(string name)
|
||||
{
|
||||
for (int iter = 0; iter < _list.Count; ++iter)
|
||||
{
|
||||
Node iterNode = _list[iter];
|
||||
if (iterNode.Name == name)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool UpdateWeight(string name, Int32 weight)
|
||||
{
|
||||
for (int iter = 0; iter < _list.Count; ++iter)
|
||||
{
|
||||
Node iterNode = _list[iter];
|
||||
if (iterNode.Name == name)
|
||||
{
|
||||
iterNode.Weight = weight;
|
||||
Update();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
T oldValue = _value;
|
||||
_value = _defaultValue;
|
||||
Int32 maxWeight = Int32.MinValue;
|
||||
for (int iter = 0; iter < _list.Count; ++iter)
|
||||
{
|
||||
Node iterNode = _list[iter];
|
||||
if (iterNode.Weight > maxWeight)
|
||||
{
|
||||
_value = iterNode.Value;
|
||||
maxWeight = iterNode.Weight;
|
||||
}
|
||||
}
|
||||
if (!object.Equals(oldValue, _value))
|
||||
{
|
||||
if (UpdatedExec != null)
|
||||
{
|
||||
UpdatedExec(oldValue, _value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateNotify()
|
||||
{
|
||||
if (UpdatedExec != null)
|
||||
{
|
||||
UpdatedExec(_value, _value);
|
||||
}
|
||||
}
|
||||
|
||||
T _value;
|
||||
T _defaultValue;
|
||||
|
||||
public void CopyTo(List<Node> list)
|
||||
{
|
||||
for (int iter = 0; iter < _list.Count; ++iter)
|
||||
{
|
||||
list.Add(_list[iter]);
|
||||
}
|
||||
}
|
||||
|
||||
public class Node
|
||||
{
|
||||
public string Name;
|
||||
public Int32 Weight;
|
||||
public T Value;
|
||||
}
|
||||
List<Node> _list = new List<Node>();
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb8c43b08f7a78f47b20075f544cb14f
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
95
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViProvider.cs
Normal file
95
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViProvider.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using System;
|
||||
|
||||
|
||||
public abstract class ViProvider<T>
|
||||
where T : struct
|
||||
{
|
||||
public abstract T Value { get; }
|
||||
}
|
||||
|
||||
public class ViSimpleProvider<T> : ViProvider<T>
|
||||
where T : struct
|
||||
{
|
||||
public ViSimpleProvider() { }
|
||||
public ViSimpleProvider(T value) { _value = value; }
|
||||
public override T Value { get { return _value; } }
|
||||
public void SetValue(T value) { _value = value; }
|
||||
T _value;
|
||||
}
|
||||
|
||||
public class ViPtrProvider<T>
|
||||
where T : class
|
||||
{
|
||||
public static implicit operator T(ViPtrProvider<T> ptr)
|
||||
{
|
||||
if (System.Object.ReferenceEquals(ptr, null))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ptr._obj;
|
||||
}
|
||||
}
|
||||
|
||||
public ViPtrProvider()
|
||||
{
|
||||
|
||||
}
|
||||
public ViPtrProvider(T obj)
|
||||
{
|
||||
Set(obj);
|
||||
}
|
||||
public ViPtrProvider(ViPtrProvider<T> ptr)
|
||||
{
|
||||
Set(ptr._obj);
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
_obj = null;
|
||||
}
|
||||
public void Set(T obj)
|
||||
{
|
||||
_obj = obj;
|
||||
}
|
||||
|
||||
T _obj;
|
||||
}
|
||||
|
||||
public class Demo_Provider
|
||||
{
|
||||
public class ViPtrProviderClass
|
||||
{
|
||||
ViPtrProvider<ViPtrProviderClass> _ptrProvider = new ViPtrProvider<ViPtrProviderClass>();
|
||||
public static implicit operator ViPtrProvider<ViPtrProviderClass>(ViPtrProviderClass obj)
|
||||
{
|
||||
if (!System.Object.ReferenceEquals(obj, null))
|
||||
{
|
||||
return obj._ptrProvider;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ViPtrProviderClass()
|
||||
{
|
||||
_ptrProvider.Set(this);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_ptrProvider.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Test()
|
||||
{
|
||||
ViPtrProviderClass obj = new ViPtrProviderClass();
|
||||
ViPtrProvider<ViPtrProviderClass> ptr = obj;
|
||||
ViPtrProviderClass obj2 = ptr;
|
||||
obj.Clear();
|
||||
ViPtrProviderClass obj4 = ptr;
|
||||
}
|
||||
}
|
||||
12
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViProvider.cs.meta
Normal file
12
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViProvider.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8819865c1a0a80f4b9717cc1466572e6
|
||||
timeCreated: 1453717662
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
280
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViRefList1.cs
Normal file
280
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViRefList1.cs
Normal file
@ -0,0 +1,280 @@
|
||||
using System;
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViRefNode1<T>
|
||||
{
|
||||
public ViRefNode1() { }
|
||||
|
||||
public bool IsAttach()
|
||||
{
|
||||
return (_list != null);
|
||||
}
|
||||
public bool IsAttach(ViRefList1<T> list)
|
||||
{
|
||||
return (list == _list);
|
||||
}
|
||||
public void Detach()
|
||||
{
|
||||
if (_list != null)
|
||||
{
|
||||
_list._Detach(this);
|
||||
_list = null;
|
||||
}
|
||||
}
|
||||
internal ViRefNode1<T> _pre;
|
||||
internal ViRefNode1<T> _next;
|
||||
internal ViRefList1<T> _list;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViRefList1<T>
|
||||
{
|
||||
public static void Next(ref ViRefNode1<T> node)
|
||||
{
|
||||
ViDebuger.AssertError(node != null && node._next != null);
|
||||
node = node._next;
|
||||
}
|
||||
//+--------------------------------------------------------------------------------------------------------------
|
||||
public ViRefList1()
|
||||
{
|
||||
_root._list = this;
|
||||
_Init();
|
||||
}
|
||||
//+--------------------------------------------------------------------------------------------------------------
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return _root._next == _root;
|
||||
}
|
||||
public UInt32 Size { get { return _cnt; } }
|
||||
public ViRefNode1<T> GetHead()
|
||||
{
|
||||
return _root._next;
|
||||
}
|
||||
public ViRefNode1<T> GetTail()
|
||||
{
|
||||
return _root._pre;
|
||||
}
|
||||
public ViRefNode1<T> CurrentNode
|
||||
{
|
||||
get { return _next; }
|
||||
}
|
||||
public void Next()
|
||||
{
|
||||
Next(ref _next);
|
||||
}
|
||||
public void BeginIterator()
|
||||
{
|
||||
_next = _root;
|
||||
Next(ref _next);
|
||||
}
|
||||
public void EndIterator()
|
||||
{
|
||||
_next = _root;
|
||||
}
|
||||
public bool IsEnd(ViRefNode1<T> node)
|
||||
{
|
||||
return node == _root;
|
||||
}
|
||||
public bool IsEnd() { return _next == _root; }
|
||||
public void PushBack(ViRefNode1<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
++_cnt;
|
||||
node._list = this;
|
||||
_PushBefore(_root, node);
|
||||
}
|
||||
public void PushFront(ViRefNode1<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
++_cnt;
|
||||
node._list = this;
|
||||
_PushAfter(_root, node);
|
||||
}
|
||||
public void Push(ViRefNode1<T> node)
|
||||
{
|
||||
if (IsEnd())
|
||||
{
|
||||
PushBack(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
PushFront(node);
|
||||
}
|
||||
}
|
||||
public void PushBack(ViRefList1<T> list)
|
||||
{
|
||||
if (list == this)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PushBefore(_root, list);
|
||||
}
|
||||
public void PushFront(ViRefList1<T> list)
|
||||
{
|
||||
if (list == this)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PushAfter(_root, list);
|
||||
}
|
||||
public void PushAfter(ViRefNode1<T> before, ViRefNode1<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
++_cnt;
|
||||
node._list = this;
|
||||
_PushAfter(before, node);
|
||||
}
|
||||
public void PushBefore(ViRefNode1<T> after, ViRefNode1<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
++_cnt;
|
||||
node._list = this;
|
||||
_PushBefore(after, node);
|
||||
}
|
||||
public void PushAfter(ViRefNode1<T> before, ViRefList1<T> list)
|
||||
{
|
||||
if (list.Size == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (before.IsAttach(list))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (before.IsAttach() == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ViDebuger.AssertError(before._list);
|
||||
ViRefList1<T> receiveList = before._list;
|
||||
ViRefNode1<T> iter = list._root._next;
|
||||
while (iter != list._root)
|
||||
{
|
||||
iter._list = receiveList;
|
||||
iter = iter._next;
|
||||
}
|
||||
ViDebuger.AssertError(receiveList != list);
|
||||
ViRefNode1<T> first = list._root._next;
|
||||
ViRefNode1<T> back = list._root._pre;
|
||||
ViRefNode1<T> next = before._next;
|
||||
_Link(before, first);
|
||||
_Link(back, next);
|
||||
receiveList._cnt += list.Size;
|
||||
list._Init();
|
||||
}
|
||||
public void PushBefore(ViRefNode1<T> after, ViRefList1<T> list)
|
||||
{
|
||||
if (list.Size == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (after.IsAttach(list))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (after.IsAttach() == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ViDebuger.AssertError(after._list);
|
||||
ViRefList1<T> receiveList = after._list;
|
||||
ViRefNode1<T> iter = list._root._next;
|
||||
while (iter != list._root)
|
||||
{
|
||||
iter._list = receiveList;
|
||||
iter = iter._next;
|
||||
}
|
||||
ViDebuger.AssertError(receiveList != list);
|
||||
ViRefNode1<T> first = list._root._next;
|
||||
ViRefNode1<T> back = list._root._pre;
|
||||
ViRefNode1<T> pre = after._pre;
|
||||
_Link(pre, first);
|
||||
_Link(back, after);
|
||||
receiveList._cnt += list.Size;
|
||||
list._Init();
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
ViRefNode1<T> next = _root._next;
|
||||
while (next != _root)
|
||||
{
|
||||
ViRefNode1<T> nextCopy = next._next;
|
||||
next._pre = null;
|
||||
next._next = null;
|
||||
next._list = null;
|
||||
next = nextCopy;
|
||||
}
|
||||
_Init();
|
||||
}
|
||||
internal void _Detach(ViRefNode1<T> node)
|
||||
{
|
||||
ViDebuger.AssertError(node._list == this);
|
||||
if (node == _next)//! 如果是正在迭代的点, 则自动将Next移到下个点
|
||||
{
|
||||
Next(ref _next);
|
||||
}
|
||||
_Link(node._pre, node._next);
|
||||
node._pre = null;
|
||||
node._next = null;
|
||||
--_cnt;
|
||||
}
|
||||
//+--------------------------------------------------------------------------------------------------------------
|
||||
static void _PushAfter(ViRefNode1<T> before, ViRefNode1<T> node)
|
||||
{
|
||||
ViRefNode1<T> next = before._next;
|
||||
ViDebuger.AssertError(next);
|
||||
_Link(before, node);
|
||||
_Link(node, next);
|
||||
}
|
||||
static void _PushBefore(ViRefNode1<T> after, ViRefNode1<T> node)
|
||||
{
|
||||
ViRefNode1<T> pre = after._pre;
|
||||
ViDebuger.AssertError(pre);
|
||||
_Link(pre, node);
|
||||
_Link(node, after);
|
||||
}
|
||||
static void _Link(ViRefNode1<T> pre, ViRefNode1<T> next)
|
||||
{
|
||||
pre._next = next;
|
||||
next._pre = pre;
|
||||
}
|
||||
private void _Init()
|
||||
{
|
||||
_Link(_root, _root);
|
||||
_next = _root;
|
||||
_cnt = 0;
|
||||
}
|
||||
//+--------------------------------------------------------------------------------------------------------------
|
||||
internal ViRefNode1<T> _root = new ViRefNode1<T>();
|
||||
internal UInt32 _cnt;
|
||||
internal ViRefNode1<T> _next;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class Demo_RefList1
|
||||
{
|
||||
#pragma warning disable 0219
|
||||
public static void Test()
|
||||
{
|
||||
ViRefList1<int> list = new ViRefList1<int>();
|
||||
ViRefNode1<int> node0 = new ViRefNode1<int>();
|
||||
ViRefNode1<int> node1 = new ViRefNode1<int>();
|
||||
ViRefNode1<int> node2 = new ViRefNode1<int>();
|
||||
list.PushBack(node0);
|
||||
list.PushBack(node1);
|
||||
list.PushBack(node2);
|
||||
|
||||
list.BeginIterator();
|
||||
while (!list.IsEnd())
|
||||
{
|
||||
ViRefNode1<int> node = list.CurrentNode;
|
||||
list.Next();
|
||||
///<使用>
|
||||
///</使用>
|
||||
}
|
||||
list.Clear();
|
||||
}
|
||||
#pragma warning restore 0219
|
||||
}
|
||||
12
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViRefList1.cs.meta
Normal file
12
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViRefList1.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c521b29a3b683ad439094f1ee725b6d3
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
313
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViRefList2.cs
Normal file
313
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViRefList2.cs
Normal file
@ -0,0 +1,313 @@
|
||||
using System;
|
||||
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViRefNode2<T>
|
||||
{
|
||||
public ViRefNode2()
|
||||
{
|
||||
|
||||
}
|
||||
public ViRefNode2(T data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
public bool IsAttach()
|
||||
{
|
||||
return (_list != null);
|
||||
}
|
||||
public bool IsAttach(ViRefList2<T> list)
|
||||
{
|
||||
return (list == _list);
|
||||
}
|
||||
public void Detach()
|
||||
{
|
||||
if (_list != null)
|
||||
{
|
||||
_list._Detach(this);
|
||||
_list = null;
|
||||
}
|
||||
}
|
||||
public T Data;
|
||||
//
|
||||
internal ViRefNode2<T> _pre;
|
||||
internal ViRefNode2<T> _next;
|
||||
internal ViRefList2<T> _list;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViRefList2<T>
|
||||
{
|
||||
public static void Next(ref ViRefNode2<T> node)
|
||||
{
|
||||
ViDebuger.AssertError(node != null && node._next != null);
|
||||
node = node._next;
|
||||
}
|
||||
//+--------------------------------------------------------------------------------------------------------------
|
||||
public ViRefList2()
|
||||
{
|
||||
_root._list = this;
|
||||
_Init();
|
||||
}
|
||||
//+--------------------------------------------------------------------------------------------------------------
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return _root._next == _root;
|
||||
}
|
||||
public UInt32 Size { get { return _cnt; } }
|
||||
public ViRefNode2<T> GetHead()
|
||||
{
|
||||
return _root._next;
|
||||
}
|
||||
public ViRefNode2<T> GetTail()
|
||||
{
|
||||
return _root._pre;
|
||||
}
|
||||
public ViRefNode2<T> CurrentNode
|
||||
{
|
||||
get { return _next; }
|
||||
}
|
||||
public void Next()
|
||||
{
|
||||
Next(ref _next);
|
||||
}
|
||||
public void BeginIterator()
|
||||
{
|
||||
_next = _root;
|
||||
Next(ref _next);
|
||||
}
|
||||
public void EndIterator()
|
||||
{
|
||||
_next = _root;
|
||||
}
|
||||
public bool IsEnd(ViRefNode2<T> node)
|
||||
{
|
||||
return node == _root;
|
||||
}
|
||||
public bool IsEnd() { return _next == _root; }
|
||||
public void PushBack(ViRefNode2<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
++_cnt;
|
||||
node._list = this;
|
||||
_PushBefore(_root, node);
|
||||
}
|
||||
public void PushFront(ViRefNode2<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
++_cnt;
|
||||
node._list = this;
|
||||
_PushAfter(_root, node);
|
||||
}
|
||||
public void Push(ViRefNode2<T> node)
|
||||
{
|
||||
if (IsEnd())
|
||||
{
|
||||
PushBack(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
PushFront(node);
|
||||
}
|
||||
}
|
||||
public void PushBack(ViRefList2<T> list)
|
||||
{
|
||||
if (list == this)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PushBefore(_root, list);
|
||||
}
|
||||
public void PushFront(ViRefList2<T> list)
|
||||
{
|
||||
if (list == this)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PushAfter(_root, list);
|
||||
}
|
||||
public void PushAfter(ViRefNode2<T> before, ViRefNode2<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
++_cnt;
|
||||
node._list = this;
|
||||
_PushAfter(before, node);
|
||||
}
|
||||
public void PushBefore(ViRefNode2<T> after, ViRefNode2<T> node)
|
||||
{
|
||||
node.Detach();
|
||||
++_cnt;
|
||||
node._list = this;
|
||||
_PushBefore(after, node);
|
||||
}
|
||||
public void PushAfter(ViRefNode2<T> before, ViRefList2<T> list)
|
||||
{
|
||||
if (list.Size == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (before.IsAttach(list))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (before.IsAttach() == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ViDebuger.AssertError(before._list);
|
||||
ViRefList2<T> receiveList = before._list;
|
||||
ViRefNode2<T> iter = list._root._next;
|
||||
while (iter != list._root)
|
||||
{
|
||||
iter._list = receiveList;
|
||||
iter = iter._next;
|
||||
}
|
||||
ViDebuger.AssertError(receiveList != list);
|
||||
ViRefNode2<T> first = list._root._next;
|
||||
ViRefNode2<T> back = list._root._pre;
|
||||
ViRefNode2<T> next = before._next;
|
||||
_Link(before, first);
|
||||
_Link(back, next);
|
||||
receiveList._cnt += list.Size;
|
||||
list._Init();
|
||||
}
|
||||
public void PushBefore(ViRefNode2<T> after, ViRefList2<T> list)
|
||||
{
|
||||
if (list.Size == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (after.IsAttach(list))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (after.IsAttach() == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ViDebuger.AssertError(after._list);
|
||||
ViRefList2<T> receiveList = after._list;
|
||||
ViRefNode2<T> iter = list._root._next;
|
||||
while (iter != list._root)
|
||||
{
|
||||
iter._list = receiveList;
|
||||
iter = iter._next;
|
||||
}
|
||||
ViDebuger.AssertError(receiveList != list);
|
||||
ViRefNode2<T> first = list._root._next;
|
||||
ViRefNode2<T> back = list._root._pre;
|
||||
ViRefNode2<T> pre = after._pre;
|
||||
_Link(pre, first);
|
||||
_Link(back, after);
|
||||
receiveList._cnt += list.Size;
|
||||
list._Init();
|
||||
}
|
||||
public void SetValue(T value)
|
||||
{
|
||||
ViRefNode2<T> next = _root._next;
|
||||
while (next != _root)
|
||||
{
|
||||
next.Data = value;
|
||||
next = next._next;
|
||||
}
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
ViRefNode2<T> next = _root._next;
|
||||
while (next != _root)
|
||||
{
|
||||
ViRefNode2<T> nextCopy = next._next;
|
||||
next._pre = null;
|
||||
next._next = null;
|
||||
next._list = null;
|
||||
next = nextCopy;
|
||||
}
|
||||
_Init();
|
||||
}
|
||||
public void ClearAndClearContent()
|
||||
{
|
||||
ViRefNode2<T> next = _root._next;
|
||||
while (next != _root)
|
||||
{
|
||||
ViRefNode2<T> nextCopy = next._next;
|
||||
next._pre = null;
|
||||
next._next = null;
|
||||
next._list = null;
|
||||
next.Data = default(T);
|
||||
next = nextCopy;
|
||||
}
|
||||
_Init();
|
||||
}
|
||||
internal void _Detach(ViRefNode2<T> node)
|
||||
{
|
||||
ViDebuger.AssertError(node._list == this);
|
||||
if (node == _next)//! 如果是正在迭代的点, 则自动将Next移到下个点
|
||||
{
|
||||
Next(ref _next);
|
||||
}
|
||||
_Link(node._pre, node._next);
|
||||
node._pre = null;
|
||||
node._next = null;
|
||||
--_cnt;
|
||||
}
|
||||
//+--------------------------------------------------------------------------------------------------------------
|
||||
static void _PushAfter(ViRefNode2<T> before, ViRefNode2<T> node)
|
||||
{
|
||||
ViRefNode2<T> next = before._next;
|
||||
ViDebuger.AssertError(next);
|
||||
_Link(before, node);
|
||||
_Link(node, next);
|
||||
}
|
||||
static void _PushBefore(ViRefNode2<T> after, ViRefNode2<T> node)
|
||||
{
|
||||
ViRefNode2<T> pre = after._pre;
|
||||
ViDebuger.AssertError(pre);
|
||||
_Link(pre, node);
|
||||
_Link(node, after);
|
||||
}
|
||||
static void _Link(ViRefNode2<T> pre, ViRefNode2<T> next)
|
||||
{
|
||||
pre._next = next;
|
||||
next._pre = pre;
|
||||
}
|
||||
private void _Init()
|
||||
{
|
||||
_Link(_root, _root);
|
||||
_next = _root;
|
||||
_cnt = 0;
|
||||
}
|
||||
//+--------------------------------------------------------------------------------------------------------------
|
||||
internal ViRefNode2<T> _root = new ViRefNode2<T>();
|
||||
internal UInt32 _cnt;
|
||||
internal ViRefNode2<T> _next;
|
||||
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class Demo_RefList2
|
||||
{
|
||||
#pragma warning disable 0219
|
||||
public static void Test()
|
||||
{
|
||||
ViRefList2<int> list = new ViRefList2<int>();
|
||||
ViRefNode2<int> node0 = new ViRefNode2<int>(); node0.Data = 0;
|
||||
ViRefNode2<int> node1 = new ViRefNode2<int>(); node1.Data = 1;
|
||||
ViRefNode2<int> node2 = new ViRefNode2<int>(); node2.Data = 2;
|
||||
list.PushBack(node0);
|
||||
list.PushBack(node1);
|
||||
list.PushBack(node2);
|
||||
|
||||
list.BeginIterator();
|
||||
while (!list.IsEnd())
|
||||
{
|
||||
ViRefNode2<int> node = list.CurrentNode;
|
||||
list.Next();
|
||||
///<使用>
|
||||
///</使用>
|
||||
}
|
||||
list.Clear();
|
||||
}
|
||||
#pragma warning restore 0219
|
||||
}
|
||||
12
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViRefList2.cs.meta
Normal file
12
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViRefList2.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d6b40b5f89df5a4a9e2295070aedff4
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
43
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViSimpleVector.cs
Normal file
43
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViSimpleVector.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
|
||||
|
||||
public class ViSimpleVector<T>
|
||||
where T : class, new()
|
||||
{
|
||||
public void Clear()
|
||||
{
|
||||
for (UInt32 idx = 0; idx < _size; ++idx)
|
||||
{
|
||||
_array[idx] = null;
|
||||
}
|
||||
_array = null;
|
||||
_size = 0;
|
||||
}
|
||||
public void Resize(UInt32 size)
|
||||
{
|
||||
if (size == 0) return;
|
||||
if (_size != 0) return;//! 不能被初始化两次,否则就去用Vector
|
||||
ViDebuger.AssertError(_array == null);
|
||||
_array = new T[size];
|
||||
_size = size;
|
||||
for (UInt32 idx = 0; idx < _size; ++idx)
|
||||
{
|
||||
_array[idx] = new T();
|
||||
}
|
||||
}
|
||||
public T Get(UInt32 idx)
|
||||
{
|
||||
if (idx < _size)
|
||||
{
|
||||
return _array[idx];
|
||||
}
|
||||
else
|
||||
return default(T);
|
||||
}
|
||||
//
|
||||
public UInt32 Size { get { return _size; } }
|
||||
//
|
||||
private T[] _array;
|
||||
private UInt32 _size;
|
||||
}
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e9667344e517ea41bc937ba7206897c
|
||||
timeCreated: 1453717662
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
159
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViTuple.cs
Normal file
159
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViTuple.cs
Normal file
@ -0,0 +1,159 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public interface ViTupleInterface
|
||||
{
|
||||
Object Value(UInt32 idx);
|
||||
UInt32 Size { get; }
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViTuple : ViTupleInterface
|
||||
{
|
||||
public Object Value(UInt32 idx)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public UInt32 Size { get { return 0; } }
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViTuple<T0> : ViTuple, ViTupleInterface
|
||||
{
|
||||
public new Object Value(UInt32 idx)
|
||||
{
|
||||
switch (idx)
|
||||
{
|
||||
case 0: return _value0;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
public T0 Value0 { get { return _value0; } set { _value0 = value; } }
|
||||
public new UInt32 Size { get { return 1; } }
|
||||
//
|
||||
public T0 _value0;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViTuple<T0, T1> : ViTuple<T0>, ViTupleInterface
|
||||
{
|
||||
public new Object Value(UInt32 idx)
|
||||
{
|
||||
switch (idx)
|
||||
{
|
||||
case 0: return _value0;
|
||||
case 1: return _value1;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
public T1 Value1 { get { return _value1; } set { _value1 = value; } }
|
||||
public new UInt32 Size { get { return 2; } }
|
||||
//
|
||||
public T1 _value1;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViTuple<T0, T1, T2> : ViTuple<T0, T1>, ViTupleInterface
|
||||
{
|
||||
public new Object Value(UInt32 idx)
|
||||
{
|
||||
switch (idx)
|
||||
{
|
||||
case 0: return _value0;
|
||||
case 1: return _value1;
|
||||
case 2: return _value2;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
public T2 Value2 { get { return _value2; } set { _value2 = value; } }
|
||||
public new UInt32 Size { get { return 3; } }
|
||||
//
|
||||
public T2 _value2;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViTuple<T0, T1, T2, T3> : ViTuple<T0, T1, T2>, ViTupleInterface
|
||||
{
|
||||
public new Object Value(UInt32 idx)
|
||||
{
|
||||
switch (idx)
|
||||
{
|
||||
case 0: return _value0;
|
||||
case 1: return _value1;
|
||||
case 2: return _value2;
|
||||
case 3: return _value3;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
public T3 Value3 { get { return _value3; } set { _value3 = value; } }
|
||||
public new UInt32 Size { get { return 4; } }
|
||||
//
|
||||
public T3 _value3;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViTuple<T0, T1, T2, T3, T4> : ViTuple<T0, T1, T2, T3>, ViTupleInterface
|
||||
{
|
||||
public new Object Value(UInt32 idx)
|
||||
{
|
||||
switch (idx)
|
||||
{
|
||||
case 0: return _value0;
|
||||
case 1: return _value1;
|
||||
case 2: return _value2;
|
||||
case 3: return _value3;
|
||||
case 4: return _value4;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
public T4 Value4 { get { return _value4; } set { _value4 = value; } }
|
||||
public new UInt32 Size { get { return 5; } }
|
||||
//
|
||||
public T4 _value4;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViTuple<T0, T1, T2, T3, T4, T5> : ViTuple<T0, T1, T2, T3, T4>, ViTupleInterface
|
||||
{
|
||||
public new Object Value(UInt32 idx)
|
||||
{
|
||||
switch (idx)
|
||||
{
|
||||
case 0: return _value0;
|
||||
case 1: return _value1;
|
||||
case 2: return _value2;
|
||||
case 3: return _value3;
|
||||
case 4: return _value4;
|
||||
case 5: return _value5;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
public T5 Value5 { get { return _value5; } set { _value5 = value; } }
|
||||
public new UInt32 Size { get { return 6; } }
|
||||
//
|
||||
public T5 _value5;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViTuple<T0, T1, T2, T3, T4, T5, T6> : ViTuple<T0, T1, T2, T3, T4, T5>, ViTupleInterface
|
||||
{
|
||||
public new Object Value(UInt32 idx)
|
||||
{
|
||||
switch (idx)
|
||||
{
|
||||
case 0: return _value0;
|
||||
case 1: return _value1;
|
||||
case 2: return _value2;
|
||||
case 3: return _value3;
|
||||
case 4: return _value4;
|
||||
case 5: return _value5;
|
||||
case 6: return _value6;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
public T6 Value6 { get { return _value6; } set { _value6 = value; } }
|
||||
public new UInt32 Size { get { return 7; } }
|
||||
//
|
||||
public T6 _value6;
|
||||
}
|
||||
12
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViTuple.cs.meta
Normal file
12
Unity/Assets/Plugins/ViSDK/ViBaseStruct/ViTuple.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90a7de394bffa3044b55c967fd8e673f
|
||||
timeCreated: 1453717662
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Unity/Assets/Plugins/ViSDK/ViGameCommon.meta
Normal file
9
Unity/Assets/Plugins/ViSDK/ViGameCommon.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ec60a317d8e7e342b6ab995ca7278b9
|
||||
folderAsset: yes
|
||||
timeCreated: 1453717661
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Unity/Assets/Plugins/ViSDK/ViGameCommon/Event.meta
Normal file
9
Unity/Assets/Plugins/ViSDK/ViGameCommon/Event.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4da9cce4bf7316f47a16d28765acdae6
|
||||
folderAsset: yes
|
||||
timeCreated: 1453717661
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
41
Unity/Assets/Plugins/ViSDK/ViGameCommon/Event/ViCallback.cs
Normal file
41
Unity/Assets/Plugins/ViSDK/ViGameCommon/Event/ViCallback.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
|
||||
|
||||
public abstract class ViAsynDelegateInterface
|
||||
{
|
||||
public static void Update()
|
||||
{
|
||||
_currentExecList.PushBack(_asynExecList);
|
||||
while (_currentExecList.IsNotEmpty())
|
||||
{
|
||||
ViAsynDelegateInterface asynCallback = _currentExecList.GetHead().Data;
|
||||
ViDebuger.AssertError(asynCallback);
|
||||
asynCallback._node.Detach();
|
||||
asynCallback._node.Data = null;
|
||||
asynCallback._AsynExec();
|
||||
}
|
||||
ViDebuger.AssertWarning(_currentExecList.IsEmpty());
|
||||
}
|
||||
public static void Clear()
|
||||
{
|
||||
_asynExecList.Clear();
|
||||
_currentExecList.Clear();
|
||||
}
|
||||
static ViDoubleLink2<ViAsynDelegateInterface> _asynExecList = new ViDoubleLink2<ViAsynDelegateInterface>();
|
||||
static ViDoubleLink2<ViAsynDelegateInterface> _currentExecList = new ViDoubleLink2<ViAsynDelegateInterface>();
|
||||
//
|
||||
public bool Active { get { return _node.IsAttach(); } }
|
||||
public void End()
|
||||
{
|
||||
_node.Data = null;
|
||||
_node.Detach();
|
||||
}
|
||||
|
||||
protected void _AttachAsyn()
|
||||
{
|
||||
_node.Data = this;
|
||||
_asynExecList.PushBack(_node);
|
||||
}
|
||||
internal abstract void _AsynExec();
|
||||
ViDoubleLinkNode2<ViAsynDelegateInterface> _node = new ViDoubleLinkNode2<ViAsynDelegateInterface>();
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f00490cf6cbec94e96dd019608a19fc
|
||||
timeCreated: 1453717662
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
160
Unity/Assets/Plugins/ViSDK/ViGameCommon/Event/ViCallback0.cs
Normal file
160
Unity/Assets/Plugins/ViSDK/ViGameCommon/Event/ViCallback0.cs
Normal file
@ -0,0 +1,160 @@
|
||||
using System;
|
||||
|
||||
|
||||
|
||||
public interface ViCallbackInterface
|
||||
{
|
||||
bool Active { get; }
|
||||
void End();
|
||||
void OnCallerClear();
|
||||
void Exec(UInt32 eventID);
|
||||
}
|
||||
|
||||
public class ViCallback : ViCallbackInterface
|
||||
{
|
||||
public delegate void Callback(UInt32 eventID);
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public bool Active { get { return _node.IsAttach(); } }
|
||||
//
|
||||
public void End()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void OnCallerClear()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void Exec(UInt32 eventID)
|
||||
{
|
||||
ViDebuger.AssertError(_delegate);
|
||||
_delegate(eventID);
|
||||
}
|
||||
internal void Attach(Callback dele, ViRefList2<ViCallbackInterface> list)
|
||||
{
|
||||
_delegate = dele;
|
||||
_node.Data = this;
|
||||
list.Push(_node);
|
||||
}
|
||||
//
|
||||
ViRefNode2<ViCallbackInterface> _node = new ViRefNode2<ViCallbackInterface>();
|
||||
Callback _delegate;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViAsynCallback : ViAsynDelegateInterface, ViCallbackInterface
|
||||
{
|
||||
public delegate void Callback(UInt32 eventId);
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public new bool Active { get { return _node.IsAttach(); } }
|
||||
public bool AsynActive { get { return base.Active; } }
|
||||
//
|
||||
public new void End()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
//
|
||||
_asynDele = null;
|
||||
base.End();
|
||||
}
|
||||
public void OnCallerClear()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void Exec()
|
||||
{
|
||||
if (AsynActive)
|
||||
{
|
||||
base.End();
|
||||
_AsynExec();
|
||||
}
|
||||
}
|
||||
public void Exec(UInt32 eventID)
|
||||
{
|
||||
ViDebuger.AssertError(_delegate);
|
||||
_asynDele = _delegate;
|
||||
_eventID = eventID;
|
||||
_AttachAsyn();
|
||||
}
|
||||
public void Invoke(UInt32 eventID, Callback dele)
|
||||
{
|
||||
ViDebuger.AssertError(dele);
|
||||
_delegate = dele;
|
||||
_asynDele = dele;
|
||||
_eventID = eventID;
|
||||
_AttachAsyn();
|
||||
}
|
||||
internal override void _AsynExec()
|
||||
{
|
||||
ViDebuger.AssertError(_asynDele);
|
||||
Callback dele = _asynDele;
|
||||
_asynDele = null;
|
||||
dele(_eventID);
|
||||
}
|
||||
internal void Attach(Callback dele, ViRefList2<ViCallbackInterface> list)
|
||||
{
|
||||
End();
|
||||
//
|
||||
_delegate = dele;
|
||||
_node.Data = this;
|
||||
list.Push(_node);
|
||||
}
|
||||
//
|
||||
ViRefNode2<ViCallbackInterface> _node = new ViRefNode2<ViCallbackInterface>();
|
||||
Callback _delegate;
|
||||
Callback _asynDele;
|
||||
UInt32 _eventID;
|
||||
}
|
||||
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViEventAsynList
|
||||
{
|
||||
public void Invoke(UInt32 eventId)
|
||||
{
|
||||
_eventList.BeginIterator();
|
||||
while (!_eventList.IsEnd())
|
||||
{
|
||||
ViCallbackInterface callback = _eventList.CurrentNode.Data;
|
||||
ViDebuger.AssertError(callback);
|
||||
_eventList.Next();
|
||||
callback.Exec(eventId);
|
||||
}
|
||||
}
|
||||
public void Attach(ViAsynCallback node, ViAsynCallback.Callback dele)
|
||||
{
|
||||
node.Attach(dele, _eventList);
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
_eventList.BeginIterator();
|
||||
while (!_eventList.IsEnd())
|
||||
{
|
||||
ViCallbackInterface callback = _eventList.CurrentNode.Data;
|
||||
ViDebuger.AssertError(callback);
|
||||
_eventList.Next();
|
||||
callback.OnCallerClear();
|
||||
}
|
||||
ViDebuger.AssertWarning(_eventList.IsEmpty());
|
||||
}
|
||||
//
|
||||
protected ViRefList2<ViCallbackInterface> _eventList = new ViRefList2<ViCallbackInterface>();
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViEventList : ViEventAsynList
|
||||
{
|
||||
public void Attach(ViCallback node, ViCallback.Callback dele)
|
||||
{
|
||||
node.Attach(dele, _eventList);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e92bcc3b6cc925469e0d6ce544300a8
|
||||
timeCreated: 1453717662
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
170
Unity/Assets/Plugins/ViSDK/ViGameCommon/Event/ViCallback1.cs
Normal file
170
Unity/Assets/Plugins/ViSDK/ViGameCommon/Event/ViCallback1.cs
Normal file
@ -0,0 +1,170 @@
|
||||
using System;
|
||||
|
||||
|
||||
public interface ViCallbackInterface<T0>
|
||||
{
|
||||
bool Active { get; }
|
||||
void End();
|
||||
void OnCallerClear();
|
||||
void Exec(UInt32 eventID, T0 param0);
|
||||
}
|
||||
|
||||
public class ViCallback<T0> : ViCallbackInterface<T0>
|
||||
{
|
||||
public delegate void Callback(UInt32 eventID, T0 param0);
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public bool Active { get { return _node.IsAttach(); } }
|
||||
//
|
||||
public void End()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void OnCallerClear()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void Exec(UInt32 eventID, T0 param0)
|
||||
{
|
||||
ViDebuger.AssertError(_delegate);
|
||||
_delegate(eventID, param0);
|
||||
}
|
||||
internal void Attach(Callback dele, ViRefList2<ViCallbackInterface<T0>> list)
|
||||
{
|
||||
_delegate = dele;
|
||||
_node.Data = this;
|
||||
list.Push(_node);
|
||||
}
|
||||
//
|
||||
ViRefNode2<ViCallbackInterface<T0>> _node = new ViRefNode2<ViCallbackInterface<T0>>();
|
||||
Callback _delegate;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViAsynCallback<T0> : ViAsynDelegateInterface, ViCallbackInterface<T0>
|
||||
{
|
||||
public delegate void Callback(UInt32 eventId, T0 param0);
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public new bool Active { get { return _node.IsAttach(); } }
|
||||
public bool AsynActive { get { return base.Active; } }
|
||||
//
|
||||
public new void End()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
//
|
||||
_asynDele = null;
|
||||
_param0 = default(T0);
|
||||
base.End();
|
||||
}
|
||||
public void OnCallerClear()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void Exec()
|
||||
{
|
||||
if (AsynActive)
|
||||
{
|
||||
base.End();
|
||||
_AsynExec();
|
||||
}
|
||||
}
|
||||
public void Exec(UInt32 eventID, T0 param0)
|
||||
{
|
||||
ViDebuger.AssertError(_delegate);
|
||||
_asynDele = _delegate;
|
||||
_eventID = eventID;
|
||||
_param0 = param0;
|
||||
_AttachAsyn();
|
||||
}
|
||||
public void Invoke(UInt32 eventID, T0 param0, Callback dele)
|
||||
{
|
||||
ViDebuger.AssertError(dele);
|
||||
_delegate = dele;
|
||||
_asynDele = _delegate;
|
||||
_eventID = eventID;
|
||||
_param0 = param0;
|
||||
_AttachAsyn();
|
||||
}
|
||||
internal override void _AsynExec()
|
||||
{
|
||||
ViDebuger.AssertError(_asynDele);
|
||||
Callback dele = _asynDele;
|
||||
T0 param0 = _param0;
|
||||
_asynDele = null;
|
||||
_param0 = default(T0);
|
||||
dele(_eventID, param0);
|
||||
}
|
||||
internal void Attach(Callback dele, ViRefList2<ViCallbackInterface<T0>> list)
|
||||
{
|
||||
End();
|
||||
//
|
||||
_delegate = dele;
|
||||
_node.Data = this;
|
||||
list.Push(_node);
|
||||
}
|
||||
//
|
||||
ViRefNode2<ViCallbackInterface<T0>> _node = new ViRefNode2<ViCallbackInterface<T0>>();
|
||||
Callback _delegate;
|
||||
Callback _asynDele;
|
||||
UInt32 _eventID;
|
||||
T0 _param0;
|
||||
}
|
||||
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViEventAsynList<T0>
|
||||
{
|
||||
public void Invoke(UInt32 eventId, T0 param0)
|
||||
{
|
||||
_eventList.BeginIterator();
|
||||
while (!_eventList.IsEnd())
|
||||
{
|
||||
ViCallbackInterface<T0> callback = _eventList.CurrentNode.Data;
|
||||
ViDebuger.AssertError(callback);
|
||||
_eventList.Next();
|
||||
callback.Exec(eventId, param0);
|
||||
}
|
||||
}
|
||||
public void Attach(ViAsynCallback<T0> node, ViAsynCallback<T0>.Callback dele)
|
||||
{
|
||||
node.Attach(dele, _eventList);
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
_eventList.BeginIterator();
|
||||
while (!_eventList.IsEnd())
|
||||
{
|
||||
ViCallbackInterface<T0> callback = _eventList.CurrentNode.Data;
|
||||
ViDebuger.AssertError(callback);
|
||||
_eventList.Next();
|
||||
callback.OnCallerClear();
|
||||
}
|
||||
ViDebuger.AssertWarning(_eventList.IsEmpty());
|
||||
}
|
||||
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return _eventList.IsEmpty();
|
||||
}
|
||||
//
|
||||
protected ViRefList2<ViCallbackInterface<T0>> _eventList = new ViRefList2<ViCallbackInterface<T0>>();
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViEventList<T0> : ViEventAsynList<T0>
|
||||
{
|
||||
public void Attach(ViCallback<T0> node, ViCallback<T0>.Callback dele)
|
||||
{
|
||||
node.Attach(dele, _eventList);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6495b2840fab1941a8b89359cb9ce9e
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
171
Unity/Assets/Plugins/ViSDK/ViGameCommon/Event/ViCallback2.cs
Normal file
171
Unity/Assets/Plugins/ViSDK/ViGameCommon/Event/ViCallback2.cs
Normal file
@ -0,0 +1,171 @@
|
||||
using System;
|
||||
|
||||
|
||||
public interface ViCallbackInterface<T0, T1>
|
||||
{
|
||||
bool Active { get; }
|
||||
void End();
|
||||
void OnCallerClear();
|
||||
void Exec(UInt32 eventID, T0 param0, T1 param1);
|
||||
}
|
||||
|
||||
public class ViCallback<T0, T1> : ViCallbackInterface<T0, T1>
|
||||
{
|
||||
public delegate void Callback(UInt32 eventID, T0 param0, T1 param1);
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public bool Active { get { return _node.IsAttach(); } }
|
||||
//
|
||||
public void End()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void OnCallerClear()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void Exec(UInt32 eventID, T0 param0, T1 param1)
|
||||
{
|
||||
ViDebuger.AssertError(_delegate);
|
||||
_delegate(eventID, param0, param1);
|
||||
}
|
||||
internal void Attach(Callback dele, ViRefList2<ViCallbackInterface<T0, T1>> list)
|
||||
{
|
||||
_delegate = dele;
|
||||
_node.Data = this;
|
||||
list.Push(_node);
|
||||
}
|
||||
//
|
||||
ViRefNode2<ViCallbackInterface<T0, T1>> _node = new ViRefNode2<ViCallbackInterface<T0, T1>>();
|
||||
Callback _delegate;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViAsynCallback<T0, T1> : ViAsynDelegateInterface, ViCallbackInterface<T0, T1>
|
||||
{
|
||||
public delegate void Callback(UInt32 eventId, T0 param0, T1 param1);
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public new bool Active { get { return _node.IsAttach(); } }
|
||||
public bool AsynActive { get { return base.Active; } }
|
||||
//
|
||||
public new void End()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
//
|
||||
_asynDele = null;
|
||||
_param0 = default(T0);
|
||||
_param1 = default(T1);
|
||||
base.End();
|
||||
}
|
||||
public void OnCallerClear()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void Exec()
|
||||
{
|
||||
if (AsynActive)
|
||||
{
|
||||
base.End();
|
||||
_AsynExec();
|
||||
}
|
||||
}
|
||||
public void Exec(UInt32 eventID, T0 param0, T1 param1)
|
||||
{
|
||||
ViDebuger.AssertError(_delegate);
|
||||
_asynDele = _delegate;
|
||||
_eventID = eventID;
|
||||
_param0 = param0;
|
||||
_param1 = param1;
|
||||
_AttachAsyn();
|
||||
}
|
||||
public void Invoke(UInt32 eventID, T0 param0, T1 param1, Callback dele)
|
||||
{
|
||||
ViDebuger.AssertError(dele);
|
||||
_delegate = dele;
|
||||
_asynDele = _delegate;
|
||||
_eventID = eventID;
|
||||
_param0 = param0;
|
||||
_param1 = param1;
|
||||
_AttachAsyn();
|
||||
}
|
||||
internal override void _AsynExec()
|
||||
{
|
||||
ViDebuger.AssertError(_asynDele);
|
||||
Callback dele = _asynDele;
|
||||
T0 param0 = _param0;
|
||||
T1 param1 = _param1;
|
||||
_asynDele = null;
|
||||
_param0 = default(T0);
|
||||
_param1 = default(T1);
|
||||
dele(_eventID, param0, param1);
|
||||
}
|
||||
internal void Attach(Callback dele, ViRefList2<ViCallbackInterface<T0, T1>> list)
|
||||
{
|
||||
End();
|
||||
//
|
||||
_delegate = dele;
|
||||
_node.Data = this;
|
||||
list.Push(_node);
|
||||
}
|
||||
//
|
||||
ViRefNode2<ViCallbackInterface<T0, T1>> _node = new ViRefNode2<ViCallbackInterface<T0, T1>>();
|
||||
Callback _delegate;
|
||||
Callback _asynDele;
|
||||
UInt32 _eventID;
|
||||
T0 _param0;
|
||||
T1 _param1;
|
||||
}
|
||||
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViEventAsynList<T0, T1>
|
||||
{
|
||||
public void Invoke(UInt32 eventId, T0 param0, T1 param1)
|
||||
{
|
||||
_eventList.BeginIterator();
|
||||
while (!_eventList.IsEnd())
|
||||
{
|
||||
ViCallbackInterface<T0, T1> callback = _eventList.CurrentNode.Data;
|
||||
ViDebuger.AssertError(callback);
|
||||
_eventList.Next();
|
||||
callback.Exec(eventId, param0, param1);
|
||||
}
|
||||
}
|
||||
public void Attach(ViAsynCallback<T0, T1> node, ViAsynCallback<T0, T1>.Callback dele)
|
||||
{
|
||||
node.Attach(dele, _eventList);
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
_eventList.BeginIterator();
|
||||
while (!_eventList.IsEnd())
|
||||
{
|
||||
ViCallbackInterface<T0, T1> callback = _eventList.CurrentNode.Data;
|
||||
ViDebuger.AssertError(callback);
|
||||
_eventList.Next();
|
||||
callback.OnCallerClear();
|
||||
}
|
||||
ViDebuger.AssertWarning(_eventList.IsEmpty());
|
||||
}
|
||||
//
|
||||
protected ViRefList2<ViCallbackInterface<T0, T1>> _eventList = new ViRefList2<ViCallbackInterface<T0, T1>>();
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViEventList<T0, T1> : ViEventAsynList<T0, T1>
|
||||
{
|
||||
public void Attach(ViCallback<T0, T1> node, ViCallback<T0, T1>.Callback dele)
|
||||
{
|
||||
node.Attach(dele, _eventList);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db5b292a66a96e149afa4c8c7e563ae3
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
177
Unity/Assets/Plugins/ViSDK/ViGameCommon/Event/ViCallback3.cs
Normal file
177
Unity/Assets/Plugins/ViSDK/ViGameCommon/Event/ViCallback3.cs
Normal file
@ -0,0 +1,177 @@
|
||||
using System;
|
||||
|
||||
|
||||
public interface ViCallbackInterface<T0, T1, T2>
|
||||
{
|
||||
bool Active { get; }
|
||||
void End();
|
||||
void OnCallerClear();
|
||||
void Exec(UInt32 eventID, T0 param0, T1 param1, T2 param2);
|
||||
}
|
||||
|
||||
public class ViCallback<T0, T1, T2> : ViCallbackInterface<T0, T1, T2>
|
||||
{
|
||||
public delegate void Callback(UInt32 eventID, T0 param0, T1 param1, T2 param2);
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public bool Active { get { return _node.IsAttach(); } }
|
||||
//
|
||||
public void End()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void OnCallerClear()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void Exec(UInt32 eventID, T0 param0, T1 param1, T2 param2)
|
||||
{
|
||||
ViDebuger.AssertError(_delegate);
|
||||
_delegate(eventID, param0, param1, param2);
|
||||
}
|
||||
internal void Attach(Callback dele, ViRefList2<ViCallbackInterface<T0, T1, T2>> list)
|
||||
{
|
||||
_delegate = dele;
|
||||
_node.Data = this;
|
||||
list.Push(_node);
|
||||
}
|
||||
//
|
||||
ViRefNode2<ViCallbackInterface<T0, T1, T2>> _node = new ViRefNode2<ViCallbackInterface<T0, T1, T2>>();
|
||||
Callback _delegate;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViAsynCallback<T0, T1, T2> : ViAsynDelegateInterface, ViCallbackInterface<T0, T1, T2>
|
||||
{
|
||||
public delegate void Callback(UInt32 eventId, T0 param0, T1 param1, T2 param2);
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public new bool Active { get { return _node.IsAttach(); } }
|
||||
public bool AsynActive { get { return base.Active; } }
|
||||
//
|
||||
public new void End()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
//
|
||||
_asynDele = null;
|
||||
_param0 = default(T0);
|
||||
_param1 = default(T1);
|
||||
_param2 = default(T2);
|
||||
base.End();
|
||||
}
|
||||
public void OnCallerClear()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void Exec()
|
||||
{
|
||||
if (AsynActive)
|
||||
{
|
||||
base.End();
|
||||
_AsynExec();
|
||||
}
|
||||
}
|
||||
public void Exec(UInt32 eventID, T0 param0, T1 param1, T2 param2)
|
||||
{
|
||||
ViDebuger.AssertError(_delegate);
|
||||
_asynDele = _delegate;
|
||||
_eventID = eventID;
|
||||
_param0 = param0;
|
||||
_param1 = param1;
|
||||
_param2 = param2;
|
||||
_AttachAsyn();
|
||||
}
|
||||
public void Invoke(UInt32 eventID, T0 param0, T1 param1, T2 param2, Callback dele)
|
||||
{
|
||||
ViDebuger.AssertError(dele);
|
||||
_delegate = dele;
|
||||
_asynDele = _delegate;
|
||||
_eventID = eventID;
|
||||
_param0 = param0;
|
||||
_param1 = param1;
|
||||
_param2 = param2;
|
||||
_AttachAsyn();
|
||||
}
|
||||
internal override void _AsynExec()
|
||||
{
|
||||
ViDebuger.AssertError(_asynDele);
|
||||
Callback dele = _asynDele;
|
||||
T0 param0 = _param0;
|
||||
T1 param1 = _param1;
|
||||
T2 param2 = _param2;
|
||||
_asynDele = null;
|
||||
_param0 = default(T0);
|
||||
_param1 = default(T1);
|
||||
_param2 = default(T2);
|
||||
dele(_eventID, param0, param1, param2);
|
||||
}
|
||||
internal void Attach(Callback dele, ViRefList2<ViCallbackInterface<T0, T1, T2>> list)
|
||||
{
|
||||
End();
|
||||
//
|
||||
_delegate = dele;
|
||||
_node.Data = this;
|
||||
list.Push(_node);
|
||||
}
|
||||
//
|
||||
ViRefNode2<ViCallbackInterface<T0, T1, T2>> _node = new ViRefNode2<ViCallbackInterface<T0, T1, T2>>();
|
||||
Callback _delegate;
|
||||
Callback _asynDele;
|
||||
UInt32 _eventID;
|
||||
T0 _param0;
|
||||
T1 _param1;
|
||||
T2 _param2;
|
||||
}
|
||||
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViEventAsynList<T0, T1, T2>
|
||||
{
|
||||
public void Invoke(UInt32 eventId, T0 param0, T1 param1, T2 param2)
|
||||
{
|
||||
_eventList.BeginIterator();
|
||||
while (!_eventList.IsEnd())
|
||||
{
|
||||
ViCallbackInterface<T0, T1, T2> callback = _eventList.CurrentNode.Data;
|
||||
ViDebuger.AssertError(callback);
|
||||
_eventList.Next();
|
||||
callback.Exec(eventId, param0, param1, param2);
|
||||
}
|
||||
}
|
||||
public void Attach(ViAsynCallback<T0, T1, T2> node, ViAsynCallback<T0, T1, T2>.Callback dele)
|
||||
{
|
||||
node.Attach(dele, _eventList);
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
_eventList.BeginIterator();
|
||||
while (!_eventList.IsEnd())
|
||||
{
|
||||
ViCallbackInterface<T0, T1, T2> callback = _eventList.CurrentNode.Data;
|
||||
ViDebuger.AssertError(callback);
|
||||
_eventList.Next();
|
||||
callback.OnCallerClear();
|
||||
}
|
||||
ViDebuger.AssertWarning(_eventList.IsEmpty());
|
||||
}
|
||||
//
|
||||
protected ViRefList2<ViCallbackInterface<T0, T1, T2>> _eventList = new ViRefList2<ViCallbackInterface<T0, T1, T2>>();
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViEventList<T0, T1, T2> : ViEventAsynList<T0, T1, T2>
|
||||
{
|
||||
public void Attach(ViCallback<T0, T1, T2> node, ViCallback<T0, T1, T2>.Callback dele)
|
||||
{
|
||||
node.Attach(dele, _eventList);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 979cf5b44441bf9499f79a83a164e716
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,88 @@
|
||||
using System;
|
||||
|
||||
|
||||
public abstract class ViFramEndCallbackInterface : ViDoubleLinkNode1<ViFramEndCallbackInterface>
|
||||
{
|
||||
public static void Update()
|
||||
{
|
||||
_currentList.PushBack(_callbackList);
|
||||
while (_currentList.IsNotEmpty())
|
||||
{
|
||||
ViFramEndCallbackInterface callback = _currentList.GetHead() as ViFramEndCallbackInterface;
|
||||
ViDebuger.AssertError(callback);
|
||||
callback._OnExec();
|
||||
}
|
||||
}
|
||||
public static void Clear()
|
||||
{
|
||||
_callbackList.Clear();
|
||||
_currentList.Clear();
|
||||
}
|
||||
//
|
||||
internal abstract void _OnExec();
|
||||
protected static ViDoubleLink1<ViFramEndCallbackInterface> _callbackList = new ViDoubleLink1<ViFramEndCallbackInterface>();
|
||||
static ViDoubleLink1<ViFramEndCallbackInterface> _currentList = new ViDoubleLink1<ViFramEndCallbackInterface>();
|
||||
}
|
||||
|
||||
public class ViFramEndCallback0 : ViFramEndCallbackInterface
|
||||
{
|
||||
public delegate void Callback();
|
||||
public new bool IsAttach()
|
||||
{
|
||||
return base.IsAttach();
|
||||
}
|
||||
public new void Detach()
|
||||
{
|
||||
_delegate = null;
|
||||
base.Detach();
|
||||
}
|
||||
public void AsynExec(Callback dele)
|
||||
{
|
||||
_delegate = dele;
|
||||
_callbackList.PushBack(this);
|
||||
}
|
||||
internal override void _OnExec()
|
||||
{
|
||||
base.Detach();
|
||||
ViDebuger.AssertError(_delegate);
|
||||
Callback tempDele = _delegate;
|
||||
_delegate = null;
|
||||
tempDele();
|
||||
}
|
||||
//
|
||||
private Callback _delegate;
|
||||
}
|
||||
|
||||
public class ViFramEndCallback1<TParam0> : ViFramEndCallbackInterface
|
||||
{
|
||||
public delegate void Callback(TParam0 param0);
|
||||
public new bool IsAttach()
|
||||
{
|
||||
return base.IsAttach();
|
||||
}
|
||||
public new void Detach()
|
||||
{
|
||||
_delegate = null;
|
||||
_param0 = default(TParam0);
|
||||
base.Detach();
|
||||
}
|
||||
public void AsynExec(Callback dele, TParam0 param0)
|
||||
{
|
||||
_delegate = dele;
|
||||
_param0 = param0;
|
||||
_callbackList.PushBack(this);
|
||||
}
|
||||
internal override void _OnExec()
|
||||
{
|
||||
base.Detach();
|
||||
ViDebuger.AssertError(_delegate);
|
||||
Callback tempDele = _delegate;
|
||||
TParam0 tempParam0 = _param0;
|
||||
_delegate = null;
|
||||
_param0 = default(TParam0);
|
||||
tempDele(tempParam0);
|
||||
}
|
||||
//
|
||||
private TParam0 _param0;
|
||||
private Callback _delegate;
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba6755f8f1dcea14881a8441921a7bb0
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class ViThreadFrameEndCallback
|
||||
{
|
||||
static readonly List<ViDelegateAssisstant.Dele> Update_ExecList = new List<ViDelegateAssisstant.Dele>();
|
||||
public static void Update()
|
||||
{
|
||||
lock (_list)
|
||||
{
|
||||
Update_ExecList.AddRange(_list);
|
||||
_list.Clear();
|
||||
}
|
||||
for (int iter = 0, end = Update_ExecList.Count; iter < end; ++iter)
|
||||
{
|
||||
Update_ExecList[iter].Invoke();
|
||||
}
|
||||
Update_ExecList.Clear();
|
||||
}
|
||||
//
|
||||
public static void Add(ViDelegateAssisstant.Dele callback)
|
||||
{
|
||||
lock (_list)
|
||||
{
|
||||
_list.Add(callback);
|
||||
}
|
||||
}
|
||||
//
|
||||
public static void Del(ViDelegateAssisstant.Dele callback)
|
||||
{
|
||||
lock (_list)
|
||||
{
|
||||
for (int iter = _list.Count - 1; iter >= 0; --iter)
|
||||
{
|
||||
if (_list[iter] == callback)
|
||||
{
|
||||
_list.RemoveAt(iter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
static readonly List<ViDelegateAssisstant.Dele> _list = new List<ViDelegateAssisstant.Dele>();
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71c15c2ab5f153d459fe9ca3373cf76d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
533
Unity/Assets/Plugins/ViSDK/ViGameCommon/Event/ViTupleCallback.cs
Normal file
533
Unity/Assets/Plugins/ViSDK/ViGameCommon/Event/ViTupleCallback.cs
Normal file
@ -0,0 +1,533 @@
|
||||
using System;
|
||||
|
||||
public interface ViTupleCallbackInterface
|
||||
{
|
||||
bool Active { get; }
|
||||
void End();
|
||||
void OnCallerClear();
|
||||
void Exec(UInt32 eventID, ViTupleInterface tuple);
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViTupleCallback : ViTupleCallbackInterface
|
||||
{
|
||||
public delegate void Callback(UInt32 eventID);
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public bool Active { get { return _node.IsAttach(); } }
|
||||
//
|
||||
public void End()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void OnCallerClear()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void Exec(UInt32 eventID, ViTupleInterface tuple)
|
||||
{
|
||||
ViDebuger.AssertError(_delegate);
|
||||
_delegate(eventID);
|
||||
}
|
||||
internal void Attach(Callback dele, ViRefList2<ViTupleCallbackInterface> list)
|
||||
{
|
||||
_delegate = dele;
|
||||
_node.Data = this;
|
||||
list.Push(_node);
|
||||
}
|
||||
//
|
||||
ViRefNode2<ViTupleCallbackInterface> _node = new ViRefNode2<ViTupleCallbackInterface>();
|
||||
Callback _delegate;
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViAsynTupleCallback : ViAsynDelegateInterface, ViTupleCallbackInterface
|
||||
{
|
||||
public delegate void Callback(UInt32 eventID);
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public new bool Active { get { return _node.IsAttach(); } }
|
||||
public bool AsynActive { get { return base.Active; } }
|
||||
//
|
||||
public new void End()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
//
|
||||
_asynDele = null;
|
||||
base.End();
|
||||
}
|
||||
public void OnCallerClear()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void Exec()
|
||||
{
|
||||
if (AsynActive)
|
||||
{
|
||||
base.End();
|
||||
_AsynExec();
|
||||
}
|
||||
}
|
||||
public void Exec(UInt32 eventID, ViTupleInterface tuple)
|
||||
{
|
||||
ViDebuger.AssertError(_delegate);
|
||||
_asynDele = _delegate;
|
||||
_eventID = eventID;
|
||||
_AttachAsyn();
|
||||
}
|
||||
internal override void _AsynExec()
|
||||
{
|
||||
ViDebuger.AssertError(_asynDele);
|
||||
Callback dele = _asynDele;
|
||||
_asynDele = null;
|
||||
dele(_eventID);
|
||||
}
|
||||
internal void Attach(Callback dele, ViRefList2<ViTupleCallbackInterface> list)
|
||||
{
|
||||
End();
|
||||
//
|
||||
_delegate = dele;
|
||||
_node.Data = this;
|
||||
list.Push(_node);
|
||||
}
|
||||
//
|
||||
ViRefNode2<ViTupleCallbackInterface> _node = new ViRefNode2<ViTupleCallbackInterface>();
|
||||
private Callback _delegate;
|
||||
Callback _asynDele;
|
||||
UInt32 _eventID;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViTupleCallback<T0> : ViTupleCallbackInterface
|
||||
{
|
||||
public delegate void Callback(UInt32 eventID, T0 param0);
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public bool Active { get { return _node.IsAttach(); } }
|
||||
//
|
||||
public void End()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void OnCallerClear()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void Exec(UInt32 eventID, ViTupleInterface tuple)
|
||||
{
|
||||
ViTuple<T0> tupleAlias = tuple as ViTuple<T0>;
|
||||
if (tupleAlias != null)
|
||||
{
|
||||
ViDebuger.AssertError(_delegate);
|
||||
_delegate(eventID, tupleAlias._value0);
|
||||
}
|
||||
}
|
||||
internal void Attach(Callback dele, ViRefList2<ViTupleCallbackInterface> list)
|
||||
{
|
||||
_delegate = dele;
|
||||
_node.Data = this;
|
||||
list.Push(_node);
|
||||
}
|
||||
//
|
||||
ViRefNode2<ViTupleCallbackInterface> _node = new ViRefNode2<ViTupleCallbackInterface>();
|
||||
Callback _delegate;
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViAsynTupleCallback<T0> : ViAsynDelegateInterface, ViTupleCallbackInterface
|
||||
{
|
||||
public delegate void Callback(UInt32 eventID, T0 param0);
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public new bool Active { get { return _node.IsAttach(); } }
|
||||
public bool AsynActive { get { return base.Active; } }
|
||||
//
|
||||
public new void End()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
//
|
||||
_asynDele = null;
|
||||
_param0 = default(T0);
|
||||
base.End();
|
||||
}
|
||||
public void OnCallerClear()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void Exec()
|
||||
{
|
||||
if (AsynActive)
|
||||
{
|
||||
base.End();
|
||||
_AsynExec();
|
||||
}
|
||||
}
|
||||
public void Exec(UInt32 eventID, ViTupleInterface tuple)
|
||||
{
|
||||
ViDebuger.AssertError(_delegate);
|
||||
ViTuple<T0> tupleAlias = tuple as ViTuple<T0>;
|
||||
if (tupleAlias != null)
|
||||
{
|
||||
_asynDele = _delegate;
|
||||
_eventID = eventID;
|
||||
_param0 = tupleAlias._value0;
|
||||
_AttachAsyn();
|
||||
}
|
||||
}
|
||||
internal override void _AsynExec()
|
||||
{
|
||||
ViDebuger.AssertError(_asynDele);
|
||||
Callback dele = _asynDele;
|
||||
T0 param0 = _param0;
|
||||
_asynDele = null;
|
||||
_param0 = default(T0);
|
||||
dele(_eventID, param0);
|
||||
}
|
||||
internal void Attach(Callback dele, ViRefList2<ViTupleCallbackInterface> list)
|
||||
{
|
||||
End();
|
||||
//
|
||||
_delegate = dele;
|
||||
_node.Data = this;
|
||||
list.Push(_node);
|
||||
}
|
||||
//
|
||||
ViRefNode2<ViTupleCallbackInterface> _node = new ViRefNode2<ViTupleCallbackInterface>();
|
||||
private Callback _delegate;
|
||||
Callback _asynDele;
|
||||
UInt32 _eventID;
|
||||
T0 _param0;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViTupleCallback<T0, T1> : ViTupleCallbackInterface
|
||||
{
|
||||
public delegate void Callback(UInt32 eventID, T0 param0, T1 param1);
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public bool Active { get { return _node.IsAttach(); } }
|
||||
//
|
||||
public void End()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void OnCallerClear()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void Exec(UInt32 eventID, ViTupleInterface tuple)
|
||||
{
|
||||
ViTuple<T0, T1> tupleAlias = tuple as ViTuple<T0, T1>;
|
||||
if (tupleAlias != null)
|
||||
{
|
||||
ViDebuger.AssertError(_delegate);
|
||||
_delegate(eventID, tupleAlias._value0, tupleAlias._value1);
|
||||
}
|
||||
}
|
||||
internal void Attach(Callback dele, ViRefList2<ViTupleCallbackInterface> list)
|
||||
{
|
||||
_delegate = dele;
|
||||
_node.Data = this;
|
||||
list.Push(_node);
|
||||
}
|
||||
//
|
||||
ViRefNode2<ViTupleCallbackInterface> _node = new ViRefNode2<ViTupleCallbackInterface>();
|
||||
Callback _delegate;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViAsynTupleCallback<T0, T1> : ViAsynDelegateInterface, ViTupleCallbackInterface
|
||||
{
|
||||
public delegate void Callback(UInt32 eventID, T0 param0, T1 param1);
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public new bool Active { get { return _node.IsAttach(); } }
|
||||
public bool AsynActive { get { return base.Active; } }
|
||||
//
|
||||
public new void End()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
//
|
||||
_asynDele = null;
|
||||
_param0 = default(T0);
|
||||
_param1 = default(T1);
|
||||
base.End();
|
||||
}
|
||||
public void OnCallerClear()
|
||||
{
|
||||
_delegate = null;
|
||||
_node.Detach();
|
||||
_node.Data = null;
|
||||
}
|
||||
public void Exec()
|
||||
{
|
||||
if (AsynActive)
|
||||
{
|
||||
base.End();
|
||||
_AsynExec();
|
||||
}
|
||||
}
|
||||
public void Exec(UInt32 eventID, ViTupleInterface tuple)
|
||||
{
|
||||
ViDebuger.AssertError(_delegate);
|
||||
ViTuple<T0, T1> tupleAlias = tuple as ViTuple<T0, T1>;
|
||||
if (tupleAlias != null)
|
||||
{
|
||||
_asynDele = _delegate;
|
||||
_eventID = eventID;
|
||||
_param0 = tupleAlias._value0;
|
||||
_param1 = tupleAlias._value1;
|
||||
_AttachAsyn();
|
||||
}
|
||||
}
|
||||
internal override void _AsynExec()
|
||||
{
|
||||
ViDebuger.AssertError(_asynDele);
|
||||
Callback dele = _asynDele;
|
||||
T0 param0 = _param0;
|
||||
T1 param1 = _param1;
|
||||
_asynDele = null;
|
||||
_param0 = default(T0);
|
||||
_param1 = default(T1);
|
||||
dele(_eventID, param0, param1);
|
||||
}
|
||||
internal void Attach(Callback dele, ViRefList2<ViTupleCallbackInterface> list)
|
||||
{
|
||||
End();
|
||||
//
|
||||
_delegate = dele;
|
||||
_node.Data = this;
|
||||
list.Push(_node);
|
||||
}
|
||||
//
|
||||
ViRefNode2<ViTupleCallbackInterface> _node = new ViRefNode2<ViTupleCallbackInterface>();
|
||||
private Callback _delegate;
|
||||
Callback _asynDele;
|
||||
UInt32 _eventID;
|
||||
T0 _param0;
|
||||
T1 _param1;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViAsynEventTupleList
|
||||
{
|
||||
public void _Invoke(UInt32 eventID, ViTupleInterface tuple)
|
||||
{
|
||||
_eventList.BeginIterator();
|
||||
while (!_eventList.IsEnd())
|
||||
{
|
||||
ViTupleCallbackInterface callback = _eventList.CurrentNode.Data;
|
||||
ViDebuger.AssertError(callback);
|
||||
_eventList.Next();
|
||||
callback.Exec(eventID, tuple);
|
||||
}
|
||||
}
|
||||
public void Invoke(UInt32 eventID)
|
||||
{
|
||||
_Invoke(eventID, null);
|
||||
}
|
||||
public void Invoke<T0>(UInt32 eventID, T0 param0)
|
||||
{
|
||||
ViTuple<T0> tuple = new ViTuple<T0>();
|
||||
tuple._value0 = param0;
|
||||
_Invoke(eventID, tuple);
|
||||
}
|
||||
public void Invoke<T0, T1>(UInt32 eventID, T0 param0, T1 param1)
|
||||
{
|
||||
ViTuple<T0, T1> tuple = new ViTuple<T0, T1>();
|
||||
tuple._value0 = param0;
|
||||
tuple._value1 = param1;
|
||||
_Invoke(eventID, tuple);
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
_eventList.BeginIterator();
|
||||
while (!_eventList.IsEnd())
|
||||
{
|
||||
ViTupleCallbackInterface callback = _eventList.CurrentNode.Data;
|
||||
ViDebuger.AssertError(callback);
|
||||
_eventList.Next();
|
||||
callback.OnCallerClear();
|
||||
}
|
||||
ViDebuger.AssertWarning(_eventList.IsEmpty());
|
||||
}
|
||||
public void Attach(ViAsynTupleCallback node, ViAsynTupleCallback.Callback dele)
|
||||
{
|
||||
node.Attach(dele, _eventList);
|
||||
}
|
||||
public void Attach<T0>(ViAsynTupleCallback<T0> node, ViAsynTupleCallback<T0>.Callback dele)
|
||||
{
|
||||
node.Attach(dele, _eventList);
|
||||
}
|
||||
public void Attach<T0, T1>(ViAsynTupleCallback<T0, T1> node, ViAsynTupleCallback<T0, T1>.Callback dele)
|
||||
{
|
||||
node.Attach(dele, _eventList);
|
||||
}
|
||||
//
|
||||
protected ViRefList2<ViTupleCallbackInterface> _eventList = new ViRefList2<ViTupleCallbackInterface>();
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViEventTupleList : ViAsynEventTupleList
|
||||
{
|
||||
public void Attach(ViTupleCallback node, ViTupleCallback.Callback dele)
|
||||
{
|
||||
node.Attach(dele, _eventList);
|
||||
}
|
||||
public void Attach<T0>(ViTupleCallback<T0> node, ViTupleCallback<T0>.Callback dele)
|
||||
{
|
||||
node.Attach(dele, _eventList);
|
||||
}
|
||||
public void Attach<T0, T1>(ViTupleCallback<T0, T1> node, ViTupleCallback<T0, T1>.Callback dele)
|
||||
{
|
||||
node.Attach(dele, _eventList);
|
||||
}
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViAsynTupleCaller
|
||||
{
|
||||
public void SetSize(UInt32 size)
|
||||
{
|
||||
_eventList.Resize(size);
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
for (UInt32 idx = 0; idx < _eventList.Size; ++idx)
|
||||
{
|
||||
_eventList.Get(idx).Clear();
|
||||
}
|
||||
_eventList.Clear();
|
||||
}
|
||||
public void _Invoke(UInt32 eventId, ViTupleInterface tuple)
|
||||
{
|
||||
ViEventTupleList eventList = _eventList.Get(eventId);
|
||||
if (eventList == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
eventList._Invoke(eventId, tuple);
|
||||
}
|
||||
public void Invoke(UInt32 eventId)
|
||||
{
|
||||
_Invoke(eventId, null);
|
||||
}
|
||||
public void Invoke<T0>(UInt32 eventId, T0 param0)
|
||||
{
|
||||
ViTuple<T0> tuple = new ViTuple<T0>();
|
||||
tuple._value0 = param0;
|
||||
_Invoke(eventId, tuple);
|
||||
}
|
||||
public void Invoke<T0, T1>(UInt32 eventId, T0 param0, T1 param1)
|
||||
{
|
||||
ViTuple<T0, T1> tuple = new ViTuple<T0, T1>();
|
||||
tuple._value0 = param0;
|
||||
tuple._value1 = param1;
|
||||
_Invoke(eventId, tuple);
|
||||
}
|
||||
public void Attach(UInt32 eventId, ViAsynTupleCallback node, ViAsynTupleCallback.Callback dele)
|
||||
{
|
||||
ViEventTupleList eventList = _eventList.Get(eventId);
|
||||
if (eventList == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
eventList.Attach(node, dele);
|
||||
}
|
||||
public void Attach<T0>(UInt32 eventId, ViAsynTupleCallback<T0> node, ViAsynTupleCallback<T0>.Callback dele)
|
||||
{
|
||||
ViEventTupleList eventList = _eventList.Get(eventId);
|
||||
if (eventList == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
eventList.Attach(node, dele);
|
||||
}
|
||||
public void Attach<T0, T1>(UInt32 eventId, ViAsynTupleCallback<T0, T1> node, ViAsynTupleCallback<T0, T1>.Callback dele)
|
||||
{
|
||||
ViEventTupleList eventList = _eventList.Get(eventId);
|
||||
if (eventList == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
eventList.Attach(node, dele);
|
||||
}
|
||||
//
|
||||
protected ViSimpleVector<ViEventTupleList> _eventList = new ViSimpleVector<ViEventTupleList>();
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViTupleCaller : ViAsynTupleCaller
|
||||
{
|
||||
public void Attach(UInt32 eventId, ViTupleCallback node, ViTupleCallback.Callback dele)
|
||||
{
|
||||
ViEventTupleList eventList = _eventList.Get(eventId);
|
||||
if (eventList == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
eventList.Attach(node, dele);
|
||||
}
|
||||
public void Attach<T0>(UInt32 eventId, ViTupleCallback<T0> node, ViTupleCallback<T0>.Callback dele)
|
||||
{
|
||||
ViEventTupleList eventList = _eventList.Get(eventId);
|
||||
if (eventList == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
eventList.Attach(node, dele);
|
||||
}
|
||||
public void Attach<T0, T1>(UInt32 eventId, ViTupleCallback<T0, T1> node, ViTupleCallback<T0, T1>.Callback dele)
|
||||
{
|
||||
ViEventTupleList eventList = _eventList.Get(eventId);
|
||||
if (eventList == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
eventList.Attach(node, dele);
|
||||
}
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class Demo_TupleCallback
|
||||
{
|
||||
#pragma warning disable 0219
|
||||
class Listener
|
||||
{
|
||||
public void Func(UInt32 eventID, int i) { }
|
||||
public void Func(UInt32 eventID, int i, float f) { }
|
||||
public ViTupleCallback<int> _node1a = new ViTupleCallback<int>();
|
||||
public ViAsynTupleCallback<int> _node1b = new ViAsynTupleCallback<int>();
|
||||
public ViTupleCallback<int, float> _node2a = new ViTupleCallback<int, float>();
|
||||
public ViAsynTupleCallback<int, float> _node2b = new ViAsynTupleCallback<int, float>();
|
||||
}
|
||||
|
||||
public static void Test()
|
||||
{
|
||||
Listener listener = new Listener();
|
||||
ViTupleCaller caller = new ViTupleCaller();
|
||||
caller.SetSize(10);
|
||||
caller.Attach(0, listener._node1a, listener.Func);
|
||||
caller.Attach(0, listener._node1b, listener.Func);
|
||||
caller.Attach(0, listener._node2a, listener.Func);
|
||||
caller.Attach(0, listener._node2b, listener.Func);
|
||||
int i = 3;
|
||||
float f = 6.0f;
|
||||
caller.Invoke(0, i, f);
|
||||
ViAsynDelegateInterface.Update();
|
||||
}
|
||||
#pragma warning restore 0219
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f16d4ff0dedf16345a453d4c1eb518a6
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Unity/Assets/Plugins/ViSDK/ViGameCommon/Log.meta
Normal file
9
Unity/Assets/Plugins/ViSDK/ViGameCommon/Log.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd2c08380b1fb2f40bd54fb5f136e480
|
||||
folderAsset: yes
|
||||
timeCreated: 1453717662
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
254
Unity/Assets/Plugins/ViSDK/ViGameCommon/Log/ViLogEx.cs
Normal file
254
Unity/Assets/Plugins/ViSDK/ViGameCommon/Log/ViLogEx.cs
Normal file
@ -0,0 +1,254 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViLogInterface
|
||||
{
|
||||
public delegate void OnPrintValueCallback(ViLogLevel logType, ViTupleInterface tuple);
|
||||
public delegate void OnPrintStringCallback(ViLogLevel logType, string msg);
|
||||
public static OnPrintValueCallback PrintValueCallback { get; set; }
|
||||
public static OnPrintStringCallback PrintStringCallback { get; set; }
|
||||
//
|
||||
static UInt32 Register(string name)
|
||||
{
|
||||
UInt32 value = 0;
|
||||
if (_logDictionary.TryGetValue(name, out value))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
value = (UInt32)_logDictionary.Count + 1;
|
||||
_logDictionary.Add(name, value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
static Dictionary<string, UInt32> _logDictionary = new Dictionary<string, UInt32>();
|
||||
//
|
||||
public ViLogInterface(ViLogLevel type, string description)
|
||||
{
|
||||
_type = type;
|
||||
_name = description;
|
||||
_description = description.Split(new char[] { '&' }, StringSplitOptions.None);
|
||||
_idx = Register(_name);
|
||||
}
|
||||
public ViLogInterface(string description)
|
||||
: this(ViLogLevel.OK, description)
|
||||
{
|
||||
|
||||
}
|
||||
//
|
||||
static ViStringBuilder _printBuilder = new ViStringBuilder(1024);
|
||||
public void Print(ViTupleInterface tuple)
|
||||
{
|
||||
if (_type < ViDebuger.LogLevel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_printBuilder.Clear();
|
||||
UInt32 idx = 0;
|
||||
for (; idx < (UInt32)Description.Length; ++idx)
|
||||
{
|
||||
_printBuilder.Add(Description[idx]);
|
||||
Object value = tuple.Value(idx);
|
||||
if (value != null)
|
||||
{
|
||||
_printBuilder.Add("(");
|
||||
_printBuilder.Add(tuple.Value(idx).ToString());
|
||||
_printBuilder.Add(")");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Console.Write("(参数不足)");
|
||||
}
|
||||
}
|
||||
for (; idx < tuple.Size; ++idx)
|
||||
{
|
||||
Object value = tuple.Value(idx);
|
||||
ViDebuger.AssertError(value);
|
||||
_printBuilder.Add("(");
|
||||
_printBuilder.Add(tuple.Value(idx).ToString());
|
||||
_printBuilder.Add(")");
|
||||
}
|
||||
_printBuilder.Add("\n");
|
||||
Print(_printBuilder.Value, tuple);
|
||||
}
|
||||
public void Print(string msg, ViTupleInterface tuple)
|
||||
{
|
||||
if (_type < ViDebuger.LogLevel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Console.WriteLine(msg);
|
||||
//System.Diagnostics.Debug.Write(msg);
|
||||
//System.Diagnostics.Trace.Write(msg);
|
||||
if (PrintValueCallback != null)
|
||||
{
|
||||
PrintValueCallback(_type, tuple);
|
||||
}
|
||||
if (PrintStringCallback != null)
|
||||
{
|
||||
PrintStringCallback(_type, msg);
|
||||
}
|
||||
}
|
||||
//
|
||||
public UInt32 Idx { get { return _idx; } }
|
||||
public ViLogLevel Type { get { return _type; } }
|
||||
public string Name { get { return _name; } }
|
||||
public string[] Description { get { return _description; } }
|
||||
//
|
||||
UInt32 _idx;
|
||||
ViLogLevel _type;
|
||||
string _name;
|
||||
string[] _description;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViLogEx : ViLogInterface
|
||||
{
|
||||
public ViLogEx(ViLogLevel type, string description) : base(type, description) { }
|
||||
public ViLogEx(string description) : base(description) { }
|
||||
//
|
||||
public void Note()
|
||||
{
|
||||
ViTuple tuple = new ViTuple();
|
||||
Print(Name, tuple);
|
||||
}
|
||||
public void Note<T0>(T0 param0)
|
||||
{
|
||||
ViTuple<T0> tuple = new ViTuple<T0>();
|
||||
tuple.Value0 = param0;
|
||||
Print(tuple);
|
||||
}
|
||||
public void Note<T0, T1>(T0 param0, T1 param1)
|
||||
{
|
||||
ViTuple<T0, T1> tuple = new ViTuple<T0, T1>();
|
||||
tuple.Value0 = param0;
|
||||
tuple.Value1 = param1;
|
||||
Print(tuple);
|
||||
}
|
||||
public void Note<T0, T1, T2>(T0 param0, T1 param1, T2 param2)
|
||||
{
|
||||
ViTuple<T0, T1, T2> tuple = new ViTuple<T0, T1, T2>();
|
||||
tuple.Value0 = param0;
|
||||
tuple.Value1 = param1;
|
||||
tuple.Value2 = param2;
|
||||
Print(tuple);
|
||||
}
|
||||
public void Note<T0, T1, T2, T3>(T0 param0, T1 param1, T2 param2, T3 param3)
|
||||
{
|
||||
ViTuple<T0, T1, T2, T3> tuple = new ViTuple<T0, T1, T2, T3>();
|
||||
tuple.Value0 = param0;
|
||||
tuple.Value1 = param1;
|
||||
tuple.Value2 = param2;
|
||||
tuple.Value3 = param3;
|
||||
Print(tuple);
|
||||
}
|
||||
public void Note<T0, T1, T2, T3, T4>(T0 param0, T1 param1, T2 param2, T3 param3, T4 param4)
|
||||
{
|
||||
ViTuple<T0, T1, T2, T3, T4> tuple = new ViTuple<T0, T1, T2, T3, T4>();
|
||||
tuple.Value0 = param0;
|
||||
tuple.Value1 = param1;
|
||||
tuple.Value2 = param2;
|
||||
tuple.Value3 = param3;
|
||||
tuple.Value4 = param4;
|
||||
Print(tuple);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViLogEx<T0> : ViLogInterface
|
||||
{
|
||||
public ViLogEx(ViLogLevel type, string description) : base(type, description) { }
|
||||
public ViLogEx(string description) : base(description) { }
|
||||
//
|
||||
public void Note(T0 param0)
|
||||
{
|
||||
ViTuple<T0> tuple = new ViTuple<T0>();
|
||||
tuple.Value0 = param0;
|
||||
Print(tuple);
|
||||
}
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViLogEx<T0, T1> : ViLogInterface
|
||||
{
|
||||
public ViLogEx(ViLogLevel type, string description) : base(type, description) { }
|
||||
public ViLogEx(string description) : base(description) { }
|
||||
//
|
||||
public void Note(T0 param0, T1 param1)
|
||||
{
|
||||
ViTuple<T0, T1> tuple = new ViTuple<T0, T1>();
|
||||
tuple.Value0 = param0;
|
||||
tuple.Value1 = param1;
|
||||
Print(tuple);
|
||||
}
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViLogEx<T0, T1, T2> : ViLogInterface
|
||||
{
|
||||
public ViLogEx(ViLogLevel type, string description) : base(type, description) { }
|
||||
public ViLogEx(string description) : base(description) { }
|
||||
//
|
||||
public void Note(T0 param0, T1 param1, T2 param2)
|
||||
{
|
||||
ViTuple<T0, T1, T2> tuple = new ViTuple<T0, T1, T2>();
|
||||
tuple.Value0 = param0;
|
||||
tuple.Value1 = param1;
|
||||
tuple.Value2 = param2;
|
||||
Print(tuple);
|
||||
}
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViLogEx<T0, T1, T2, T3> : ViLogInterface
|
||||
{
|
||||
public ViLogEx(ViLogLevel type, string description) : base(type, description) { }
|
||||
public ViLogEx(string description) : base(description) { }
|
||||
//
|
||||
public void Note(T0 param0, T1 param1, T2 param2, T3 param3)
|
||||
{
|
||||
ViTuple<T0, T1, T2, T3> tuple = new ViTuple<T0, T1, T2, T3>();
|
||||
tuple.Value0 = param0;
|
||||
tuple.Value1 = param1;
|
||||
tuple.Value2 = param2;
|
||||
tuple.Value3 = param3;
|
||||
Print(tuple);
|
||||
}
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public class ViLogEx<T0, T1, T2, T3, T4> : ViLogInterface
|
||||
{
|
||||
public ViLogEx(ViLogLevel type, string description) : base(type, description) { }
|
||||
public ViLogEx(string description) : base(description) { }
|
||||
//
|
||||
public void Note(T0 param0, T1 param1, T2 param2, T3 param3, T4 param4)
|
||||
{
|
||||
ViTuple<T0, T1, T2, T3, T4> tuple = new ViTuple<T0, T1, T2, T3, T4>();
|
||||
tuple.Value0 = param0;
|
||||
tuple.Value1 = param1;
|
||||
tuple.Value2 = param2;
|
||||
tuple.Value3 = param3;
|
||||
tuple.Value4 = param4;
|
||||
Print(tuple);
|
||||
}
|
||||
}
|
||||
|
||||
public class Demo_LogEx
|
||||
{
|
||||
#pragma warning disable 0219
|
||||
public static ViLogEx _log0 = new ViLogEx("&+&=&");
|
||||
public static ViLogEx<int, int, int> _log1 = new ViLogEx<int, int, int>("&-&=&");
|
||||
|
||||
public static void Test()
|
||||
{
|
||||
_log0.Note(1, 2, 3);
|
||||
_log1.Note(1, 2, -1);
|
||||
}
|
||||
#pragma warning restore 0219
|
||||
}
|
||||
|
||||
|
||||
12
Unity/Assets/Plugins/ViSDK/ViGameCommon/Log/ViLogEx.cs.meta
Normal file
12
Unity/Assets/Plugins/ViSDK/ViGameCommon/Log/ViLogEx.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 745efab48e6d1644f81f9867123b0960
|
||||
timeCreated: 1453717662
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Unity/Assets/Plugins/ViSDK/ViGameCommon/Tick.meta
Normal file
9
Unity/Assets/Plugins/ViSDK/ViGameCommon/Tick.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8d071eb332be47942b2eb8e62f20f8ce
|
||||
folderAsset: yes
|
||||
timeCreated: 1453717661
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
86
Unity/Assets/Plugins/ViSDK/ViGameCommon/Tick/ViLodTick.cs
Normal file
86
Unity/Assets/Plugins/ViSDK/ViGameCommon/Tick/ViLodTick.cs
Normal file
@ -0,0 +1,86 @@
|
||||
using System;
|
||||
|
||||
|
||||
|
||||
public class ViLodTickNode : ViRefNode1<ViLodTickNode>
|
||||
{
|
||||
//+----------------------------------------------------------------------------------------------------------------
|
||||
static public void Update(float deltaTime)
|
||||
{
|
||||
_tickList.BeginIterator();
|
||||
while (!_tickList.IsEnd())
|
||||
{
|
||||
ViLodTickNode tickNode = _tickList.CurrentNode as ViLodTickNode;
|
||||
ViDebuger.AssertError(tickNode);
|
||||
_tickList.Next();
|
||||
tickNode.Exec(deltaTime);
|
||||
}
|
||||
}
|
||||
static private ViRefList1<ViLodTickNode> _tickList = new ViRefList1<ViLodTickNode>();
|
||||
|
||||
//+----------------------------------------------------------------------------------------------------------------
|
||||
public delegate void Callback(float deltaTime);
|
||||
|
||||
public float AccumulateTime { get { return _accumulateTime; } }
|
||||
|
||||
public void SetSpan(float span)
|
||||
{
|
||||
_span = span;
|
||||
}
|
||||
public void ClearAccumulateTime()
|
||||
{
|
||||
_accumulateTime = 0.0f;
|
||||
}
|
||||
public new bool IsAttach()
|
||||
{
|
||||
return base.IsAttach();
|
||||
}
|
||||
public void Attach(Callback dele)
|
||||
{
|
||||
_delegate = dele;
|
||||
_tickList.Push(this);
|
||||
}
|
||||
public new void Detach()
|
||||
{
|
||||
_delegate = null;
|
||||
_accumulateTime = 0.0f;
|
||||
base.Detach();
|
||||
}
|
||||
//
|
||||
private void Exec(float deltaTime)
|
||||
{
|
||||
_accumulateTime += deltaTime;
|
||||
if (_accumulateTime >= _span)
|
||||
{
|
||||
_accumulateTime -= _span;
|
||||
_delegate(_span);
|
||||
}
|
||||
}
|
||||
private Callback _delegate;
|
||||
private float _span;
|
||||
private float _accumulateTime;
|
||||
}
|
||||
|
||||
public class Demo_LodTickNode
|
||||
{
|
||||
#pragma warning disable 0219
|
||||
public class Listener
|
||||
{
|
||||
public void Func(float deltaTime)
|
||||
{
|
||||
Console.Write("Func");
|
||||
Console.WriteLine(deltaTime);
|
||||
}
|
||||
public ViLodTickNode _node = new ViLodTickNode();
|
||||
}
|
||||
|
||||
public static void Test()
|
||||
{
|
||||
Listener listener = new Listener();
|
||||
listener._node.Attach(listener.Func);
|
||||
listener._node.SetSpan(1.0f);
|
||||
ViLodTickNode.Update(1.1f);
|
||||
ViLodTickNode.Update(0.1f);
|
||||
}
|
||||
#pragma warning restore 0219
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d96cad11b334d3b4eb2921d66406a12c
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Unity/Assets/Plugins/ViSDK/ViGameCommon/Tick/ViTick.cs
Normal file
39
Unity/Assets/Plugins/ViSDK/ViGameCommon/Tick/ViTick.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
|
||||
|
||||
|
||||
public class ViTickNode : ViRefNode1<ViTickNode>
|
||||
{
|
||||
//+----------------------------------------------------------------------------------------------------------------
|
||||
static public void Update(float deltaTime)
|
||||
{
|
||||
_tickList.BeginIterator();
|
||||
while (!_tickList.IsEnd())
|
||||
{
|
||||
ViTickNode tickNode = _tickList.CurrentNode as ViTickNode;
|
||||
ViDebuger.AssertError(tickNode);
|
||||
_tickList.Next();
|
||||
tickNode._delegate(deltaTime);
|
||||
}
|
||||
}
|
||||
static private ViRefList1<ViTickNode> _tickList = new ViRefList1<ViTickNode>();
|
||||
|
||||
//+----------------------------------------------------------------------------------------------------------------
|
||||
public delegate void Callback(float deltaTime);
|
||||
public new bool IsAttach()
|
||||
{
|
||||
return base.IsAttach();
|
||||
}
|
||||
public void Attach(Callback dele)
|
||||
{
|
||||
_delegate = dele;
|
||||
_tickList.Push(this);
|
||||
}
|
||||
public new void Detach()
|
||||
{
|
||||
_delegate = null;
|
||||
base.Detach();
|
||||
}
|
||||
//
|
||||
private Callback _delegate;
|
||||
}
|
||||
12
Unity/Assets/Plugins/ViSDK/ViGameCommon/Tick/ViTick.cs.meta
Normal file
12
Unity/Assets/Plugins/ViSDK/ViGameCommon/Tick/ViTick.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a467c61174c928b47a7f78bce2e2b655
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Unity/Assets/Plugins/ViSDK/ViGameCommon/Time.meta
Normal file
9
Unity/Assets/Plugins/ViSDK/ViGameCommon/Time.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1cc0bca6ca1c4ac42804046780f6e2da
|
||||
folderAsset: yes
|
||||
timeCreated: 1453717661
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
314
Unity/Assets/Plugins/ViSDK/ViGameCommon/Time/ViTimeNodeEx.cs
Normal file
314
Unity/Assets/Plugins/ViSDK/ViGameCommon/Time/ViTimeNodeEx.cs
Normal file
@ -0,0 +1,314 @@
|
||||
using System;
|
||||
|
||||
|
||||
|
||||
using ViTime64 = System.Int64;
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViTimeNode1 : ViTimeNodeInterface
|
||||
{
|
||||
public delegate void Callback(ViTimeNodeInterface node);
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public new void Detach()
|
||||
{
|
||||
_delegate = null;
|
||||
_execTime = 0;
|
||||
base.Detach();
|
||||
}
|
||||
//
|
||||
internal void _SetDelegate(Callback dele)
|
||||
{
|
||||
_delegate = dele;
|
||||
}
|
||||
internal override void _Exce(ViTimer timer)
|
||||
{
|
||||
Callback dele = _delegate;
|
||||
_delegate = null;
|
||||
_execTime = 0;
|
||||
dele(this);
|
||||
}
|
||||
private Callback _delegate;
|
||||
}
|
||||
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViTimeNodeEx1<T> : ViTimeNodeInterface
|
||||
{
|
||||
public delegate void Callback(ViTimeNodeInterface node, T param);
|
||||
//
|
||||
public Callback Delegate { get { return _delegate; } }
|
||||
public T Value
|
||||
{
|
||||
get { return _param; }
|
||||
set { _param = value; }
|
||||
}
|
||||
//
|
||||
public new void Detach()
|
||||
{
|
||||
_delegate = null;
|
||||
_execTime = 0;
|
||||
_param = default(T);
|
||||
base.Detach();
|
||||
}
|
||||
public T _param;
|
||||
//
|
||||
internal override void _Exce(ViTimer timer)
|
||||
{
|
||||
Callback dele = _delegate;
|
||||
_delegate = null;
|
||||
T param = _param;
|
||||
_param = default(T);
|
||||
_execTime = 0;
|
||||
dele(this, param);
|
||||
}
|
||||
internal void _SetDelegate(Callback dele)
|
||||
{
|
||||
_delegate = dele;
|
||||
}
|
||||
//
|
||||
private Callback _delegate;
|
||||
}
|
||||
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViTimeNode2 : ViTimeNodeInterface
|
||||
{
|
||||
public delegate void Callback(ViTimeNodeInterface node);
|
||||
//
|
||||
public Callback Delegate
|
||||
{
|
||||
get { return _delegate; }
|
||||
set { _delegate = value; }
|
||||
}
|
||||
public UInt32 ReserveCnt { get { return _reserveCnt; } }
|
||||
public UInt32 Span { get { return _span; } }
|
||||
//
|
||||
public void Start(ViTimer timer, UInt32 cnt, UInt32 span)
|
||||
{
|
||||
if (cnt > 0)
|
||||
{
|
||||
_reserveCnt = cnt - 1;
|
||||
_span = span;
|
||||
SetTime(timer.Time + _span);
|
||||
timer.Add(this);
|
||||
}
|
||||
}
|
||||
public new bool GetReserveDuration(ViTimer timer, ref ViTime64 reserveTime)
|
||||
{
|
||||
if (base.GetReserveDuration(timer, ref reserveTime))
|
||||
{
|
||||
ViDebuger.AssertError(reserveTime > 0);
|
||||
reserveTime += _span * _reserveCnt;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
public void SetReserveTime(ViTimer timer, UInt32 span, ViTime64 reserveTime)
|
||||
{
|
||||
if (span != 0)
|
||||
{
|
||||
_span = span;
|
||||
ViTime64 reserveTimeMod = (reserveTime > 0) ? (reserveTime - 1) : 0;
|
||||
_reserveCnt = (UInt32)(reserveTimeMod / _span);
|
||||
UInt32 reserveSpan = (UInt32)(reserveTimeMod % _span + 1);
|
||||
SetTime(timer.Time + (Int64)reserveSpan);
|
||||
timer.Add(this);
|
||||
}
|
||||
}
|
||||
public new void Detach()
|
||||
{
|
||||
_delegate = null;
|
||||
_span = 0;
|
||||
_reserveCnt = 0;
|
||||
base.Detach();
|
||||
}
|
||||
//
|
||||
internal override void _Exce(ViTimer timer)
|
||||
{
|
||||
if (_reserveCnt > 0)
|
||||
{
|
||||
--_reserveCnt;
|
||||
_delegate(this);
|
||||
SetTime(timer.Time + _span);
|
||||
timer.Add(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
Callback dele = _delegate;
|
||||
_delegate = null;
|
||||
dele(this);
|
||||
_execTime = 0;
|
||||
_span = 0;
|
||||
}
|
||||
}
|
||||
//
|
||||
private UInt32 _span;
|
||||
private UInt32 _reserveCnt;
|
||||
private Callback _delegate;
|
||||
}
|
||||
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViTimeNode3 : ViTimeNodeInterface
|
||||
{
|
||||
public delegate void Callback(ViTimeNodeInterface node);
|
||||
//
|
||||
public Callback TickDelegate
|
||||
{
|
||||
get { return _tickDelegate; }
|
||||
set { _tickDelegate = value; }
|
||||
}
|
||||
public Callback EndDelegate
|
||||
{
|
||||
get { return _endDelegate; }
|
||||
set { _endDelegate = value; }
|
||||
}
|
||||
public UInt32 ReserveCnt { get { return _reserveCnt; } }
|
||||
public UInt32 Span { get { return _span; } }
|
||||
//
|
||||
public void Start(ViTimer timer, UInt32 cnt, UInt32 span)
|
||||
{
|
||||
if (cnt > 0)
|
||||
{
|
||||
_reserveCnt = cnt - 1;
|
||||
_span = span;
|
||||
SetTime(timer.Time + _span);
|
||||
timer.Add(this);
|
||||
}
|
||||
}
|
||||
internal override void _Exce(ViTimer timer)
|
||||
{
|
||||
if (_reserveCnt == 0)
|
||||
{
|
||||
Callback dele = _endDelegate;
|
||||
_tickDelegate = null;
|
||||
_endDelegate = null;
|
||||
dele(this);
|
||||
//
|
||||
_execTime = 0;
|
||||
_span = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_tickDelegate(this);
|
||||
--_reserveCnt;
|
||||
SetTime(timer.Time + _span);
|
||||
timer.Add(this);
|
||||
}
|
||||
}
|
||||
public new bool GetReserveDuration(ViTimer timer, ref ViTime64 reserveTime)
|
||||
{
|
||||
if (base.GetReserveDuration(timer, ref reserveTime))
|
||||
{
|
||||
ViDebuger.AssertError(reserveTime > 0);
|
||||
reserveTime += (Int64)_span * _reserveCnt;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
public void SetReserveTime(ViTimer timer, UInt32 span, ViTime64 reserveTime)
|
||||
{
|
||||
if (span != 0)
|
||||
{
|
||||
_span = span;
|
||||
ViTime64 reserveTimeMod = (reserveTime > 0) ? (reserveTime - 1) : 0;
|
||||
_reserveCnt = (UInt32)(reserveTimeMod / _span);
|
||||
UInt32 reserveSpan = (UInt32)(reserveTimeMod % _span + 1);
|
||||
SetTime(timer.Time + reserveSpan);
|
||||
timer.Add(this);
|
||||
}
|
||||
}
|
||||
public new void Detach()
|
||||
{
|
||||
_tickDelegate = null;
|
||||
_endDelegate = null;
|
||||
_execTime = 0;
|
||||
_span = 0;
|
||||
_reserveCnt = 0;
|
||||
base.Detach();
|
||||
}
|
||||
//
|
||||
private UInt32 _span;
|
||||
private UInt32 _reserveCnt;
|
||||
private Callback _tickDelegate;
|
||||
private Callback _endDelegate;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViTimeNode4 : ViTimeNodeInterface
|
||||
{
|
||||
public delegate void Callback(ViTimeNodeInterface node);
|
||||
//
|
||||
public Callback Delegate
|
||||
{
|
||||
get { return _delegate; }
|
||||
set { _delegate = value; }
|
||||
}
|
||||
public UInt32 Span { get { return _span; } }
|
||||
//
|
||||
public void Start(ViTimer timer, UInt32 span, Callback callback)
|
||||
{
|
||||
_span = span;
|
||||
_delegate = callback;
|
||||
SetTime(timer.Time + _span);
|
||||
timer.Add(this);
|
||||
}
|
||||
public new void Detach()
|
||||
{
|
||||
_delegate = null;
|
||||
_span = 0;
|
||||
base.Detach();
|
||||
}
|
||||
//
|
||||
internal override void _Exce(ViTimer timer)
|
||||
{
|
||||
SetTime(timer.Time + _span);
|
||||
timer.Add(this);
|
||||
//
|
||||
if (_delegate != null)
|
||||
{
|
||||
_delegate(this);
|
||||
}
|
||||
}
|
||||
//
|
||||
private UInt32 _span;
|
||||
private Callback _delegate;
|
||||
}
|
||||
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class Demo_TimeNode
|
||||
{
|
||||
#pragma warning disable 0219
|
||||
public class Listener
|
||||
{
|
||||
public void Func(ViTimeNodeInterface node)
|
||||
{
|
||||
|
||||
}
|
||||
public ViTimeNode1 _node = new ViTimeNode1();
|
||||
}
|
||||
|
||||
public static void Test()
|
||||
{
|
||||
ViTimer timer = new ViTimer();
|
||||
Listener listener = new Listener();
|
||||
timer.Start(0, 10, 10, 10);
|
||||
listener._node.SetTime(10);
|
||||
listener._node._SetDelegate(listener.Func);
|
||||
timer.Add(listener._node);
|
||||
timer.Update(9);
|
||||
timer.Update(11);
|
||||
listener._node.Detach();
|
||||
timer.End();
|
||||
}
|
||||
#pragma warning restore 0219
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 940b8284cf3aabb49a44b56292bd131b
|
||||
timeCreated: 1453717662
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
302
Unity/Assets/Plugins/ViSDK/ViGameCommon/Time/ViTimer.cs
Normal file
302
Unity/Assets/Plugins/ViSDK/ViGameCommon/Time/ViTimer.cs
Normal file
@ -0,0 +1,302 @@
|
||||
using System;
|
||||
|
||||
|
||||
|
||||
using ViTime64 = System.Int64;
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public abstract class ViTimeNodeInterface : ViDoubleLinkNode1<ViTimeNodeInterface>
|
||||
{
|
||||
public ViTime64 Time
|
||||
{
|
||||
get { return _execTime; }
|
||||
}
|
||||
//
|
||||
public new bool IsAttach() { return base.IsAttach(); }
|
||||
public void SetTime(ViTime64 time) { _execTime = time; }
|
||||
public ViTime64 GetReserveDuration(ViTimer timer)
|
||||
{
|
||||
if (base.IsAttach())
|
||||
{
|
||||
return (_execTime > timer.Time) ? (_execTime - timer.Time) : 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public bool GetReserveDuration(ViTimer timer, ref ViTime64 reserveTime)
|
||||
{
|
||||
if (base.IsAttach())
|
||||
{
|
||||
reserveTime = (_execTime > timer.Time) ? (_execTime - timer.Time) : 1;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
reserveTime = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool Exec(ViTimer timer)
|
||||
{
|
||||
if (IsAttach())
|
||||
{
|
||||
Detach();
|
||||
_Exce(timer);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal abstract void _Exce(ViTimer timer);
|
||||
//
|
||||
protected ViTime64 _execTime;
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
internal class TimeRoll
|
||||
{
|
||||
public UInt32 Span { get { return _span; } }
|
||||
public ViTime64 TimeInf { get { return _timeInf; } }
|
||||
public ViTime64 TimeISup { get { return _timeSup; } }
|
||||
//
|
||||
public void Init(ViTime64 startTime, UInt32 rollSize, UInt32 span)
|
||||
{
|
||||
ViDebuger.AssertError(rollSize != 0);
|
||||
_timeListArray.Resize(rollSize);
|
||||
_span = span;
|
||||
_timeInf = startTime;
|
||||
_timeSup = startTime + span * rollSize;
|
||||
}
|
||||
public bool InRange(ViTime64 time)
|
||||
{
|
||||
return (_timeInf <= time && time < _timeSup);
|
||||
}
|
||||
public bool IsRoll()
|
||||
{
|
||||
return _idx == 0;
|
||||
}
|
||||
public void ResetTime(ViTime64 deltaTime)
|
||||
{
|
||||
for (UInt32 idx = 0; idx < _timeListArray.Size; ++idx)
|
||||
{
|
||||
ResetTime(_timeListArray.Get(idx), deltaTime);
|
||||
}
|
||||
}
|
||||
public static void ResetTime(ViDoubleLink1<ViTimeNodeInterface> list, ViTime64 deltaTime)
|
||||
{
|
||||
ViDoubleLinkNode1<ViTimeNodeInterface> iter = list.GetHead();
|
||||
while (!list.IsEnd(iter))
|
||||
{
|
||||
ViTimeNodeInterface iterNode = iter as ViTimeNodeInterface;
|
||||
ViDebuger.AssertError(iterNode);
|
||||
ViDoubleLink1<ViTimeNodeInterface>.Next(ref iter);
|
||||
//
|
||||
iterNode.SetTime(iterNode.Time + deltaTime);
|
||||
}
|
||||
}
|
||||
public void Add(ViTimeNodeInterface node)
|
||||
{
|
||||
ViTime64 time = node.Time;
|
||||
ViDebuger.AssertError(_timeInf <= time && time < _timeSup);
|
||||
UInt32 slot = _idx;
|
||||
if (time > _timeInf)
|
||||
{
|
||||
UInt32 deltaSlot = (UInt32)((time - _timeInf) / _span);
|
||||
slot = deltaSlot + _idx;
|
||||
ViDebuger.AssertError(deltaSlot < _timeListArray.Size);
|
||||
if (slot >= _timeListArray.Size)
|
||||
{
|
||||
slot -= _timeListArray.Size;
|
||||
}
|
||||
}
|
||||
ViDebuger.AssertError(slot < _timeListArray.Size);
|
||||
_timeListArray.Get(slot).PushBack(node);
|
||||
}
|
||||
public ViDoubleLink1<ViTimeNodeInterface> Current { get { return _timeListArray.Get(_idx); } }
|
||||
public UInt32 Next()
|
||||
{
|
||||
++_idx;
|
||||
if (_idx == _timeListArray.Size)
|
||||
{
|
||||
_idx = 0;
|
||||
}
|
||||
_timeInf += _span;
|
||||
_timeSup += _span;
|
||||
return _idx;
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
for (UInt32 idx = 0; idx < _timeListArray.Size; ++idx)
|
||||
{
|
||||
_timeListArray.Get(idx).Clear();
|
||||
}
|
||||
_timeListArray.Clear();
|
||||
_timeInf = 0;
|
||||
_timeSup = 0;
|
||||
_span = 0;
|
||||
_idx = 0;
|
||||
}
|
||||
//
|
||||
ViTime64 _timeInf;
|
||||
ViTime64 _timeSup;
|
||||
UInt32 _span;
|
||||
UInt32 _idx;
|
||||
ViSimpleVector<ViDoubleLink1<ViTimeNodeInterface>> _timeListArray = new ViSimpleVector<ViDoubleLink1<ViTimeNodeInterface>>();
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public class ViTimer
|
||||
{
|
||||
public ViTime64 Time { get { return _time; } }
|
||||
|
||||
public void Start(ViTime64 startTime, UInt32 span, UInt32 rollSize0, UInt32 rollSize1)
|
||||
{
|
||||
_time = startTime;
|
||||
_roll0.Init(startTime, rollSize0, span);
|
||||
_roll1.Init(startTime, rollSize1, span * rollSize0);
|
||||
}
|
||||
public void End()
|
||||
{
|
||||
_roll0.Clear();
|
||||
_roll1.Clear();
|
||||
_currentList.Clear();
|
||||
_reserveList.Clear();
|
||||
_time = 0;
|
||||
}
|
||||
|
||||
public void ResetTime(ViTime64 time)
|
||||
{
|
||||
ViTime64 deltaTime = time - _time;
|
||||
_time = time;
|
||||
//
|
||||
_roll0.ResetTime(deltaTime);
|
||||
_roll1.ResetTime(deltaTime);
|
||||
TimeRoll.ResetTime(_reserveList, deltaTime);
|
||||
}
|
||||
|
||||
public void Update(ViTime64 time)
|
||||
{
|
||||
if (_time >= time)
|
||||
{
|
||||
return;
|
||||
}
|
||||
//! Update迭代
|
||||
ViTime64 updateTime = _time;
|
||||
ViTime64 span = _roll0.Span;
|
||||
ViTime64 topTime = time - span;
|
||||
while (updateTime <= topTime)
|
||||
{
|
||||
//! 更新时间
|
||||
updateTime += span;
|
||||
if (_roll0.IsRoll())
|
||||
{
|
||||
_AddFastEvent(_roll1.Current, _roll0);
|
||||
_roll1.Next();
|
||||
if (_roll1.IsRoll())
|
||||
{
|
||||
_AddEvent(_reserveList, _roll1);
|
||||
}
|
||||
}
|
||||
_time = updateTime;
|
||||
_currentList.PushBack(_roll0.Current);
|
||||
_roll0.Next();
|
||||
_ExecTimeList(_currentList);
|
||||
}
|
||||
}
|
||||
public void Add(ViTimeNodeInterface node)
|
||||
{
|
||||
if (node.Time < _roll0.TimeInf)
|
||||
{
|
||||
node.SetTime(_roll0.TimeInf);
|
||||
}
|
||||
if (_roll0.InRange(node.Time))
|
||||
{
|
||||
_roll0.Add(node);
|
||||
return;
|
||||
}
|
||||
if (_roll1.InRange(node.Time))
|
||||
{
|
||||
_roll1.Add(node);
|
||||
return;
|
||||
}
|
||||
_AddEvent(_reserveList, node);
|
||||
}
|
||||
//
|
||||
static void _AddEvent(ViDoubleLink1<ViTimeNodeInterface> list, ViTimeNodeInterface node)
|
||||
{
|
||||
ViDoubleLinkNode1<ViTimeNodeInterface> iter = list.GetHead();
|
||||
while (!list.IsEnd(iter))
|
||||
{
|
||||
ViTimeNodeInterface timeNode = iter as ViTimeNodeInterface;
|
||||
ViDebuger.AssertError(timeNode);
|
||||
ViDoubleLink1<ViTimeNodeInterface>.Next(ref iter);
|
||||
if (timeNode.Time > node.Time)
|
||||
{
|
||||
ViDoubleLink1<ViTimeNodeInterface>.PushBefore(iter, node);
|
||||
return;
|
||||
}
|
||||
}
|
||||
list.PushBack(node);
|
||||
}
|
||||
static void _AddFastEvent(ViDoubleLink1<ViTimeNodeInterface> list, TimeRoll timeRoll)
|
||||
{
|
||||
ViDoubleLinkNode1<ViTimeNodeInterface> iter = list.GetHead();
|
||||
while (!list.IsEnd(iter))
|
||||
{
|
||||
ViTimeNodeInterface timeNode = iter as ViTimeNodeInterface;
|
||||
ViDebuger.AssertError(timeNode);
|
||||
ViDoubleLink1<ViTimeNodeInterface>.Next(ref iter);
|
||||
if (timeRoll.InRange(timeNode.Time))
|
||||
{
|
||||
timeRoll.Add(timeNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
ViDebuger.Error("timeNode.Time" + timeNode.Time + " in not in timeRoll.Range");
|
||||
}
|
||||
}
|
||||
}
|
||||
static void _AddEvent(ViDoubleLink1<ViTimeNodeInterface> list, TimeRoll timeRoll)
|
||||
{
|
||||
ViDoubleLinkNode1<ViTimeNodeInterface> iter = list.GetHead();
|
||||
while (!list.IsEnd(iter))
|
||||
{
|
||||
ViTimeNodeInterface timeNode = iter as ViTimeNodeInterface;
|
||||
ViDebuger.AssertError(timeNode);
|
||||
ViDoubleLink1<ViTimeNodeInterface>.Next(ref iter);
|
||||
if (timeRoll.InRange(timeNode.Time))
|
||||
{
|
||||
timeRoll.Add(timeNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
void _ExecTimeList(ViDoubleLink1<ViTimeNodeInterface> list)
|
||||
{
|
||||
while (list.IsNotEmpty())
|
||||
{
|
||||
ViTimeNodeInterface timeNode = list.GetHead() as ViTimeNodeInterface;
|
||||
ViDebuger.AssertError(timeNode);
|
||||
timeNode.Detach();
|
||||
timeNode._Exce(this);
|
||||
}
|
||||
ViDebuger.AssertError(list.IsEmpty());
|
||||
}
|
||||
//
|
||||
ViTime64 _time;
|
||||
TimeRoll _roll0 = new TimeRoll();
|
||||
TimeRoll _roll1 = new TimeRoll();
|
||||
ViDoubleLink1<ViTimeNodeInterface> _currentList = new ViDoubleLink1<ViTimeNodeInterface>();
|
||||
ViDoubleLink1<ViTimeNodeInterface> _reserveList = new ViDoubleLink1<ViTimeNodeInterface>();
|
||||
}
|
||||
12
Unity/Assets/Plugins/ViSDK/ViGameCommon/Time/ViTimer.cs.meta
Normal file
12
Unity/Assets/Plugins/ViSDK/ViGameCommon/Time/ViTimer.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be2244b9238a7d74c935c8e66b68eab3
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using ViTime64 = System.Int64;
|
||||
//
|
||||
public static class ViTimerInstance
|
||||
{
|
||||
public static ViTime64 Time64 { get { return _iLocalAccumulateTime; } }
|
||||
public static double Time { get { return _accumulateTime; } }
|
||||
public static ViTimer Timer { get { return _timer; } }
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public static void Start(ViTime64 time1970, ViTime64 accumulateTime, UInt32 span, UInt32 rollSize0, UInt32 rollSize1)
|
||||
{
|
||||
_timer.End();
|
||||
//
|
||||
_accumulateTime = 0.0;
|
||||
_iLocalAccumulateTime = 0;
|
||||
//
|
||||
_timer.Start(accumulateTime, span, rollSize0, rollSize1);
|
||||
}
|
||||
public static void End()
|
||||
{
|
||||
_timer.End();
|
||||
}
|
||||
public static void Update(float deltaTime)
|
||||
{
|
||||
ViDebuger.AssertError(_timer);
|
||||
_accumulateTime += deltaTime;
|
||||
_iLocalAccumulateTime = (ViTime64)(_accumulateTime * 1000);
|
||||
_timer.Update((ViTime64)(_accumulateTime * 100));
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
static public void ResetTime(ViTimeNode1 node, float deltaTime)
|
||||
{
|
||||
if (node.IsAttach())
|
||||
{
|
||||
node.SetTime(_timer.Time + (ViTime64)(deltaTime * 100));
|
||||
_timer.Add(node);
|
||||
}
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
static public void SetTime(ViTimeNode1 node, float deltaTime, ViTimeNode1.Callback dele)
|
||||
{
|
||||
node._SetDelegate(dele);
|
||||
node.SetTime(_timer.Time + (ViTime64)(deltaTime * 100));
|
||||
_timer.Add(node);
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
static public void SetTime<T>(ViTimeNodeEx1<T> node, float deltaTime, ViTimeNodeEx1<T>.Callback dele)
|
||||
{
|
||||
node._SetDelegate(dele);
|
||||
node.SetTime(_timer.Time + (ViTime64)(deltaTime * 100));
|
||||
_timer.Add(node);
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public static void SetFreq(ViTimeNodeInterface node, float oldFreq, float newFreq)
|
||||
{
|
||||
if (node.IsAttach() == false)//! 如果回调已经发生过了, 则无法进行重新设置
|
||||
{
|
||||
return;
|
||||
}
|
||||
ViTime64 currentTime = _timer.Time;
|
||||
ViTime64 delta = node.Time - currentTime;
|
||||
ViTime64 deltaTimeOldMod = (delta > 0) ? delta : 0;
|
||||
ViTime64 deltaTime = (ViTime64)(deltaTimeOldMod * oldFreq);
|
||||
ViTime64 deltaTimeNewMod = (ViTime64)(deltaTime / newFreq);
|
||||
node.SetTime(_timer.Time + deltaTimeNewMod);
|
||||
_timer.Add(node);
|
||||
}
|
||||
public static void Modify(ViTimeNodeInterface node, ViTime64 deltaTime)
|
||||
{
|
||||
if (node.IsAttach() == false)//! 如果回调已经发生过了, 则无法进行重新设置
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (node.Time > -deltaTime)
|
||||
{
|
||||
node.SetTime(node.Time + deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
node.SetTime(0);
|
||||
}
|
||||
_timer.Add(node);
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
private static ViTimer _timer = new ViTimer();
|
||||
private static double _accumulateTime;
|
||||
private static ViTime64 _iLocalAccumulateTime;
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a940b3e593cf0241936c5bd88991eb4
|
||||
timeCreated: 1453717662
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using ViTime64 = System.Int64;
|
||||
//
|
||||
public class ViVisualCustomTimerInstance
|
||||
{
|
||||
public ViTime64 Time64 { get { return _iLocalAccumulateTime; } }
|
||||
public double Time { get { return _accumulateTime; } }
|
||||
public ViTimer Timer { get { return _timer; } }
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public void Start(ViTime64 time1970, ViTime64 accumulateTime, UInt32 span, UInt32 rollSize0, UInt32 rollSize1)
|
||||
{
|
||||
_timer.End();
|
||||
//
|
||||
_accumulateTime = 0.0;
|
||||
_iLocalAccumulateTime = 0;
|
||||
//
|
||||
_timer.Start(accumulateTime, span, rollSize0, rollSize1);
|
||||
}
|
||||
public void End()
|
||||
{
|
||||
_timer.End();
|
||||
}
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
ViDebuger.AssertError(_timer);
|
||||
_accumulateTime += deltaTime;
|
||||
_iLocalAccumulateTime = (ViTime64)(_accumulateTime * 1000);
|
||||
_timer.Update((ViTime64)(_accumulateTime * 100));
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public void ResetTime(ViTimeNode1 node, float deltaTime)
|
||||
{
|
||||
if (node.IsAttach())
|
||||
{
|
||||
node.SetTime(_timer.Time + (ViTime64)(deltaTime * 100));
|
||||
_timer.Add(node);
|
||||
}
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public void SetTime(ViTimeNode1 node, float deltaTime, ViTimeNode1.Callback dele)
|
||||
{
|
||||
node._SetDelegate(dele);
|
||||
node.SetTime(_timer.Time + (ViTime64)(deltaTime * 100));
|
||||
_timer.Add(node);
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public void SetTime<T>(ViTimeNodeEx1<T> node, float deltaTime, ViTimeNodeEx1<T>.Callback dele)
|
||||
{
|
||||
node._SetDelegate(dele);
|
||||
node.SetTime(_timer.Time + (ViTime64)(deltaTime * 100));
|
||||
_timer.Add(node);
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public void SetFreq(ViTimeNodeInterface node, float oldFreq, float newFreq)
|
||||
{
|
||||
if (node.IsAttach() == false)//! 如果回调已经发生过了, 则无法进行重新设置
|
||||
{
|
||||
return;
|
||||
}
|
||||
ViTime64 currentTime = _timer.Time;
|
||||
ViTime64 delta = node.Time - currentTime;
|
||||
ViTime64 deltaTimeOldMod = (delta > 0) ? delta : 0;
|
||||
ViTime64 deltaTime = (ViTime64)(deltaTimeOldMod * oldFreq);
|
||||
ViTime64 deltaTimeNewMod = (ViTime64)(deltaTime / newFreq);
|
||||
node.SetTime(_timer.Time + deltaTimeNewMod);
|
||||
_timer.Add(node);
|
||||
}
|
||||
public void Modify(ViTimeNodeInterface node, ViTime64 deltaTime)
|
||||
{
|
||||
if (node.IsAttach() == false)//! 如果回调已经发生过了, 则无法进行重新设置
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (node.Time > -deltaTime)
|
||||
{
|
||||
node.SetTime(node.Time + deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
node.SetTime(0);
|
||||
}
|
||||
_timer.Add(node);
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
private ViTimer _timer = new ViTimer();
|
||||
private double _accumulateTime;
|
||||
private ViTime64 _iLocalAccumulateTime;
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 070a492c5bf74f629ad859cf32a067e0
|
||||
timeCreated: 1751868346
|
||||
@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using ViTime64 = System.Int64;
|
||||
//
|
||||
public static class ViVisualTimerInstance
|
||||
{
|
||||
public static ViTime64 Time64 { get { return _iLocalAccumulateTime; } }
|
||||
public static double Time { get { return _accumulateTime; } }
|
||||
public static ViTimer Timer { get { return _timer; } }
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public static void Start(ViTime64 time1970, ViTime64 accumulateTime, UInt32 span, UInt32 rollSize0, UInt32 rollSize1)
|
||||
{
|
||||
_timer.End();
|
||||
//
|
||||
_accumulateTime = 0.0;
|
||||
_iLocalAccumulateTime = 0;
|
||||
//
|
||||
_timer.Start(accumulateTime, span, rollSize0, rollSize1);
|
||||
}
|
||||
public static void End()
|
||||
{
|
||||
_timer.End();
|
||||
}
|
||||
public static void Update(float deltaTime)
|
||||
{
|
||||
ViDebuger.AssertError(_timer);
|
||||
_accumulateTime += deltaTime;
|
||||
_iLocalAccumulateTime = (ViTime64)(_accumulateTime * 1000);
|
||||
_timer.Update((ViTime64)(_accumulateTime * 100));
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
static public void ResetTime(ViTimeNode1 node, float deltaTime)
|
||||
{
|
||||
if (node.IsAttach())
|
||||
{
|
||||
node.SetTime(_timer.Time + (ViTime64)(deltaTime * 100));
|
||||
_timer.Add(node);
|
||||
}
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
static public void SetTime(ViTimeNode1 node, float deltaTime, ViTimeNode1.Callback dele)
|
||||
{
|
||||
node._SetDelegate(dele);
|
||||
node.SetTime(_timer.Time + (ViTime64)(deltaTime * 100));
|
||||
_timer.Add(node);
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
static public void SetTime<T>(ViTimeNodeEx1<T> node, float deltaTime, ViTimeNodeEx1<T>.Callback dele)
|
||||
{
|
||||
node._SetDelegate(dele);
|
||||
node.SetTime(_timer.Time + (ViTime64)(deltaTime * 100));
|
||||
_timer.Add(node);
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
public static void SetFreq(ViTimeNodeInterface node, float oldFreq, float newFreq)
|
||||
{
|
||||
if (node.IsAttach() == false)//! 如果回调已经发生过了, 则无法进行重新设置
|
||||
{
|
||||
return;
|
||||
}
|
||||
ViTime64 currentTime = _timer.Time;
|
||||
ViTime64 delta = node.Time - currentTime;
|
||||
ViTime64 deltaTimeOldMod = (delta > 0) ? delta : 0;
|
||||
ViTime64 deltaTime = (ViTime64)(deltaTimeOldMod * oldFreq);
|
||||
ViTime64 deltaTimeNewMod = (ViTime64)(deltaTime / newFreq);
|
||||
node.SetTime(_timer.Time + deltaTimeNewMod);
|
||||
_timer.Add(node);
|
||||
}
|
||||
public static void Modify(ViTimeNodeInterface node, ViTime64 deltaTime)
|
||||
{
|
||||
if (node.IsAttach() == false)//! 如果回调已经发生过了, 则无法进行重新设置
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (node.Time > -deltaTime)
|
||||
{
|
||||
node.SetTime(node.Time + deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
node.SetTime(0);
|
||||
}
|
||||
_timer.Add(node);
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
private static ViTimer _timer = new ViTimer();
|
||||
private static double _accumulateTime;
|
||||
private static ViTime64 _iLocalAccumulateTime;
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47b876c351c701445a6769a15758d081
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
333
Unity/Assets/Plugins/ViSDK/ViGameCommon/ViConstValueReader.cs
Normal file
333
Unity/Assets/Plugins/ViSDK/ViGameCommon/ViConstValueReader.cs
Normal file
@ -0,0 +1,333 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.IO;
|
||||
|
||||
public class ViConstValueReader
|
||||
{
|
||||
public static void Load(string fileName)
|
||||
{
|
||||
XmlDocument xml = new XmlDocument();
|
||||
xml.Load(fileName);
|
||||
Load(xml["Root"]);
|
||||
}
|
||||
|
||||
public static void Load(XmlNode root)
|
||||
{
|
||||
LoadBool("BoolData", root);
|
||||
LoadBoolList("BoolListData", root);
|
||||
LoadInt32("Int32Data", root);
|
||||
LoadInt32List("Int32ListData", root);
|
||||
LoadFloat("FloatData", root);
|
||||
LoadFloatList("FloatListData", root);
|
||||
LoadString("StringData", root);
|
||||
LoadStringList("StringListData", root);
|
||||
LoadVector3("Vector3Data", root);
|
||||
LoadVector3List("Vector3ListData", root);
|
||||
}
|
||||
|
||||
static void LoadBool(XmlNode node)
|
||||
{
|
||||
XmlElement nameElement = node["Name"];
|
||||
XmlElement valueElement = node["Value"];
|
||||
if (nameElement != null && valueElement != null)
|
||||
{
|
||||
bool value;
|
||||
ViStringSerialize.Read(valueElement.InnerText, out value);
|
||||
//Log("ConstValue<bool>[" + nameElement.InnerText + "] = " + value);
|
||||
ViConstValueList<bool>.AddValue(nameElement.InnerText, value);
|
||||
}
|
||||
}
|
||||
static void LoadReefBool(string name, XmlNode node)
|
||||
{
|
||||
foreach (XmlNode element in node.SelectNodes(name))
|
||||
{
|
||||
LoadBool(element);
|
||||
}
|
||||
}
|
||||
static void LoadBool(string name, XmlNode node)
|
||||
{
|
||||
LoadReefBool(name, node);
|
||||
foreach (XmlNode element in node.ChildNodes)
|
||||
{
|
||||
LoadReefBool(name, element);
|
||||
}
|
||||
}
|
||||
|
||||
//+-----------------------------------------------------------------------------
|
||||
static void LoadBoolList(XmlNode node)
|
||||
{
|
||||
XmlElement nameElement = node["Name"];
|
||||
XmlNodeList elementList = node.SelectNodes("Value");
|
||||
List<bool> valueList = new List<bool>(elementList.Count);
|
||||
foreach (XmlNode element in elementList)
|
||||
{
|
||||
bool value;
|
||||
ViStringSerialize.Read(element.InnerText, out value);
|
||||
valueList.Add(value);
|
||||
}
|
||||
//Log("ConstValue<BoolList>[" + nameElement.InnerText + "] = " + valueList);
|
||||
ViConstValueList<List<bool>>.AddValue(nameElement.InnerText, valueList);
|
||||
}
|
||||
static void LoadReefBoolList(string name, XmlNode node)
|
||||
{
|
||||
foreach (XmlNode element in node.SelectNodes(name))
|
||||
{
|
||||
LoadBoolList(element);
|
||||
}
|
||||
}
|
||||
static void LoadBoolList(string name, XmlNode node)
|
||||
{
|
||||
LoadReefBoolList(name, node);
|
||||
foreach (XmlNode element in node.ChildNodes)
|
||||
{
|
||||
LoadReefBoolList(name, element);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
static void LoadInt32(XmlNode node)
|
||||
{
|
||||
XmlElement nameElement = node["Name"];
|
||||
XmlElement valueElement = node["Value"];
|
||||
if (nameElement != null && valueElement != null)
|
||||
{
|
||||
Int32 value;
|
||||
ViStringSerialize.Read(valueElement.InnerText, out value);
|
||||
//Log("ConstValue<Int32>[" + nameElement.InnerText + "] = " + value);
|
||||
ViConstValueList<Int32>.AddValue(nameElement.InnerText, value);
|
||||
}
|
||||
}
|
||||
static void LoadReefInt32(string name, XmlNode node)
|
||||
{
|
||||
foreach (XmlNode element in node.SelectNodes(name))
|
||||
{
|
||||
LoadInt32(element);
|
||||
}
|
||||
}
|
||||
static void LoadInt32(string name, XmlNode node)
|
||||
{
|
||||
LoadReefInt32(name, node);
|
||||
foreach (XmlNode element in node.ChildNodes)
|
||||
{
|
||||
LoadReefInt32(name, element);
|
||||
}
|
||||
}
|
||||
|
||||
//+-----------------------------------------------------------------------------
|
||||
static void LoadInt32List(XmlNode node)
|
||||
{
|
||||
XmlElement nameElement = node["Name"];
|
||||
XmlNodeList elementList = node.SelectNodes("Value");
|
||||
List<Int32> valueList = new List<Int32>(elementList.Count);
|
||||
foreach (XmlNode element in elementList)
|
||||
{
|
||||
Int32 value;
|
||||
ViStringSerialize.Read(element.InnerText, out value);
|
||||
valueList.Add(value);
|
||||
}
|
||||
//Log("ConstValue<Int32List>[" + nameElement.InnerText + "] = " + valueList);
|
||||
ViConstValueList<List<Int32>>.AddValue(nameElement.InnerText, valueList);
|
||||
}
|
||||
static void LoadReefInt32List(string name, XmlNode node)
|
||||
{
|
||||
foreach (XmlNode element in node.SelectNodes(name))
|
||||
{
|
||||
LoadInt32List(element);
|
||||
}
|
||||
}
|
||||
static void LoadInt32List(string name, XmlNode node)
|
||||
{
|
||||
LoadReefInt32List(name, node);
|
||||
foreach (XmlNode element in node.ChildNodes)
|
||||
{
|
||||
LoadReefInt32List(name, element);
|
||||
}
|
||||
}
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
static void LoadFloat(XmlNode node)
|
||||
{
|
||||
XmlElement nameElement = node["Name"];
|
||||
XmlElement valueElement = node["Value"];
|
||||
if (nameElement != null && valueElement != null)
|
||||
{
|
||||
float value;
|
||||
ViStringSerialize.Read(valueElement.InnerText, out value);
|
||||
//Log("ConstValue<Float>[" + nameElement.InnerText + "] = " + value);
|
||||
ViConstValueList<float>.AddValue(nameElement.InnerText, value);
|
||||
}
|
||||
}
|
||||
static void LoadReefFloat(string name, XmlNode node)
|
||||
{
|
||||
foreach (XmlNode element in node.SelectNodes(name))
|
||||
{
|
||||
LoadFloat(element);
|
||||
}
|
||||
}
|
||||
static void LoadFloat(string name, XmlNode node)
|
||||
{
|
||||
LoadReefFloat(name, node);
|
||||
foreach (XmlNode element in node.ChildNodes)
|
||||
{
|
||||
LoadReefFloat(name, element);
|
||||
}
|
||||
}
|
||||
|
||||
//+-----------------------------------------------------------------------------
|
||||
static void LoadFloatList(XmlNode node)
|
||||
{
|
||||
XmlElement nameElement = node["Name"];
|
||||
XmlNodeList elementList = node.SelectNodes("Value");
|
||||
List<float> valueList = new List<float>(elementList.Count);
|
||||
foreach (XmlNode element in elementList)
|
||||
{
|
||||
float value;
|
||||
ViStringSerialize.Read(element.InnerText, out value);
|
||||
valueList.Add(value);
|
||||
}
|
||||
//Log("ConstValue<FloatList>[" + nameElement.InnerText + "] = " + valueList);
|
||||
ViConstValueList<List<float>>.AddValue(nameElement.InnerText, valueList);
|
||||
}
|
||||
static void LoadReefFloatList(string name, XmlNode node)
|
||||
{
|
||||
foreach (XmlNode element in node.SelectNodes(name))
|
||||
{
|
||||
LoadFloatList(element);
|
||||
}
|
||||
}
|
||||
static void LoadFloatList(string name, XmlNode node)
|
||||
{
|
||||
LoadReefFloatList(name, node);
|
||||
foreach (XmlNode element in node.ChildNodes)
|
||||
{
|
||||
LoadReefFloatList(name, element);
|
||||
}
|
||||
}
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
static void LoadString(XmlNode node)
|
||||
{
|
||||
XmlElement nameElement = node["Name"];
|
||||
XmlElement valueElement = node["Value"];
|
||||
if (nameElement != null && valueElement != null)
|
||||
{
|
||||
//Log("ConstValue<String>[" + nameElement.InnerText + "] = " + valueElement.InnerText);
|
||||
ViConstValueList<string>.AddValue(nameElement.InnerText, valueElement.InnerText);
|
||||
}
|
||||
}
|
||||
static void LoadReefString(string name, XmlNode node)
|
||||
{
|
||||
foreach (XmlNode element in node.SelectNodes(name))
|
||||
{
|
||||
LoadString(element);
|
||||
}
|
||||
}
|
||||
static void LoadString(string name, XmlNode node)
|
||||
{
|
||||
LoadReefString(name, node);
|
||||
foreach (XmlNode element in node.ChildNodes)
|
||||
{
|
||||
LoadReefString(name, element);
|
||||
}
|
||||
}
|
||||
|
||||
//+-----------------------------------------------------------------------------
|
||||
static void LoadStringList(XmlNode node)
|
||||
{
|
||||
XmlElement nameElement = node["Name"];
|
||||
XmlNodeList elementList = node.SelectNodes("Value");
|
||||
List<string> valueList = new List<string>(elementList.Count);
|
||||
foreach (XmlNode element in elementList)
|
||||
{
|
||||
valueList.Add(element.InnerText);
|
||||
}
|
||||
//Log("ConstValue<StringList>[" + nameElement.InnerText + "] = " + valueList);
|
||||
ViConstValueList<List<string>>.AddValue(nameElement.InnerText, valueList);
|
||||
}
|
||||
static void LoadReefStringList(string name, XmlNode node)
|
||||
{
|
||||
foreach (XmlNode element in node.SelectNodes(name))
|
||||
{
|
||||
LoadStringList(element);
|
||||
}
|
||||
}
|
||||
static void LoadStringList(string name, XmlNode node)
|
||||
{
|
||||
LoadReefStringList(name, node);
|
||||
foreach (XmlNode element in node.ChildNodes)
|
||||
{
|
||||
LoadReefStringList(name, element);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//+-------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
static void LoadVector3(XmlNode node)
|
||||
{
|
||||
XmlElement nameElement = node["Name"];
|
||||
XmlElement valueElement = node["Value"];
|
||||
if (nameElement != null && valueElement != null)
|
||||
{
|
||||
ViVector3 value;
|
||||
ViVector3Serialize.Read(valueElement.InnerText, out value);
|
||||
//Log("ConstValue<Vector3>[" + nameElement.InnerText + "] = " + value);
|
||||
ViConstValueList<ViVector3>.AddValue(nameElement.InnerText, value);
|
||||
}
|
||||
}
|
||||
static void LoadReefVector3(string name, XmlNode node)
|
||||
{
|
||||
foreach (XmlNode element in node.SelectNodes(name))
|
||||
{
|
||||
LoadVector3(element);
|
||||
}
|
||||
}
|
||||
static void LoadVector3(string name, XmlNode node)
|
||||
{
|
||||
LoadReefVector3(name, node);
|
||||
foreach (XmlNode element in node.ChildNodes)
|
||||
{
|
||||
LoadReefVector3(name, element);
|
||||
}
|
||||
}
|
||||
|
||||
//+-----------------------------------------------------------------------------
|
||||
static void LoadVector3List(XmlNode node)
|
||||
{
|
||||
XmlElement nameElement = node["Name"];
|
||||
XmlNodeList elementList = node.SelectNodes("Value");
|
||||
List<ViVector3> valueList = new List<ViVector3>(elementList.Count);
|
||||
foreach (XmlNode element in elementList)
|
||||
{
|
||||
ViVector3 value;
|
||||
ViVector3Serialize.Read(element.InnerText, out value);
|
||||
valueList.Add(value);
|
||||
}
|
||||
//Log("ConstValue<Vector3List>[" + nameElement.InnerText + "] = " + valueList);
|
||||
ViConstValueList<List<ViVector3>>.AddValue(nameElement.InnerText, valueList);
|
||||
}
|
||||
static void LoadReefVector3List(string name, XmlNode node)
|
||||
{
|
||||
foreach (XmlNode element in node.SelectNodes(name))
|
||||
{
|
||||
LoadVector3List(element);
|
||||
}
|
||||
}
|
||||
static void LoadVector3List(string name, XmlNode node)
|
||||
{
|
||||
LoadReefVector3List(name, node);
|
||||
foreach (XmlNode element in node.ChildNodes)
|
||||
{
|
||||
LoadReefVector3List(name, element);
|
||||
}
|
||||
}
|
||||
|
||||
static void Log(string log)
|
||||
{
|
||||
ViDebuger.Note(log);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4eed8403abbb4f4194ba58ea2897c42
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
216
Unity/Assets/Plugins/ViSDK/ViGameCommon/ViFomatString.cs
Normal file
216
Unity/Assets/Plugins/ViSDK/ViGameCommon/ViFomatString.cs
Normal file
@ -0,0 +1,216 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
|
||||
public class ViFomatDictionary
|
||||
{
|
||||
public Dictionary<string, string> ReplaceList { get { return _replaceList; } }
|
||||
public ViDoubleLink2<ViFomatString> RegisterList { get { return _registerList; } }
|
||||
|
||||
public void Set(string oldValue, string newValue)
|
||||
{
|
||||
ReplaceList[oldValue] = newValue;
|
||||
}
|
||||
|
||||
public void Broadcast()
|
||||
{
|
||||
ViDoubleLinkNode2<ViFomatString> iter = RegisterList.GetHead();
|
||||
while (!RegisterList.IsEnd(iter))
|
||||
{
|
||||
ViFomatString iterFomat = iter.Data;
|
||||
ViDoubleLink2<ViFomatString>.Next(ref iter);
|
||||
iterFomat.OnReplace();
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGet(ref string value)
|
||||
{
|
||||
string newValue;
|
||||
if (ReplaceList.TryGetValue(value, out newValue))
|
||||
{
|
||||
value = newValue;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
ReplaceList.Clear();
|
||||
}
|
||||
|
||||
public void Register(ViDoubleLinkNode2<ViFomatString> node)
|
||||
{
|
||||
RegisterList.PushBack(node);
|
||||
}
|
||||
|
||||
Dictionary<string, string> _replaceList = new Dictionary<string, string>();
|
||||
ViDoubleLink2<ViFomatString> _registerList = new ViDoubleLink2<ViFomatString>();
|
||||
}
|
||||
|
||||
public class ViFomatString
|
||||
{
|
||||
public static ViFomatDictionary Dictionary { get { return _dictionary; } }
|
||||
static ViFomatDictionary _dictionary = new ViFomatDictionary();
|
||||
|
||||
public static implicit operator string(ViFomatString data)
|
||||
{
|
||||
return data.Desc;
|
||||
}
|
||||
|
||||
public ViFomatString(string name)
|
||||
{
|
||||
_name = name;
|
||||
Fomat(true);
|
||||
}
|
||||
public ViFomatString(string name, bool replace)
|
||||
{
|
||||
_name = name;
|
||||
Fomat(replace);
|
||||
}
|
||||
|
||||
void Fomat(bool replace)
|
||||
{
|
||||
_desc = _name;
|
||||
if (replace)
|
||||
{
|
||||
_replaceNode.Data = this;
|
||||
Dictionary.TryGet(ref _desc);
|
||||
Dictionary.Register(_replaceNode);
|
||||
}
|
||||
_descFragmentList = _desc.Split(Sign);
|
||||
}
|
||||
|
||||
public string Name { get { return _name; } }
|
||||
public string Desc { get { return _desc; } }
|
||||
public string[] DescFragmentList { get { return _descFragmentList; } }
|
||||
|
||||
public string Print()
|
||||
{
|
||||
return Desc;
|
||||
}
|
||||
|
||||
public string Print(string value0)
|
||||
{
|
||||
_valueCache.Clear();
|
||||
_valueCache.Add(value0);
|
||||
return PrintEx(_descFragmentList, _valueCache);
|
||||
}
|
||||
|
||||
public string Print(string value0, string value1)
|
||||
{
|
||||
_valueCache.Clear();
|
||||
_valueCache.Add(value0);
|
||||
_valueCache.Add(value1);
|
||||
return PrintEx(_descFragmentList, _valueCache);
|
||||
}
|
||||
|
||||
public string Print(string value0, string value1, string value2)
|
||||
{
|
||||
_valueCache.Clear();
|
||||
_valueCache.Add(value0);
|
||||
_valueCache.Add(value1);
|
||||
_valueCache.Add(value2);
|
||||
return PrintEx(_descFragmentList, _valueCache);
|
||||
}
|
||||
|
||||
public string Print(string value0, string value1, string value2, string value3)
|
||||
{
|
||||
_valueCache.Clear();
|
||||
_valueCache.Add(value0);
|
||||
_valueCache.Add(value1);
|
||||
_valueCache.Add(value2);
|
||||
_valueCache.Add(value3);
|
||||
return PrintEx(_descFragmentList, _valueCache);
|
||||
}
|
||||
|
||||
public string Print(string value0, string value1, string value2, string value3, string value4)
|
||||
{
|
||||
_valueCache.Clear();
|
||||
_valueCache.Add(value0);
|
||||
_valueCache.Add(value1);
|
||||
_valueCache.Add(value2);
|
||||
_valueCache.Add(value3);
|
||||
_valueCache.Add(value4);
|
||||
return PrintEx(_descFragmentList, _valueCache);
|
||||
}
|
||||
|
||||
public string Print(string value0, string value1, string value2, string value3, string value4, string value5)
|
||||
{
|
||||
_valueCache.Clear();
|
||||
_valueCache.Add(value0);
|
||||
_valueCache.Add(value1);
|
||||
_valueCache.Add(value2);
|
||||
_valueCache.Add(value3);
|
||||
_valueCache.Add(value4);
|
||||
_valueCache.Add(value5);
|
||||
return PrintEx(_descFragmentList, _valueCache);
|
||||
}
|
||||
|
||||
public string Print(string value0, string value1, string value2, string value3, string value4, string value5, string value6)
|
||||
{
|
||||
_valueCache.Clear();
|
||||
_valueCache.Add(value0);
|
||||
_valueCache.Add(value1);
|
||||
_valueCache.Add(value2);
|
||||
_valueCache.Add(value3);
|
||||
_valueCache.Add(value4);
|
||||
_valueCache.Add(value5);
|
||||
_valueCache.Add(value6);
|
||||
return PrintEx(_descFragmentList, _valueCache);
|
||||
}
|
||||
|
||||
public string Print(string[] valueArray)
|
||||
{
|
||||
_valueCache.Clear();
|
||||
for (int index = 0; index < valueArray.Length; ++ index)
|
||||
{
|
||||
_valueCache.Add(valueArray[index]);
|
||||
}
|
||||
return PrintEx(_descFragmentList, _valueCache);
|
||||
}
|
||||
|
||||
public void OnReplace()
|
||||
{
|
||||
_desc = _name;
|
||||
if (Dictionary.TryGet(ref _desc))
|
||||
{
|
||||
_descFragmentList = _desc.Split(Sign);
|
||||
}
|
||||
}
|
||||
|
||||
static ViStringBuilder _printBuilder = new ViStringBuilder(1024);
|
||||
static string PrintEx(string[] logList, List<string> valueList)
|
||||
{
|
||||
_printBuilder.Clear();
|
||||
int iter = 0;
|
||||
int minCount = (logList.Length < valueList.Count) ? logList.Length : valueList.Count;
|
||||
for (; iter < minCount; ++iter)
|
||||
{
|
||||
_printBuilder.Add(logList[iter]);
|
||||
_printBuilder.Add(valueList[iter]);
|
||||
}
|
||||
for (; iter < logList.Length; ++iter)
|
||||
{
|
||||
_printBuilder.Add(logList[iter]);
|
||||
}
|
||||
for (; iter < valueList.Count; ++iter)
|
||||
{
|
||||
_printBuilder.Add(valueList[iter]);
|
||||
}
|
||||
return _printBuilder.Value;
|
||||
}
|
||||
|
||||
string _name;
|
||||
string _desc;
|
||||
string[] _descFragmentList;
|
||||
List<string> _valueCache = new List<string>();
|
||||
ViDoubleLinkNode2<ViFomatString> _replaceNode = new ViDoubleLinkNode2<ViFomatString>();
|
||||
|
||||
static char[] Sign = { '&' };
|
||||
}
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7559afc2c2d0d147a44db47b4b2616e
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
103
Unity/Assets/Plugins/ViSDK/ViGameCommon/ViWorkFlowEvent.cs
Normal file
103
Unity/Assets/Plugins/ViSDK/ViGameCommon/ViWorkFlowEvent.cs
Normal file
@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
public class ViWorkFlowEvent
|
||||
{
|
||||
public delegate void DeleCompleteCallback();
|
||||
public bool Active { get { return Count <= 0; } }
|
||||
public Int32 Count { get { return _waitList.Count; } }
|
||||
|
||||
public void Wait(string key)
|
||||
{
|
||||
Wait(key, null);
|
||||
}
|
||||
|
||||
public void Wait(string key, DeleCompleteCallback callback)
|
||||
{
|
||||
if (IsWaiting(key))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Node newNode = new Node(key, callback);
|
||||
_waitList.Add(newNode);
|
||||
}
|
||||
|
||||
public bool IsWaiting(string key)
|
||||
{
|
||||
for (int iter = 0; iter < _waitList.Count; ++iter)
|
||||
{
|
||||
if (_waitList[iter].Name == key)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool EraseWaiting(string key)
|
||||
{
|
||||
bool result = false;
|
||||
for (int iter = _waitList.Count-1; iter >= 0; --iter)
|
||||
{
|
||||
if (_waitList[iter].Name == key)
|
||||
{
|
||||
_waitList.RemoveAt(iter);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public void Complete(string key)
|
||||
{
|
||||
EraseWaiting(key);
|
||||
if (_waitList.Count == 0)
|
||||
{
|
||||
_framEndCallback.AsynExec(this.Invoke);
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset(DeleCompleteCallback callback)
|
||||
{
|
||||
_waitList.Clear();
|
||||
_framEndCallback.Detach();
|
||||
//
|
||||
_callback = callback;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_waitList.Clear();
|
||||
_framEndCallback.Detach();
|
||||
_callback = null;
|
||||
}
|
||||
|
||||
ViFramEndCallback0 _framEndCallback = new ViFramEndCallback0();
|
||||
void Invoke()
|
||||
{
|
||||
DeleCompleteCallback dele = _callback;
|
||||
_callback = null;
|
||||
if (dele != null)
|
||||
{
|
||||
dele();
|
||||
}
|
||||
}
|
||||
|
||||
struct Node
|
||||
{
|
||||
public Node(string name, DeleCompleteCallback callback)
|
||||
{
|
||||
Name = name;
|
||||
Callback = callback;
|
||||
}
|
||||
public string Name;
|
||||
public DeleCompleteCallback Callback;
|
||||
}
|
||||
|
||||
DeleCompleteCallback _callback;
|
||||
List<Node> _waitList = new List<Node>();
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27823d46efc0adf45abf09d7160fbaf2
|
||||
timeCreated: 1453717662
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Unity/Assets/Plugins/ViSDK/ViMath.meta
Normal file
9
Unity/Assets/Plugins/ViSDK/ViMath.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0193505fd64250c4baff3cc3a06f474c
|
||||
folderAsset: yes
|
||||
timeCreated: 1453717661
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
150
Unity/Assets/Plugins/ViSDK/ViMath/ViAngle.cs
Normal file
150
Unity/Assets/Plugins/ViSDK/ViMath/ViAngle.cs
Normal file
@ -0,0 +1,150 @@
|
||||
using System;
|
||||
|
||||
public struct ViAngle
|
||||
{
|
||||
|
||||
public static readonly float INF = -ViMathDefine.PI;
|
||||
public static readonly float SUP = ViMathDefine.PI;
|
||||
|
||||
public ViAngle(ViAngle rAngle)
|
||||
{
|
||||
_value = rAngle.Value;
|
||||
}
|
||||
public ViAngle(float angle)
|
||||
{
|
||||
_value = angle;
|
||||
Normalize();
|
||||
}
|
||||
public float Value { get { return _value; } set { _value = value; Normalize(); } }
|
||||
public void SetValue(float value) { _value = value; Normalize(); }
|
||||
//
|
||||
public static float Normalize(float angle)
|
||||
{
|
||||
Normalize(ref angle);
|
||||
return angle;
|
||||
}
|
||||
public static void Normalize(ref float angle)
|
||||
{
|
||||
if (angle >= ViMathDefine.PI)
|
||||
{
|
||||
if (angle > ViMathDefine.PI_X3)
|
||||
{
|
||||
angle = angle - (Int32)(angle / ViMathDefine.PI_X2) * ViMathDefine.PI_X2;
|
||||
}
|
||||
else
|
||||
{
|
||||
angle = angle - ViMathDefine.PI_X2;
|
||||
}
|
||||
}
|
||||
else if (angle < -ViMathDefine.PI)
|
||||
{
|
||||
if (angle < -ViMathDefine.PI_X3)
|
||||
{
|
||||
angle = angle - (Int32)(angle / ViMathDefine.PI_X2 - 1) * ViMathDefine.PI_X2;
|
||||
}
|
||||
else
|
||||
{
|
||||
angle = angle + ViMathDefine.PI_X2;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static float Diff(ViAngle from, ViAngle to)
|
||||
{
|
||||
float fDiff = from.Value - to.Value;
|
||||
if (fDiff < -ViMathDefine.PI)
|
||||
{
|
||||
return fDiff + ViMathDefine.PI_X2;
|
||||
}
|
||||
else if (fDiff >= ViMathDefine.PI)
|
||||
{
|
||||
return fDiff - ViMathDefine.PI_X2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return fDiff;
|
||||
}
|
||||
}
|
||||
public static float SameSignAngle(ViAngle angle, ViAngle record)
|
||||
{
|
||||
if (angle.Value > record.Value + ViMathDefine.PI)
|
||||
{
|
||||
return angle.Value - ViMathDefine.PI_X2;
|
||||
}
|
||||
else if (angle.Value < record.Value - ViMathDefine.PI)
|
||||
{
|
||||
return angle.Value + ViMathDefine.PI_X2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return angle.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public static ViAngle operator +(ViAngle kAngle1, ViAngle kAngle2)
|
||||
{
|
||||
return new ViAngle(kAngle1.Value + kAngle2.Value);
|
||||
}
|
||||
public static ViAngle operator -(ViAngle kAngle1, ViAngle kAngle2)
|
||||
{
|
||||
return new ViAngle(kAngle1.Value - kAngle2.Value);
|
||||
}
|
||||
public bool IsBetween(ViAngle kLeft, ViAngle kRight)
|
||||
{
|
||||
if (kLeft.Value <= kRight.Value)
|
||||
{
|
||||
return (kLeft.Value <= Value && Value <= kRight.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (kLeft.Value <= Value || Value <= kRight.Value);
|
||||
}
|
||||
}
|
||||
public void Lerp(ViAngle a, ViAngle b, float t)
|
||||
{
|
||||
_value = a.Value * t + SameSignAngle(a, b) * (1 - t);
|
||||
Normalize();
|
||||
}
|
||||
void Normalize()
|
||||
{
|
||||
Normalize(ref _value);
|
||||
}
|
||||
|
||||
//
|
||||
private float _value;
|
||||
}
|
||||
|
||||
public class Demo_Angle
|
||||
{
|
||||
#pragma warning disable 0219
|
||||
public static void Test()
|
||||
{
|
||||
|
||||
ViAngle angle0 = new ViAngle(ViMathDefine.PI * 0.5f);
|
||||
ViAngle angle1 = new ViAngle(-ViMathDefine.PI);
|
||||
|
||||
float fDiff = ViAngle.Diff(angle0, angle1);//-pi/ 2
|
||||
float fSameSignAngle = ViAngle.SameSignAngle(angle0, angle1);//- 1.5pi
|
||||
bool bIsIn = angle1.IsBetween(angle1, angle0);//true
|
||||
|
||||
ViAngle angle2 = new ViAngle(8.0f);
|
||||
ViAngle angle3 = new ViAngle(12.0f);
|
||||
|
||||
float fDiff1 = ViAngle.Diff(angle2, angle3);
|
||||
float fSameSignAngle1 = ViAngle.SameSignAngle(angle2, angle3);
|
||||
bool bIsIn1 = angle1.IsBetween(angle2, angle3);
|
||||
|
||||
ViAngle angle4 = new ViAngle(3.0f);
|
||||
ViAngle angle5 = new ViAngle(-3.0f);
|
||||
ViAngle angle6 = new ViAngle(-3.1f);
|
||||
ViAngle angle7 = new ViAngle(1.0f);
|
||||
bool bIsIn2 = angle6.IsBetween(angle4, angle5);
|
||||
ViDebuger.AssertError(bIsIn2 == true);
|
||||
bool bIsIn3 = angle6.IsBetween(angle5, angle4);
|
||||
ViDebuger.AssertError(bIsIn3 == false);
|
||||
bool bIsIn4 = angle7.IsBetween(angle4, angle5);
|
||||
ViDebuger.AssertError(bIsIn4 == false);
|
||||
bool bIsIn5 = angle7.IsBetween(angle5, angle4);
|
||||
ViDebuger.AssertError(bIsIn5 == true);
|
||||
}
|
||||
#pragma warning restore 0219
|
||||
}
|
||||
12
Unity/Assets/Plugins/ViSDK/ViMath/ViAngle.cs.meta
Normal file
12
Unity/Assets/Plugins/ViSDK/ViMath/ViAngle.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: caaa7979f3bf43b4db57c9de4bb5e16b
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
113
Unity/Assets/Plugins/ViSDK/ViMath/ViAngleCursor.cs
Normal file
113
Unity/Assets/Plugins/ViSDK/ViMath/ViAngleCursor.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using System;
|
||||
|
||||
public class ViAngleCursor1
|
||||
{
|
||||
public float Direction { get { return _curDiretion; } set { _curDiretion = value; ViAngle.Normalize(ref _curDiretion); } }
|
||||
public float RotSpd { get { return _rotSpd; } set { _rotSpd = ViMathDefine.Max(1.0f, Math.Abs(value)); } }
|
||||
|
||||
public bool Update(float deltaTime, float newDir)
|
||||
{
|
||||
if (newDir == _curDiretion)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
float maxRot = deltaTime * _rotSpd;
|
||||
float deltaAngle = newDir - _curDiretion;
|
||||
ViAngle.Normalize(ref deltaAngle);
|
||||
if (Math.Abs(deltaAngle) < maxRot)
|
||||
{
|
||||
_curDiretion = newDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
_curDiretion += maxRot * ViMathDefine.Sign(deltaAngle);
|
||||
}
|
||||
ViAngle.Normalize(ref _curDiretion);
|
||||
return true;
|
||||
}
|
||||
|
||||
float _curDiretion;
|
||||
float _rotSpd = 10.0f;
|
||||
}
|
||||
|
||||
public class ViAngleCursor2
|
||||
{
|
||||
public float CurrentSpeed { get { return _currentSpeed; } }
|
||||
public float Direction
|
||||
{
|
||||
get { return _curDiretion; }
|
||||
set
|
||||
{
|
||||
_curDiretion = value;
|
||||
ViAngle.Normalize(ref _curDiretion);
|
||||
_currentSpeed = 0.0f;
|
||||
}
|
||||
}
|
||||
public float Accelerate { get { return _accelerate; } set { _accelerate = ViMathDefine.Max(0.0f, value); } }
|
||||
public float MinSpeed { get { return _minSpeed; } set { _minSpeed = ViMathDefine.Max(0.0f, value); } }
|
||||
public float MaxSpeed { get { return _maxSpeed; } set { _maxSpeed = ViMathDefine.Max(0.0f, value); } }
|
||||
public bool IsFiltering { get { return (_currentSpeed != 0.0f); } }
|
||||
|
||||
public ViAngleCursor2()
|
||||
{
|
||||
SetSample(3.14f, 0.23f);
|
||||
}
|
||||
public bool Update(float deltaTime, float newDir)
|
||||
{
|
||||
float deltaAngle = newDir - _curDiretion;
|
||||
if (deltaAngle == 0.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ViAngle.Normalize(ref deltaAngle);
|
||||
float maxRot = 0.0f;
|
||||
if (deltaAngle > 0.0f)
|
||||
{
|
||||
_currentSpeed = Math.Abs(_currentSpeed);
|
||||
float newSpeed = _currentSpeed + _accelerate * deltaTime;
|
||||
float brakingSpeed = ViMathDefine.Sqrt(deltaAngle * _accelerate * 2.0f);
|
||||
_currentSpeed = ViMathDefine.Min(ViMathDefine.Clamp(newSpeed, _minSpeed, _maxSpeed), brakingSpeed);
|
||||
maxRot = _currentSpeed * deltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentSpeed = -Math.Abs(_currentSpeed);
|
||||
float newSpeed = _currentSpeed - _accelerate * deltaTime;
|
||||
float brakingSpeed = -ViMathDefine.Sqrt(-deltaAngle * _accelerate * 2.0f);
|
||||
_currentSpeed = ViMathDefine.Max(ViMathDefine.Clamp(newSpeed, -_maxSpeed, -_minSpeed), brakingSpeed);
|
||||
maxRot = _currentSpeed * deltaTime;
|
||||
}
|
||||
if (Math.Abs(deltaAngle) < Math.Abs(maxRot))
|
||||
{
|
||||
_curDiretion = newDir;
|
||||
_currentSpeed = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
_curDiretion += maxRot;
|
||||
}
|
||||
ViAngle.Normalize(ref _curDiretion);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetSample(float distance, float duration)
|
||||
{
|
||||
SetSample(distance, duration, 0.0f);
|
||||
}
|
||||
public void SetSample(float distance, float duration, float minSpeedScale)
|
||||
{
|
||||
ViDebuger.AssertWarning(distance >= 0, "distance >= 0");
|
||||
ViDebuger.AssertWarning(duration >= 0, "duration >= 0");
|
||||
float avgSpeed = distance / duration;
|
||||
_minSpeed = avgSpeed * minSpeedScale;
|
||||
_maxSpeed = avgSpeed * (2.0f - minSpeedScale);
|
||||
_accelerate = 2.0f * (_maxSpeed - _minSpeed) / duration;
|
||||
}
|
||||
|
||||
|
||||
float _curDiretion;
|
||||
float _accelerate = 2.0f;
|
||||
float _currentSpeed = 0.0f;
|
||||
float _minSpeed = 0.0f;
|
||||
float _maxSpeed = 4.0f;
|
||||
}
|
||||
11
Unity/Assets/Plugins/ViSDK/ViMath/ViAngleCursor.cs.meta
Normal file
11
Unity/Assets/Plugins/ViSDK/ViMath/ViAngleCursor.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b10f5bc7670b8544ad5553d594230db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
140
Unity/Assets/Plugins/ViSDK/ViMath/ViInterpolation.cs
Normal file
140
Unity/Assets/Plugins/ViSDK/ViMath/ViInterpolation.cs
Normal file
@ -0,0 +1,140 @@
|
||||
using System;
|
||||
|
||||
public class ViValueInterpolation
|
||||
{
|
||||
public float Value { get { return _currentValue; } }
|
||||
public float Accelerate { get { return _accelerate; } set { _accelerate = ViMathDefine.Max(0.0f, value); } }
|
||||
public float MinSpeed { get { return _minSpeed; } set { _minSpeed = ViMathDefine.Max(0.0f, value); } }
|
||||
public float MaxSpeed { get { return _maxSpeed; } set { _maxSpeed = ViMathDefine.Max(0.0f, value); } }
|
||||
public float TimeScale { get { return _timeScale; } set { _timeScale = ViMathDefine.Max(0.0f, value); } }
|
||||
public float CurrentSpeed { get { return _currentSpeed; } }
|
||||
public bool IsFiltering { get { return (_currentSpeed != 0.0f); } }
|
||||
|
||||
public bool Update(float destValue, float deltaTime)
|
||||
{
|
||||
float diff = destValue - _currentValue;
|
||||
if (diff == 0.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
deltaTime *= TimeScale;
|
||||
if (diff > 0.0f)
|
||||
{
|
||||
float newSpeed = _currentSpeed + _accelerate * deltaTime;
|
||||
float brakingSpeed = ViMathDefine.Sqrt(diff * _accelerate * 2.0f);
|
||||
_currentSpeed = ViMathDefine.Min(ViMathDefine.Clamp(newSpeed, _minSpeed, _maxSpeed), brakingSpeed);
|
||||
float deltaDist = _currentSpeed * deltaTime;
|
||||
_currentValue += deltaDist;
|
||||
if (_currentValue >= destValue)
|
||||
{
|
||||
_currentValue = destValue;
|
||||
_currentSpeed = 0.0f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float newSpeed = _currentSpeed - _accelerate * deltaTime;
|
||||
float brakingSpeed = -ViMathDefine.Sqrt(-diff * _accelerate * 2.0f);
|
||||
_currentSpeed = ViMathDefine.Max(ViMathDefine.Clamp(newSpeed, -_maxSpeed, -_minSpeed), brakingSpeed);
|
||||
float deltaDist = _currentSpeed * deltaTime;
|
||||
_currentValue += deltaDist;
|
||||
if (_currentValue <= destValue)
|
||||
{
|
||||
_currentValue = destValue;
|
||||
_currentSpeed = 0.0f;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void StopAt(float fDistance)
|
||||
{
|
||||
_currentValue = fDistance;
|
||||
_currentSpeed = 0.0f;
|
||||
}
|
||||
|
||||
public void SetSample(float distance, float duration)
|
||||
{
|
||||
SetSample(distance, duration, 0.0f);
|
||||
}
|
||||
public void SetSample(float distance, float duration, float minSpeedScale)
|
||||
{
|
||||
ViDebuger.AssertWarning(distance >= 0, "distance >= 0");
|
||||
ViDebuger.AssertWarning(duration >= 0, "duration >= 0");
|
||||
float avgSpeed = distance / duration;
|
||||
_minSpeed = avgSpeed * minSpeedScale;
|
||||
_maxSpeed = avgSpeed * (2.0f - minSpeedScale);
|
||||
_accelerate = 2.0f * (_maxSpeed - _minSpeed) / duration;
|
||||
}
|
||||
|
||||
float _accelerate = 2.0f;
|
||||
float _currentSpeed = 0.0f;
|
||||
float _minSpeed = 0.0f;
|
||||
float _maxSpeed = 4.0f;
|
||||
float _timeScale = 1.0f;
|
||||
float _currentValue = 0.0f;
|
||||
}
|
||||
|
||||
public class ViVector3Interpolation
|
||||
{
|
||||
public ViVector3 Value { get { return _currentValue; } }
|
||||
public float Accelerate { get { return _accelerate; } set { _accelerate = ViMathDefine.Max(0.0f, value); } }
|
||||
public float MinSpeed { get { return _minSpeed; } set { _minSpeed = ViMathDefine.Max(0.0f, value); } }
|
||||
public float MaxSpeed { get { return _maxSpeed; } set { _maxSpeed = ViMathDefine.Max(0.0f, value); } }
|
||||
public float TimeScale { get { return _timeScale; } set { _timeScale = ViMathDefine.Max(0.0f, value); } }
|
||||
public float CurrentSpeed { get { return _currentSpeed; } }
|
||||
public bool IsFiltering { get { return (_currentSpeed != 0.0f); } }
|
||||
|
||||
public bool Update(ViVector3 desireValue, float deltaTime)
|
||||
{
|
||||
ViVector3 diff = desireValue - _currentValue;
|
||||
float diffLen = diff.Length;
|
||||
if (diffLen == 0.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
deltaTime *= TimeScale;
|
||||
float newSpeed = _currentSpeed + _accelerate * deltaTime;
|
||||
float brakingSpeed = ViMathDefine.Sqrt(diffLen * _accelerate * 2.0f);
|
||||
_currentSpeed = ViMathDefine.Min(ViMathDefine.Clamp(newSpeed, _minSpeed, _maxSpeed), brakingSpeed);
|
||||
float frontDistance = _currentSpeed * deltaTime;
|
||||
if (frontDistance > diffLen)
|
||||
{
|
||||
_currentValue = desireValue;
|
||||
_currentSpeed = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
ViVector3 deltaDist = frontDistance * diff.normalized;
|
||||
_currentValue += deltaDist;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void StopAt(ViVector3 fDistance)
|
||||
{
|
||||
_currentValue = fDistance;
|
||||
_currentSpeed = 0.0f;
|
||||
}
|
||||
|
||||
public void SetSample(float distance, float duration)
|
||||
{
|
||||
SetSample(distance, duration, 0.0f);
|
||||
}
|
||||
public void SetSample(float distance, float duration, float minSpeedScale)
|
||||
{
|
||||
ViDebuger.AssertWarning(distance >= 0, "distance >= 0");
|
||||
ViDebuger.AssertWarning(duration >= 0, "duration >= 0");
|
||||
float avgSpeed = distance / duration;
|
||||
_minSpeed = avgSpeed * minSpeedScale;
|
||||
_maxSpeed = avgSpeed * (2.0f - minSpeedScale);
|
||||
_accelerate = 2.0f * (_maxSpeed - _minSpeed) / duration;
|
||||
}
|
||||
|
||||
float _accelerate = 2.0f;
|
||||
float _currentSpeed = 0.0f;
|
||||
float _minSpeed = 0.0f;
|
||||
float _maxSpeed = 4.0f;
|
||||
float _timeScale = 1.0f;
|
||||
ViVector3 _currentValue;
|
||||
}
|
||||
12
Unity/Assets/Plugins/ViSDK/ViMath/ViInterpolation.cs.meta
Normal file
12
Unity/Assets/Plugins/ViSDK/ViMath/ViInterpolation.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57371fba9a4a0bb4fa4ca6cb70c5a91d
|
||||
timeCreated: 1453717662
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
796
Unity/Assets/Plugins/ViSDK/ViMath/ViMathDefine.cs
Normal file
796
Unity/Assets/Plugins/ViSDK/ViMath/ViMathDefine.cs
Normal file
@ -0,0 +1,796 @@
|
||||
using System;
|
||||
|
||||
using Int8 = System.SByte;
|
||||
using UInt8 = System.Byte;
|
||||
|
||||
public static class ViMathDefine
|
||||
{
|
||||
public static readonly float PI = 3.141593f;
|
||||
public static readonly float PI_X2 = PI * 2;
|
||||
public static readonly float PI_X3 = PI * 3;
|
||||
public static readonly float PI_X4 = PI * 4;
|
||||
public static readonly float PI_HALF = PI * 0.5f;
|
||||
public static readonly float Infinity = float.PositiveInfinity;
|
||||
public static readonly float NegativeInfinity = float.NegativeInfinity;
|
||||
public static readonly float Deg2Rad = 0.01745329f;
|
||||
public static readonly float Rad2Deg = 57.29578f;
|
||||
public static readonly float Epsilon = float.Epsilon;
|
||||
public static float Sin(float f)
|
||||
{
|
||||
return (float)Math.Sin((double)f);
|
||||
}
|
||||
|
||||
public static float Cos(float f)
|
||||
{
|
||||
return (float)Math.Cos((double)f);
|
||||
}
|
||||
|
||||
public static float Tan(float f)
|
||||
{
|
||||
return (float)Math.Tan((double)f);
|
||||
}
|
||||
|
||||
public static float Asin(float f)
|
||||
{
|
||||
return (float)Math.Asin((double)f);
|
||||
}
|
||||
|
||||
public static float Acos(float f)
|
||||
{
|
||||
return (float)Math.Acos((double)f);
|
||||
}
|
||||
|
||||
public static float Atan(float f)
|
||||
{
|
||||
return (float)Math.Atan((double)f);
|
||||
}
|
||||
|
||||
public static float Atan2(float y, float x)
|
||||
{
|
||||
return (float)Math.Atan2((double)y, (double)x);
|
||||
}
|
||||
|
||||
public static float Sqrt(float f)
|
||||
{
|
||||
return (float)Math.Sqrt((double)f);
|
||||
}
|
||||
|
||||
public static Int32 IntInf(float value)
|
||||
{
|
||||
if (value >= 0)
|
||||
{
|
||||
return (Int32)value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (Int32)(value - 0.999f);
|
||||
}
|
||||
}
|
||||
public static Int32 IntSup(float value)
|
||||
{
|
||||
if (value >= 0)
|
||||
{
|
||||
return (Int32)(value + 0.999f);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (Int32)value;
|
||||
}
|
||||
}
|
||||
public static UInt32 IntSup(Int32 total, Int32 span)
|
||||
{
|
||||
if (span <= 0 || total < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return (UInt32)((total + span - 1) / span);
|
||||
}
|
||||
public static UInt32 IntSup(UInt32 total, UInt32 span)
|
||||
{
|
||||
if (span == 0)
|
||||
{
|
||||
return total;
|
||||
}
|
||||
return (total + span - 1) / span;
|
||||
}
|
||||
public static Int32 IntNear(float value)
|
||||
{
|
||||
if (value >= 0)
|
||||
{
|
||||
return (Int32)(value + 0.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (Int32)(value - 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
public static float Abs(float value)
|
||||
{
|
||||
return Math.Abs(value);
|
||||
}
|
||||
public static Int8 Abs(Int8 value)
|
||||
{
|
||||
return Math.Abs(value);
|
||||
}
|
||||
public static Int16 Abs(Int16 value)
|
||||
{
|
||||
return Math.Abs(value);
|
||||
}
|
||||
public static Int32 Abs(Int32 value)
|
||||
{
|
||||
return Math.Abs(value);
|
||||
}
|
||||
public static Int64 Abs(Int64 value)
|
||||
{
|
||||
return Math.Abs(value);
|
||||
}
|
||||
public static float Min(float a, float b)
|
||||
{
|
||||
return ((a >= b) ? b : a);
|
||||
}
|
||||
public static double Min(double a, double b)
|
||||
{
|
||||
return ((a >= b) ? b : a);
|
||||
}
|
||||
public static Int8 Min(Int8 a, Int8 b)
|
||||
{
|
||||
return ((a >= b) ? b : a);
|
||||
}
|
||||
public static UInt8 Min(UInt8 a, UInt8 b)
|
||||
{
|
||||
return ((a >= b) ? b : a);
|
||||
}
|
||||
public static Int16 Min(Int16 a, Int16 b)
|
||||
{
|
||||
return ((a >= b) ? b : a);
|
||||
}
|
||||
public static UInt16 Min(UInt16 a, UInt16 b)
|
||||
{
|
||||
return ((a >= b) ? b : a);
|
||||
}
|
||||
public static Int32 Min(Int32 a, Int32 b)
|
||||
{
|
||||
return ((a >= b) ? b : a);
|
||||
}
|
||||
public static UInt32 Min(UInt32 a, UInt32 b)
|
||||
{
|
||||
return ((a >= b) ? b : a);
|
||||
}
|
||||
public static Int64 Min(Int64 a, Int64 b)
|
||||
{
|
||||
return ((a >= b) ? b : a);
|
||||
}
|
||||
public static UInt64 Min(UInt64 a, UInt64 b)
|
||||
{
|
||||
return ((a >= b) ? b : a);
|
||||
}
|
||||
public static float Min(params float[] values)
|
||||
{
|
||||
int length = values.Length;
|
||||
if (length == 0)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
float num2 = values[0];
|
||||
for (int i = 1; i < length; i++)
|
||||
{
|
||||
if (values[i] < num2)
|
||||
{
|
||||
num2 = values[i];
|
||||
}
|
||||
}
|
||||
return num2;
|
||||
}
|
||||
public static int Min(params int[] values)
|
||||
{
|
||||
int length = values.Length;
|
||||
if (length == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int num2 = values[0];
|
||||
for (int i = 1; i < length; i++)
|
||||
{
|
||||
if (values[i] < num2)
|
||||
{
|
||||
num2 = values[i];
|
||||
}
|
||||
}
|
||||
return num2;
|
||||
}
|
||||
public static float Max(float a, float b)
|
||||
{
|
||||
return ((a <= b) ? b : a);
|
||||
}
|
||||
public static double Max(double a, double b)
|
||||
{
|
||||
return ((a <= b) ? b : a);
|
||||
}
|
||||
public static Int8 Max(Int8 a, Int8 b)
|
||||
{
|
||||
return ((a <= b) ? b : a);
|
||||
}
|
||||
public static UInt8 Max(UInt8 a, UInt8 b)
|
||||
{
|
||||
return ((a <= b) ? b : a);
|
||||
}
|
||||
public static Int16 Max(Int16 a, Int16 b)
|
||||
{
|
||||
return ((a <= b) ? b : a);
|
||||
}
|
||||
public static UInt16 Max(UInt16 a, UInt16 b)
|
||||
{
|
||||
return ((a <= b) ? b : a);
|
||||
}
|
||||
public static Int32 Max(Int32 a, Int32 b)
|
||||
{
|
||||
return ((a <= b) ? b : a);
|
||||
}
|
||||
public static UInt32 Max(UInt32 a, UInt32 b)
|
||||
{
|
||||
return ((a <= b) ? b : a);
|
||||
}
|
||||
public static Int64 Max(Int64 a, Int64 b)
|
||||
{
|
||||
return ((a <= b) ? b : a);
|
||||
}
|
||||
public static UInt64 Max(UInt64 a, UInt64 b)
|
||||
{
|
||||
return ((a <= b) ? b : a);
|
||||
}
|
||||
public static float Max(params float[] values)
|
||||
{
|
||||
int length = values.Length;
|
||||
if (length == 0)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
float num2 = values[0];
|
||||
for (int i = 1; i < length; i++)
|
||||
{
|
||||
if (values[i] > num2)
|
||||
{
|
||||
num2 = values[i];
|
||||
}
|
||||
}
|
||||
return num2;
|
||||
}
|
||||
public static int Max(params int[] values)
|
||||
{
|
||||
int length = values.Length;
|
||||
if (length == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int num2 = values[0];
|
||||
for (int i = 1; i < length; i++)
|
||||
{
|
||||
if (values[i] > num2)
|
||||
{
|
||||
num2 = values[i];
|
||||
}
|
||||
}
|
||||
return num2;
|
||||
}
|
||||
|
||||
public static bool InRange(Int8 value, Int8 inf, Int8 sup)
|
||||
{
|
||||
return inf <= value && value <= sup;
|
||||
}
|
||||
public static bool InRange(Int16 value, Int16 inf, Int16 sup)
|
||||
{
|
||||
return inf <= value && value <= sup;
|
||||
}
|
||||
public static bool InRange(Int32 value, Int32 inf, Int32 sup)
|
||||
{
|
||||
return inf <= value && value <= sup;
|
||||
}
|
||||
public static bool InRange(Int64 value, Int64 inf, Int64 sup)
|
||||
{
|
||||
return inf <= value && value <= sup;
|
||||
}
|
||||
public static bool InRange(float value, float inf, float sup)
|
||||
{
|
||||
return inf <= value && value <= sup;
|
||||
}
|
||||
|
||||
public static float Pow(float f, float p)
|
||||
{
|
||||
return (float)Math.Pow((double)f, (double)p);
|
||||
}
|
||||
|
||||
public static float Exp(float power)
|
||||
{
|
||||
return (float)Math.Exp((double)power);
|
||||
}
|
||||
|
||||
public static float Log(float f, float p)
|
||||
{
|
||||
return (float)Math.Log((double)f, (double)p);
|
||||
}
|
||||
|
||||
public static float Log(float f)
|
||||
{
|
||||
return (float)Math.Log((double)f);
|
||||
}
|
||||
|
||||
public static float Log10(float f)
|
||||
{
|
||||
return (float)Math.Log10((double)f);
|
||||
}
|
||||
|
||||
public static float Ceil(float f)
|
||||
{
|
||||
return (float)Math.Ceiling((double)f);
|
||||
}
|
||||
|
||||
public static float Floor(float f)
|
||||
{
|
||||
return (float)Math.Floor((double)f);
|
||||
}
|
||||
|
||||
public static float Round(float f)
|
||||
{
|
||||
return (float)Math.Round((double)f);
|
||||
}
|
||||
|
||||
public static int CeilToInt(float f)
|
||||
{
|
||||
return (int)Math.Ceiling((double)f);
|
||||
}
|
||||
|
||||
public static int FloorToInt(float f)
|
||||
{
|
||||
return (int)Math.Floor((double)f);
|
||||
}
|
||||
|
||||
public static int RoundToInt(float f)
|
||||
{
|
||||
return (int)Math.Round((double)f);
|
||||
}
|
||||
|
||||
public static float Float(Int32 numerator, Int32 denominator)
|
||||
{
|
||||
return (float)(((double)numerator) / ((double)denominator));
|
||||
}
|
||||
|
||||
public static float Sign(float f)
|
||||
{
|
||||
return ((f < 0f) ? -1f : 1f);
|
||||
}
|
||||
public static float Radius2Degree(float radius)
|
||||
{
|
||||
return 180.0f - radius * Rad2Deg;
|
||||
}
|
||||
public static float Clamp(float value, float min, float max)
|
||||
{
|
||||
if (value < min)
|
||||
{
|
||||
value = min;
|
||||
return value;
|
||||
}
|
||||
if (value > max)
|
||||
{
|
||||
value = max;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static int Clamp(int value, int min, int max)
|
||||
{
|
||||
if (value < min)
|
||||
{
|
||||
value = min;
|
||||
return value;
|
||||
}
|
||||
if (value > max)
|
||||
{
|
||||
value = max;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static Int64 Clamp(Int64 value, Int64 min, Int64 max)
|
||||
{
|
||||
if (value < min)
|
||||
{
|
||||
value = min;
|
||||
return value;
|
||||
}
|
||||
if (value > max)
|
||||
{
|
||||
value = max;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static float Clamp01(float value)
|
||||
{
|
||||
if (value < 0f)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
if (value > 1f)
|
||||
{
|
||||
return 1f;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static float Lerp(float from, float to, float t)
|
||||
{
|
||||
return (from + ((to - from) * Clamp01(t)));
|
||||
}
|
||||
|
||||
public static float Wrap(float val, float low, float high)// 取值范围[low, high)
|
||||
{
|
||||
float ret = (val);
|
||||
float rang = (high - low);
|
||||
|
||||
while (ret >= high)
|
||||
{
|
||||
ret -= rang;
|
||||
}
|
||||
while (ret < low)
|
||||
{
|
||||
ret += rang;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static int Wrap(int val, int low, int high)// 取值范围[low, high)
|
||||
{
|
||||
int ret = (val);
|
||||
int rang = (high - low);
|
||||
|
||||
while (ret >= high)
|
||||
{
|
||||
ret -= rang;
|
||||
}
|
||||
while (ret < low)
|
||||
{
|
||||
ret += rang;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
public static float MoveTowards(float current, float target, float maxDelta)
|
||||
{
|
||||
if (Abs((float)(target - current)) <= maxDelta)
|
||||
{
|
||||
return target;
|
||||
}
|
||||
return (current + (Sign(target - current) * maxDelta));
|
||||
}
|
||||
|
||||
//public static float MoveTowardsAngle(float current, float target, float maxDelta)
|
||||
//{
|
||||
// target = current + DeltaAngle(current, target);
|
||||
// return MoveTowards(current, target, maxDelta);
|
||||
//}
|
||||
|
||||
public static float SmoothStep(float from, float to, float t)
|
||||
{
|
||||
t = Clamp01(t);
|
||||
t = (((-2f * t) * t) * t) + ((3f * t) * t);
|
||||
return ((to * t) + (from * (1f - t)));
|
||||
}
|
||||
|
||||
public static float Gamma(float value, float absmax, float gamma)
|
||||
{
|
||||
bool flag = false;
|
||||
if (value < 0f)
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
float num = Abs(value);
|
||||
if (num > absmax)
|
||||
{
|
||||
return (!flag ? num : -num);
|
||||
}
|
||||
float num2 = Pow(num / absmax, gamma) * absmax;
|
||||
return (!flag ? num2 : -num2);
|
||||
}
|
||||
|
||||
public static bool Approximately(float a, float b)
|
||||
{
|
||||
return (Abs((float)(b - a)) < Max((float)(1E-06f * Max(Abs(a), Abs(b))), (float)1.121039E-44f));
|
||||
}
|
||||
|
||||
//public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed)
|
||||
//{
|
||||
// float deltaTime = Time.deltaTime;
|
||||
// return SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime);
|
||||
//}
|
||||
|
||||
//public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime)
|
||||
//{
|
||||
// float deltaTime = Time.deltaTime;
|
||||
// float positiveInfinity = float.PositiveInfinity;
|
||||
// return SmoothDamp(current, target, ref currentVelocity, smoothTime, positiveInfinity, deltaTime);
|
||||
//}
|
||||
|
||||
//public static float SmoothDamp(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed, float deltaTime)
|
||||
//{
|
||||
// smoothTime = Max(0.0001f, smoothTime);
|
||||
// float num = 2f / smoothTime;
|
||||
// float num2 = num * deltaTime;
|
||||
// float num3 = 1f / (((1f + num2) + ((0.48f * num2) * num2)) + (((0.235f * num2) * num2) * num2));
|
||||
// float num4 = current - target;
|
||||
// float num5 = target;
|
||||
// float max = maxSpeed * smoothTime;
|
||||
// num4 = Clamp(num4, -max, max);
|
||||
// target = current - num4;
|
||||
// float num7 = (currentVelocity + (num * num4)) * deltaTime;
|
||||
// currentVelocity = (currentVelocity - (num * num7)) * num3;
|
||||
// float num8 = target + ((num4 + num7) * num3);
|
||||
// if (((num5 - current) > 0f) == (num8 > num5))
|
||||
// {
|
||||
// num8 = num5;
|
||||
// currentVelocity = (num8 - num5) / deltaTime;
|
||||
// }
|
||||
// return num8;
|
||||
//}
|
||||
|
||||
//public static float SmoothDampAngle(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed)
|
||||
//{
|
||||
// float deltaTime = Time.deltaTime;
|
||||
// return SmoothDampAngle(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime);
|
||||
//}
|
||||
|
||||
//public static float SmoothDampAngle(float current, float target, ref float currentVelocity, float smoothTime)
|
||||
//{
|
||||
// float deltaTime = Time.deltaTime;
|
||||
// float positiveInfinity = float.PositiveInfinity;
|
||||
// return SmoothDampAngle(current, target, ref currentVelocity, smoothTime, positiveInfinity, deltaTime);
|
||||
//}
|
||||
|
||||
//public static float SmoothDampAngle(float current, float target, ref float currentVelocity, float smoothTime, float maxSpeed, float deltaTime)
|
||||
//{
|
||||
// target = current + DeltaAngle(current, target);
|
||||
// return SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime);
|
||||
//}
|
||||
|
||||
public static float Repeat(float t, float length)
|
||||
{
|
||||
return (t - (Floor(t / length) * length));
|
||||
}
|
||||
|
||||
public static float PingPong(float t, float length)
|
||||
{
|
||||
t = Repeat(t, length * 2f);
|
||||
return (length - Abs((float)(t - length)));
|
||||
}
|
||||
|
||||
public static float InverseLerp(float from, float to, float value)
|
||||
{
|
||||
if (from < to)
|
||||
{
|
||||
if (value < from)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
if (value > to)
|
||||
{
|
||||
return 1f;
|
||||
}
|
||||
value -= from;
|
||||
value /= to - from;
|
||||
return value;
|
||||
}
|
||||
if (from <= to)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
if (value < to)
|
||||
{
|
||||
return 1f;
|
||||
}
|
||||
if (value > from)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
return (1f - ((value - to) / (from - to)));
|
||||
}
|
||||
}
|
||||
|
||||
public class ViMath2D
|
||||
{
|
||||
public static readonly float FRONT_X = 0.0f;
|
||||
public static readonly float FRONT_Y = -1.0f;
|
||||
|
||||
public static float Length(float x, float y)
|
||||
{
|
||||
return (float)Math.Sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
public static float Length2(float x, float y)
|
||||
{
|
||||
return (x * x + y * y);
|
||||
}
|
||||
public static float Length(float fSrcX, float fSrcY, float fDesX, float fDesY)
|
||||
{
|
||||
float deltaX = fDesX - fSrcX;
|
||||
float deltaY = fDesY - fSrcY;
|
||||
return (float)Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
|
||||
}
|
||||
|
||||
public static float Length2(float fSrcX, float fSrcY, float fDesX, float fDesY)
|
||||
{
|
||||
float deltaX = fDesX - fSrcX;
|
||||
float deltaY = fDesY - fSrcY;
|
||||
return (deltaX * deltaX + deltaY * deltaY);
|
||||
}
|
||||
|
||||
public static float GetAngle(float fX, float fY)
|
||||
{
|
||||
float angle = (float)Math.Atan2(fX, -fY);
|
||||
return angle;
|
||||
}
|
||||
public static void CaculateAngle(float fAngle, ref float fX, ref float fY)
|
||||
{
|
||||
fY = -(float)Math.Cos(fAngle);
|
||||
fX = (float)Math.Sin(fAngle);
|
||||
}
|
||||
public static float GetRotateAngle(float fSrcX, float fSrcy, float fDesX, float fDesY)
|
||||
{
|
||||
//if(abs(fSrcX) <= 0.001f && abs(fSrcy) <= 0.001f
|
||||
// || abs(fDesX) <= 0.001f && abs(fDesY) <= 0.001f)
|
||||
//{
|
||||
// return 0.0f;
|
||||
//}
|
||||
float fDesAngle = GetAngle(fDesX, fDesY);
|
||||
float fSrcAngle = GetAngle(fSrcX, fSrcy);
|
||||
float fRotateAngle = fDesAngle - fSrcAngle;
|
||||
// 映射到(-M_PI, M_PI)区间上来
|
||||
if (fRotateAngle > ViMathDefine.PI)
|
||||
fRotateAngle -= ViMathDefine.PI_X2;
|
||||
else if (fRotateAngle < -ViMathDefine.PI)
|
||||
fRotateAngle += ViMathDefine.PI_X2;
|
||||
return fRotateAngle;
|
||||
}
|
||||
|
||||
public static void Rotate(float fSrcX, float fSrcy, float fRotateAngle, ref float fDesX, ref float fDesY)
|
||||
{
|
||||
//! 逆时针旋转
|
||||
float fSin = (float)Math.Sin(fRotateAngle);
|
||||
float fCon = (float)Math.Cos(fRotateAngle);
|
||||
//! 顺时针旋转
|
||||
//float fSin = sin(-fRotateAngle);
|
||||
//float fCon = cos(-fRotateAngle);
|
||||
fDesX = fCon * fSrcX - fSin * fSrcy;
|
||||
fDesY = fSin * fSrcX + fCon * fSrcy;
|
||||
}
|
||||
|
||||
public static void Rotate(ref float fX, ref float fY, float fRotateAngle)
|
||||
{
|
||||
float fSin = (float)Math.Sin(fRotateAngle);
|
||||
float fCon = (float)Math.Cos(fRotateAngle);
|
||||
//! 顺时针旋转
|
||||
//float fSin = sin(-fRotateAngle);
|
||||
//float fCon = cos(-fRotateAngle);
|
||||
float fDesX = fCon * fX - fSin * fY;
|
||||
float fDesY = fSin * fX + fCon * fY;
|
||||
fX = fDesX;
|
||||
fY = fDesY;
|
||||
}
|
||||
|
||||
public static void RotateRight90(ref float x, ref float y)
|
||||
{
|
||||
float temp = x;
|
||||
x = y;
|
||||
y = -temp;
|
||||
}
|
||||
public static void RotateLeft90(ref float x, ref float y)
|
||||
{
|
||||
float temp = x;
|
||||
x = -y;
|
||||
y = temp;
|
||||
}
|
||||
public static int GetSide(float fromX, float fromY, float toX, float toY, float x, float y)
|
||||
{
|
||||
float s = (fromX - x) * (toY - y) - (fromY - y) * (toX - x);
|
||||
if (s == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (s < 0)//! 右侧
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool GetCross(ViVector3 from, float speed, ViVector3 targetPos, ViVector3 targetVelocity, out float time, out ViVector3 direction)
|
||||
{
|
||||
float deltaX = targetPos.x - from.x;
|
||||
float deltaY = targetPos.y - from.y;
|
||||
float sqrValue = (deltaX * deltaX + deltaY * deltaY) * speed * speed + 2 * deltaX * deltaY * targetVelocity.x * targetVelocity.x - deltaX * deltaX * targetVelocity.y * targetVelocity.y - deltaY * deltaY * targetVelocity.x * targetVelocity.x;
|
||||
if (sqrValue >= 0)
|
||||
{
|
||||
float temp1 = -deltaX * targetVelocity.x - deltaY * targetVelocity.y + ViMathDefine.Sqrt(sqrValue);
|
||||
float temp2 = -deltaX * targetVelocity.x - deltaY * targetVelocity.y - ViMathDefine.Sqrt(sqrValue);
|
||||
if (temp1 == 0f && temp2 == 0f)
|
||||
{
|
||||
time = 0f;
|
||||
direction = ViVector3.ZERO;
|
||||
return false;
|
||||
}
|
||||
else if (temp1 == 0f)
|
||||
{
|
||||
time = (deltaX * deltaX + deltaY * deltaY) / temp2;
|
||||
}
|
||||
else if (temp2 == 0f)
|
||||
{
|
||||
time = (deltaX * deltaX + deltaY * deltaY) / temp1;
|
||||
}
|
||||
else
|
||||
{
|
||||
time = (deltaX * deltaX + deltaY * deltaY) / ViMathDefine.Max(temp1, temp2);
|
||||
}
|
||||
direction = new ViVector3(targetVelocity.x + deltaX / time, targetVelocity.y + deltaY / time, 0);
|
||||
direction.Normalize();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
time = 0f;
|
||||
direction = ViVector3.ZERO;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ViMath3D
|
||||
{
|
||||
public static void Convert(ViVector3 diretion, float roll, out ViVector3 horizDir, out ViVector3 normal)
|
||||
{
|
||||
horizDir = diretion;
|
||||
horizDir.z = 0.0f;
|
||||
horizDir.Normalize();
|
||||
diretion.Normalize();
|
||||
ViVector3 rotateAxis = ViVector3.Cross(diretion, ViVector3.UNIT_Z);
|
||||
rotateAxis.Normalize();
|
||||
ViQuaternion verticalRotateQuat = ViQuaternion.FromAxisAngle(rotateAxis, ViMathDefine.PI_HALF);
|
||||
normal = verticalRotateQuat * diretion;
|
||||
ViQuaternion rollRotateQuat = ViQuaternion.FromAxisAngle(diretion, roll);
|
||||
normal = rollRotateQuat * normal;
|
||||
}
|
||||
|
||||
//public static void Convert(ViVector3 horizDir, ViVector3 normal, out ViVector3 diretion, out float roll)
|
||||
//{
|
||||
// normal.Normalize();
|
||||
// ViVector3 rotateAxis = ViVector3.Cross(horizDir, ViVector3.UNIT_Z);
|
||||
// if (rotateAxis == normal)
|
||||
// {
|
||||
// diretion = horizDir;
|
||||
// roll = 0.0f;
|
||||
// }
|
||||
// diretion = ViVector3.Cross(rotateAxis, normal);
|
||||
// if (ViVector3.Angle(horizDir, diretion) < ViMathDefine.PI_HALF)
|
||||
// {
|
||||
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// diretion = -diretion;
|
||||
// rotateAxis = -rotateAxis;
|
||||
// }
|
||||
// ViQuaternion verticalRotateQuat = ViQuaternion.FromAxisAngle(rotateAxis, ViMathDefine.PI_HALF);
|
||||
// ViVector3 normal1 = verticalRotateQuat * diretion;
|
||||
// ViVector3 normalRotAxisDir = ViVector3.Cross(normal1, normal);
|
||||
// if (ViVector3.Angle(horizDir, diretion) < ViMathDefine.PI_HALF)
|
||||
// {
|
||||
// roll = ViVector3.Angle(normal1, normal);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// roll = -ViVector3.Angle(normal1, normal);
|
||||
// }
|
||||
|
||||
//}
|
||||
}
|
||||
12
Unity/Assets/Plugins/ViSDK/ViMath/ViMathDefine.cs.meta
Normal file
12
Unity/Assets/Plugins/ViSDK/ViMath/ViMathDefine.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e56e778ebed13b478243494f0b33093
|
||||
timeCreated: 1453717662
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
297
Unity/Assets/Plugins/ViSDK/ViMath/ViQuaternion.cs
Normal file
297
Unity/Assets/Plugins/ViSDK/ViMath/ViQuaternion.cs
Normal file
@ -0,0 +1,297 @@
|
||||
using System;
|
||||
|
||||
public struct ViQuaternion
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
public float z;
|
||||
public float w;
|
||||
|
||||
public ViQuaternion(float x, float y, float z, float w)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
static public ViQuaternion FromAxisAngle(ViVector3 axis, float radians)
|
||||
{
|
||||
axis.Normalize();
|
||||
ViVector3 scaledAxis = axis * (float)Math.Sin(radians * 0.5f);
|
||||
return new ViQuaternion(scaledAxis.x, scaledAxis.y, scaledAxis.z, (float)Math.Cos(radians * 0.5f));
|
||||
}
|
||||
|
||||
static public ViQuaternion FromAxisAngle(float x, float y, float z, float fRadians)
|
||||
{
|
||||
return ViQuaternion.FromAxisAngle(new ViVector3(x, y, z), fRadians);
|
||||
}
|
||||
|
||||
//static public Quaternion FromTransform(Matrix3D xfrm)
|
||||
//{
|
||||
// Quaternion quat = new Quaternion();
|
||||
|
||||
// // Check the sum of the diagonal
|
||||
// float tr = xfrm[0, 0] + xfrm[1, 1] + xfrm[2, 2];
|
||||
// if (tr > 0.0f)
|
||||
// {
|
||||
// // The sum is positive
|
||||
// // 4 muls, 1 div, 6 adds, 1 trig function call
|
||||
// float s = (float)Math.Sqrt(tr + 1.0f);
|
||||
// quat.W = s * 0.5f;
|
||||
// s = 0.5f / s;
|
||||
// quat.X = (xfrm[1, 2] - xfrm[2, 1]) * s;
|
||||
// quat.Y = (xfrm[2, 0] - xfrm[0, 2]) * s;
|
||||
// quat.Z = (xfrm[0, 1] - xfrm[1, 0]) * s;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // The sum is negative
|
||||
// // 4 muls, 1 div, 8 adds, 1 trig function call
|
||||
// int[] nIndex = { 1, 2, 0 };
|
||||
// int i, j, k;
|
||||
// i = 0;
|
||||
// if (xfrm[1, 1] > xfrm[i, i])
|
||||
// i = 1;
|
||||
// if (xfrm[2, 2] > xfrm[i, i])
|
||||
// i = 2;
|
||||
// j = nIndex[i];
|
||||
// k = nIndex[j];
|
||||
|
||||
// float s = (float)Math.Sqrt((xfrm[i, i] - (xfrm[j, j] + xfrm[k, k])) + 1.0f);
|
||||
// quat[i] = s * 0.5f;
|
||||
// if (s != 0.0)
|
||||
// {
|
||||
// s = 0.5f / s;
|
||||
// }
|
||||
// quat[j] = (xfrm[i, j] + xfrm[j, i]) * s;
|
||||
// quat[k] = (xfrm[i, k] + xfrm[k, i]) * s;
|
||||
// quat[3] = (xfrm[j, k] - xfrm[k, j]) * s;
|
||||
// }
|
||||
// return quat;
|
||||
//}
|
||||
|
||||
public float this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
ViDebuger.AssertError(0 <= index && index <= 3);
|
||||
if (index <= 1)
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
return this.x;
|
||||
}
|
||||
return this.y;
|
||||
}
|
||||
if (index == 2)
|
||||
{
|
||||
return this.z;
|
||||
}
|
||||
return this.w;
|
||||
}
|
||||
set
|
||||
{
|
||||
ViDebuger.AssertError(0 <= index && index <= 3);
|
||||
if (index <= 1)
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
this.x = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.y = value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (index == 2)
|
||||
{
|
||||
this.z = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.w = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void GetAxisAngle(out ViVector3 axis, out float radians)
|
||||
{
|
||||
radians = (float)Math.Acos(this.w);
|
||||
if (radians != 0)
|
||||
{
|
||||
axis = new ViVector3(this.x, this.y, this.z);
|
||||
axis /= (float)Math.Sin(radians);
|
||||
axis.Normalize();
|
||||
radians *= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
axis = ViVector3.UNIT_X;
|
||||
}
|
||||
}
|
||||
|
||||
static public bool operator ==(ViQuaternion a, ViQuaternion b)
|
||||
{
|
||||
return (a.x == b.x) && (a.y == b.y) && (a.z == b.z) && (a.w == b.w);
|
||||
}
|
||||
|
||||
static public bool operator !=(ViQuaternion a, ViQuaternion b)
|
||||
{
|
||||
return (a.x != b.x) || (a.y != b.y) || (a.z != b.z) || (a.w != b.w);
|
||||
}
|
||||
|
||||
public override bool Equals(object o)
|
||||
{
|
||||
if (o is ViQuaternion)
|
||||
{
|
||||
ViQuaternion q = (ViQuaternion)o;
|
||||
return (this.x == q.x) && (this.y == q.y) && (this.z == q.z) && (this.w == q.w);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.x.GetHashCode() ^ ((~this.y.GetHashCode()) ^ (this.z.GetHashCode() ^ (~this.w.GetHashCode())));
|
||||
}
|
||||
|
||||
static public ViQuaternion operator +(ViQuaternion a, ViQuaternion b)
|
||||
{
|
||||
return new ViQuaternion(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
|
||||
}
|
||||
|
||||
static public ViQuaternion operator -(ViQuaternion a, ViQuaternion b)
|
||||
{
|
||||
return new ViQuaternion(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
|
||||
}
|
||||
|
||||
static public ViQuaternion operator *(ViQuaternion a, float f)
|
||||
{
|
||||
return new ViQuaternion(a.x * f, a.y * f, a.z * f, a.w * f);
|
||||
}
|
||||
|
||||
static public ViQuaternion operator /(ViQuaternion a, float f)
|
||||
{
|
||||
if (f == 0)
|
||||
{
|
||||
throw new DivideByZeroException("Dividing quaternion by zero");
|
||||
}
|
||||
return new ViQuaternion(a.x / f, a.y / f, a.z / f, a.w / f);
|
||||
}
|
||||
|
||||
static public ViVector3 operator *(ViQuaternion a, ViVector3 pt)
|
||||
{
|
||||
//ViQuaternion quatResult = a * new ViQuaternion(pt.x, pt.y, pt.z, 0) * a.GetUnitInverse();
|
||||
//return new ViVector3(quatResult.x, quatResult.y, quatResult.z);
|
||||
ViVector3 uv, uuv;
|
||||
ViVector3 qvec = new ViVector3(a.x, a.y, a.z);
|
||||
uv = ViVector3.Cross(qvec, pt);
|
||||
uuv = ViVector3.Cross(qvec, uv);
|
||||
uv *= (2.0f * a.w);
|
||||
uuv *= 2.0f;
|
||||
|
||||
return pt + uv + uuv;
|
||||
}
|
||||
|
||||
static public ViQuaternion operator *(ViQuaternion a, ViQuaternion b)
|
||||
{
|
||||
float E = (a.x + a.z) * (b.x + b.y);
|
||||
float F = (a.z - a.x) * (b.x - b.y);
|
||||
float G = (a.w + a.y) * (b.w - b.z);
|
||||
float H = (a.w - a.y) * (b.w + b.z);
|
||||
float A = F - E;
|
||||
float B = F + E;
|
||||
return new ViQuaternion(
|
||||
(a.w - a.x) * (b.y + b.z) + (B + G - H) * 0.5f,
|
||||
(a.y + a.z) * (b.w - b.x) + (B - G + H) * 0.5f,
|
||||
(a.z - a.y) * (b.y - b.z) + (A + G + H) * 0.5f,
|
||||
(a.w + a.x) * (b.w + b.x) + (A - G - H) * 0.5f);
|
||||
}
|
||||
|
||||
public ViQuaternion GetConjugate()
|
||||
{
|
||||
return new ViQuaternion(-this.x, -this.y, -this.z, this.w);
|
||||
}
|
||||
|
||||
public ViQuaternion GetInverse()
|
||||
{
|
||||
return this.GetConjugate() / this.GetMagnitudeSquared();
|
||||
}
|
||||
|
||||
public ViQuaternion GetUnitInverse()
|
||||
{
|
||||
return this.GetConjugate();
|
||||
}
|
||||
|
||||
public float GetMagnitude()
|
||||
{
|
||||
return (float)Math.Sqrt(this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z);
|
||||
}
|
||||
|
||||
public float GetMagnitudeSquared()
|
||||
{
|
||||
return this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z;
|
||||
}
|
||||
|
||||
public void Normalize()
|
||||
{
|
||||
float length = this.GetMagnitude();
|
||||
if (length == 0)
|
||||
{
|
||||
throw new DivideByZeroException("Can not normalize quaternion when it's magnitude is zero.");
|
||||
}
|
||||
this.x /= length;
|
||||
this.y /= length;
|
||||
this.z /= length;
|
||||
this.w /= length;
|
||||
}
|
||||
|
||||
static public float DotProduct(ViQuaternion a, ViQuaternion b)
|
||||
{
|
||||
return a.x * b.x +
|
||||
a.y * b.y +
|
||||
a.z * b.z +
|
||||
a.w * b.w;
|
||||
}
|
||||
|
||||
static public ViQuaternion Slerp(ViQuaternion a, ViQuaternion b, float t)
|
||||
{
|
||||
float fScale0, fScale1;
|
||||
double dCos = ViQuaternion.DotProduct(a, b);
|
||||
|
||||
if ((1.0 - Math.Abs(dCos)) > 1e-6f)
|
||||
{
|
||||
double dTemp = Math.Acos(Math.Abs(dCos));
|
||||
double dSin = Math.Sin(dTemp);
|
||||
fScale0 = (float)(Math.Sin((1.0 - t) * dTemp) / dSin);
|
||||
fScale1 = (float)(Math.Sin(t * dTemp) / dSin);
|
||||
}
|
||||
else
|
||||
{
|
||||
fScale0 = 1.0f - t;
|
||||
fScale1 = t;
|
||||
}
|
||||
if (dCos < 0.0)
|
||||
fScale1 = -fScale1;
|
||||
|
||||
return (a * fScale0) + (b * fScale1);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("( x={0}, y={1}, z={2}, w={3} )", this.x, this.y, this.z, this.w);
|
||||
}
|
||||
|
||||
|
||||
static public readonly ViQuaternion Zero = new ViQuaternion(0, 0, 0, 0);
|
||||
static public readonly ViQuaternion Origin = new ViQuaternion(0, 0, 0, 0);
|
||||
static public readonly ViQuaternion XAxis = new ViQuaternion(1, 0, 0, 0);
|
||||
static public readonly ViQuaternion YAxis = new ViQuaternion(0, 1, 0, 0);
|
||||
static public readonly ViQuaternion ZAxis = new ViQuaternion(0, 0, 1, 0);
|
||||
static public readonly ViQuaternion WAxis = new ViQuaternion(0, 0, 0, 1);
|
||||
|
||||
}
|
||||
12
Unity/Assets/Plugins/ViSDK/ViMath/ViQuaternion.cs.meta
Normal file
12
Unity/Assets/Plugins/ViSDK/ViMath/ViQuaternion.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf7cbae3c7f8fa849a5943f75adafc4a
|
||||
timeCreated: 1453717663
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
376
Unity/Assets/Plugins/ViSDK/ViMath/ViVector3.cs
Normal file
376
Unity/Assets/Plugins/ViSDK/ViMath/ViVector3.cs
Normal file
@ -0,0 +1,376 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ViArrayIdx = System.Int32;
|
||||
|
||||
public struct ViVector3
|
||||
{
|
||||
public const float kEpsilon = 1E-05f;
|
||||
public float x;
|
||||
public float y;
|
||||
public float z;
|
||||
|
||||
public float Length { get { return ViMathDefine.Sqrt((x * x) + (y * y) + (z * z)); } }
|
||||
public float Length2 { get { return ((x * x) + (y * y) + (z * z)); } }
|
||||
|
||||
public ViVector3(float x, float y, float z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public ViVector3(float x, float y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = 0f;
|
||||
}
|
||||
|
||||
public void Scale(ViVector3 scale)
|
||||
{
|
||||
this.x *= scale.x;
|
||||
this.y *= scale.y;
|
||||
this.z *= scale.z;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.x.GetHashCode() ^ ((~this.y.GetHashCode()) ^ (this.z.GetHashCode()));
|
||||
}
|
||||
|
||||
public override bool Equals(object other)
|
||||
{
|
||||
if (!(other is ViVector3))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ViVector3 vector = (ViVector3)other;
|
||||
return ((this.x.Equals(vector.x) && this.y.Equals(vector.y)) && this.z.Equals(vector.z));
|
||||
}
|
||||
public void Normalize()
|
||||
{
|
||||
float num = Magnitude(this);
|
||||
if (num > 1E-05f)
|
||||
{
|
||||
this = (ViVector3)(this / num);
|
||||
}
|
||||
else
|
||||
{
|
||||
this = ZERO;
|
||||
}
|
||||
}
|
||||
public static ViVector3 Normalize(ViVector3 value)
|
||||
{
|
||||
float num = Magnitude(value);
|
||||
if (num > 1E-05f)
|
||||
{
|
||||
return (ViVector3)(value / num);
|
||||
}
|
||||
return ZERO;
|
||||
}
|
||||
public ViVector3 normalized
|
||||
{
|
||||
get
|
||||
{
|
||||
return Normalize(this);
|
||||
}
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("({0:F2}, {1:F2}, {2:F2})", this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
public string ToString(string format)
|
||||
{
|
||||
return string.Format("({0}, {1}, {2})", this.x.ToString(format), this.y.ToString(format), this.z.ToString(format));
|
||||
}
|
||||
|
||||
public static float Dot(ViVector3 lhs, ViVector3 rhs)
|
||||
{
|
||||
return (((lhs.x * rhs.x) + (lhs.y * rhs.y)) + (lhs.z * rhs.z));
|
||||
}
|
||||
public static ViVector3 Cross(ViVector3 v1, ViVector3 v2)
|
||||
{
|
||||
ViVector3 result;
|
||||
result.x = (v1.y * v2.z) - (v1.z * v2.y);
|
||||
result.y = (v1.z * v2.x) - (v1.x * v2.z);
|
||||
result.z = (v1.x * v2.y) - (v1.y * v2.x);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static ViVector3 Project(ViVector3 vector, ViVector3 onNormal)
|
||||
{
|
||||
float num = Dot(onNormal, onNormal);
|
||||
if (num < float.Epsilon)
|
||||
{
|
||||
return ZERO;
|
||||
}
|
||||
return (ViVector3)((onNormal * Dot(vector, onNormal)) / num);
|
||||
}
|
||||
|
||||
public static ViVector3 Exclude(ViVector3 excludeThis, ViVector3 fromThat)
|
||||
{
|
||||
return (fromThat - Project(fromThat, excludeThis));
|
||||
}
|
||||
|
||||
public static float Angle(ViVector3 from, ViVector3 to)
|
||||
{
|
||||
return (ViMathDefine.Acos(ViMathDefine.Clamp(Dot(from.normalized, to.normalized), -1f, 1f)));
|
||||
}
|
||||
|
||||
public static float Distance(ViVector3 a, ViVector3 b)
|
||||
{
|
||||
float deltaX = a.x - b.x;
|
||||
float deltaY = a.y - b.y;
|
||||
float deltaZ = a.z - b.z;
|
||||
return ViMathDefine.Sqrt((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ));
|
||||
}
|
||||
public static float Distance2(ViVector3 a, ViVector3 b)
|
||||
{
|
||||
float deltaX = a.x - b.x;
|
||||
float deltaY = a.y - b.y;
|
||||
float deltaZ = a.z - b.z;
|
||||
return (deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ);
|
||||
}
|
||||
|
||||
public static float DistanceH(ViVector3 a, ViVector3 b)
|
||||
{
|
||||
float deltaX = a.x - b.x;
|
||||
float deltaY = a.y - b.y;
|
||||
return ViMathDefine.Sqrt((deltaX * deltaX) + (deltaY * deltaY));
|
||||
}
|
||||
public static float DistanceH2(ViVector3 a, ViVector3 b)
|
||||
{
|
||||
float deltaX = a.x - b.x;
|
||||
float deltaY = a.y - b.y;
|
||||
return (deltaX * deltaX) + (deltaY * deltaY);
|
||||
}
|
||||
|
||||
public static ViVector3 ClampMagnitude(ViVector3 vector, float maxLength)
|
||||
{
|
||||
if (vector.sqrMagnitude > (maxLength * maxLength))
|
||||
{
|
||||
return (ViVector3)(vector.normalized * maxLength);
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
||||
public static float Magnitude(ViVector3 a)
|
||||
{
|
||||
return ViMathDefine.Sqrt(((a.x * a.x) + (a.y * a.y)) + (a.z * a.z));
|
||||
}
|
||||
|
||||
public static ViVector3 Lerp(ViVector3 from, ViVector3 to, float perc)
|
||||
{
|
||||
return (from * (1 - perc) + to * perc);
|
||||
}
|
||||
|
||||
public float magnitude
|
||||
{
|
||||
get
|
||||
{
|
||||
return ViMathDefine.Sqrt(((this.x * this.x) + (this.y * this.y)) + (this.z * this.z));
|
||||
}
|
||||
}
|
||||
public static float SqrMagnitude(ViVector3 a)
|
||||
{
|
||||
return (((a.x * a.x) + (a.y * a.y)) + (a.z * a.z));
|
||||
}
|
||||
|
||||
public float sqrMagnitude
|
||||
{
|
||||
get
|
||||
{
|
||||
return (((this.x * this.x) + (this.y * this.y)) + (this.z * this.z));
|
||||
}
|
||||
}
|
||||
public static ViVector3 Min(ViVector3 lhs, ViVector3 rhs)
|
||||
{
|
||||
return new ViVector3(ViMathDefine.Min(lhs.x, rhs.x), ViMathDefine.Min(lhs.y, rhs.y), ViMathDefine.Min(lhs.z, rhs.z));
|
||||
}
|
||||
|
||||
public static ViVector3 Max(ViVector3 lhs, ViVector3 rhs)
|
||||
{
|
||||
return new ViVector3(ViMathDefine.Max(lhs.x, rhs.x), ViMathDefine.Max(lhs.y, rhs.y), ViMathDefine.Max(lhs.z, rhs.z));
|
||||
}
|
||||
|
||||
public static ViVector3 ZERO
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ViVector3(0f, 0f, 0f);
|
||||
}
|
||||
}
|
||||
public static ViVector3 UNIT_X
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ViVector3(1f, 0f, 0f);
|
||||
}
|
||||
}
|
||||
public static ViVector3 UNIT_Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ViVector3(0f, 1f, 0f);
|
||||
}
|
||||
}
|
||||
public static ViVector3 UNIT_Z
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ViVector3(0f, 0f, 1f);
|
||||
}
|
||||
}
|
||||
|
||||
public static ViVector3 UNIT
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ViVector3(1f, 1f, 1f);
|
||||
}
|
||||
}
|
||||
public static ViVector3 operator +(ViVector3 a, ViVector3 b)
|
||||
{
|
||||
return new ViVector3(a.x + b.x, a.y + b.y, a.z + b.z);
|
||||
}
|
||||
|
||||
public static ViVector3 operator -(ViVector3 a, ViVector3 b)
|
||||
{
|
||||
return new ViVector3(a.x - b.x, a.y - b.y, a.z - b.z);
|
||||
}
|
||||
|
||||
public static ViVector3 operator -(ViVector3 a)
|
||||
{
|
||||
return new ViVector3(-a.x, -a.y, -a.z);
|
||||
}
|
||||
|
||||
public static ViVector3 operator *(ViVector3 a, float d)
|
||||
{
|
||||
return new ViVector3(a.x * d, a.y * d, a.z * d);
|
||||
}
|
||||
|
||||
public static ViVector3 operator *(float d, ViVector3 a)
|
||||
{
|
||||
return new ViVector3(a.x * d, a.y * d, a.z * d);
|
||||
}
|
||||
|
||||
public static ViVector3 operator /(ViVector3 a, float d)
|
||||
{
|
||||
return new ViVector3(a.x / d, a.y / d, a.z / d);
|
||||
}
|
||||
|
||||
public static bool operator ==(ViVector3 lhs, ViVector3 rhs)
|
||||
{
|
||||
return (SqrMagnitude(lhs - rhs) < 9.999999E-11f);
|
||||
}
|
||||
|
||||
public static bool operator !=(ViVector3 lhs, ViVector3 rhs)
|
||||
{
|
||||
return (SqrMagnitude(lhs - rhs) >= 9.999999E-11f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class ViVector3Serialize
|
||||
{
|
||||
public static void Append(ViOStream OS, ViVector3 value)
|
||||
{
|
||||
OS.Append((Int16)ViMathDefine.IntNear(value.x * 10));
|
||||
OS.Append((Int16)ViMathDefine.IntNear(value.y * 10));
|
||||
OS.Append((Int16)ViMathDefine.IntNear(value.z * 10));
|
||||
}
|
||||
public static void Read(ViIStream IS, out ViVector3 value)
|
||||
{
|
||||
Int16 iX;
|
||||
Int16 iY;
|
||||
Int16 iZ;
|
||||
IS.Read(out iX);
|
||||
value.x = iX * 0.1f;
|
||||
IS.Read(out iY);
|
||||
value.y = iY * 0.1f;
|
||||
IS.Read(out iZ);
|
||||
value.z = iZ * 0.1f;
|
||||
}
|
||||
public static bool Read(ViStringIStream IS, out ViVector3 value)
|
||||
{
|
||||
value = ViVector3.ZERO;
|
||||
if (IS.Read(out value.x) == false) { return false; }
|
||||
if (IS.Read(out value.y) == false) { return false; }
|
||||
if (IS.Read(out value.z) == false) { return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void Read(string strValue, out ViVector3 value)
|
||||
{
|
||||
string[] values = strValue.Split(new char[] { ' ' });
|
||||
value = new ViVector3();
|
||||
if (values.Length == 3)
|
||||
{
|
||||
value.x = Convert.ToSingle(values[0]);
|
||||
value.y = Convert.ToSingle(values[1]);
|
||||
value.z = Convert.ToSingle(values[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ViDebuger.Warning("ViVector3Serialize.Read Fail");
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Read(ViStringIStream IS, out List<ViVector3> list)
|
||||
{
|
||||
ViArrayIdx size;
|
||||
IS.Read(out size);
|
||||
list = new List<ViVector3>((int)size);
|
||||
for (ViArrayIdx idx = 0; idx < size; ++idx)
|
||||
{
|
||||
ViVector3 value;
|
||||
if (Read(IS, out value) == false) { return false; }
|
||||
list.Add(value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void Read(string strValue, out List<ViVector3> list)
|
||||
{
|
||||
ViDebuger.Error("Not Completed");
|
||||
list = new List<ViVector3>();
|
||||
}
|
||||
|
||||
|
||||
public static void PrintTo(ViVector3 value, ref string strValue)
|
||||
{
|
||||
strValue += "(";
|
||||
strValue += value.x;
|
||||
strValue += ", ";
|
||||
strValue += value.y;
|
||||
strValue += ", ";
|
||||
strValue += value.z;
|
||||
strValue += ")";
|
||||
}
|
||||
|
||||
|
||||
public static void PrintTo(ViVector3 value, ViStringBuilder strValue)
|
||||
{
|
||||
strValue .Add("(");
|
||||
strValue .Add(value.x);
|
||||
strValue .Add(", ");
|
||||
strValue .Add(value.y);
|
||||
strValue .Add(", ");
|
||||
strValue .Add(value.z);
|
||||
strValue .Add(")");
|
||||
}
|
||||
|
||||
public static void PrintTo(List<ViVector3> list, ViStringBuilder strValue)
|
||||
{
|
||||
strValue .Add("(");
|
||||
for (int iter = 0; iter < list.Count; ++iter)
|
||||
{
|
||||
ViVector3 value = list[iter];
|
||||
PrintTo(value, strValue);
|
||||
strValue .Add(",");
|
||||
}
|
||||
strValue .Add(")");
|
||||
}
|
||||
}
|
||||
12
Unity/Assets/Plugins/ViSDK/ViMath/ViVector3.cs.meta
Normal file
12
Unity/Assets/Plugins/ViSDK/ViMath/ViVector3.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7ae7c0958733a984298b337c00ba8b26
|
||||
timeCreated: 1453717662
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Unity/Assets/Plugins/ViSDK/ViNet.meta
Normal file
9
Unity/Assets/Plugins/ViSDK/ViNet.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b1d2355a07810a4596b5494fd4b03bf
|
||||
folderAsset: yes
|
||||
timeCreated: 1453717661
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
71
Unity/Assets/Plugins/ViSDK/ViNet/ViNet.cs
Normal file
71
Unity/Assets/Plugins/ViSDK/ViNet/ViNet.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
//
|
||||
public class ViNet
|
||||
{
|
||||
public ViOStream OS { get { return _client.OS; } }
|
||||
public ViDelegateAssisstant.Dele ConnectCallback = null;
|
||||
public ViDelegateAssisstant.Dele ConnectFailedCallback = null;
|
||||
public ViDelegateAssisstant.Dele DisconnectCallback = null;
|
||||
public ViDelegateAssisstant.Dele<ViIStream> ReceiveCallback = null;
|
||||
//
|
||||
public void Start(string address)
|
||||
{
|
||||
_client.ConnectCallback = _OnConnected;
|
||||
_client.DisconnectCallback = _OnDisConnected;
|
||||
_client.ReceiveCallback = _OnReveived;
|
||||
_client.ConnectFailedCallback = _OnConnectError;
|
||||
_client.Start(address);
|
||||
}
|
||||
//
|
||||
public void Connect()
|
||||
{
|
||||
_client.Connect();
|
||||
}
|
||||
//
|
||||
public void ResetSendStream()
|
||||
{
|
||||
_client.ResetSendStream();
|
||||
}
|
||||
//
|
||||
public void SendStream()
|
||||
{
|
||||
_client.WriteToCache();
|
||||
}
|
||||
//
|
||||
public void FreshSendCache()
|
||||
{
|
||||
_client.SendCache();
|
||||
}
|
||||
//
|
||||
void _OnConnected()
|
||||
{
|
||||
ViDelegateAssisstant.Invoke(ConnectCallback);
|
||||
}
|
||||
//
|
||||
void _OnDisConnected()
|
||||
{
|
||||
ViDelegateAssisstant.Invoke(DisconnectCallback);
|
||||
}
|
||||
//
|
||||
void _OnConnectError()
|
||||
{
|
||||
ViDelegateAssisstant.Invoke(ConnectFailedCallback);
|
||||
}
|
||||
//
|
||||
void _OnReveived(ViIStream IS)
|
||||
{
|
||||
ViDelegateAssisstant.Invoke(ReceiveCallback, IS);
|
||||
}
|
||||
//
|
||||
public void End()
|
||||
{
|
||||
_client.End();
|
||||
//
|
||||
ConnectCallback = null;
|
||||
DisconnectCallback = null;
|
||||
ReceiveCallback = null;
|
||||
ConnectFailedCallback = null;
|
||||
}
|
||||
//
|
||||
ViNetClient _client = new ViNetClient();
|
||||
}
|
||||
11
Unity/Assets/Plugins/ViSDK/ViNet/ViNet.cs.meta
Normal file
11
Unity/Assets/Plugins/ViSDK/ViNet/ViNet.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec7d3a276deb7d443b5967bfbf4795c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
150
Unity/Assets/Plugins/ViSDK/ViNet/ViNetClient.cs
Normal file
150
Unity/Assets/Plugins/ViSDK/ViNet/ViNetClient.cs
Normal file
@ -0,0 +1,150 @@
|
||||
using System;
|
||||
//using UnityWebSocket;
|
||||
//
|
||||
public class ViNetClientBuffer
|
||||
{
|
||||
public static byte[] Convert(byte[] buffer, int len)
|
||||
{
|
||||
if (len < BufferList.Length)
|
||||
{
|
||||
byte[] localBuffer = BufferList[len];
|
||||
if (localBuffer == null)
|
||||
{
|
||||
localBuffer = new byte[len];
|
||||
BufferList[len] = localBuffer;
|
||||
}
|
||||
for (int iter = 0; iter < len; ++iter)
|
||||
{
|
||||
localBuffer[iter] = buffer[iter];
|
||||
}
|
||||
return localBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] result = new byte[len];
|
||||
Array.Copy(buffer, result, len);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
//
|
||||
static readonly byte[][] BufferList = new byte[256][];
|
||||
}
|
||||
//
|
||||
public class ViNetClient
|
||||
{
|
||||
public ViDelegateAssisstant.Dele ConnectCallback = null;
|
||||
public ViDelegateAssisstant.Dele ConnectFailedCallback = null;
|
||||
public ViDelegateAssisstant.Dele DisconnectCallback = null;
|
||||
public ViDelegateAssisstant.Dele<ViIStream> ReceiveCallback = null;
|
||||
public ViOStream OS { get { return this._OS; } }
|
||||
//
|
||||
public void Start(string address)
|
||||
{
|
||||
/*
|
||||
_socket = new WebSocket(address);
|
||||
_socket.OnOpen += _OnConnected;
|
||||
_socket.OnClose += _OnDisConnected;
|
||||
_socket.OnMessage += _OnReceived;
|
||||
_socket.OnError += _OnConnectError;
|
||||
*/
|
||||
}
|
||||
//
|
||||
public void Connect()
|
||||
{
|
||||
/*if(_socket.ReadyState != WebSocketState.Closed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_socket.ConnectAsync();
|
||||
*/
|
||||
}
|
||||
//
|
||||
public void ResetSendStream()
|
||||
{
|
||||
this.OS.Reset();
|
||||
}
|
||||
//
|
||||
public void WriteToCache()
|
||||
{
|
||||
_OSCache.Append(OS);
|
||||
OS.Reset();
|
||||
}
|
||||
//
|
||||
public void SendCache()
|
||||
{
|
||||
/*
|
||||
if (_socket == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_socket.ReadyState != WebSocketState.Open)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_OSCache.Length > 0)
|
||||
{
|
||||
_socket.SendAsync(ViNetClientBuffer.Convert(this._OSCache.Cache, this._OSCache.Length));
|
||||
_OSCache.Reset();
|
||||
}
|
||||
*/
|
||||
}
|
||||
//
|
||||
public void End()
|
||||
{
|
||||
/*
|
||||
if (_socket != null)
|
||||
{
|
||||
_socket.OnOpen -= _OnConnected;
|
||||
_socket.OnClose -= _OnDisConnected;
|
||||
_socket.OnMessage -= _OnReceived;
|
||||
_socket.OnError -= _OnConnectError;
|
||||
if (_socket.ReadyState != WebSocketState.Closed)
|
||||
{
|
||||
_socket.CloseAsync();
|
||||
}
|
||||
_socket = null;
|
||||
}
|
||||
//
|
||||
ConnectCallback = null;
|
||||
DisconnectCallback = null;
|
||||
ReceiveCallback = null;
|
||||
ConnectFailedCallback = null;
|
||||
*/
|
||||
}
|
||||
//
|
||||
|
||||
/*
|
||||
void _OnConnected(object sender, OpenEventArgs args)
|
||||
{
|
||||
ViDelegateAssisstant.Invoke(this.ConnectCallback);
|
||||
}
|
||||
//
|
||||
void _OnDisConnected(object sender, CloseEventArgs args)
|
||||
{
|
||||
ViDelegateAssisstant.Invoke(this.DisconnectCallback);
|
||||
}
|
||||
//
|
||||
void _OnConnectError(object sender, ErrorEventArgs args)
|
||||
{
|
||||
ViDelegateAssisstant.Invoke(this.ConnectFailedCallback);
|
||||
}
|
||||
//
|
||||
static ViIStream CACHE_OnReceive_Stream = new ViIStream();
|
||||
void _OnReceived(object sender, MessageEventArgs args)
|
||||
{
|
||||
byte[] buffer = args.RawData;
|
||||
ViIStream stream = CACHE_OnReceive_Stream;
|
||||
stream.Init(buffer, 0, buffer.Length);
|
||||
//
|
||||
if (stream.RemainLength > 0)
|
||||
{
|
||||
ViDelegateAssisstant.Invoke(ReceiveCallback, stream);
|
||||
}
|
||||
}
|
||||
//*/
|
||||
ViOStream _OS = new ViOStream();
|
||||
ViOStream _OSCache = new ViOStream();
|
||||
//
|
||||
//WebSocket _socket= null;
|
||||
|
||||
}
|
||||
11
Unity/Assets/Plugins/ViSDK/ViNet/ViNetClient.cs.meta
Normal file
11
Unity/Assets/Plugins/ViSDK/ViNet/ViNetClient.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b62eaef3aef077f44a3ffad049b3e0f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Unity/Assets/Plugins/ViSDK/ViSystem.meta
Normal file
9
Unity/Assets/Plugins/ViSDK/ViSystem.meta
Normal file
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 077c1098fb3f8224b8666e1fe27e8dcd
|
||||
folderAsset: yes
|
||||
timeCreated: 1453717661
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Unity/Assets/Plugins/ViSDK/ViSystem/ViAccumulateVersion.cs
Normal file
22
Unity/Assets/Plugins/ViSDK/ViSystem/ViAccumulateVersion.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
public class ViAccumulateVersion<T>
|
||||
{
|
||||
public static void Accumulate()
|
||||
{
|
||||
++s_accumulateFlag;
|
||||
}
|
||||
static UInt64 s_accumulateFlag;
|
||||
|
||||
public void UpdateAccumulate()
|
||||
{
|
||||
m_AccumulateFlag = s_accumulateFlag;
|
||||
}
|
||||
public bool IsAccumulateUpdated()
|
||||
{
|
||||
return (m_AccumulateFlag == s_accumulateFlag);
|
||||
}
|
||||
|
||||
UInt64 m_AccumulateFlag;
|
||||
};
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 001383be490b5c342b20b96397b430ee
|
||||
timeCreated: 1523429518
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user